Exemplo n.º 1
0
 /**
  * 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;
 }