public function execute() { if (!isset($this->term) || is_null($this->term)) { throw new InvalidArgumentException('Missing term.'); } /***** * Total Beds */ $db = new PHPWS_DB('hms_bed'); $db->addJoin('', 'hms_bed', 'hms_room', 'room_id', 'id'); $db->addJoin('', 'hms_room', 'hms_floor', 'floor_id', 'id'); $db->addJoin('', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id'); $db->addWhere('hms_bed.term', $this->term); $this->totalBedCount = $db->count(); if (PHPWS_Error::logIfError($this->totalBedCount)) { PHPWS_Core::initModClass('hms', 'exception', 'DatabaseException.php'); throw new DatabaseException($this->totalBedCount->toString()); } /******* * Unavailable Beds */ $db = new PHPWS_DB('hms_bed'); $db->addColumn('hms_residence_hall.hall_name'); $db->addColumn('hms_bed.*'); $db->addColumn('hms_room.*'); $db->addJoin('', 'hms_bed', 'hms_room', 'room_id', 'id'); $db->addJoin('', 'hms_room', 'hms_floor', 'floor_id', 'id'); $db->addJoin('', 'hms_floor', 'hms_residence_hall', 'residence_hall_id', 'id'); $db->addWhere('hms_room.reserved', 1, null, 'OR', 'foo'); $db->addWhere('hms_room.ra', 1, null, 'OR', 'foo'); $db->addWhere('hms_room.private', 1, null, 'OR', 'foo'); $db->addWhere('hms_room.overflow', 1, null, 'OR', 'foo'); $db->addWhere('hms_room.parlor', 1, null, 'OR', 'foo'); $db->addWhere('hms_room.offline', 1, null, 'OR', 'foo'); $db->addWhere('hms_bed.ra_roommate', 1, null, 'OR', 'foo'); $db->addWhere('hms_bed.international_reserved', 1, null, 'OR', 'foo'); $db->addWhere('hms_bed.term', $this->term); $db->addOrder(array('hms_residence_hall.hall_name', 'hms_room.room_number', 'bed_letter')); $this->unavailableBeds = $db->select(); if (PHPWS_Error::logIfError($this->unavailableBeds)) { PHPWS_Core::initModClass('hms', 'exception/DatabaseException.php'); throw new DatabaseException($this->unavailableBeds->toString()); } }
/** * Queues a Remove Assignment * * NOTE: If the queue contains a Create Assignment for the same * user to the same room, this will NOT queue a room assignment, * but rather will delete the original assignment, UNLESS the * $force_queue flag is set. The $force_queue flag being true will * queue a removal no matter what. * * MORE NOTE: If this requires immediate processing because banner * commits are enabled, the it will be sent straight to Banner, * and so the force_queue flag will be ignored. */ public static function queueRemoveAssignment(Student $student, $term, HMS_Residence_Hall $hall, HMS_Bed $bed, $refund) { $entry = new BannerQueueItem(0, BANNER_QUEUE_REMOVAL, $student, $term, $hall, $bed, null, null, $refund); if (BannerQueue::processImmediately($term)) { return $entry->process(); } // Otherwise, look for an corresponding assignment $db = new PHPWS_DB('hms_banner_queue'); $db->addWhere('type', BANNER_QUEUE_ASSIGNMENT); $db->addWhere('asu_username', $student->getUsername()); $db->addWhere('building_code', $hall->getBannerBuildingCode()); $db->addWhere('bed_code', $bed->getBannerId()); $db->addWhere('term', $term); $result = $db->count(); if (PHPWS_Error::logIfError($result)) { throw new DatabaseException($result->toString()); } if ($result == 0) { return $entry->save(); } else { return $db->delete(); } }
public function execute(CommandContext $context) { if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'edit_terms')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to edit terms.'); } $successCmd = CommandFactory::getCommand('ShowEditTerm'); $errorCmd = CommandFactory::getCommand('ShowCreateTerm'); $year = $context->get('year_drop'); $sem = $context->get('term_drop'); if (!isset($year) || is_null($year) || empty($year)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a year.'); $errorCmd->redirect(); } if (!isset($sem) || is_null($sem) || empty($sem)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a semester.'); $errorCmd->redirect(); } // Check to see if the specified term already exists if (!Term::isValidTerm($year . $sem)) { $term = new Term(NULL); $term->setTerm($year . $sem); $term->setBannerQueue(1); try { $term->save(); } catch (DatabaseException $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error saving the term. Please try again or contact ESS.'); $errorCmd->redirect(); } } else { $term = new Term($year . $sem); // The term already exists, make sure there are no halls for this term $db = new PHPWS_DB('hms_residence_hall'); $db->addWhere('term', $term->getTerm()); $num = $db->count(); if (!is_null($num) && $num > 0) { NQ::simple('hms', hms\NotificationView::ERROR, 'One or more halls already exist for this term, so nothing can be copied.'); $errorCmd->redirect(); } } $text = Term::toString($term->getTerm()); $copy = $context->get('copy_pick'); $copyAssignments = false; $copyRoles = false; // If you want to copy roles and/or assignments // you must also copy the hall structure. if (isset($copy['struct'])) { // Copy hall structure if (isset($copy['assign'])) { // Copy assignments. $copyAssignments = true; } if (isset($copy['role'])) { // Copy roles. $copyRoles = true; } } else { // either $copy == 'nothing', or the view didn't specify... either way, we're done NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully."); $successCmd->redirect(); } # Figure out which term we're copying from, if there isn't one then use the "current" term. $fromTerm = $context->get('from_term'); if (is_null($fromTerm)) { $fromTerm = Term::getCurrentTerm(); } PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); $db = new PHPWS_DB(); try { $db->query('BEGIN'); # Get the halls from the current term $halls = HMS_Residence_Hall::get_halls($fromTerm); set_time_limit(36000); foreach ($halls as $hall) { $hall->copy($term->getTerm(), $copyAssignments, $copyRoles); } $db->query('COMMIT'); } catch (Exception $e) { $db->query('ROLLBACK'); PHPWS_Error::log(print_r($e, true), 'hms'); NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error copying the hall structure and/or assignments. The term was created, but nothing was copied.'); $errorCmd->redirect(); } if ($copyAssignments) { NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully. The hall structure and assignments were copied successfully."); } else { NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully and hall structure copied successfully."); } Term::setSelectedTerm($term->getTerm()); $successCmd->redirect(); }
public function getPanel() { $panel = new PHPWS_Panel('calendar'); $vars['aop'] = 'schedules'; $tabs['schedules'] = array('title' => dgettext('calendar', 'Schedules'), 'link' => PHPWS_Text::linkAddress('calendar', $vars)); if (Current_User::allow('calendar', 'settings')) { $vars['aop'] = 'settings'; $tabs['settings'] = array('title' => dgettext('calendar', 'Settings'), 'link' => PHPWS_Text::linkAddress('calendar', $vars)); } if (Current_User::isUnrestricted('calendar') && Current_User::allow('calendar', 'edit_public')) { $vars['aop'] = 'approval'; $db = new PHPWS_DB('calendar_suggestions'); $count = $db->count(); if (PHPWS_Error::isError($count)) { PHPWS_Error::log($count); $count = 0; } $tabs['approval'] = array('title' => sprintf(dgettext('calendar', 'Approval (%s)'), $count), 'link' => PHPWS_Text::linkAddress('calendar', $vars)); } $panel->quickSetTabs($tabs); return $panel; }
function getDiffOptions() { $links = array(); if (!$this->getVrCurrent()) { $db = new PHPWS_DB('wiki_pages_version'); $db->addWhere('source_id', $this->getSourceId()); $links[] = PHPWS_Text::moduleLink(dgettext('wiki', 'Current'), 'wiki', array('page' => $this->getTitle(FALSE), 'page_op' => 'compare', 'oVer' => $this->getVrNumber(), 'nVer' => $db->count())); } $db2 = new PHPWS_DB('wiki_pages_version'); $db2->addWhere('source_id', $this->getSourceId()); $db2->addColumn('vr_number', 'min'); if ($this->getVrNumber() != $db2->select('min')) { $links[] = PHPWS_Text::moduleLink(dgettext('wiki', 'Previous'), 'wiki', array('page' => $this->getTitle(FALSE), 'page_op' => 'compare', 'oVer' => $this->getVrNumber() - 1, 'nVer' => $this->getVrNumber())); } return implode(' | ', $links); }
public function tallyItems() { if ($this->ftype == IMAGE_FOLDER) { $db = new PHPWS_DB('images'); } elseif ($this->ftype == DOCUMENT_FOLDER) { $db = new PHPWS_DB('documents'); } elseif ($this->ftype == MULTIMEDIA_FOLDER) { $db = new PHPWS_DB('multimedia'); } $db->addWhere('folder_id', $this->id); return $db->count(); }
/** * Returns a count of pending requests */ public static function countPendingRequests($asu_username, $term) { $db = new PHPWS_DB('hms_roommate'); $db->addWhere('requestee', $asu_username, 'ILIKE'); $db->addWhere('confirmed', 0); $db->addWhere('term', $term); $db->addWhere('requested_on', time() - ROOMMATE_REQ_TIMEOUT, '>='); $result = $db->count(); return $result; }
function isOrphaned() { $db = new PHPWS_DB('wiki_pages'); $db->addWhere('pagetext', '%' . $this->getTitle(FALSE) . '%', 'LIKE'); $db->addWhere('id', $this->getId(), '!='); if ($db->count()) { return PHPWS_Text::moduleLink(dgettext('wiki', 'No'), 'wiki', array('page' => $this->getTitle(FALSE), 'page_op' => 'whatlinkshere')); } return dgettext('wiki', 'Yes'); }
function getKeyMods($match = null, $select_name = 'exclude', $multiple = true, $count = true) { PHPWS_Core::initCoreClass('Key.php'); $db = new PHPWS_DB('phpws_key'); $db->addOrder('module asc'); $result = $db->getObjects('Key'); if ($result) { foreach ($result as $item) { if ($count) { $db = new PHPWS_DB('phpws_key'); $db->addWhere('module', $item->module); $qty = $db->count(); if ($qty == 1) { $qty_label = dgettext('whatsnew', 'item'); } else { $qty_label = dgettext('whatsnew', 'items'); } $items[$item->module] = $item->module . ' (' . $qty . ' ' . $qty_label . ')'; } else { $items[$item->module] = $item->module; } } } if ($items) { if ($multiple) { $form = new PHPWS_Form(); $form->addMultiple($select_name, $items); if (!empty($match) && is_array($match)) { $form->setMatch($select_name, $match); } return $form->get($select_name); } else { $form = new PHPWS_Form(); $form->addSelect($select_name, $items); if (!empty($match) && is_string($match)) { $form->setMatch($select_name, $match); } return $form->get($select_name); } } else { return dgettext('whatsnew', 'No keyed items.'); } }
/** * Returns the number of items in the Banner queue for this term * TODO: Move this to the BannerQueue class. * @return Integer The number of items in the banner queue. */ public function getQueueCount() { $db = new PHPWS_DB('hms_banner_queue'); $db->addWhere('term', $this->term); $result = $db->count(); if (PHPWS_Error::logIfError($result)) { throw new DatabaseException($result->__toString()); } return $result; }
public static function countLotteryAssigned($term) { $db = new PHPWS_DB('hms_assignment'); $db->addWhere('term', $term); $db->addWhere('reason', ASSIGN_LOTTERY); $count = $db->count(); if (PHPWS_Error::isError($count)) { throw new DatabaseException($count->toString()); } return $count; }
public static function getUnprintedCount() { $db = new PHPWS_DB('faxmaster_fax'); $db->addWhere('printed', 0); $db->addWhere('hidden', 0); $db->addWhere('archived', 0); // don't include archived faxes, even if they aren't printed return $db->count(); }