Example #1
0
 /**
  * Set can enroll property
  * 
  * @access public
  * @param array $courses
  * @return array courses with canRoll property added
  */
 public function setCanEnroll($courses)
 {
     $auth = new AuthenticationService();
     $storage = $auth->getIdentity();
     $currentUser = NULL;
     if ($auth->hasIdentity()) {
         $currentUser = $this->query->find('Users\\Entity\\User', $storage['id']);
     }
     foreach ($courses as $course) {
         $nonAuthorizedEnroll = false;
         $canEnroll = true;
         $users = $course->getUsers();
         $canLeave = false;
         if ($auth->hasIdentity()) {
             $courseAiId = $this->objectUtilities->getId($course->getAi());
             if (in_array(Role::INSTRUCTOR_ROLE, $storage['roles']) && $storage['id'] == $courseAiId) {
                 $nonAuthorizedEnroll = true;
             }
         }
         if (!is_null($currentUser)) {
             $canLeave = $users->contains($currentUser);
         }
         if ($canLeave === true || $nonAuthorizedEnroll === true || $course->getStudentsNo() >= $course->getCapacity()) {
             $canEnroll = false;
         }
         $course->canEnroll = $canEnroll;
         $course->canLeave = $canLeave;
     }
     return $courses;
 }
Example #2
0
 /**
  * Prepare entities diffs
  * 
  * @access public
  * @param array $entities
  * @param array $entitiesLogs
  * 
  * @return \ArrayIterator array of entities diff
  */
 public function prepareDiffs($entities, $entitiesLogs)
 {
     $preparedEntities = $this->objectUtilities->prepareForDisplay($entities);
     $entitiesComparisonData = array();
     foreach ($preparedEntities as $entity) {
         $entityBeforeClass = get_class($entity);
         $entityHasChanges = false;
         foreach ($entitiesLogs as $logsPerEntity) {
             foreach ($logsPerEntity as $entityLog) {
                 if ($entity->getId() == $entityLog->getObjectId()) {
                     $entityAfterArray = $this->objectUtilities->prepareForDisplay(array($entityLog->getData()), $entity);
                     $entityBefore = $entity;
                     if (method_exists($entity, "getStatus") && $entity->getStatus() == Status::STATUS_NOT_APPROVED) {
                         // get empty object to compare after data with empty before
                         $entityBefore = new $entityBeforeClass();
                         $entityBefore->id = $entity->getId();
                     }
                     $entitiesComparisonData[] = array("before" => $entityBefore, "after" => reset($entityAfterArray));
                     $entityHasChanges = true;
                     break 2;
                 }
             }
         }
         // add unchanged entity to comparison data
         if ($entityHasChanges === false) {
             $entitiesComparisonData[] = array("before" => $entity, "after" => $entity);
         }
     }
     return new \ArrayIterator($entitiesComparisonData);
 }