/**
  * Manage permissions
  * @requiresRight id GRANT
  */
 public function adminPermissions()
 {
     $resource = new \core_kernel_classes_Resource($this->getRequestParameter('id'));
     $accessRights = AdminService::getUsersPermissions($resource->getUri());
     $this->setData('privileges', PermissionProvider::getRightLabels());
     $users = array();
     $roles = array();
     foreach ($accessRights as $uri => $privileges) {
         $identity = new \core_kernel_classes_Resource($uri);
         if ($identity->isInstanceOf(\tao_models_classes_RoleService::singleton()->getRoleClass())) {
             $roles[$uri] = array('label' => $identity->getLabel(), 'privileges' => $privileges);
         } else {
             $users[$uri] = array('label' => $identity->getLabel(), 'privileges' => $privileges);
         }
     }
     $this->setData('users', $users);
     $this->setData('roles', $roles);
     $this->setData('isClass', $resource->isClass());
     $this->setData('uri', $resource->getUri());
     $this->setData('label', _dh($resource->getLabel()));
     $this->setView('AdminAccessController/index.tpl');
 }
 /**
  * return a LTI link URI from a valid delivery id
  * @author Christophe GARCIA <*****@*****.**>
  */
 public function getUrl()
 {
     try {
         if ($this->getRequestMethod() != \Request::HTTP_GET) {
             throw new \common_exception_NotImplemented('Only GET method is accepted to request this service.');
         }
         if (!$this->hasRequestParameter('deliveryId')) {
             $this->returnFailure(new \common_exception_MissingParameter('At least one mandatory parameter was required but found missing in your request'));
         }
         $selectedDelivery = new \core_kernel_classes_Resource($this->getRequestParameter('deliveryId'));
         if (!$selectedDelivery->isInstanceOf(new \core_kernel_classes_Class(TAO_DELIVERY_CLASS))) {
             $this->returnFailure(new \common_exception_NotFound('Delivery not found'));
         }
         try {
             $selectedDelivery->getUniquePropertyValue(new \core_kernel_classes_Property(\TAO_DELIVERY_RESULTSERVER_PROP));
         } catch (Exception $e) {
             $this->returnFailure(new \common_exception_BadRequest('The delivery is not associated to a Result server storage policy'));
         }
         $this->returnSuccess(LTIDeliveryTool::singleton()->getLaunchUrl(array('delivery' => $selectedDelivery->getUri())));
     } catch (Exception $ex) {
         $this->returnFailure($ex);
     }
 }
 /**
  * Validate an xml file, convert file linked inside and store it into media manager
  * @param \core_kernel_classes_Resource $instance the instance to edit
  * @param string $lang language of the shared stimulus
  * @param string $xmlFile File to store
  * @return \common_report_Report
  */
 protected function replaceSharedStimulus($instance, $lang, $xmlFile)
 {
     //if the class does not belong to media classes create a new one with its name (for items)
     $mediaClass = new core_kernel_classes_Class(MediaService::ROOT_CLASS_URI);
     if (!$instance->isInstanceOf($mediaClass)) {
         $report = \common_report_Report::createFailure('The instance ' . $instance->getUri() . ' is not a Media instance');
         return $report;
     }
     SharedStimulusImporter::isValidSharedStimulus($xmlFile);
     $name = basename($xmlFile, '.xml');
     $name .= '.xhtml';
     $filepath = dirname($xmlFile) . '/' . $name;
     \tao_helpers_File::copy($xmlFile, $filepath);
     $service = MediaService::singleton();
     if (!$service->editMediaInstance($filepath, $instance->getUri(), $lang)) {
         $report = \common_report_Report::createFailure(__('Fail to edit Shared Stimulus'));
     } else {
         $report = \common_report_Report::createSuccess(__('Shared Stimulus edited successfully'));
     }
     return $report;
 }
 /**
  * Recompile deliveries
  */
 private function compileAction()
 {
     $deliveryIds = array_slice($this->params, 1);
     $deliveryClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDelivery');
     $this->report = new Report(Report::TYPE_INFO, 'Recompile deliveries:');
     foreach ($deliveryIds as $deliveryId) {
         $delivery = new \core_kernel_classes_Resource($deliveryId);
         if (!$delivery->exists()) {
             $this->report->add(new Report(Report::TYPE_ERROR, "Delivery {$deliveryId} does not exists"));
             continue;
         } else {
             if (!$delivery->isInstanceOf($deliveryClass)) {
                 $this->report->add(new Report(Report::TYPE_ERROR, "{$deliveryId} is not delivery resource"));
                 continue;
             }
         }
         try {
             $newDelivery = $this->compileDelivery($delivery);
         } catch (\common_Exception $e) {
             $this->report->add(new Report(Report::TYPE_ERROR, $e->getMessage()));
         }
         $this->report->add(new Report(Report::TYPE_SUCCESS, "{$deliveryId} successfully compiled. New Id: {$newDelivery->getUri()}"));
     }
 }
 /**
  * Whether delivery is repetition of main delivery
  * @param \core_kernel_classes_Resource $delivery
  * @return bool
  */
 public function isRepeated(\core_kernel_classes_Resource $delivery)
 {
     return $delivery->isInstanceOf(new \core_kernel_classes_Class(self::CLASS_URI));
 }