summaryrefslogtreecommitdiff
path: root/htdocs/src/ModerationSchedule.inc.php
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-08-30 12:29:19 -0700
committerJesse Morgan <jesse@jesterpm.net>2017-09-04 11:16:53 -0700
commite121bbebe3ccd990b66a7b04289adf481a4aa2af (patch)
tree5955357921d66db47769cba75d950cea3894dd04 /htdocs/src/ModerationSchedule.inc.php
parent558684e32769d9dbd0d27a6feb3bbb9cf9aa22d7 (diff)
Working on the moderation schedule iterator
Diffstat (limited to 'htdocs/src/ModerationSchedule.inc.php')
-rw-r--r--htdocs/src/ModerationSchedule.inc.php105
1 files changed, 105 insertions, 0 deletions
diff --git a/htdocs/src/ModerationSchedule.inc.php b/htdocs/src/ModerationSchedule.inc.php
new file mode 100644
index 0000000..cca6697
--- /dev/null
+++ b/htdocs/src/ModerationSchedule.inc.php
@@ -0,0 +1,105 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class ModerationSchedule implements Iterator {
+ private $moderators;
+ private $exceptions;
+
+ private $year;
+ private $week;
+ private $expos;
+
+ public function __construct() {
+ $this->moderators = array();
+ $this->exceptions = array();
+ }
+
+ public function getNumberOfModerators() {
+ return count($this->moderators);
+ }
+
+
+ // Iterator methods
+
+ public function rewind() {
+ $this->year = date('o');
+ $this->week = date('W') + 0;
+ $this->expos = 0;
+ }
+
+ public function current() {
+ // Get the scheduled mod.
+ $modpos = $this->week % $this->getNumberOfModerators();
+ $moderator = $this->moderators[$modpos]['user_id'];
+
+ // Check for exceptions
+ if (count($this->exceptions) > 0) {
+ // Skip exceptions prior to the current() date.
+ while (
+ // We have exceptions to search
+ $this->expos < count($this->exceptions) and
+ // and the year is less than the current() year
+ ($this->exceptions[$this->expos]['year'] < $this->year or
+ // or if it is the current() year, but less than the week.
+ ($this->exceptions[$this->expos]['year'] == $this->year
+ and $this->exceptions[$this->expos]['week'] < $this->week))
+ ) {
+
+ $this->expos++;
+ }
+
+ // Check if the top exception is for today.
+ if ($this->exceptions[$this->expos]['year'] == $this->year
+ and $this->exceptions[$this->expos]['week'] == $this->week
+ ) {
+ // Yes, return the replacement
+ $moderator = $this->exceptions[$this->expos]['user_id'];
+ }
+ }
+
+ return User::getById($moderator);
+ }
+
+ public function key() {
+ // TODO: Return "key" for "current" moderator (date)
+ }
+
+ public function next() {
+ // TODO: Impl. next
+ }
+
+ public function valid() {
+ // The schedule continues forever.
+ return true;
+ }
+
+ private function query() {
+ $db = getDatabase();
+ $this->rewind();
+
+ // Get the moderators
+ $query = "SELECT * FROM moderation_schedule ORDER BY position";
+ $this->moderators = $db->fetchAssocRows($query);
+
+ // Get the exceptions
+ $year = date('o');
+ $week = date('W');
+
+ $query = "SELECT * FROM moderator_exceptions"
+ . " WHERE year >= $year AND week >= $week"
+ . " ORDER BY year, week";
+ $this->exceptions = $db->fetchAssocRows($query);
+ }
+}
+
+?>
+