/** * @license http://opensource.org/licenses/lgpl-3.0.html * @author Matthew McNaney <mcnaney at gmail dot com> */ function election_update(&$content, $version) { switch (1) { case version_compare($version, '1.0.1', '<'): $db = \phpws2\Database::getDB(); $single = $db->addTable('elect_single_chair_vote'); $single->renameField($single->getField('ballotId'), 'singleId'); $sdt = new \phpws2\Database\Datatype\Integer($single, 'electionId'); $sdt->add(); $multiple = $db->addTable('elect_multi_chair_vote'); $multiple->renameField($multiple->getField('ballotId'), 'multipleId'); $mdt = new \phpws2\Database\Datatype\Integer($multiple, 'electionId'); $mdt->add(); $ref = $db->addTable('elect_referendum_vote'); $rdt = new \phpws2\Database\Datatype\Integer($ref, 'electionId'); $rdt->add(); $vcomplete = $db->addTable('elect_vote_complete'); $vhash = $vcomplete->addDataType('voterHash', 'varchar'); $electionId = $vcomplete->addDataType('electionId', 'int'); $vcomplete->create(); $voter = $db->addTable('elect_voter'); $voter->drop(true); case version_compare($version, '1.0.2', '<'): $db = \phpws2\Database::getDB(); $vcomplete = $db->addTable('elect_vote_complete'); $vcomplete->renameField($vcomplete->getField('voterHash'), 'bannerId'); case version_compare($version, '1.0.3', '<'): $db = \phpws2\Database::getDB(); $candidate = $db->addTable('elect_candidate'); $title_column = new \phpws2\Database\Datatype\Varchar($candidate, 'title'); $title_column->add(); case version_compare($version, '1.0.4', '<'): $db = \phpws2\Database::getDB(); $db->exec('ALTER TABLE elect_single_chair_vote add unique singlevote (voterHash, electionId, singleId)'); $db->exec('ALTER TABLE elect_multi_chair_vote add unique multivote (voterHash, electionId, multipleId, candidateId);'); $db->exec('ALTER TABLE elect_referendum_vote add unique refvote (voterHash, electionId, referendumId);'); $db->exec('ALTER TABLE elect_vote_complete add unique finalvote (bannerId, electionId);'); $tbl = $db->addTable('elect_referendum_vote'); $newdt = new \phpws2\Database\Datatype\Varchar($tbl, 'answer', 10); $tbl->alter($tbl->getDataType('answer'), $newdt); case version_compare($version, '2.0.0', '<'): $db = \phpws2\Database::getDB(); $tbl = $db->addTable('elect_multiple'); $newdt = new \phpws2\Database\Datatype\Text($tbl, 'category'); $tbl->alter($tbl->getDataType('category'), $newdt); } return true; }
function tailgate_update(&$content, $currentVersion) { switch ($currentVersion) { case version_compare($currentVersion, '1.1.0', '<'): $db = \phpws2\Database::getDB(); $tbl = $db->addTable('tg_student'); $column = $tbl->getDataType('user_id'); $unique = new \phpws2\Database\Unique($column); $unique->add(); $content[] = <<<EOF <pre> +added unique index to user_id in tg_student +safety checks added </pre> EOF; case version_compare($currentVersion, '1.2.0', '<'): $db = \phpws2\Database::getDB(); $tbl = $db->addTable('tg_game'); $dt = new \Database\Datatype\Smallint($tbl, 'lottery_started'); $dt->setDefault(0); $dt->add(); $db = \phpws2\Database::getDB(); $tbl = $db->addTable('tg_lottery'); $dt = new \Database\Datatype\Smallint($tbl, 'emailed'); $dt->setDefault(0); $dt->add(); $db = \phpws2\Database::getDB(); $tbl = $db->addTable('tg_lottery'); $columns[] = $tbl->getDataType('student_id'); $columns[] = $tbl->getDataType('game_id'); $unique = new \phpws2\Database\Unique($columns); $unique->add(); $content[] = <<<EOF <pre> + Flagging beginning of lottery + Logging winner emails + Unique keys added to tg_lottery to prevent repeats </pre> EOF; } return true; }
public function getTotalWinners($game_id) { $db = \phpws2\Database::getDB(); $tbl = $db->addTable('tg_lottery'); $tbl->addFieldConditional('game_id', $game_id); $tbl->addFieldConditional('winner', 1); $col = $tbl->addField('id'); $col->showCount(true); return (int) $db->selectColumn(); }
public static function resetReferendum($electionId, $bannerId) { $referendumIds = Election::getReferendumIds($electionId); if (empty($referendumIds)) { return; } $db = \phpws2\Database::getDB(); $tbl = $db->addTable('elect_referendum_vote'); foreach ($referendumIds as $var) { $id = $var['id']; $hash = StudentFactory::getVoteHash($id, $bannerId); $tbl->addFieldConditional('voterHash', $hash); $tbl->addFieldConditional('referendumId', $id); $tbl->addFieldConditional('electionId', $electionId); $db->delete(); $db->clearConditional(); } }
public static function getReferendumIds($electionId) { $db = \phpws2\Database::getDB(); $tbl = $db->addTable('elect_referendum'); $tbl->addFieldConditional('electionId', $electionId); $tbl->addField('id'); return $db->select(); }
public function delete($student_id) { $student = new Resource(); $student->setId($student_id); self::deleteResource($student); $db = \phpws2\Database::getDB(); $lottery = $db->addTable('tg_lottery'); $lottery->addFieldConditional('student_id', $student_id); $db->delete(); }