/**
  * Update criteria from a criteriagroup
  *
  * @param array $criteriagroupJS
  * @param Criteriagroup $criteriagroupDB
  * @return array
  */
 protected function publishCriteria($criteriagroupJS = array(), Criteriagroup $criteriagroupDB)
 {
     $processedCriteria = array();
     // Retrieve existing criteriagroups for this condition
     $existingCriteria = $criteriagroupDB->getCriteria();
     foreach ($criteriagroupJS->criterion as $criterionJS) {
         //criterion attributes
         $data = isset($criterionJS->data) ? $criterionJS->data : null;
         $ctype = isset($criterionJS->type) ? $criterionJS->type : null;
         //echo "criterionid ".$criterionJS->id."<br>\n";
         // Current criterion has never been published or criterion entity has been deleted => create it
         if (empty($criterionJS->critid) || !$existingCriteria->containsKey($criterionJS->critid)) {
             //echo "criterion add <br>\n";
             $criterionDB = $this->stepConditionsManager->createCriterion($data, $ctype, $criteriagroupDB);
             $uniqId = "_CRIT" . uniqid();
             $this->uniqId2crit[$uniqId] = $criterionDB;
             // Update json structure with new resource ID
             $criterionJS->critid = $uniqId;
         } else {
             //echo "criterion edit <br>\n";
             //retrieve criterion
             $criterionDB = $existingCriteria->get($criterionJS->critid);
             //edit criterion in DB
             $criterionDB = $this->stepConditionsManager->editCriterion($data, $ctype, $criteriagroupDB, $criterionDB);
         }
         // Store criteria to know it doesn't have to be deleted when we will clean the condition
         $processedCriteria[] = $criterionDB;
     }
     return $processedCriteria;
 }
 private function storeResource(array $resources, ResourceNode $node)
 {
     $resource = $this->resourceManager->getResourceFromNode($node);
     if (empty($resources[$node->getId()])) {
         $resources[$node->getId()] = $resource;
     }
     return $resources;
 }
Esempio n. 3
0
 /**
  * Count the number of resources in a workspace
  *
  * @param Workspace $workspace
  *
  * @return integer
  */
 public function countResources(Workspace $workspace)
 {
     //@todo count directory from dql
     $root = $this->resourceManager->getWorkspaceRoot($workspace);
     if (!$root) {
         return 0;
     }
     $descendants = $this->resourceManager->getDescendants($root);
     return count($descendants);
 }
Esempio n. 4
0
 /**
  * Find accessible Paths.
  *
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  *
  * @return array
  */
 public function findAccessibleByUser(Workspace $workspace = null)
 {
     $roots = [];
     if (!empty($workspace)) {
         $root = $this->resourceManager->getWorkspaceRoot($workspace);
         $roots[] = $root->getPath();
     }
     $token = $this->securityToken->getToken();
     $userRoles = $this->utils->getRoles($token);
     $entities = $this->om->getRepository('InnovaPathBundle:Path\\Path')->findAccessibleByUser($roots, $userRoles);
     // Check edit and delete access for paths
     $paths = [];
     foreach ($entities as $entity) {
         $paths[] = ['entity' => $entity, 'canEdit' => $this->isAllow('EDIT', $entity), 'canDelete' => $this->isAllow('DELETE', $entity)];
     }
     return $paths;
 }
Esempio n. 5
0
 /**
  * Create a new path
  * @param  \Innova\PathBundle\Entity\Path\Path $path
  * @param  \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  * @return \Innova\PathBundle\Entity\Path\Path
  */
 public function create(Path $path, Workspace $workspace)
 {
     // Check if JSON structure is built
     $structure = $path->getStructure();
     if (empty($structure)) {
         // Initialize path structure
         $path->initializeStructure();
     }
     // Persist Path
     $this->om->persist($path);
     $this->om->flush();
     // Create a new resource node
     $parent = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findWorkspaceRoot($workspace);
     $resourceType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('innova_path');
     $path = $this->resourceManager->create($path, $resourceType, $this->securityToken->getToken()->getUser(), $workspace, $parent, null);
     return $path;
 }
Esempio n. 6
0
 /**
  * Create a Scorm archive for a ResourceNode.
  *
  * @param ResourceNode $node
  * @param string       $locale
  * @param string       $scormVersion
  *
  * @return \ZipArchive
  *
  * @throws ResourceNotFoundException
  * @throws \Exception
  */
 public function export(ResourceNode $node, $locale = 'en', $scormVersion = '2004')
 {
     if ('2004' !== $scormVersion && '1.2' !== $scormVersion) {
         // Invalid Scorm version
         throw new \Exception('SCORM export : Invalid SCORM version.');
     }
     $resource = $this->resourceManager->getResourceFromNode($node);
     if (!$resource) {
         throw new ResourceNotFoundException('SCORM export : The resource ' . $node->getName() . ' was not found');
     }
     // Export the Resource and all it's sub-resources
     $exportedResources = $this->exportResource($resource, $locale);
     // Create the manifest for the Scorm package
     if ('1.2' === $scormVersion) {
         $manifest = new Scorm12Manifest($node, $exportedResources);
     } else {
         $manifest = new Scorm2004Manifest($node, $exportedResources);
     }
     $package = $this->createPackage($node, $locale, $manifest, $exportedResources);
     return $package;
 }
 /**
  * Load activity data from ResourceNode id.
  *
  * @param int $nodeId
  *
  * @return JsonResponse
  *
  * @Route(
  *      "/load_activity/{nodeId}",
  *      name         = "innova_path_load_activity",
  *      requirements = { "id"     = "\d+" },
  *      options      = { "expose" = true }
  * )
  * @Method("GET")
  */
 public function loadActivityAction($nodeId)
 {
     $activity = [];
     $node = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneById($nodeId);
     if (!empty($node)) {
         $resource = $this->resourceManager->getResourceFromNode($node);
         if (!empty($resource)) {
             $activity['id'] = $resource->getId();
             $activity['name'] = $resource->getTitle();
             $activity['description'] = $resource->getDescription();
             // Primary resources
             $activity['primaryResource'] = null;
             $primaryResource = $resource->getPrimaryResource();
             if (!empty($primaryResource)) {
                 $activity['primaryResource'] = ['resourceId' => $primaryResource->getId(), 'name' => $primaryResource->getName(), 'type' => $primaryResource->getResourceType()->getName(), 'mimeType' => $primaryResource->getMimeType()];
             }
             // Process activity parameters
             $parameters = $resource->getParameters();
             if (!empty($parameters)) {
                 // Secondary resources
                 $activity['resources'] = [];
                 $secondaryResources = $parameters->getSecondaryResources();
                 if (!empty($secondaryResources)) {
                     foreach ($secondaryResources as $secondaryResource) {
                         $activity['resources'][] = ['resourceId' => $secondaryResource->getId(), 'name' => $secondaryResource->getName(), 'type' => $secondaryResource->getResourceType()->getName(), 'mimeType' => $secondaryResource->getMimeType(), 'propagateToChildren' => true];
                     }
                 }
                 // Global Parameters
                 $activity['withTutor'] = $parameters->isWithTutor();
                 $activity['who'] = $parameters->getWho();
                 $activity['where'] = $parameters->getWhere();
                 $activity['duration'] = $parameters->getMaxDuration();
                 // Duration in seconds
                 $activity['evaluationType'] = $parameters->getEvaluationType();
                 //manual/automatic
             }
         }
     }
     return new JsonResponse($activity);
 }
Esempio n. 8
0
 /**
  * @param  \Innova\PathBundle\Entity\Step               $step
  * @param  \stdClass                                    $stepStructure
  * @return \Innova\PathBundle\Manager\PublishingManager
  * @throws \LogicException
  */
 public function updateActivity(Step $step, \stdClass $stepStructure)
 {
     $newActivity = false;
     $activity = $step->getActivity();
     if (empty($activity)) {
         if (!empty($stepStructure->activityId)) {
             // Load activity from DB
             $activity = $this->om->getRepository('ClarolineCoreBundle:Resource\\Activity')->findOneById($stepStructure->activityId);
             if (empty($activity)) {
                 // Can't find Activity => create a new one
                 $newActivity = true;
                 $activity = new Activity();
             }
         } else {
             // Create new activity
             $newActivity = true;
             $activity = new Activity();
         }
     }
     // Update activity properties
     if (!empty($stepStructure->name)) {
         $name = $stepStructure->name;
     } else {
         // Create a default name
         $name = $step->getPath()->getName() . ' - ' . Step::DEFAULT_NAME . ' ' . $step->getOrder();
     }
     $activity->setName($name);
     $activity->setTitle($name);
     $description = !empty($stepStructure->description) ? $stepStructure->description : ' ';
     $activity->setDescription($description);
     // Link resource if needed
     if (!empty($stepStructure->primaryResource) && !empty($stepStructure->primaryResource[0]) && !empty($stepStructure->primaryResource[0]->resourceId)) {
         $resource = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneById($stepStructure->primaryResource[0]->resourceId);
         if (!empty($resource)) {
             $activity->setPrimaryResource($resource);
         } else {
             $warning = $this->translator->trans('warning_primary_resource_deleted', array('resourceId' => $stepStructure->primaryResource[0]->resourceId, 'resourceName' => $stepStructure->primaryResource[0]->name), "innova_tools");
             $this->session->getFlashBag()->add('warning', $warning);
             $stepStructure->primaryResource = array();
         }
     } elseif ($activity->getPrimaryResource()) {
         // Step had a resource which has been deleted
         $activity->setPrimaryResource(null);
     }
     // Generate Claroline resource node and rights
     if ($newActivity) {
         // It's a new Activity, so use Step parameters
         $activity->setParameters($step->getParameters());
         $activityType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('activity');
         $creator = $step->getPath()->getCreator();
         $workspace = $step->getWorkspace();
         // Store Activity in same directory than parent Path
         $parent = $step->getPath()->getResourceNode()->getParent();
         if (empty($parent)) {
             $parent = $this->resourceManager->getWorkspaceRoot($workspace);
         }
         $activity = $this->resourceManager->create($activity, $activityType, $creator, $workspace, $parent);
     } else {
         // Activity already exists => update ResourceNode
         $activity->getResourceNode()->setName($activity->getTitle());
     }
     // Update JSON structure
     $stepStructure->activityId = $activity->getId();
     // Store Activity in Step
     $step->setActivity($activity);
     return $this;
 }