Esempio n. 1
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. 2
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. 3
0
 /**
  * Get the list of Paths for Widgets
  * @param PathWidgetConfig $config
  * @param Workspace $workspace
  * @return array
  */
 public function getWidgetPaths(PathWidgetConfig $config = null, Workspace $workspace = null)
 {
     $roots = array();
     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')->findWidgetPaths($userRoles, $roots, $config);
     // Check edit and delete access for paths
     $paths = array();
     foreach ($entities as $entity) {
         $paths[] = array('entity' => $entity, 'canEdit' => $this->isAllow('EDIT', $entity));
     }
     return $paths;
 }
Esempio n. 4
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;
 }