Esempio n. 1
0
 /**
  * Transform Step data to export it
  * @param  \Innova\PathBundle\Entity\Step $step
  * @return array
  */
 public function export(Step $step)
 {
     $parent = $step->getParent();
     $activity = $step->getActivity();
     $data = array('uid' => $step->getId(), 'parent' => !empty($parent) ? $parent->getId() : null, 'activityId' => !empty($activity) ? $activity->getId() : null, 'activityNodeId' => !empty($activity) ? $activity->getResourceNode()->getId() : null, 'order' => $step->getOrder(), 'lvl' => $step->getLvl(), 'inheritedResources' => array());
     $inheritedResources = $step->getInheritedResources();
     foreach ($inheritedResources as $inherited) {
         $data['inheritedResources'][] = array('resource' => $inherited->getResource()->getId(), 'lvl' => $inherited->getLvl());
     }
     return $data;
 }
 /**
  * Manage resource inheritance
  * @param  \Innova\PathBundle\Entity\Step               $step
  * @param  array                                        $propagatedResources
  * @param  array                                        $excludedResources
  * @return \Innova\PathBundle\Manager\PublishingManager
  */
 protected function publishPropagatedResources(Step $step, array $propagatedResources = array(), array $excludedResources = array())
 {
     $inheritedResources = array();
     $currentInherited = $step->getInheritedResources();
     if (!empty($propagatedResources)) {
         foreach ($propagatedResources as $resource) {
             if (!in_array($resource['id'], $excludedResources)) {
                 // Resource is not excluded => link it to step
                 // Retrieve resource node
                 $resourceNode = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneById($resource['resourceId']);
                 if (!($inherited = $step->hasInheritedResource($resourceNode->getId()))) {
                     // Inherited resource doesn't exist => Create inherited resource
                     $inherited = new InheritedResource();
                 }
                 // Update inherited resource properties
                 $inherited->setResource($resourceNode);
                 $inherited->setLvl($resource['lvl']);
                 // Add inherited resource to Step
                 $step->addInheritedResource($inherited);
                 $this->om->persist($inherited);
                 // Store resource ID to clean step
                 $inheritedResources[] = $resourceNode->getId();
             }
         }
     }
     // Clean inherited resources which no long exists
     foreach ($currentInherited as $inherited) {
         $resourceId = $inherited->getResource()->getId();
         if (!in_array($resourceId, $inheritedResources)) {
             $step->removeInheritedResource($inherited);
             $this->om->remove($inherited);
         }
     }
     return $this;
 }