/**
  * Get items
  * @author Mohamed Labib <*****@*****.**>
  * 
  * @access public
  * 
  * @param int $offset
  * @param int $itemCountPerPage
  * @return array items queried
  */
 public function getItems($offset, $itemCountPerPage)
 {
     $this->setCriteria();
     $this->criteria->setFirstResult($offset);
     $this->criteria->setMaxResults($itemCountPerPage);
     return $this->query->filter($this->entityName, $this->criteria);
     //($pageNumber-1) for zero based count
 }
Example #2
0
 /**
  * Remove not used outlines
  * 
  * @access public
  */
 public function cleanUpOutlines()
 {
     $criteria = Criteria::create();
     $expr = Criteria::expr();
     $criteria->andWhere($expr->isNull("course"));
     $outlinesToBeRemoved = $this->query->filter("Courses\\Entity\\Outline", $criteria);
     foreach ($outlinesToBeRemoved as $outline) {
         $this->query->remove($outline);
     }
 }
 /**
  * setup form
  * 
  * 
  * @access public
  * @param string $name ,default is null
  * @param array $options ,default is null
  */
 public function __construct($name = null, $options = null)
 {
     $this->query = $options['query'];
     unset($options['query']);
     parent::__construct($name, $options);
     $this->setAttribute('class', 'form form-inline');
     $this->setAttribute('method', 'GET');
     $this->add(array('name' => 'title', 'type' => 'Zend\\Form\\Element\\Text', 'attributes' => array('class' => 'form-control'), 'options' => array('label' => 'Title')));
     $this->add(array('name' => 'directUrl', 'type' => 'Zend\\Form\\Element\\Text', 'attributes' => array('class' => 'form-control'), 'options' => array('label' => 'Url')));
     $this->add(array('name' => 'type', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('class' => 'form-control'), 'options' => array('label' => 'Type', "value_options" => array(MenuItem::TYPE_PAGE => "Page", MenuItem::TYPE_DIRECT_URL => "Direct Url"), 'empty_option' => "All")));
     $this->add(array('name' => 'menu', 'type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'attributes' => array('class' => 'form-control'), 'options' => array('label' => 'Menu', 'object_manager' => $this->query->setEntity('CMS\\Entity\\Menu')->entityManager, 'target_class' => 'CMS\\Entity\\Menu', 'property' => "title", 'find_method' => array('name' => 'findAll', 'params' => array()), 'display_empty_item' => true, 'empty_item_label' => "All")));
     $this->add(array('name' => 'status', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('class' => 'form-control'), 'options' => array('label' => 'Status', "value_options" => array(Status::STATUS_ACTIVE => Status::STATUS_ACTIVE_TEXT, Status::STATUS_INACTIVE => Status::STATUS_INACTIVE_TEXT), 'empty_option' => "All")));
     $this->add(array('name' => 'filter', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('class' => 'btn btn-success', 'value' => 'Filter')));
     $this->add(array('name' => 'reset', 'type' => 'Zend\\Form\\Element', 'attributes' => array('class' => 'btn btn-danger resetButton', 'value' => 'Reset', 'type' => 'button')));
 }
 /**
  * Save OrganizationUser
  * Add new role if user does not have it
  * 
  * @access public
  * @param Organizations\Entity\OrganizationUser $organizationUser
  * @param array $data ,default is empty array
  */
 public function save($organizationUser, $data = array())
 {
     $this->query->setEntity('Organizations\\Entity\\OrganizationUser')->save($organizationUser, $data);
     $roleExists = false;
     $user = $organizationUser->getUser();
     foreach ($user->getRoles() as $role) {
         if ($role->getName() == $organizationUser->getRole()->getName()) {
             $roleExists = true;
             break;
         }
     }
     if ($roleExists === false) {
         $user->addRole($organizationUser->getRole());
         $this->query->setEntity('Users\\Entity\\User')->save($user, array());
     }
 }
Example #5
0
 /**
  * Update listed resources
  * 
  * @access public
  * @param array $dataArray
  * @param bool $isAdminUser
  * @param string $userEmail
  */
 public function updateListedResources($dataArray, $isAdminUser, $userEmail)
 {
     if (isset($dataArray['editedName'])) {
         $editedResourceNames = $dataArray['editedName'];
         foreach ($editedResourceNames as $key => $name) {
             $resource = $this->query->findOneBy('Courses\\Entity\\Resource', array('id' => $key));
             $resource->setName($name);
             if ($isAdminUser === false) {
                 $resource->setStatus(Status::STATUS_NOT_APPROVED);
             }
             if (isset($dataArray['editedType'][$key])) {
                 $resource->setType($dataArray['editedType'][$key]);
                 unset($dataArray['editedType'][$key]);
             }
             $this->query->save($resource);
         }
     }
     if (isset($dataArray['editedType'])) {
         $editedResourceType = $dataArray['editedType'];
         foreach ($editedResourceType as $key => $Type) {
             $resource = $this->query->findOneBy('Courses\\Entity\\Resource', array('id' => $key));
             $resource->setType($Type);
             if ($isAdminUser === false) {
                 $resource->setStatus(Status::STATUS_NOT_APPROVED);
             }
             $this->query->save($resource);
         }
     }
     if ($isAdminUser === false) {
         $this->sendMail($userEmail, true);
     }
 }
Example #6
0
 public function updateQuestion($oldQuestionTitle, $newQuestionTitle, $evaluation)
 {
     $evaluationId = $evaluation->getId();
     $question = $this->query->findOneBy("Courses\\Entity\\Question", array('questionTitle' => $oldQuestionTitle, 'evaluation' => $evaluationId));
     $question->setQuestionTitle($newQuestionTitle);
     $question->setStatus($evaluation->getStatus());
     $this->query->save($question);
 }
 /**
  * Validate Access Control for actions
  * 
  * @access public
  * 
  * @param Zend\Http\PhpEnvironment\Response $response
  * @param mixed $roleArray string or array of roles
  * @param Organizations\Entity\Organization $organization ,default is null
  * @param bool $atLeastOneRoleFlag ,default is false
  * @return array bool is access valid or not and redirect url if redirect is needed
  */
 public function validateOrganizationAccessControl($response, $roleArray, $organization = null, $atLeastOneRoleFlag = false)
 {
     $accessValid = true;
     $url = null;
     $auth = new AuthenticationService();
     $storage = $auth->getIdentity();
     if ($auth->hasIdentity() && !in_array(Role::ADMIN_ROLE, $storage['roles'])) {
         if (!is_null($organization)) {
             $currentUserOrganizationUser = $this->query->findOneBy('Organizations\\Entity\\OrganizationUser', array("user" => $storage['id'], "organization" => $organization->getId()));
             if (!is_object($currentUserOrganizationUser)) {
                 $url = $this->router->assemble(array(), array('name' => 'noaccess'));
                 $accessValid = false;
             }
         }
         if ($accessValid === true) {
             if (!is_array($roleArray)) {
                 $roleArray = array($roleArray);
             }
             $notacceptedAgreementRoles = array();
             $acceptedAgreementRoles = array();
             foreach ($roleArray as $role) {
                 if (!(isset($storage["agreements"][$role]) && (int) $storage["agreements"][$role] === Status::STATUS_ACTIVE)) {
                     $notacceptedAgreementRoles[] = $role;
                 } elseif ($atLeastOneRoleFlag === true) {
                     $acceptedAgreementRoles[] = $role;
                 }
             }
             if (count($notacceptedAgreementRoles) > 0 && $atLeastOneRoleFlag === false || $atLeastOneRoleFlag === true && count($acceptedAgreementRoles) == 0) {
                 $glue = ", ";
                 if ($atLeastOneRoleFlag === true) {
                     $glue = ", or ";
                 }
                 $notacceptedAgreementRolesString = implode($glue, $notacceptedAgreementRoles);
                 $url = $this->router->assemble(array('id' => $storage['id'], 'role' => $notacceptedAgreementRolesString), array('name' => 'noAgreement'));
                 $accessValid = false;
             }
         }
         if ($accessValid === false) {
             $response->setStatusCode(302);
         }
     }
     return array("isValid" => $accessValid, "redirectUrl" => $url);
 }
Example #8
0
 public function saveCourseVotes($questionIds, $values, $userObj, $evalObj)
 {
     // removing unset value form array
     unset($values['submit']);
     //looping over values
     for ($i = 0; $i < count($questionIds); $i++) {
         $vote = new \Courses\Entity\Vote();
         $questionObj = $this->query->findOneBy('Courses\\Entity\\Question', array('id' => $questionIds[$i]));
         $vote->setEvaluation($evalObj);
         $vote->setUser($userObj);
         $vote->setQuestion($questionObj);
         // each key is radios_XX  where x is question Id
         $vote->setVote($values['radios_' . $questionIds[$i]]);
         // save vote
         $this->query->setEntity('Courses\\Entity\\Vote')->save($vote);
         // update course evaluation percentage
         $evalObj->setPercentage($this->getVotePercentage($evalObj));
         $this->query->setEntity('Courses\\Entity\\Evaluation')->save($evalObj);
     }
 }
Example #9
0
 /**
  * this function meant to list all courses assigned to user if instructor
  */
 public function prepareInstructorCourses($userId)
 {
     //desired courses which user is assigned to
     $courses = array();
     $allCourses = $this->query->findAll('Courses\\Entity\\Course');
     foreach ($allCourses as $course) {
         if ($course->getAi()->id == $userId) {
             array_push($courses, $course);
         }
     }
     return $courses;
 }
Example #10
0
 public function respondeToExamRequest($response, $requestId, $tvtcResponse = null)
 {
     $request = $this->query->findOneBy('Courses\\Entity\\ExamBook', array('id' => $requestId));
     // tvtc response
     if ($tvtcResponse != null) {
         $request->setTvtcStatus($response);
         $this->query->save($request);
     } else {
         $request->setAdminStatus($response);
         $this->query->save($request);
     }
 }
Example #11
0
 /**
  * Save page
  * 
  * @access public
  * @param CMS\Entity\Page $page
  * @param array $data ,default is empty array
  * @param bool $editFlag ,default is false
  */
 public function save($page, $data = array(), $editFlag = false)
 {
     if (array_key_exists(FormButtons::SAVE_AND_PUBLISH_BUTTON, $data)) {
         $page->setStatus(Status::STATUS_ACTIVE);
     } elseif (array_key_exists(FormButtons::UNPUBLISH_BUTTON, $data)) {
         $page->setStatus(Status::STATUS_INACTIVE);
     } elseif (array_key_exists(FormButtons::SAVE_BUTTON, $data) && $editFlag === false) {
         $page->setStatus(Status::STATUS_INACTIVE);
     }
     if ($editFlag === true) {
         $data = array();
     }
     $this->query->setEntity("CMS\\Entity\\Page")->save($page, $data);
 }
Example #12
0
 /**
  * prepare object for display
  * 
  * 
  * @access public
  * @param array $objectsArray
  * @param mixed $sampleObject object used to get expected properties when $objectsArray is array of arrays not array of objects ,default is null
  * @param int $depthLevel ,default is 0
  * @param int $maxDepthLevel depth level including first object level ,default is 3
  * @return array objects prepared for display
  */
 public function prepareForDisplay($objectsArray, $sampleObject = null, $depthLevel = 0, $maxDepthLevel = 3)
 {
     $depthLevel++;
     foreach ($objectsArray as &$object) {
         $notObject = false;
         // support array of arrays instead of array of objects
         if (is_array($object)) {
             $object = (object) $object;
             $notObject = true;
         }
         $objectProperties = $this->prepareForStatusDisplay($object);
         if (($notObject === false || $notObject === true && !is_null($sampleObject)) && $depthLevel == 1) {
             if (is_null($sampleObject)) {
                 $sampleObjectForWrapper = $object;
             } else {
                 $sampleObjectForWrapper = $sampleObject;
             }
             $wrapped = AbstractWrapper::wrap($sampleObjectForWrapper, $this->query->entityManager);
             $meta = $wrapped->getMetadata();
         }
         foreach ($objectProperties as $objectPropertyName => $objectPropertyValue) {
             if (is_string($objectPropertyValue) && strlen($objectPropertyValue) <= 5) {
                 $textObjectPropertyName = $objectPropertyName . "Text";
                 if (array_key_exists($objectPropertyValue, $this->languages)) {
                     $object->{$textObjectPropertyName} = $this->languages[$objectPropertyValue];
                 } elseif (strlen($objectPropertyValue) == 2 && array_key_exists($objectPropertyValue, $this->countries)) {
                     $object->{$textObjectPropertyName} = $this->countries[$objectPropertyValue];
                 }
             } elseif ($objectPropertyValue instanceof \DateTime) {
                 $formattedString = $objectPropertyValue->format("D, d M Y");
                 if ($formattedString == Time::UNIX_DATE_STRING) {
                     $formattedString = $objectPropertyValue->format("H:i");
                 }
                 $object->{$objectPropertyName} = $formattedString;
             } elseif (is_object($objectPropertyValue) && $depthLevel != $maxDepthLevel) {
                 $objectsPropertyValue = $this->prepareForDisplay(array($objectPropertyValue), $sampleObject, $depthLevel, $maxDepthLevel);
                 $object->{$objectPropertyName} = reset($objectsPropertyValue);
             } elseif (is_array($objectPropertyValue) && array_key_exists("id", $objectPropertyValue) && isset($meta) && $meta->isSingleValuedAssociation($objectPropertyName)) {
                 $object->{$objectPropertyName} = $this->query->find($meta->getAssociationMapping($objectPropertyName)["targetEntity"], $objectPropertyValue["id"]);
             }
         }
     }
     return $objectsArray;
 }
Example #13
0
 /**
  * Disapprove entities changes
  * 
  * @access public
  * 
  * @param array $entities
  * @param array $entitiesLogs
  * 
  * @return bool process result
  */
 public function disapproveChanges($entities, $entitiesLogs)
 {
     $processResult = true;
     foreach ($entitiesLogs as $logsPerEntity) {
         foreach ($logsPerEntity as $entityLog) {
             $entityLogClass = get_class($entityLog);
             $this->query->setEntity($entityLogClass)->remove($entityLog, true);
         }
     }
     foreach ($entities as $entity) {
         if (property_exists($entity, "status") && $entity->status == Status::STATUS_NOT_APPROVED) {
             $entityClass = get_class($entity);
             $this->query->setEntity($entityClass)->remove($entity, true);
         }
     }
     if (count($entities) > 0 && count($entitiesLogs) > 0) {
         // flush all entities changes
         $this->query->entityManager->flush();
     }
     return $processResult;
 }
Example #14
0
 /**
  * authenticate() - defined by AdapterInterface.  
  * Attempt an authentication.  
  * Previous to this call, this adapter would have already been configured 
  * with all necessary information to successfully connect to a database table 
  * and attempt to find a record matching the provided identity.
  * 
  * 
  * @access public
  * @throws RuntimeException if answering the authentication query is impossible
  * @return Result
  */
 public function authenticate()
 {
     $this->authenticateSetup();
     $entities = $this->_query->findBy('Users\\Entity\\User', array('username' => $this->_identity));
     return $this->validateResult($entities);
 }
 /**
  * Set entities dependencies
  * 
  * @access public
  */
 public function setEntitiesDependencies()
 {
     if (empty(self::$entitiesDependencies)) {
         self::$entitiesDependencies = $this->query->getEntitiesDependenciesClasses();
     }
 }
 /**
  * set validation constraints
  * 
  * 
  * @uses InputFilter
  * 
  * @access public
  * 
  * @param Utilities\Service\Query\Query $query
  * @return InputFilter validation constraints
  */
 public function getInputFilter($query)
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         $query->setEntity("Organizations\\Entity\\OrganizationUser");
         $inputFilter->add(array('name' => 'user', 'required' => true, 'validators' => array(array('name' => 'Utilities\\Service\\Validator\\UniqueObject', 'options' => array('use_context' => true, 'object_manager' => $query->entityManager, 'object_repository' => $query->entityRepository, 'fields' => array('user', 'organization', 'role'), 'messages' => array(UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "There is already another organization user with the same user and role"))))));
         $inputFilter->add(array('name' => 'role', 'required' => true));
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }