Ejemplo n.º 1
0
 public function execute(CommandContext $context)
 {
     // Check permissions
     if (!Current_User::allow('hms', 'damage_assessment')) {
         throw new PermissionException('You do not have permission to perform room damage assessment.');
     }
     $data = $_POST['responsibilities'];
     // For each responsibility object submitted
     foreach ($data as $row) {
         // Load it from the database
         $resp = RoomDamageResponsibilityFactory::getResponsibilityById($row['id']);
         $resp->setAmount(round($row['assessedCost']));
         $resp->setState('assessed');
         $resp->setAssessedOn(time());
         $resp->setAssessedBy(UserStatus::getUsername());
         RoomDamageResponsibilityFactory::save($resp);
     }
     header('HTTP/1.1 200 Ok');
 }
 public function execute(CommandContext $context)
 {
     $term = $context->get('term');
     if (!isset($term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     // Get the list of floors which the current user has permission to assess
     // Get the list of role memberships this user has
     $hms_perm = new HMS_Permission();
     $memberships = $hms_perm->getMembership('assess_damage', NULL, UserStatus::getUsername());
     if (empty($memberships)) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException("You do not have permission to assess damages on any residence halls or floors.");
     }
     // Use the roles to instantiate a list of floors this user has access to
     $floors = array();
     foreach ($memberships as $member) {
         if ($member['class'] == 'hms_residence_hall') {
             $hall = new HMS_Residence_Hall($member['instance']);
             if (!is_array($floors)) {
                 $floors = array();
             }
             $hallFloors = $hall->getFloors();
             if (!is_array($hallFloors)) {
                 $hallFloors = array();
             }
             $floors = array_merge($floors, $hallFloors);
         } else {
             if ($member['class'] == 'hms_floor') {
                 $floors[] = new HMS_Floor($member['instance']);
             } else {
                 throw new Exception('Unknown object type.');
             }
         }
     }
     // Remove duplicate floors
     $uniqueFloors = array();
     foreach ($floors as $floor) {
         $uniqueFloors[$floor->getId()] = $floor;
     }
     // Filter the list of floors for just the term we're interested in
     foreach ($uniqueFloors as $k => $f) {
         if ($f->getTerm() != $term) {
             unset($uniqueFloors[$k]);
         }
     }
     // Get the list of damages with pending assessments on those floors
     $damages = RoomDamageFactory::getDamagesToAssessByFloor($uniqueFloors, $term);
     $roomList = array();
     // For each damage, get the list of responsible students
     foreach ($damages as &$dmg) {
         $pId = $dmg->getRoomPersistentId();
         $dmg->responsibilities = RoomDamageResponsibilityFactory::getResponsibilitiesByDmg($dmg);
         foreach ($dmg->responsibilities as &$resp) {
             $student = StudentFactory::getStudentByBannerId($resp->getBannerId(), $term);
             $resp->studentName = $student->getName();
         }
         $roomList[$dmg->getRoomPersistentId()][] = $dmg;
     }
     $rooms = array();
     foreach ($roomList as $pId => $dmgList) {
         $roomObj = RoomFactory::getRoomByPersistentId($pId, $term);
         $roomObj->hallName = $roomObj->get_parent()->get_parent()->getHallName();
         $roomObj->damages = $dmgList;
         $rooms[] = $roomObj;
     }
     // JSON enocde it all and send it to Angular
     $context->setContent(json_encode($rooms));
 }
 private function addDamage(array $dmg, HMS_Room $room)
 {
     $damage = new RoomDamage($room, $this->term, $dmg['damage_type'], $dmg['side'], $dmg['note']);
     // Save the damage
     RoomDamageFactory::save($damage);
     // Determine the residents which were responsible
     // For each resident submitted
     foreach ($dmg['residents'] as $resident) {
         // If the resident was selected as being responsible for this damage
         if (isset($resident['selected']) && $resident['selected']) {
             // Create the student
             $student = StudentFactory::getStudentByBannerId($resident['studentId'], $this->term);
             // Create the responsibility
             $resp = new RoomDamageResponsibility($student, $damage);
             RoomDamageResponsibilityFactory::save($resp);
         }
     }
 }