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

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