/** * 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; }); }
/** * 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; }); }
/** * 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; }); }
/** * Get eligiblities formated in a way that is compatible * with the eligibilityTable component * * @return array */ private function _getEligibilities() { $testCenter = $this->getCurrentInstance(); $data = array_map(function ($eligibility) { $eligibility['id'] = $eligibility['uri']; return $eligibility; }, $this->eligibilityService->getEligibilities($testCenter, ['sort' => true])); return DataTableHelper::paginate($data, $this->getRequestOptions()); }