vendor/pimcore/pimcore/models/Document/Page.php line 27

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @category   Pimcore
  12.  * @package    Document
  13.  *
  14.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  15.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  16.  */
  17. namespace Pimcore\Model\Document;
  18. use Pimcore\Model\Redirect;
  19. use Pimcore\Model\Site;
  20. use Pimcore\Model\Tool\Targeting\TargetGroup;
  21. /**
  22.  * @method \Pimcore\Model\Document\Page\Dao getDao()
  23.  */
  24. class Page extends TargetingDocument
  25. {
  26.     /**
  27.      * Contains the title of the page (meta-title)
  28.      *
  29.      * @var string
  30.      */
  31.     protected $title '';
  32.     /**
  33.      * Contains the description of the page (meta-description)
  34.      *
  35.      * @var string
  36.      */
  37.     protected $description '';
  38.     /**
  39.      * @var array
  40.      */
  41.     protected $metaData = [];
  42.     /**
  43.      * Static type of the document
  44.      *
  45.      * @var string
  46.      */
  47.     protected $type 'page';
  48.     /**
  49.      * @var string
  50.      */
  51.     protected $prettyUrl;
  52.     /**
  53.      * Comma separated IDs of target groups
  54.      *
  55.      * @var string
  56.      */
  57.     protected $targetGroupIds '';
  58.     /**
  59.      * @inheritdoc
  60.      */
  61.     public function delete(bool $isNested false)
  62.     {
  63.         if ($this->getId() == 1) {
  64.             throw new \Exception('root-node cannot be deleted');
  65.         }
  66.         // check for redirects pointing to this document, and delete them too
  67.         $redirects = new Redirect\Listing();
  68.         $redirects->setCondition('target = ?'$this->getId());
  69.         $redirects->load();
  70.         foreach ($redirects->getRedirects() as $redirect) {
  71.             $redirect->delete();
  72.         }
  73.         if ($site Site::getByRootId($this->getId())) {
  74.             $site->delete();
  75.         }
  76.         parent::delete($isNested);
  77.     }
  78.     /**
  79.      * @return string
  80.      */
  81.     public function getDescription()
  82.     {
  83.         return $this->description;
  84.     }
  85.     /**
  86.      * @return string
  87.      */
  88.     public function getTitle()
  89.     {
  90.         return \Pimcore\Tool\Text::removeLineBreaks($this->title);
  91.     }
  92.     /**
  93.      * @param string $description
  94.      *
  95.      * @return $this
  96.      */
  97.     public function setDescription($description)
  98.     {
  99.         $this->description str_replace("\n"' '$description);
  100.         return $this;
  101.     }
  102.     /**
  103.      * @param string $title
  104.      *
  105.      * @return $this
  106.      */
  107.     public function setTitle($title)
  108.     {
  109.         $this->title $title;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @param array $metaData
  114.      *
  115.      * @return $this
  116.      */
  117.     public function setMetaData($metaData)
  118.     {
  119.         $this->metaData $metaData;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return array
  124.      */
  125.     public function getMetaData()
  126.     {
  127.         return $this->metaData;
  128.     }
  129.     /**
  130.      * Returns the full path of the document including the key (path+key)
  131.      *
  132.      * @param bool $force
  133.      *
  134.      * @return string
  135.      */
  136.     public function getFullPath(bool $force false)
  137.     {
  138.         $path parent::getFullPath($force);
  139.         // do not use pretty url's when in admin, the current document is wrapped by a hardlink or this document isn't in the current site
  140.         if (!\Pimcore::inAdmin() && !($this instanceof Hardlink\Wrapper\WrapperInterface) && \Pimcore\Tool\Frontend::isDocumentInCurrentSite($this)) {
  141.             // check for a pretty url
  142.             $prettyUrl $this->getPrettyUrl();
  143.             if (!empty($prettyUrl) && strlen($prettyUrl) > 1) {
  144.                 return $prettyUrl;
  145.             }
  146.         }
  147.         return $path;
  148.     }
  149.     /**
  150.      * @param string $prettyUrl
  151.      *
  152.      * @return $this
  153.      */
  154.     public function setPrettyUrl($prettyUrl)
  155.     {
  156.         $this->prettyUrl '/' trim($prettyUrl' /');
  157.         if (strlen($this->prettyUrl) < 2) {
  158.             $this->prettyUrl null;
  159.         }
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return string
  164.      */
  165.     public function getPrettyUrl()
  166.     {
  167.         return $this->prettyUrl;
  168.     }
  169.     /**
  170.      * Set linked Target Groups as set in properties panel as list of IDs
  171.      *
  172.      * @param string|array $targetGroupIds
  173.      */
  174.     public function setTargetGroupIds($targetGroupIds)
  175.     {
  176.         if (is_array($targetGroupIds)) {
  177.             $targetGroupIds implode(','$targetGroupIds);
  178.         }
  179.         $targetGroupIds trim($targetGroupIds' ,');
  180.         if (!empty($targetGroupIds)) {
  181.             $targetGroupIds ',' $targetGroupIds ',';
  182.         }
  183.         $this->targetGroupIds $targetGroupIds;
  184.     }
  185.     /**
  186.      * Get serialized list of Target Group IDs
  187.      *
  188.      * @return string
  189.      */
  190.     public function getTargetGroupIds(): string
  191.     {
  192.         return $this->targetGroupIds;
  193.     }
  194.     /**
  195.      * Set assigned target groups
  196.      *
  197.      * @param TargetGroup[]|int[] $targetGroups
  198.      */
  199.     public function setTargetGroups(array $targetGroups)
  200.     {
  201.         $ids array_map(function ($targetGroup) {
  202.             if (is_numeric($targetGroup)) {
  203.                 return (int)$targetGroup;
  204.             } elseif ($targetGroup instanceof TargetGroup) {
  205.                 return $targetGroup->getId();
  206.             }
  207.             return null;
  208.         }, $targetGroups);
  209.         $ids array_filter($ids, function ($id) {
  210.             return null !== $id && $id 0;
  211.         });
  212.         $this->setTargetGroupIds($ids);
  213.     }
  214.     /**
  215.      * Return list of assigned target groups (via properties panel)
  216.      *
  217.      * @return TargetGroup[]
  218.      */
  219.     public function getTargetGroups(): array
  220.     {
  221.         $ids explode(','$this->targetGroupIds);
  222.         $targetGroups array_map(function ($id) {
  223.             $id trim($id);
  224.             if (!empty($id)) {
  225.                 $targetGroup TargetGroup::getById($id);
  226.                 if ($targetGroup) {
  227.                     return $targetGroup;
  228.                 }
  229.             }
  230.         }, $ids);
  231.         $targetGroups array_filter($targetGroups);
  232.         return $targetGroups;
  233.     }
  234.     /**
  235.      * @param bool $hdpi
  236.      *
  237.      * @return string
  238.      */
  239.     public function getPreviewImageFilesystemPath($hdpi false)
  240.     {
  241.         $suffix '';
  242.         if ($hdpi) {
  243.             $suffix '@2x';
  244.         }
  245.         return PIMCORE_SYSTEM_TEMP_DIRECTORY '/document-page-previews/document-page-screenshot-' $this->getId() . $suffix '.jpg';
  246.     }
  247. }