Ejemplo n.º 1
0
 protected function syncMaterialTree($materialTree, Bubble $parent, $cid)
 {
     $em = $this->getEntityManager();
     $l2p = $this->getClient();
     $owner = $this->getAuthService()->getIdentity();
     foreach ($materialTree as $material) {
         // find child matching material
         $children = $parent->getChildren();
         $found = null;
         if ($children) {
             foreach ($children as $child) {
                 /* @var $child Edge */
                 $childBubble = $child->getTo();
                 if ($material->isDirectory && $childBubble instanceof L2PMaterialFolder && $childBubble->getL2pItemId() == $material->itemId || !$material->isDirectory && $childBubble instanceof L2PMaterialAttachment && $childBubble->getL2pItemId() == $material->itemId) {
                     $found = $childBubble;
                     break;
                 }
             }
         }
         if (!$found) {
             if ($material->isDirectory) {
                 $instance = new L2PMaterialFolder();
             } else {
                 $instance = new L2PMaterialAttachment();
                 $instance->setFilename($this->getMaterialDownloadUrl($material, $cid));
             }
             $instance->setL2pItemId($material->itemId)->setTitle($material->name)->setOwner($owner);
             $em->persist($instance);
             $em->flush($instance);
             $edge = new Edge();
             $edge->setFrom($parent)->setTo($instance);
             $em->persist($edge);
             $em->flush($edge);
             $found = $instance;
         } else {
             $found->setTitle($material->name);
             if (!$material->isDirectory) {
                 $found->setFilename($this->getMaterialDownloadUrl($material, $cid));
             }
             $em->flush($found);
         }
         if ($material->isDirectory) {
             $this->syncMaterialTree($material->children, $found, $cid);
         }
     }
     return true;
 }