/**
  * @requiresRight id WRITE
  */
 public function commitResource()
 {
     $resource = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
     // prevent escaping on input
     $message = isset($_POST['message']) ? $_POST['message'] : '';
     $revision = RevisionService::commit($resource, $message);
     $this->returnJson(array('success' => true, 'id' => $revision->getVersion(), 'modified' => \tao_helpers_Date::displayeDate($revision->getDateCreated()), 'author' => UserHelper::renderHtmlUser($revision->getAuthorId()), 'message' => $revision->getMessage(), 'commitMessage' => __('%s has been committed', $resource->getLabel())));
 }
 /**
  * Fetch POST data
  * Get login by cookie
  * Get Ip
  * If check parameters is true, check mandatory parameters
  *
  * @param bool $check
  * @return array
  * @throws \common_exception_MissingParameter
  */
 protected function getData($check = false)
 {
     $data = parent::getData($check);
     $data['login'] = UserHelper::getUserLogin(\common_session_SessionManager::getSession()->getUser());
     if ($this->hasRequestParameter('testCenter')) {
         $data[DiagnosticStorage::DIAGNOSTIC_TEST_CENTER] = $this->getRequestParameter('testCenter');
     }
     if ($this->hasRequestParameter('workstation')) {
         $data[DiagnosticStorage::DIAGNOSTIC_WORKSTATION] = trim($this->getRequestParameter('workstation'));
     }
     return $data;
 }
Example #3
0
 /**
  * actions that get prevented by a lock are forwareded to this action
  * parameter view is currently ignored
  */
 public function locked()
 {
     $resource = new core_kernel_classes_Resource($this->getRequestParameter('id'));
     $lockData = LockManager::getImplementation()->getLockData($resource);
     $this->setData('topclass-label', $this->hasRequestParameter('topclass-label') ? $this->getRequestParameter('topclass-label') : __('Resource'));
     if (AclProxy::hasAccess(common_session_SessionManager::getSession()->getUser(), __CLASS__, 'forceRelease', array('uri' => $resource->getUri()))) {
         $this->setData('id', $resource->getUri());
         $this->setData('forceRelease', true);
     }
     $this->setData('lockDate', $lockData->getCreationTime());
     $this->setData('ownerHtml', UserHelper::renderHtmlUser($lockData->getOwnerId()));
     if ($this->hasRequestParameter('view') && $this->hasRequestParameter('ext')) {
         $this->setView($this->getRequestParameter('view'), $this->getRequestParameter('ext'));
     } else {
         $this->setView('Lock/locked.tpl', 'tao');
     }
 }
 /**
  * Gets the list of authorized proctors for a selection of test centers
  * @param $testCenters
  * @return array
  * @throws \common_exception_Error
  */
 protected function getAuthorization($testCenters)
 {
     $requestOptions = $this->getRequestOptions();
     $currentUser = SessionManager::getSession()->getUser();
     $proctors = ProctorManagementService::singleton()->getAssignedProctors($currentUser->getIdentifier(), $testCenters);
     return DataTableHelper::paginate($proctors, $requestOptions, function ($proctors) use($testCenters) {
         $testCentersByProctors = ProctorManagementService::singleton()->getProctorsAuthorization($testCenters);
         $nbTestCenters = count($testCenters);
         $authorizations = array();
         foreach ($proctors as $proctor) {
             $userId = $proctor->getUri();
             $user = UserHelper::getUser($proctor);
             $lastName = UserHelper::getUserLastName($user);
             $firstName = UserHelper::getUserFirstName($user, empty($lastName));
             $login = UserHelper::getUserStringProp($user, PROPERTY_USER_LOGIN);
             $authorizedLabel = array();
             if (isset($testCentersByProctors[$userId])) {
                 $authorized = array_intersect($testCentersByProctors[$userId], $testCenters);
                 if (count($authorized) == $nbTestCenters) {
                     $status = self::FULLY_AUTHORIZED;
                 } else {
                     foreach ($authorized as $testCenterUri) {
                         $testCenter = new \core_kernel_classes_Resource($testCenterUri);
                         $authorizedLabel[] = $testCenter->getLabel();
                     }
                     $status = self::PARTIALLY_AUTHORIZED;
                 }
             } else {
                 $status = self::NOT_AUTHORIZED;
             }
             $authorizations[] = array('id' => $userId, 'firstname' => $firstName, 'lastname' => $lastName, 'login' => $login, 'status' => $status, 'authorized' => implode(', ', $authorizedLabel));
         }
         return $authorizations;
     });
 }
 /**
  * Adjusts a list of delivery executions: add information, format the result
  *
  * @param DeliveryExecution[] $deliveryExecutions
  * @param array $options
  * @return array
  * @throws \oat\oatbox\service\ServiceNotFoundException
  */
 private static function adjustDeliveryExecutions($deliveryExecutions, $options)
 {
     // paginate, then format the data
     return DataTableHelper::paginate($deliveryExecutions, $options, function ($deliveryExecutions) {
         $testSessionConnectivityStatusService = ServiceManager::getServiceManager()->get(TestSessionConnectivityStatusService::SERVICE_ID);
         $executions = [];
         foreach ($deliveryExecutions as $cachedData) {
             $state = ['status' => $cachedData[DeliveryMonitoringService::COLUMN_STATUS], 'progress' => $cachedData[DeliveryMonitoringService::COLUMN_CURRENT_ASSESSMENT_ITEM]];
             $testTaker = [];
             $extraFields = [];
             $user = UserHelper::getUser($cachedData[DeliveryMonitoringService::TEST_TAKER]);
             if ($user) {
                 /* @var $user User */
                 $testTaker['id'] = $cachedData[DeliveryMonitoringService::TEST_TAKER];
                 $testTaker['lastName'] = _dh($cachedData[DeliveryMonitoringService::TEST_TAKER_LAST_NAME]);
                 $testTaker['firstName'] = _dh($cachedData[DeliveryMonitoringService::TEST_TAKER_FIRST_NAME]);
                 $userExtraFields = self::_getUserExtraFields();
                 foreach ($userExtraFields as $field) {
                     $extraFields[$field['id']] = isset($cachedData[$field['id']]) ? _dh($cachedData[$field['id']]) : '';
                 }
             }
             $rawConnectivity = isset($cachedData[DeliveryMonitoringService::CONNECTIVITY]) ? $cachedData[DeliveryMonitoringService::CONNECTIVITY] : false;
             $online = $testSessionConnectivityStatusService->isOnline($cachedData[DeliveryMonitoringService::DELIVERY_EXECUTION_ID], $rawConnectivity);
             $executions[] = array('id' => $cachedData[DeliveryMonitoringService::DELIVERY_EXECUTION_ID], 'delivery' => array('uri' => $cachedData[DeliveryMonitoringService::DELIVERY_ID], 'label' => _dh($cachedData[DeliveryMonitoringService::DELIVERY_NAME])), 'date' => DateHelper::displayeDate($cachedData[DeliveryMonitoringService::COLUMN_START_TIME]), 'timer' => ['remaining' => $cachedData[DeliveryMonitoringService::COLUMN_REMAINING_TIME], 'extraTime' => floatval($cachedData[DeliveryMonitoringService::COLUMN_EXTRA_TIME]), 'consumedExtraTime' => floatval($cachedData[DeliveryMonitoringService::COLUMN_CONSUMED_EXTRA_TIME])], 'testTaker' => $testTaker, 'extraFields' => $extraFields, 'state' => $state, 'online' => $online);
         }
         return $executions;
     });
 }
 /**
  * Gets the test takers assigned to a delivery
  *
  * @param $deliveryId
  * @param array $options
  * @param string $testCenterId
  * @return User[]
  */
 public function getDeliveryTestTakers($deliveryId, $testCenterId, $options = array())
 {
     $groups = $this->getGroupClass()->searchInstances(array(PROPERTY_GROUP_DELVIERY => $deliveryId, self::PROPERTY_GROUP_TEST_CENTERS => $testCenterId), array('recursive' => true, 'like' => false));
     $userIds = array();
     foreach ($groups as $group) {
         foreach (GroupsService::singleton()->getUsers($group) as $user) {
             $userIds[] = $user->getUri();
         }
     }
     $userIds = array_unique($userIds);
     $users = array();
     foreach ($userIds as $id) {
         // assume Tao Users
         $users[] = new core_kernel_users_GenerisUser($this->getResource($id));
     }
     usort($users, function ($a, $b) {
         return strcasecmp(UserHelper::getUserLastName($a), UserHelper::getUserLastName($b));
     });
     return $users;
 }
 /**
  * Gets the list of assessment reports related to a test site
  *
  * @param $testCenter
  * @param array [$options]
  * @return array
  */
 public static function getReports($testCenter, $options = array())
 {
     $periodStart = null;
     $periodEnd = null;
     if (isset($options['periodStart'])) {
         $periodStart = new DateTime($options['periodStart']);
         $periodStart->setTime(0, 0, 0);
         $periodStart = DateHelper::getTimeStamp($periodStart->getTimestamp());
     }
     if (isset($options['periodEnd'])) {
         $periodEnd = new DateTime($options['periodEnd']);
         $periodEnd->setTime(23, 59, 59);
         $periodEnd = DateHelper::getTimeStamp($periodEnd->getTimestamp());
     }
     $deliveryService = ServiceManager::getServiceManager()->get(DeliveryService::CONFIG_ID);
     $deliveries = EligibilityService::singleton()->getEligibleDeliveries($testCenter);
     $filteredExecutions = array();
     foreach ($deliveries as $delivery) {
         if ($delivery->exists()) {
             $deliveryExecutions = $deliveryService->getDeliveryExecutions($delivery->getUri());
             foreach ($deliveryExecutions as $deliveryExecution) {
                 $startTime = $deliveryExecution->getStartTime();
                 $finishTime = $deliveryExecution->getFinishTime();
                 if ($finishTime && $periodStart && $periodStart > DateHelper::getTimeStamp($finishTime)) {
                     continue;
                 }
                 if (!$finishTime && $periodStart && $periodEnd && (DateHelper::getTimeStamp($startTime) > $periodEnd || DateHelper::getTimeStamp($startTime) < $periodStart)) {
                     continue;
                 }
                 if ($startTime && $periodEnd && $periodEnd < DateHelper::getTimeStamp($startTime)) {
                     continue;
                 }
                 $filteredExecutions[] = $deliveryExecution;
             }
         }
     }
     $deliveryExecutionStateService = ServiceManager::getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID);
     return DataTableHelper::paginate($filteredExecutions, $options, function ($deliveryExecutions) use($deliveryExecutionStateService) {
         $reports = [];
         foreach ($deliveryExecutions as $deliveryExecution) {
             /* @var $deliveryExecution DeliveryExecution */
             $startTime = $deliveryExecution->getStartTime();
             $finishTime = $deliveryExecution->getFinishTime();
             $userId = $deliveryExecution->getUserIdentifier();
             $user = UserHelper::getUser($userId);
             $authorizationData = self::getDeliveryLog()->get($deliveryExecution->getIdentifier(), 'TEST_AUTHORISE');
             $proctor = empty($authorizationData) ? '' : UserHelper::getUser($authorizationData[0][DeliveryLog::DATA]['proctorUri']);
             $procActions = self::getProctorActions($deliveryExecution);
             $reports[] = array('id' => $deliveryExecution->getIdentifier(), 'delivery' => $deliveryExecution->getDelivery()->getLabel(), 'testtaker' => $user ? UserHelper::getUserName($user, true) : '', 'proctor' => $proctor ? UserHelper::getUserName($proctor, true) : '', 'status' => $deliveryExecutionStateService->getState($deliveryExecution), 'start' => $startTime ? DateHelper::displayeDate($startTime) : '', 'end' => $finishTime ? DateHelper::displayeDate($finishTime) : '', 'pause' => $procActions['pause'], 'resume' => $procActions['resume'], 'irregularities' => $procActions['irregularities']);
         }
         return $reports;
     });
 }
 /**
  * @return User
  */
 private function getUser()
 {
     if (!$this->user) {
         $this->user = UserHelper::getUser($this->deliveryExecution->getUserIdentifier());
     }
     return $this->user;
 }