Example #1
0
 /**
  * Get a list of resources based on client id, resource type and resource repo class.
  *
  * @param integer $clientId
  * @param string $resourceType
  * @param string $resourceRepoClass
  * @return array
  */
 public function getClientResources($clientId, $resourceType, $resourceRepoClass, $status)
 {
     if ($clientId) {
         $parentClientIds = Repo_Client::getInstance()->getParentClients($clientId);
         $clientIds = $parentClientIds;
         $clientIds[] = $clientId;
     } else {
         $clientIds = array();
     }
     // Get all the resources
     $resources = $resourceRepoClass::getInstance()->getClientsResources($clientIds, $status);
     // Get all the access rows
     $accessRows = Repo_ResourceAccess::getInstance()->getClientResources($clientId, $resourceType);
     $allowedResources = array();
     // Filter out those not allowed for this client
     foreach ($resources as $_r) {
         if (!$clientId || $_r->client_id == $clientId || in_array($_r->client_id, $accessRows)) {
             $allowedResources[] = $_r;
         }
     }
     return $allowedResources;
 }
 /**
  * Survey detail page: edit/delete functionality.
  *
  * It is the central place for a survey object.
  */
 public function surveyDetailAction()
 {
     $id = $this->_request->getParam('id');
     $survey = new Object_Survey($id);
     $surveyId = $survey->getId();
     if (empty($surveyId)) {
         // No survey defined, redirect to list survey.
         $this->_redirect('/admin/client/survey');
         return false;
     }
     // loading all questions from csv file:
     $csvFile = $survey->getCSVFile();
     $this->view->csvError = '';
     if ($csvFile !== FALSE && file_exists($csvFile)) {
         //get the question content and validate it:
         if (($handle = fopen($csvFile, "r")) !== FALSE) {
             $processCSV = $survey->addCSVQuestions($handle, $survey->client_id, $surveyId, $this->_request->getParam('name'));
             if (isset($processCSV['error'])) {
                 $this->view->csvError = $processCSV['error'];
             }
             unlink($csvFile);
         }
     }
     $form = new Form_Admin_Client_Survey(false, array('survey' => $survey));
     // Check for user update
     if ($this->_request->isPost()) {
         $params = $this->_request->getPost();
         if ($form->isValid($params)) {
             // Update user if necessary
             $form->updateSurvey($survey);
             $form->setSurvey($survey);
         } else {
             $form->populate($params);
         }
     }
     $this->view->survey = $survey;
     $this->view->client = new Object_Client($survey->client_id);
     $this->view->form = $form;
     // Survey questions
     $this->view->surveyQuestions = Repo_Survey::getInstance()->getSurveyQuestions($surveyId);
     // Feedback Question Types
     $question_repo = Repo_Question::getInstance();
     $this->view->feedbackQuestionTypeLabels = json_encode($question_repo->feedbackQuestionTypeLabels);
     $this->view->questionTags = Repo_QuestionTag::getInstance()->getTags();
     // Survey access control for resource access
     $this->view->childClients = $this->view->client->getChildClients();
     $this->view->accessClients = Repo_ResourceAccess::getInstance()->getResourceClients(Object_Survey::RESOURCE_TYPE, $survey->getId());
 }