src/Cms/FileBundle/Entity/Node.php line 48

Open in your IDE?
  1. <?php
  2. namespace Cms\FileBundle\Entity;
  3. use Cms\ContainerBundle\Entity\Container;
  4. use Cms\CoreBundle\Model\Interfaces\Nestable\NestableInterface;
  5. use Cms\CoreBundle\Model\Interfaces\Nestable\NestableTrait;
  6. use Cms\FileBundle\Entity\Nodes\File;
  7. use Cms\FileBundle\Entity\Nodes\Files\DocumentFile;
  8. use Cms\FileBundle\Entity\Nodes\Files\GenericFile;
  9. use Cms\FileBundle\Entity\Nodes\Files\ImageFile;
  10. use Cms\FileBundle\Entity\Nodes\Folder;
  11. use Cms\TenantBundle\Entity\TenantedEntity;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. /**
  16.  * Represents a "filesystem" object, like a folder or file.
  17.  * Nodes are stored as trees, just as a real filesystem would.
  18.  *
  19.  * Class Node
  20.  * @package Cms\FileBundle\Entity
  21.  *
  22.  * @ORM\Entity(repositoryClass = "Cms\FileBundle\Doctrine\NodeRepository")
  23.  * @ORM\InheritanceType("SINGLE_TABLE")
  24.  * @ORM\DiscriminatorColumn(name = "_discr", type = "string")
  25.  * @ORM\DiscriminatorMap({
  26.  *     "folder" = "Cms\FileBundle\Entity\Nodes\Folder",
  27.  *     "file" = "Cms\FileBundle\Entity\Nodes\File",
  28.  *     "generic" = "Cms\FileBundle\Entity\Nodes\Files\GenericFile",
  29.  *     "image" = "Cms\FileBundle\Entity\Nodes\Files\ImageFile",
  30.  *     "document" = "Cms\FileBundle\Entity\Nodes\Files\DocumentFile",
  31.  * })
  32.  * @ORM\Table(
  33.  *      name = "cms__file__node",
  34.  *      indexes = {
  35.  *          @ORM\Index(
  36.  *              name = "idx__name",
  37.  *              columns = {
  38.  *                  "name"
  39.  *              }
  40.  *          )
  41.  *      }
  42.  * )
  43.  * @Gedmo\Tree(type = "nested")
  44.  */
  45. abstract class Node extends TenantedEntity implements NestableInterface
  46. {
  47.     const DISCRS = [
  48.         Folder::DISCR => Folder::class,
  49.         File::DISCR => File::class,
  50.         GenericFile::DISCR => GenericFile::class,
  51.         ImageFile::DISCR => ImageFile::class,
  52.         DocumentFile::DISCR => DocumentFile::class,
  53.     ];
  54.     const DISCR null;
  55.     const TYPE null;
  56.     /**
  57.      * Basic tree-related fields.
  58.      */
  59.     use NestableTrait;
  60.     /**
  61.      * The Node that acts as the parent for this one.
  62.      * If no parent is given, then this Node is a "root" level node.
  63.      *
  64.      * @var Node
  65.      *
  66.      * @ORM\ManyToOne(targetEntity = "Node", inversedBy = "children")
  67.      * @ORM\JoinColumn(name = "parent", referencedColumnName = "id", onDelete = "CASCADE")
  68.      * @Gedmo\TreeParent
  69.      */
  70.     protected $parent;
  71.     /**
  72.      * The direct descendant Nodes of this one.
  73.      *
  74.      * @var ArrayCollection|Node[]
  75.      *
  76.      * @ORM\OneToMany(targetEntity = "Node", mappedBy = "parent")
  77.      */
  78.     protected $children;
  79.     /**
  80.      * The Container that this item is tied to.
  81.      * ALL Nodes MUST be tied to some Container in the system.
  82.      * This needs to be set on every Node.
  83.      * However, descendant Nodes MUST have the same Container as their "root".
  84.      *
  85.      * @var Container|null
  86.      *
  87.      * @ORM\ManyToOne(targetEntity = "Cms\ContainerBundle\Entity\Container")
  88.      * @ORM\JoinColumn(name = "container", referencedColumnName = "id", onDelete = "SET NULL")
  89.      */
  90.     protected $container;
  91.     /**
  92.      * @var string
  93.      *
  94.      * @ORM\Column(
  95.      *  type = "string",
  96.      *  nullable = false
  97.      * )
  98.      */
  99.     protected $name;
  100.     /**
  101.      * {@inheritdoc}
  102.      */
  103.     public function __construct()
  104.     {
  105.         $this->children = new ArrayCollection();
  106.     }
  107.     /**
  108.      * @return string
  109.      */
  110.     public function getType()
  111.     {
  112.         if (static::TYPE === null) {
  113.             throw new \Exception();
  114.         }
  115.         return static::TYPE;
  116.     }
  117.     /**
  118.      * {@inheritdoc}
  119.      * @return Node
  120.      */
  121.     public function getParent()
  122.     {
  123.         return $this->parent;
  124.     }
  125.     /**
  126.      * {@inheritdoc}
  127.      * @return ArrayCollection|Node[]
  128.      */
  129.     public function getChildren()
  130.     {
  131.         return $this->children;
  132.     }
  133.     /**
  134.      * @return Container|null
  135.      */
  136.     public function getContainer()
  137.     {
  138.         return $this->container;
  139.     }
  140.     /**
  141.      * {@inheritdoc}
  142.      * @param Node $value
  143.      */
  144.     public function setParent(NestableInterface $value null)
  145.     {
  146.         $this->parent $value;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @param Container|null $value
  151.      * @return $this
  152.      */
  153.     public function setContainer(?Container $value)
  154.     {
  155.         $this->container $value;
  156.         return $this;
  157.     }
  158.     /**
  159.      * {@inheritdoc}
  160.      */
  161.     public function getName()
  162.     {
  163.         return $this->name;
  164.     }
  165.     /**
  166.      * {@inheritdoc}
  167.      */
  168.     public function setName($value)
  169.     {
  170.         $this->name $value;
  171.         return $this;
  172.     }
  173.     /**
  174.      * @return string
  175.      */
  176.     public function ui()
  177.     {
  178.         return $this->getName();
  179.     }
  180. }