/**
  * @covers Kunstmaan\MediaBundle\Entity\Folder::getParent
  * @covers Kunstmaan\MediaBundle\Entity\Folder::setParent
  */
 public function testGetParent()
 {
     $parent = new Folder();
     $parent->setId(45);
     $this->object->setParent($parent);
     $this->assertEquals(45, $this->object->getParent()->getId());
 }
 /**
  * @param Folder $folder The folder
  *
  * @throws \Exception
  */
 public function save(Folder $folder)
 {
     $em = $this->getEntityManager();
     $parent = $folder->getParent();
     $em->beginTransaction();
     try {
         // Find where to insert the new item
         $children = $parent->getChildren(true);
         if ($children->isEmpty()) {
             // No children yet - insert as first child
             $this->persistAsFirstChildOf($folder, $parent);
         } else {
             $previousChild = null;
             foreach ($children as $child) {
                 // Alphabetical sorting - could be nice if we implemented a sorting strategy
                 if (strcasecmp($folder->getName(), $child->getName()) < 0) {
                     break;
                 }
                 $previousChild = $child;
             }
             if (is_null($previousChild)) {
                 $this->persistAsPrevSiblingOf($folder, $children[0]);
             } else {
                 $this->persistAsNextSiblingOf($folder, $previousChild);
             }
         }
         $em->commit();
         $em->flush();
     } catch (\Exception $e) {
         $em->rollback();
         throw $e;
     }
 }
 /**
  * @param Folder $folder The folder
  *
  * @throws \Exception
  */
 public function save(Folder $folder)
 {
     $em = $this->getEntityManager();
     $parent = $folder->getParent();
     $em->beginTransaction();
     try {
         if (!is_null($parent)) {
             $this->persistInOrderedTree($folder, $parent);
         } else {
             $em->persist($folder);
         }
         $em->commit();
         $em->flush();
     } catch (\Exception $e) {
         $em->rollback();
         throw $e;
     }
 }