/** * @param $params * @return Report */ public function __invoke($params) { \common_ext_ExtensionsManager::singleton()->getExtensionById('taoProctoring'); \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf'); \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest'); $report = new Report(Report::TYPE_INFO, 'Updating of delivery monitoring cache...'); $testCenters = TestCenterService::singleton()->getRootClass()->getInstances(true); $deliveryMonitoringService = $this->getServiceLocator()->get(DeliveryMonitoringService::CONFIG_ID); $deliveryService = $this->getServiceLocator()->get(DeliveryService::CONFIG_ID); $eligibilityService = EligibilityService::singleton(); foreach ($testCenters as $testCenter) { $deliveries = $eligibilityService->getEligibleDeliveries($testCenter, false); foreach ($deliveries as $delivery) { if ($delivery->exists()) { $deliveryExecutions = $deliveryService->getCurrentDeliveryExecutions($delivery->getUri(), $testCenter->getUri()); foreach ($deliveryExecutions as $deliveryExecution) { $data = $deliveryMonitoringService->getData($deliveryExecution, true); if ($deliveryMonitoringService->save($data)) { $report->add(new Report(Report::TYPE_SUCCESS, "Delivery execution {$deliveryExecution->getUri()} successfully updated.")); } else { $errors = $data->getErrors(); $errorsStr = " " . PHP_EOL; array_walk($errors, function ($val, $key) use(&$errorsStr) { $errorsStr .= " {$key} - {$val}" . PHP_EOL; }); $report->add(new Report(Report::TYPE_ERROR, "Delivery execution {$deliveryExecution->getUri()} was not updated. {$errorsStr}")); } } } } } return $report; }
private function getEligibilityService() { if (is_null($this->eligibilityService)) { $this->eligibilityService = EligibilityService::singleton(); } return $this->eligibilityService; }
/** * Get resumable (active) deliveries. * @param User $user User instance. If not given then all deliveries will be returned regardless of user URI. * @return type */ public function getResumableDeliveries(User $user) { $deliveryExecutionService = \taoDelivery_models_classes_execution_ServiceProxy::singleton(); $userUri = $user->getIdentifier(); $started = array_merge($deliveryExecutionService->getActiveDeliveryExecutions($userUri), $deliveryExecutionService->getPausedDeliveryExecutions($userUri), $deliveryExecutionService->getDeliveryExecutionsByStatus($userUri, DeliveryExecution::STATE_AWAITING), $deliveryExecutionService->getDeliveryExecutionsByStatus($userUri, DeliveryExecution::STATE_AUTHORIZED)); $eligibilityService = EligibilityService::singleton(); $resumable = array(); foreach ($started as $deliveryExecution) { $delivery = $deliveryExecution->getDelivery(); if ($delivery->exists() && $eligibilityService->isDeliveryEligible($delivery, $user)) { $resumable[] = $deliveryExecution; } } return $resumable; }
public static function eligiblityChange(EligiblityChanged $event) { /** @var DeliveryMonitoringService $monitoringService */ $monitoringService = ServiceManager::getServiceManager()->get(DeliveryMonitoringService::CONFIG_ID); $eligiblity = $event->getEligiblity(); $before = array_map([__CLASS__, 'getNormalizedItem'], $event->getPreviousTestTakerCollection()); $after = array_map([__CLASS__, 'getNormalizedItem'], $event->getActualTestTakersCollection()); $newTestTakers = array_diff($after, $before); $delivery = EligibilityService::singleton()->getDelivery($eligiblity); //might be we would like to remove newly uneliglbe executions later foreach ($newTestTakers as $testTakerUri) { $executions = taoDelivery_models_classes_execution_ServiceProxy::singleton()->getUserExecutions($delivery, $testTakerUri); foreach ($executions as $execution) { $deliverMonitoringData = $monitoringService->getData($execution, false); $deliverMonitoringData->updateData([DeliveryMonitoringService::TEST_CENTER_ID]); $monitoringService->save($deliverMonitoringData); } } }
/** * Test the method to get the by-pass proctoring status * * @dataProvider byPassProctorProvider */ public function testByPassProctor($property, $result) { $eligibilityProphet = $this->prophesize(core_kernel_classes_Resource::class); $eligibilityProphet->getOnePropertyValue(new core_kernel_classes_Property(EligibilityService::PROPERTY_BYPASSPROCTOR_URI))->willReturn($property); $this->assertEquals($result, $this->eligilityService->canByPassProctor($eligibilityProphet->reveal())); }
/** * Gets the test takers available for a delivery as a table page * * @param core_kernel_classes_Resource $delivery * @param core_kernel_classes_Resource $testCenter * @param array [$options] * @param string [$testCenterId] * @return array * @throws \Exception * @throws \common_exception_Error * @throws \oat\oatbox\service\ServiceNotFoundException */ public static function getAvailableTestTakers($delivery, $testCenter, $options = array()) { $deliveryService = ServiceManager::getServiceManager()->get(DeliveryService::CONFIG_ID); $users = EligibilityService::singleton()->getEligibleTestTakers($testCenter, $delivery); $assignedUsers = $deliveryService->getDeliveryTestTakers($delivery->getUri(), $testCenter->getUri(), $options); array_walk($assignedUsers, function (&$value) { $value = $value->getIdentifier(); }); $users = array_diff($users, $assignedUsers); array_walk($users, function (&$user) { $user = new \core_kernel_users_GenerisUser(new \core_kernel_classes_Resource($user)); }); usort($users, function ($a, $b) { return strcasecmp(UserHelper::getUserLastName($a), UserHelper::getUserLastName($b)); }); return DataTableHelper::paginate($users, $options, function ($users) { $testTakers = array(); foreach ($users as $user) { $userId = $user->getIdentifier(); $lastName = UserHelper::getUserLastName($user); $firstName = UserHelper::getUserFirstName($user, empty($lastName)); $testTakers[] = array('id' => $userId, 'firstname' => _dh($firstName), 'lastname' => _dh($lastName), 'identifier' => $userId); } return $testTakers; }); }
/** * Gets all deliveries available for a test center * @param string|core_kernel_classes_Resource $testCenterId * @return array * @deprecated */ public function getTestCenterDeliveries($testCenterId) { \common_Logger::w('Use of deprecated method: DeliveryService::getTestCenterDeliveries()'); $testCenter = $this->getResource($testCenterId); return EligibilityService::singleton()->getEligibleDeliveries($testCenter); }
/** * 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; }); }
$i = 0; $proctorNum = 1; $ttNum = 1; $subClass = $testTakerService->createSubClass($testTakerService->getRootClass(), 'jmeter_test_taker_' . $totalTtNum); while ($i < $totalProctorNum) { if ($userService->loginAvailable('Jmeter_proctor_' . $proctorNum)) { $tts = array(); //create sample group $testCenter = $testCenterService->createInstance(new \core_kernel_classes_Class($testCenterService::CLASS_URI), 'jmeter_test_center_' . $proctorNum); $proctor = $userService->addUser('Jmeter_proctor_' . $proctorNum, 'Jmeter_proctor_' . $proctorNum, new \core_kernel_classes_Resource("http://www.tao.lu/Ontologies/TAOProctor.rdf#ProctorRole"), $userClass); $proctor->setPropertyValue(new core_kernel_classes_Property($proctorManagementService::PROPERTY_ASSIGNED_PROCTOR_URI), $testCenter); $proctor->setPropertyValue(new core_kernel_classes_Property($proctorManagementService::PROPERTY_ADMINISTRATOR_URI), $testCenter); $i++; $j = 0; while ($j < $ttByProctor) { if ($userService->loginAvailable('jmeter_TT_' . $ttNum)) { $tt = $testTakerCrudService->createFromArray(array(PROPERTY_USER_LOGIN => 'jmeter_TT_' . $ttNum, PROPERTY_USER_PASSWORD => 'jmeter_TT_' . $ttNum, RDFS_LABEL => 'jmeter_tt' . $ttNum, PROPERTY_USER_FIRSTNAME => 'jmeter_tt_' . $ttNum, PROPERTY_USER_LASTNAME => 'jmeter_tt_' . $ttNum, RDF_TYPE => $subClass)); $tts[] = $tt->getUri(); $j++; } $ttNum++; } $testCenterService->addTestTaker($tt->getUri(), $testCenter); //add delivery to eligible list \oat\taoProctoring\model\EligibilityService::singleton()->createEligibility($testCenter, $delivery); \oat\taoProctoring\model\EligibilityService::singleton()->setEligibleTestTakers($testCenter, $delivery, $tts); //assign tt to delivery \oat\taoProctoring\helpers\DeliveryHelper::assignTestTakers($tts, $delivery->getUri(), $testCenter->getUri()); } $proctorNum++; }
/** * @param \core_kernel_classes_Resource $delivery * @param User $user * @return bool */ protected function isEligible(\core_kernel_classes_Resource $delivery, User $user) { $eligibilityService = EligibilityService::singleton(); return $eligibilityService->isDeliveryEligible($delivery, $user); }
/** * Initialize the service and the default data */ public function __construct() { parent::__construct(); $this->service = $this->getClassService(); $this->eligibilityService = EligibilityService::singleton(); }
/** * Update test center uri */ private function updateTestCenterId() { $uri = null; $delivery = $this->deliveryExecution->getDelivery(); $user = $this->getUser(); $testCenter = EligibilityService::singleton()->getTestCenter($delivery, $user); if ($testCenter) { $uri = $testCenter->getUri(); } else { $deliverLog = ServiceManager::getServiceManager()->get(DeliveryLog::SERVICE_ID); $loggedEvent = $deliverLog->get($this->deliveryExecution->getIdentifier(), 'TEST_AUTHORISE'); $loggedEvent = reset($loggedEvent); $uri = isset($loggedEvent['data']['test_center']) ? $loggedEvent['data']['test_center'] : null; } $this->addValue(DeliveryMonitoringService::TEST_CENTER_ID, $uri, true); }