/**
  * @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;
 }
 /**
  *
  */
 public function testGetTestCenters()
 {
     $testCenterClass = TestCenterService::singleton()->getRootClass();
     $subject = $this->subjectsService->createInstance($this->subjectsService->getRootClass(), 'testSubject');
     $oneTC = $testCenterClass->createInstance('testTCInstance');
     $this->testCenterService->addTestTaker($subject->getUri(), $oneTC);
     $oneTC2 = $testCenterClass->createInstance('testTCInstance2');
     $subclass = $testCenterClass->createSubClass('testTCSubclass');
     $oneTC3 = $subclass->createInstance('testSubTCInstance');
     $this->testCenterService->addTestTaker($subject->getUri(), $oneTC3);
     $generisUser = new \core_kernel_users_GenerisUser($subject);
     $testCenters = $this->testCenterService->getTestCentersByTestTaker($generisUser);
     $this->assertTrue(is_array($testCenters));
     $this->assertTrue(count($testCenters) == 2);
     array_walk($testCenters, function (&$testCenter) {
         $testCenter = $testCenter->getUri();
     });
     $this->assertContains($oneTC->getUri(), $testCenters);
     $this->assertNotContains($oneTC2->getUri(), $testCenters);
     $this->assertContains($oneTC3->getUri(), $testCenters);
     $this->assertTrue($this->testCenterService->deleteResource($oneTC));
     $this->assertTrue($this->testCenterService->deleteResource($oneTC2));
     $this->assertTrue($this->testCenterService->deleteResource($oneTC3));
     $this->assertTrue($this->testCenterService->deleteClass($subclass));
     $subject->delete();
 }
 /**
  * Return all proctor assigned to test centers managed by an admin (eventually in the list of test centers)
  * @param string $testCenterAdminUri
  * @param array $testCenters
  * @return User[]
  */
 public function getAssignedProctors($testCenterAdminUri, $testCenters = array())
 {
     $testCenterService = TestCenterService::singleton();
     $testCenterAdmin = new core_kernel_classes_Resource($testCenterAdminUri);
     $testCentersAdmin = $testCenterAdmin->getPropertyValues(new core_kernel_classes_Property(self::PROPERTY_ADMINISTRATOR_URI));
     //get all sub test centers
     foreach ($testCentersAdmin as $testCenter) {
         $children = $testCenterService->getSubTestCenters($testCenter);
         $testCentersAdmin = array_merge($testCentersAdmin, $children);
     }
     //get test centers in common between administrable test centers and test centers list
     if (!empty($testCenters)) {
         //get parent testCenter
         $allTestCenters = $testCenters;
         foreach ($testCenters as $testCenter) {
             $parents = $testCenterService->getRootClass()->searchInstances(array(TestCenterService::PROPERTY_CHILDREN_URI => $testCenter), ['recursive' => true]);
             $parents = array_keys($parents);
             $allTestCenters = array_merge($allTestCenters, $parents);
         }
         $testCentersAdmin = array_intersect($testCentersAdmin, $allTestCenters);
     }
     $proctorClass = $this->getRootClass();
     $users = array();
     foreach ($testCentersAdmin as $testCenterUri) {
         $assignedProctors = $proctorClass->searchInstances(array(self::PROPERTY_ASSIGNED_PROCTOR_URI => $testCenterUri), array('recursive' => true, 'like' => false));
         $users = array_merge($users, $assignedProctors);
     }
     return $users;
 }
 /**
  * Gets the test takers available for a delivery
  *
  * @param User $proctor
  * @param string $deliveryId
  * @param string $testCenterId
  * @param array $options
  * @return User[]
  */
 public function getAvailableTestTakers(User $proctor, $deliveryId, $testCenterId, $options = array())
 {
     $testCenterService = TestCenterService::singleton();
     // test takers already assigned are excluded
     $excludeIds = array();
     foreach ($this->getDeliveryTestTakers($deliveryId, $testCenterId) as $user) {
         $excludeIds[$user->getIdentifier()] = true;
     }
     // determine testcenters managed per proctor with delivery available
     $availableIn = array();
     foreach ($testCenterService->getTestCentersByDelivery($deliveryId) as $testCenter) {
         $availableIn[$testCenter->getUri()] = true;
     }
     // get testtakers from those centers that are not excluded
     $users = array();
     foreach ($testCenterService->getTestCentersByProctor($proctor) as $testCenter) {
         $testCenterUri = $testCenter->getUri();
         if (array_key_exists($testCenterUri, $availableIn)) {
             foreach ($testCenterService->getTestTakers($testCenterUri) as $userResource) {
                 $uri = $userResource->getUri();
                 if (!array_key_exists($uri, $excludeIds) && !array_key_exists($uri, $users)) {
                     $users[$uri] = new \core_kernel_users_GenerisUser($userResource);
                 }
             }
         }
     }
     return array_values($users);
 }
 /**
  * Gets a list of available test sites
  *
  * @param string $testCenterId
  * @return core_kernel_classes_Resource
  * @throws ServiceNotFoundException
  * @throws \common_Exception
  * @throws \common_exception_Error
  */
 public static function getTestCenter($testCenterId)
 {
     $testCenterService = TestCenterService::singleton();
     return $testCenterService->getTestCenter($testCenterId);
 }
if (!common_ext_ExtensionsManager::singleton()->isEnabled('taoProctoring')) {
    echo 'extension taoProctoring needs to be installed and enabled in order to run this script !';
    die;
}
foreach ($todefine as $contant => $value) {
    define($contant, $value);
}
$params = $argv;
array_shift($params);
$totalTtNum = isset($params[0]) ? $params[0] : 500;
$ttByProctor = isset($params[1]) && is_numeric($params[1]) && $params[1] !== 0 ? $params[1] : 20;
$totalProctorNum = $totalTtNum / $ttByProctor;
$totalProctorNum = $totalProctorNum < 1 ? 1 : $totalProctorNum;
$testTakerCrudService = oat\taoTestTaker\models\CrudService::singleton();
$userService = \tao_models_classes_UserService::singleton();
$testCenterService = \oat\taoProctoring\model\TestCenterService::singleton();
$proctorManagementService = \oat\taoProctoring\model\ProctorManagementService::singleton();
$testTakerService = \oat\taoTestTaker\models\TestTakerService::singleton();
$userClass = new \core_kernel_classes_Class(CLASS_TAO_USER);
//create delivery
$tests = [];
$testClazz = new core_kernel_classes_Class(TAO_TEST_CLASS);
foreach ($testClazz->getInstances(true) as $instance) {
    $tests[$instance->getUri()] = $instance->getLabel();
}
$testUris = array_keys($tests);
if (!empty($testUris)) {
    $i = 0;
    $delivery = null;
    $deliveryClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDelivery');
    while (is_null($delivery) && $i < count($testUris)) {
 protected function getClassService()
 {
     return TestCenterService::singleton();
 }