public function __construct()
 {
     parent::__construct();
     $this->scheduleService = DeliveryScheduleService::singleton();
     $this->testTakersService = DeliveryTestTakersService::singleton();
     switch ($this->getRequestMethod()) {
         case "GET":
             $this->action = 'get';
             break;
         case "PUT":
             $this->action = 'update';
             break;
         case "POST":
             $this->action = 'create';
             break;
         case "DELETE":
             $this->sendData(array('message' => 'Method is not implemented'), 501);
             exit;
         default:
             $this->sendData(array('message' => 'Not found'), 404);
             exit;
     }
 }
 /**
  * Function returns extended delivery data (e.g. groups, number of executions etc.)
  * @param \core_kernel_classes_Resource $delivery
  * @return void
  */
 private function getFullDeliveryData(\core_kernel_classes_Resource $delivery)
 {
     $result = array();
     if (\taoDelivery_models_classes_execution_ServiceProxy::singleton()->implementsMonitoring()) {
         $execs = \taoDelivery_models_classes_execution_ServiceProxy::singleton()->getExecutionsByDelivery($delivery);
         $result['executions'] = count($execs);
     }
     $result['published'] = $this->service->getCompilationDate($delivery);
     //groups
     $groups = array_keys($this->getServiceManager()->get('taoDeliverySchedule/DeliveryGroupsService')->getGroups($delivery));
     $result['groups'] = \tao_helpers_Uri::encodeArray($groups);
     //Test takers
     $result = $result + DeliveryTestTakersService::singleton()->getDeliveryTestTakers($delivery);
     //Max. number of executions
     $deliveryMaxexecProperty = new \core_kernel_classes_Property(TAO_DELIVERY_MAXEXEC_PROP);
     $result['maxexec'] = (string) $delivery->getOnePropertyValue($deliveryMaxexecProperty);
     //Result server
     $resultServerProp = new \core_kernel_classes_Property(TAO_DELIVERY_RESULTSERVER_PROP);
     $result['resultserver'] = $delivery->getOnePropertyValue($resultServerProp)->getUri();
     $result['resultserver'] = \tao_helpers_Uri::encode($result['resultserver']);
     $result['repeatedDeliveries'] = $this->getServiceManager()->get(RepeatedDeliveryService::CONFIG_ID)->getRepeatedDeliveriesData($delivery);
     return $result;
 }
 /**
  * Get repeated deliveries data
  * @param \core_kernel_classes_Resource $delivery
  * @return array
  */
 public function getRepeatedDeliveriesData(\core_kernel_classes_Resource $delivery)
 {
     $result = array();
     $repeatedDeliveryClass = new \core_kernel_classes_Class(self::CLASS_URI);
     $repeatedDeliveries = $repeatedDeliveryClass->searchInstances(array(self::PROPERTY_REPETITION_OF => $delivery->getUri()), array('like' => false));
     foreach ($repeatedDeliveries as $repeatedDelivery) {
         $repetitionNumber = (string) $repeatedDelivery->getUniquePropertyValue(new \core_kernel_classes_Property(self::PROPERTY_NUMBER_OF_REPETITION));
         $result[$repetitionNumber] = array();
         //groups
         $groups = array_keys($this->getServiceManager()->get('taoDeliverySchedule/DeliveryGroupsService')->getGroups($repeatedDelivery));
         $result[$repetitionNumber]['groups'] = \tao_helpers_Uri::encodeArray($groups);
         //Test takers
         $result[$repetitionNumber] = array_merge($result[$repetitionNumber], DeliveryTestTakersService::singleton()->getDeliveryTestTakers($repeatedDelivery));
     }
     return $result;
 }
 /**
  * Save the delivery.
  * 
  * @param \core_kernel_classes_Class $delivery
  * @param array $params Array of delivery parameters (uri=>value)
  * @return \core_kernel_classes_Class $delivery instance
  */
 public function save(\core_kernel_classes_Class $delivery, array $params)
 {
     if (!empty($params['repeatedDelivery']) && isset($params[RepeatedDeliveryService::PROPERTY_NUMBER_OF_REPETITION])) {
         $repeatedDeliveryService = ServiceManager::getServiceManager()->get(RepeatedDeliveryService::CONFIG_ID);
         $delivery = $repeatedDeliveryService->getDelivery($delivery, $params[RepeatedDeliveryService::PROPERTY_NUMBER_OF_REPETITION], true);
     } else {
         $data = $this->sanitizeParams($params);
         $binder = new \tao_models_classes_dataBinding_GenerisFormDataBinder($delivery);
         $delivery = $binder->bind($data);
     }
     if (isset($params['groups'])) {
         $groups = array_filter($params['groups']);
         $groups = array_map(array('\\tao_helpers_Uri', 'decode'), $groups);
         ServiceManager::getServiceManager()->get('taoDeliverySchedule/DeliveryGroupsService')->saveGroups($delivery, $groups);
     }
     if (isset($params['ttexcluded'])) {
         $ttExcluded = is_array($params['ttexcluded']) ? $params['ttexcluded'] : array();
         DeliveryTestTakersService::singleton()->saveExcludedTestTakers($delivery, $ttExcluded);
     }
     return $delivery;
 }