diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2011-10-06 14:55:18 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2017-09-04 11:16:53 -0700 |
commit | fa9a4f7eb160fc435dc34c493e6822d2fbb7e484 (patch) | |
tree | 3f0abf30ba7ba35089f44fc4acf29437095b65b7 | |
parent | b025f5ea3b560b9c66625a9f3112b26d48611b94 (diff) |
Completed schedule iterator and almost completed exception iterator. Still need to add the 'Add Exception' page and make use of the schedule in the moderator email code.
-rw-r--r-- | design/database.sql | 4 | ||||
-rw-r--r-- | htdocs/moderate/schedule/index.php | 48 | ||||
-rw-r--r-- | htdocs/src/ModerationSchedule.inc.php | 94 |
3 files changed, 105 insertions, 41 deletions
diff --git a/design/database.sql b/design/database.sql index b908bc0..60b7006 100644 --- a/design/database.sql +++ b/design/database.sql @@ -105,8 +105,10 @@ CREATE TABLE moderator_exceptions ( year INTEGER UNSIGNED NOT NULL, week TINYINT UNSIGNED NOT NULL, user_id INTEGER UNSIGNED NOT NULL, + substitute INTEGER UNSIGNED NOT NULL, - PRIMARY KEY(year, week) + + PRIMARY KEY(year, week, user_id) ); diff --git a/htdocs/moderate/schedule/index.php b/htdocs/moderate/schedule/index.php index 93dfc3a..9015350 100644 --- a/htdocs/moderate/schedule/index.php +++ b/htdocs/moderate/schedule/index.php @@ -16,37 +16,61 @@ require_once('../src/header.inc.php'); echo "<h3>Moderation Schedule</h3>"; // List out moderators in order with next moderation week +$ui = new ModerationSchedule(); +$ui->query(); + +echo "<div class=\"userrow header\">" + . "<span class=\"name\">Name</span>" + . " <span class=\"email\">Email</span>" + . " <span class=\"admin\">Next Week</span>" + . " </div>"; +for ($i = 0; $i < $ui->getNumberOfModerators(); $i++, $ui->next()) { + $user = $ui->current(); + + printf("<div class=\"userrow\">" + . "<span class=\"name\">%s %s</span>" + . " <span class=\"email\"><a href=\"mailto:%s\">%s</a></span>" + . " <span class=\"admin\">%s</span></div>", + $user->getName(), + $ui->isException() ? '*' : '', + $user->getEmail(), $user->getEmail(), + date('F j', $ui->key()) + ); +} echo "<h3>Exceptions</h3>"; echo "<p><a href=\"exception.php\">New Exception</a></p>"; // List out exceptions in order. - -$ui = new UserIterator(); -$ui->query(); +$exceptions = new ModerationExceptions(); +$exceptions->query(); echo "<div class=\"userrow header\">" . "<span class=\"name\">Name</span>" . " <span class=\"email\">Email</span>" - . " <span class=\"admin\">Admin</span>" - . " <span class=\"actions\">Actions</span></div>"; + . " <span class=\"admin\">Exception Week</span>" + . " </div>"; + +while ($exceptions->valid()) { + $user = $exceptions->current(); -foreach ($ui as $user) { printf("<div class=\"userrow\">" . "<span class=\"name\">%s</span>" . " <span class=\"email\"><a href=\"mailto:%s\">%s</a></span>" - . " <span class=\"admin\">%s</span>" - . " <span class=\"actions\">" - . " <a class=\"smallbutton\" href=\"editor.php?id=%s\">edit</a>" - . " <a class=\"smallbutton\" href=\"delete.php?id=%s\">delete</a></span></div>", + . " <span class=\"admin\">%s</span></div>", $user->getName(), $user->getEmail(), $user->getEmail(), - $user->isAdmin() ? 'Yes' : 'No', - $user->getId(), $user->getId() + date('F j', $exceptions->key()) ); + + + + $exceptions->next(); } + + require_once('../src/footer.inc.php'); ?> diff --git a/htdocs/src/ModerationSchedule.inc.php b/htdocs/src/ModerationSchedule.inc.php index 4f5c6db..4c094e4 100644 --- a/htdocs/src/ModerationSchedule.inc.php +++ b/htdocs/src/ModerationSchedule.inc.php @@ -18,6 +18,9 @@ class ModerationSchedule implements Iterator { private $week; private $expos; + private $moderator; + private $exceptionfor; + public function __construct() { $this->moderators = array(); $this->exceptions = array(); @@ -31,22 +34,59 @@ class ModerationSchedule implements Iterator { // Iterator methods public function rewind() { - $this->year = date('o'); + $this->year = date('o') + 0; $this->week = date('W') + 0; $this->expos = 0; + $this->nextModerator(); } public function current() { + return $this->moderator; + } + + public function key() { + return strtotime($this->year . 'W' . + ($this->week < 10 ? '0' : '') . $this->week); + } + + public function next() { + if ($this->week == 53) { + // Check for leap year + if (date('N', mktime(0, 0, 0, 1, 1, $this->year)) == 4 + or date('N', mktime(0, 0, 0, 12, 31, $this->year)) == 4) { + + $this->week++; + + } else { + $this->week = 1; + $this->year++; + } + + } else if ($this->week > 53) { + $this->week = 1; + $this->year++; + + } else { + $this->week++; + } + + $this->nextModerator(); + } + + private function nextModerator() { + // Clear out the exception flag. + $this->exceptionfor = null; + // Get the scheduled mod. $modpos = $this->week % $this->getNumberOfModerators(); - $moderator = $this->moderators[$modpos]['user_id']; + $this->moderator = User::getById($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 + $this->expos < (count($this->exceptions) - 1) 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. @@ -57,30 +97,19 @@ class ModerationSchedule implements Iterator { $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); - } + // Check if any of the top exception apply today. + while($this->exceptions[$this->expos]['year'] == $this->year + and $this->exceptions[$this->expos]['week'] == $this->week) { - public function key() { - return strtotime($this->year . 'W' . - ($this->week < 10 ? '0' : '') . $this->week); - } + if ($this->exceptions[$i]['user_id'] == $this->moderator->getId()) { + // Yes, return the replacement + $this->exceptionfor = $this->moderator; + $this->moderator = User::getById($this->exceptions[$this->expos]['user_id']); + break; + } - public function next() { - if ($this->week == 53) { - $this->week = 1; - $this->year++; - - } else { - $this->week++; + $this->expos++; + } } } @@ -89,12 +118,19 @@ class ModerationSchedule implements Iterator { return true; } - private function query() { + public function isException() { + return $this->exceptionfor !== null; + } + + public function getExceptionFor() { + return $this->exceptionfor; + } + + public function query() { $db = getDatabase(); - $this->rewind(); // Get the moderators - $query = "SELECT * FROM moderation_schedule ORDER BY position"; + $query = "SELECT * FROM moderator_schedule ORDER BY position"; $this->moderators = $db->fetchAssocRows($query); // Get the exceptions @@ -105,6 +141,8 @@ class ModerationSchedule implements Iterator { . " WHERE year >= $year AND week >= $week" . " ORDER BY year, week"; $this->exceptions = $db->fetchAssocRows($query); + + $this->rewind(); } } |