예제 #1
0
 /**
  * Replace a node icon.
  *
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $resource
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceIcon $icon
  *
  * @return \Claroline\CoreBundle\Entity\Resource\ResourceNode
  */
 public function replace(ResourceNode $resource, ResourceIcon $icon)
 {
     $this->om->startFlushSuite();
     $oldIcon = $resource->getIcon();
     if (!$oldIcon->isShortcut()) {
         $oldShortcutIcon = $oldIcon->getShortcutIcon();
         $shortcutIcon = $icon->getShortcutIcon();
         if (!is_null($oldShortcutIcon) && !is_null($shortcutIcon)) {
             $nodes = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findBy(array('icon' => $oldShortcutIcon));
             foreach ($nodes as $node) {
                 $node->setIcon($shortcutIcon);
                 $this->om->persist($node);
             }
         }
     }
     $this->delete($oldIcon);
     $resource->setIcon($icon);
     $this->om->persist($resource);
     $this->om->endFlushSuite();
     return $resource;
 }