vendor/score/cms/src/Entity/Page/Page.php line 28

Open in your IDE?
  1. <?php
  2. namespace Score\CmsBundle\Entity\Page;
  3. use Doctrine\Common\Collections\Criteria;
  4. use Doctrine\Common\Collections\Expr\Comparison;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Score\BaseBundle\Entity\BaseEntity;
  9. use Score\CmsBundle\Entity\Access\Access;
  10. use Score\CmsBundle\Entity\Access\AccessPage;
  11. use Score\CmsBundle\Entity\Block\BlockJoint;
  12. use Score\CmsBundle\Entity\Block\BlockJointPage;
  13. use Score\CmsBundle\Entity\Menu;
  14. use Score\CmsBundle\Entity\Metatag\MetatagPage;
  15. use Score\CmsBundle\Entity\User;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. /**
  18.  * @UniqueEntity("seoId",message="page.seoId.unique")
  19.  * @ORM\Entity(repositoryClass="Score\CmsBundle\Entity\Page\PageRepository")
  20.  * @ORM\Table(name="cms_page")
  21.  * @ORM\HasLifecycleCallbacks()
  22.  */
  23. class Page extends BaseEntity {
  24.     /**
  25.      * @ORM\Column(type="string", length=200)
  26.      */
  27.     protected $name;
  28.     /**
  29.      * @ORM\Column(name="title", type="string", length=200)
  30.      */
  31.     protected $title;
  32.     /**
  33.      * @ORM\Column(name="menu_name", type="string", length=200, nullable = true)
  34.      */
  35.     protected $menuName;
  36.     /**
  37.      * @ORM\Column(type="string", length=200, nullable = true)
  38.      */
  39.     protected $linkName;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
  42.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
  43.      */
  44.     protected $parentPage;
  45.     /**
  46.      * @ORM\Column(type="integer", nullable = true)
  47.      */
  48.     protected $lvl;
  49.     /**
  50.      * @ORM\Column(type="integer", nullable = true)
  51.      */
  52.     protected $sortOrder;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable = true, unique=true)
  55.      */
  56.     protected $seoId;
  57.     /**
  58.      * @ORM\Column(name="content", type="text", length=10000, nullable = true)
  59.      */
  60.     protected $content;
  61.     /**
  62.      * @ORM\Column(type="string", length=100, nullable = true)
  63.      */
  64.     protected $status;
  65.     /**
  66.      * @ORM\Column(type="string", nullable = true)
  67.      */
  68.     protected $lang;
  69.     /**
  70.      * @ORM\Column(type="integer", nullable = true)
  71.      */
  72.     protected $parentId;
  73.     /**
  74.      * @ORM\Column(name="config_data", type="text", length=10000, nullable = true)
  75.      */
  76.     protected $configData;
  77.     /**
  78.      * @ORM\Column(type="string", length=100, nullable = true)
  79.      */
  80.     protected $layout;
  81.     protected $keywordItemPage;
  82.     /**
  83.      * @ORM\Column(type="string", length=2000, nullable = true)
  84.      */
  85.     protected $redirectUrl;
  86.     /**
  87.      * @ORM\Column(type="string", length=100, nullable = true)
  88.      */
  89.     protected $redirectWindow;
  90.     /**
  91.      * @ORM\Column(type="string", length=1000, nullable = true)
  92.      */
  93.     protected $icon;
  94.     /**
  95.      * @ORM\Column(type="string", length=2000, nullable = true)
  96.      */
  97.     protected $teaser;
  98.     /**
  99.      * @ORM\OneToMany(targetEntity="\Score\CmsBundle\Entity\Multisite\SiteItemPage", mappedBy="page",cascade={"persist","remove"})
  100.      */
  101.     protected $siteItemPage = [];
  102.     /**
  103.      * @ORM\Column(name="p_search", type="text", nullable=true)
  104.      */
  105.     protected $search;
  106.     protected $multisite;
  107.     /**
  108.      * @ORM\OneToMany(targetEntity=AccessPage::class, mappedBy="page", cascade={"persist", "remove"}, orphanRemoval=true)
  109.      */
  110.     protected $accesses;
  111.     /**
  112.      * @ORM\OneToMany(targetEntity=BlockJointPage::class, mappedBy="page", cascade={"persist", "remove"}, orphanRemoval=true)
  113.      * @ORM\OrderBy({"sortOrder"="ASC", "place"="ASC"})
  114.      */
  115.     protected $blockJoints;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity="Page", mappedBy="parentPage")
  118.      * @ORM\OrderBy({"sortOrder"="ASC"})
  119.      */
  120.     protected $children;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity=MetatagPage::class, mappedBy="page", cascade={"persist", "remove"}, orphanRemoval=true)
  123.      */
  124.     protected $metatags;
  125.     /**
  126.      * @ORM\ManyToOne(targetEntity="Page", inversedBy="redirectedPages")
  127.      * @ORM\JoinColumn(name="redirect_to_id", referencedColumnName="id", nullable=true)
  128.      */
  129.     protected $redirectToPage;
  130.     /**
  131.      * @ORM\OneToMany(targetEntity="Page", mappedBy="redirectToPage")
  132.      */
  133.     protected $redirectedPages;
  134.     /**
  135.      * @ORM\Column(type="string", name="user_id", length=255, nullable=true)
  136.      */
  137.     protected $userId;
  138.     /**
  139.      * @ORM\OneToMany(targetEntity=Menu::class, mappedBy="page", cascade={"persist", "remove"}, orphanRemoval=true)
  140.      */
  141.     protected $menus;
  142.     /**
  143.      * Constructor
  144.      */
  145.     public function __construct() {
  146.         $this->accesses = new ArrayCollection();
  147.         $this->blockJoints = new ArrayCollection();
  148.         $this->metatags = new ArrayCollection();
  149.         $this->children = new ArrayCollection();
  150.         $this->redirectedPages = new ArrayCollection();
  151.         $this->menus = new ArrayCollection();
  152.     }
  153.     public function __toString() {
  154.         return $this->getLvlPrefix() . $this->getName();
  155.     }
  156.     public function getKeywordItemPage() {
  157.         return $this->keywordItemPage;
  158.     }
  159.     public function setKeywordItemPage($keywordItemPage) {
  160.         $this->keywordItemPage = $keywordItemPage;
  161.         return $this;
  162.     }
  163.     public function getLayout() {
  164.         return $this->layout;
  165.     }
  166.     public function setLayout($layout) {
  167.         $this->layout = $layout;
  168.         return $this;
  169.     }
  170.     /**
  171.      * Set name
  172.      *
  173.      * @param string $name
  174.      * @return Page
  175.      */
  176.     public function setName($name) {
  177.         $this->name = $name;
  178.         return $this;
  179.     }
  180.     /**
  181.      * Get name
  182.      *
  183.      * @return string
  184.      */
  185.     public function getName() {
  186.         return $this->name;
  187.     }
  188.     /**
  189.      * Set title
  190.      *
  191.      * @param string $title
  192.      * @return Page
  193.      */
  194.     public function setTitle($title) {
  195.         $this->title = $title;
  196.         return $this;
  197.     }
  198.     /**
  199.      * Get title
  200.      *
  201.      * @return string
  202.      */
  203.     public function getTitle() {
  204.         return $this->title;
  205.     }
  206.     /**
  207.      * Get menuName
  208.      *
  209.      * @return string
  210.      */
  211.     public function getMenuName() {
  212.         return $this->menuName;
  213.     }
  214.     /**
  215.      * Set menuName
  216.      *
  217.      * @param string $menuName
  218.      * @return Page
  219.      */
  220.     public function setMenuName($menuName) {
  221.         $this->menuName = $menuName;
  222.         return $this;
  223.     }
  224.     /**
  225.      * Set linkName
  226.      *
  227.      * @param string $linkName
  228.      * @return Page
  229.      */
  230.     public function setLinkName($linkName) {
  231.         $this->linkName = $linkName;
  232.         return $this;
  233.     }
  234.     /**
  235.      * Get linkName
  236.      *
  237.      * @return string
  238.      */
  239.     public function getLinkName() {
  240.         return $this->linkName;
  241.     }
  242.     /**
  243.      * Set lvl
  244.      *
  245.      * @param integer $lvl
  246.      * @return Page
  247.      */
  248.     public function setLvl($lvl) {
  249.         $this->lvl = $lvl;
  250.         return $this;
  251.     }
  252.     /**
  253.      * Get lvl
  254.      *
  255.      * @return integer
  256.      */
  257.     public function getLvl() {
  258.         return $this->lvl;
  259.     }
  260.     /**
  261.      * Set sortOrder
  262.      *
  263.      * @param integer $sortOrder
  264.      * @return Page
  265.      */
  266.     public function setSortOrder($sortOrder) {
  267.         $this->sortOrder = $sortOrder;
  268.         return $this;
  269.     }
  270.     /**
  271.      * Get sortOrder
  272.      *
  273.      * @return integer
  274.      */
  275.     public function getSortOrder() {
  276.         return $this->sortOrder;
  277.     }
  278.     /**
  279.      * Set seoId
  280.      *
  281.      * @param string $seoId
  282.      * @return Page
  283.      */
  284.     public function setSeoId($seoId) {
  285.         $this->seoId = $seoId;
  286.         return $this;
  287.     }
  288.     /**
  289.      * Get seoId
  290.      *
  291.      * @return string
  292.      */
  293.     public function getSeoId() {
  294.         return $this->seoId;
  295.     }
  296.     /**
  297.      * Set content
  298.      *
  299.      * @param string $content
  300.      * @return Page
  301.      */
  302.     public function setContent($content) {
  303.         $this->content = $content;
  304.         return $this;
  305.     }
  306.     /**
  307.      * Get content
  308.      *
  309.      * @return string
  310.      */
  311.     public function getContent() {
  312.         return $this->content;
  313.     }
  314.     /**
  315.      * Set status
  316.      *
  317.      * @param string $status
  318.      * @return Page
  319.      */
  320.     public function setStatus($status) {
  321.         $this->status = $status;
  322.         return $this;
  323.     }
  324.     /**
  325.      * Get status
  326.      *
  327.      * @return string
  328.      */
  329.     public function getStatus() {
  330.         return $this->status;
  331.     }
  332.     /**
  333.      * Set lang
  334.      *
  335.      * @param string $lang
  336.      * @return Page
  337.      */
  338.     public function setLang($lang) {
  339.         $this->lang = $lang;
  340.         return $this;
  341.     }
  342.     /**
  343.      * Get lang
  344.      *
  345.      * @return string
  346.      */
  347.     public function getLang() {
  348.         return $this->lang;
  349.     }
  350.     /**
  351.      * Set parentPage
  352.      *
  353.      * @param Page $parentPage
  354.      * @return Page
  355.      */
  356.     public function setParentPage(Page $parentPage = null) {
  357.         $this->parentPage = $parentPage;
  358.         return $this;
  359.     }
  360.     /**
  361.      * Get parentPage
  362.      *
  363.      * @return Page
  364.      */
  365.     public function getParentPage() {
  366.         return $this->parentPage;
  367.     }
  368.     function getParentId() {
  369.         return $this->parentId;
  370.     }
  371.     function setParentId($parentId) {
  372.         $this->parentId = $parentId;
  373.     }
  374.     public function getRedirectUrl() {
  375.         return $this->redirectUrl;
  376.     }
  377.     public function getRedirectWindow() {
  378.         return $this->redirectWindow;
  379.     }
  380.     public function getIcon() {
  381.         return $this->icon;
  382.     }
  383.     public function iconThumb($width, $height) {
  384.         if (!$this->getIcon()) {
  385.             return '';
  386. //            return 'default_' . $width . 'x' . $height . '.png';
  387.         }
  388.         $parts = explode('.', $this->getIcon());
  389.         $extension = end($parts);
  390.         return str_replace('.' . $extension, '', $this->getIcon()) . '_thumb_' . $width . 'x' . $height . '.' . $extension;
  391.     }
  392.     public function getTeaser() {
  393.         return $this->teaser;
  394.     }
  395.     public function setRedirectUrl($redirectUrl) {
  396.         $this->redirectUrl = $redirectUrl;
  397.     }
  398.     public function setRedirectWindow($redirectWindow) {
  399.         $this->redirectWindow = $redirectWindow;
  400.     }
  401.     public function setIcon($icon) {
  402.         $this->icon = $icon;
  403.     }
  404.     public function setTeaser($teaser) {
  405.         $this->teaser = $teaser;
  406.     }
  407.     public function getLvlPrefix() {
  408.         if (!$this->getLvl()) return "";
  409.         return str_repeat('- ', $this->getLvl() - 1);
  410.     }
  411.     public function hasLeftBar() {
  412.         if ('menu-left-center-right' == $this->getLayout() or 'menu-left-center' == $this->getLayout()) {
  413.             return true;
  414.         }
  415.     }
  416.     public function hasRightBar() {
  417.         if ('menu-left-center-right' == $this->getLayout() or 'menu-center-right' == $this->getLayout()) {
  418.             return true;
  419.         }
  420.     }
  421.     function getConfigData() {
  422.         return $this->configData;
  423.     }
  424.     function setConfigData($configData): void {
  425.         $this->configData = $configData;
  426.     }
  427.     /**
  428.      * Get the value of siteItemPage
  429.      */
  430.     public function getSiteItemPage() {
  431.         return $this->siteItemPage;
  432.     }
  433.     /**
  434.      * Set the value of siteItemPage
  435.      *
  436.      * @return  self
  437.      */
  438.     public function setSiteItemPage($siteItemPage) {
  439.         $this->siteItemPage = $siteItemPage;
  440.         return $this;
  441.     }
  442.     /**
  443.      * Get the value of multisite
  444.      */
  445.     public function getMultisite() {
  446.         return $this->multisite;
  447.     }
  448.     /**
  449.      * Set the value of multisite
  450.      *
  451.      * @return  self
  452.      */
  453.     public function setMultisite($multisite) {
  454.         $this->multisite = $multisite;
  455.         return $this;
  456.     }
  457.     /**
  458.      * Get the value of search
  459.      */
  460.     public function getSearch() {
  461.         return $this->search;
  462.     }
  463.     /**
  464.      * Set the value of search
  465.      *
  466.      * @return  self
  467.      */
  468.     public function setSearch($search) {
  469.         $this->search = $search;
  470.         return $this;
  471.     }
  472.     /**
  473.      * @return Collection<int, Access>
  474.      */
  475.     public function getAccesses(): Collection {
  476.         return $this->accesses;
  477.     }
  478.     public function addAccess(AccessPage $access): self {
  479.         if (!$this->accesses->contains($access)) {
  480.             $this->accesses[] = $access;
  481.             $access->setPage($this);
  482.         }
  483.         return $this;
  484.     }
  485.     public function removeAccess(Access $access): self {
  486.         $this->accesses->removeElement($access);
  487.         //$access->setPage(null);
  488.         return $this;
  489.     }
  490.     /**
  491.      * @return Collection<int, BlockJointPage>
  492.      */
  493.     public function getBlockJoints(): Collection {
  494.         return $this->blockJoints;
  495.     }
  496.     public function addBlockJoint(BlockJointPage $blockJoint): self {
  497.         if (!$this->blockJoints->contains($blockJoint)) {
  498.             $this->blockJoints[] = $blockJoint;
  499.             $blockJoint->setPage($this);
  500.         }
  501.         return $this;
  502.     }
  503.     public function removeBlockJoint(BlockJoint $blockJoint): self {
  504.         $this->blockJoints->removeElement($blockJoint);
  505.         return $this;
  506.     }
  507.     public function getChildren() {
  508.         return $this->children;
  509.     }
  510.     public function getAllChildren() {
  511.         $children = $this->getChildren()->toArray();
  512.         $subChildren = [];
  513.         foreach ($this->getChildren() as $ch) {
  514.             foreach ($ch->getAllChildren() as $sub) {
  515.                 $subChildren[] = $sub;
  516.             }
  517.         }
  518.         $colection = new ArrayCollection(
  519.             array_merge($children, $subChildren)
  520.         );
  521.         return $colection;
  522.     }
  523.     public function getAllParents($withRoot = false) {
  524.         $parent = $this->getParentPage();
  525.         $parents = [];
  526.         while ($parent) {
  527.             if ($parent->getName() !== "root" || $withRoot) {
  528.                 $parents[] = $parent;
  529.             }
  530.             $parent = $parent->getParentPage();
  531.         }
  532.         $colection = new ArrayCollection($parents);
  533.         return $colection;
  534.     }
  535.     /**
  536.      * @return Collection<int, MetatagPage>
  537.      */
  538.     public function getMetatags(): Collection {
  539.         return $this->metatags;
  540.     }
  541.     public function addMetatag(MetatagPage $metatag): self {
  542.         if (!$this->metatags->contains($metatag)) {
  543.             $this->metatags[] = $metatag;
  544.             $metatag->setPage($this);
  545.         }
  546.         return $this;
  547.     }
  548.     public function removeMetatag(MetatagPage $metatag): self {
  549.         $this->metatags->removeElement($metatag);
  550.         return $this;
  551.     }
  552.     public function setRedirectToPage(Page $redirectToPage = null) {
  553.         $this->redirectToPage = $redirectToPage;
  554.         return $this;
  555.     }
  556.     /**
  557.      * @return Page
  558.      */
  559.     public function getRedirectToPage() {
  560.         return $this->redirectToPage;
  561.     }
  562.     /**
  563.      * @return Collection<int, Page>
  564.      */
  565.     public function getRedirectedPages() {
  566.         return $this->redirectedPages;
  567.     }
  568.     public function setUserId($userId) {
  569.         $this->userId = $userId;
  570.         return $this;
  571.     }
  572.     public function getUserId() {
  573.         return $this->userId;
  574.     }
  575.     /**
  576.      * @return Collection<int, Menu>
  577.      */
  578.     public function getMenus(): Collection {
  579.         return $this->menus;
  580.     }
  581.     public function addMenu(Menu $menu): self {
  582.         if (!$this->menus->contains($menu)) {
  583.             $this->menus[] = $menu;
  584.             $menu->setPage($this);
  585.         }
  586.         return $this;
  587.     }
  588.     public function removeMenu(Menu $menu): self {
  589.         $this->menus->removeElement($menu);
  590.         return $this;
  591.     }
  592. }