コード例 #1
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;
 }
コード例 #2
0
ファイル: Step.php プロジェクト: stmolivier/PathBundle
 public function jsonSerialize()
 {
     // Initialize data array
     $jsonArray = array('id' => $this->id, 'resourceId' => $this->id, 'activityId' => null, 'lvl' => $this->lvl, 'name' => $this->getName(), 'description' => $this->getDescription(), 'primaryResource' => array(), 'resources' => array(), 'excludedResources' => array(), 'children' => array(), 'withTutor' => false, 'who' => null, 'where' => null, 'duration' => null);
     // Get activity properties
     if (!empty($this->activity)) {
         // Get activity ID
         $jsonArray['activityId'] = $this->activity->getId();
         // The ID of the linked Activity
         // Get primary resource
         $primaryResource = $this->activity->getPrimaryResource();
         if (!empty($primaryResource)) {
             $jsonArray['primaryResource'] = array(array('id' => $primaryResource->getId(), 'resourceId' => $primaryResource->getId(), 'name' => $primaryResource->getName(), 'type' => $primaryResource->getResourceType()->getName(), 'mimeType' => $primaryResource->getMimeType()));
         }
     }
     // Get parameters
     if (!empty($this->parameters)) {
         // Get parameters of the step
         $parameters = $this->parameters;
     } else {
         if (!empty($this->activity)) {
             // Get parameters of the Activity
             $parameters = $this->activity->getParameters();
         }
     }
     if (!empty($parameters)) {
         // Secondary resources
         $secondaryResources = $parameters->getSecondaryResources();
         if (!empty($secondaryResources)) {
             // Get propagated resources of the current step
             $propagatedResources = $this->getPropagatedResources($this->lvl);
             foreach ($secondaryResources as $secondaryResource) {
                 $jsonArray['resources'][] = array('id' => $secondaryResource->getId(), 'resourceId' => $secondaryResource->getId(), 'name' => $secondaryResource->getName(), 'type' => $secondaryResource->getResourceType()->getName(), 'mimeType' => $secondaryResource->getMimeType(), 'propagateToChildren' => in_array($secondaryResource->getId(), $propagatedResources));
             }
         }
         // Global Parameters
         $jsonArray['withTutor'] = $parameters->isWithTutor();
         $jsonArray['who'] = $parameters->getWho();
         $jsonArray['where'] = $parameters->getWhere();
         $jsonArray['duration'] = $parameters->getMaxDuration();
         // Duration in seconds
     }
     // Excluded resources
     $parentResources = $this->getParentsSecondaryResources();
     foreach ($parentResources as $resource) {
         $exist = false;
         foreach ($this->inheritedResources as $inherited) {
             if ($inherited->getResource()->getId() == $resource->getId()) {
                 $exist = true;
                 break;
             }
         }
         // Parent resource not found in step
         if (!$exist) {
             $jsonArray['excludedResources'][] = $resource->getId();
         }
     }
     // Get step children
     if (!empty($this->children)) {
         $jsonArray['children'] = array_values($this->children->toArray());
     }
     return $jsonArray;
 }
コード例 #3
0
 public function addPermissionsToResource(Activity $activity, array $roles)
 {
     $primary = $activity->getPrimaryResource();
     $secondaries = [];
     $nodes = [];
     if ($primary) {
         $nodes[] = $primary;
     }
     foreach ($activity->getParameters()->getSecondaryResources() as $res) {
         $secondaries[] = $res;
     }
     $nodes = array_merge($nodes, $secondaries);
     $this->rightsManager->initializePermissions($nodes, $roles);
 }
コード例 #4
0
ファイル: Step.php プロジェクト: claroline/distribution
 public function jsonSerialize()
 {
     $accessibleFrom = $this->getAccessibleFrom();
     $accessibleUntil = $this->getAccessibleUntil();
     // Initialize data array
     $jsonArray = ['id' => $this->id, 'resourceId' => $this->id, 'activityId' => null, 'activityHeight' => $this->activityHeight, 'lvl' => $this->lvl, 'name' => $this->getName(), 'description' => $this->getDescription(), 'primaryResource' => [], 'resources' => [], 'excludedResources' => [], 'children' => [], 'withTutor' => false, 'who' => null, 'where' => null, 'duration' => null, 'accessibleFrom' => $accessibleFrom instanceof \DateTime ? $accessibleFrom->format('Y-m-d H:i:s') : null, 'accessibleUntil' => $accessibleUntil instanceof \DateTime ? $accessibleUntil->format('Y-m-d H:i:s') : null, 'evaluationType' => null];
     // Get activity properties
     if (!empty($this->activity)) {
         // Get activity ID
         $jsonArray['activityId'] = $this->activity->getId();
         // The ID of the linked Activity
         // Get primary resource
         $primaryResource = $this->activity->getPrimaryResource();
         if (!empty($primaryResource)) {
             $jsonArray['primaryResource'] = [['id' => $primaryResource->getId(), 'resourceId' => $primaryResource->getId(), 'name' => $primaryResource->getName(), 'type' => $primaryResource->getResourceType()->getName(), 'mimeType' => $primaryResource->getMimeType()]];
         }
     }
     // Get parameters
     if (!empty($this->parameters)) {
         // Get parameters of the step
         $parameters = $this->parameters;
     } elseif (!empty($this->activity)) {
         // Get parameters of the Activity
         $parameters = $this->activity->getParameters();
     }
     if (!empty($parameters)) {
         // Secondary resources
         $secondaryResources = $parameters->getSecondaryResources();
         if (!empty($secondaryResources)) {
             // Get propagated resources of the current step
             $propagatedResources = $this->getPropagatedResources($this->lvl);
             foreach ($secondaryResources as $secondaryResource) {
                 $jsonArray['resources'][] = ['id' => $secondaryResource->getId(), 'resourceId' => $secondaryResource->getId(), 'name' => $secondaryResource->getName(), 'type' => $secondaryResource->getResourceType()->getName(), 'mimeType' => $secondaryResource->getMimeType(), 'propagateToChildren' => in_array($secondaryResource->getId(), $propagatedResources)];
             }
         }
         // Global Parameters
         $jsonArray['withTutor'] = $parameters->isWithTutor();
         $jsonArray['who'] = $parameters->getWho();
         $jsonArray['where'] = $parameters->getWhere();
         $jsonArray['duration'] = $parameters->getMaxDuration();
         // Duration in seconds
         $jsonArray['evaluationType'] = $parameters->getEvaluationType();
         // manual/automatic
     }
     // Excluded resources
     $parentResources = $this->getParentsSecondaryResources();
     /** @var \Claroline\CoreBundle\Entity\Resource\ResourceNode $resource */
     foreach ($parentResources as $resource) {
         $exist = false;
         /** @var \Innova\PathBundle\Entity\InheritedResource $inherited */
         foreach ($this->inheritedResources as $inherited) {
             if ($inherited->getResource()->getId() === $resource->getId()) {
                 $exist = true;
                 break;
             }
         }
         // Parent resource not found in step
         if (!$exist) {
             $jsonArray['excludedResources'][] = $resource->getId();
         }
     }
     // Get condition
     if (!empty($this->condition)) {
         // Get condition of the step
         $jsonArray['condition'] = $this->condition;
     }
     // Get step children
     if (!empty($this->children)) {
         // Reorder children
         // The property OrderBy only works when we grab data from the DB,
         // so if we have modified the Path after it, children may be not ordered
         $iterator = $this->children->getIterator();
         $iterator->uasort(function ($a, $b) {
             /*
              * @var \Innova\PathBundle\Entity\Step $a
              * @var \Innova\PathBundle\Entity\Step $b
              */
             return $a->getOrder() < $b->getOrder() ? -1 : 1;
         });
         $this->children = new ArrayCollection(iterator_to_array($iterator));
         $jsonArray['children'] = array_values($this->children->toArray());
     }
     return $jsonArray;
 }