public function isDeliveryExecutionAllowed(core_kernel_classes_Resource $delivery, User $user)
 {
     $userUri = $user->getIdentifier();
     if (is_null($delivery)) {
         common_Logger::w("Attempt to start the compiled delivery " . $delivery->getUri() . " related to no delivery");
         return false;
     }
     //first check the user is assigned
     if (!taoDelivery_models_classes_AssignmentService::singleton()->isUserAssigned($delivery, $user)) {
         common_Logger::w("User " . $userUri . " attempts to start the compiled delivery " . $delivery->getUri() . " he was not assigned to.");
         return false;
     }
     $settings = $this->getDeliverySettings($delivery);
     //check Tokens
     $usedTokens = count(taoDelivery_models_classes_execution_ServiceProxy::singleton()->getUserExecutions($delivery, $userUri));
     if ($settings[TAO_DELIVERY_MAXEXEC_PROP] != 0 and $usedTokens >= $settings[TAO_DELIVERY_MAXEXEC_PROP]) {
         common_Logger::d("Attempt to start the compiled delivery " . $delivery->getUri() . "without tokens");
         return false;
     }
     //check time
     $startDate = date_create('@' . $settings[TAO_DELIVERY_START_PROP]);
     $endDate = date_create('@' . $settings[TAO_DELIVERY_END_PROP]);
     if (!$this->areWeInRange($startDate, $endDate)) {
         common_Logger::d("Attempt to start the compiled delivery " . $delivery->getUri() . " at the wrong date");
         return false;
     }
     return true;
 }
 public function deleteInstance(core_kernel_classes_Resource $assembly)
 {
     taoDelivery_models_classes_AssignmentService::singleton()->onDelete($assembly);
     $runtimeResource = $assembly->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_COMPILEDDELIVERY_RUNTIME));
     $runtimeResource->delete();
     // cleanup data
     return $assembly->delete();
 }
 /**
  * Gets the test takers assigned to a delivery
  *
  * @param $deliveryId
  * @param array $options
  * @return User[]
  */
 public function getDeliveryTestTakers($deliveryId, $options = array())
 {
     $delivery = new \core_kernel_classes_Resource($deliveryId);
     $userIds = \taoDelivery_models_classes_AssignmentService::singleton()->getAssignedUsers($delivery);
     $users = array();
     foreach ($userIds as $id) {
         // assume Tao Users
         $users[] = new core_kernel_users_GenerisUser(new \core_kernel_classes_Resource($id));
     }
     return $users;
 }
 /**
  * Set a view with the list of process instances (both started or finished) and available process definitions
  *
  * @access public
  * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu}
  * @param processDefinitionUri
  * @return void
  */
 public function index()
 {
     $label = common_session_SessionManager::getSession()->getUserLabel();
     $this->setData('login', $label);
     //get deliveries for the current user (set in groups extension)
     $user = common_session_SessionManager::getSession()->getUser();
     $this->setData('startedDeliveries', $this->service->getResumableDeliveries($user));
     $finishedDeliveries = is_null($user) ? array() : $this->executionService->getFinishedDeliveryExecutions($user->getIdentifier());
     $this->setData('finishedDeliveries', $finishedDeliveries);
     $deliveryData = array();
     if (!is_null($user)) {
         $available = taoDelivery_models_classes_AssignmentService::singleton()->getAvailableDeliveries($user);
         foreach ($available as $uri) {
             $delivery = new core_kernel_classes_Resource($uri);
             $deliveryData[] = $this->getDeliverySettings($delivery, $user);
         }
     }
     $this->setData('availableDeliveries', $deliveryData);
     $this->setData('processViewData', array());
     $this->setData('client_config_url', $this->getClientConfigUrl());
     $this->setView('runtime/index.tpl');
 }
 public function excludeTesttaker()
 {
     $assembly = $this->getCurrentInstance();
     $this->setData('assemblyUri', $assembly->getUri());
     // define the subjects excluded from the current delivery
     $property = new core_kernel_classes_Property(TAO_DELIVERY_EXCLUDEDSUBJECTS_PROP);
     $excluded = array();
     foreach ($assembly->getPropertyValues($property) as $uri) {
         $user = new core_kernel_classes_Resource($uri);
         $excluded[$uri] = $user->getLabel();
     }
     $assigned = array();
     foreach (taoDelivery_models_classes_AssignmentService::singleton()->getAssignedUsers($assembly) as $userId) {
         if (!in_array($userId, array_keys($excluded))) {
             $user = new core_kernel_classes_Resource($userId);
             $assigned[$userId] = $user->getLabel();
         }
     }
     $this->setData('assigned', $assigned);
     $this->setData('excluded', $excluded);
     $this->setView('Delivery/excludeTesttaker.tpl');
 }