1 <?php
  2 
  3 /**
  4  * Object Oriented Framework: Bildet einen Artikel der Struktur ab.
  5  *
  6  * @package redaxo\structure
  7  */
  8 class rex_article extends rex_structure_element
  9 {
 10     /**
 11      * Return the current article id.
 12      *
 13      * @return int
 14      */
 15     public static function getCurrentId()
 16     {
 17         return rex_addon::get('structure')->getProperty('article_id', 1);
 18     }
 19 
 20     /**
 21      * Return the current article.
 22      *
 23      * @param int $clang
 24      *
 25      * @return null|self
 26      */
 27     public static function getCurrent($clang = null)
 28     {
 29         return self::get(self::getCurrentId(), $clang);
 30     }
 31 
 32     /**
 33      * Return the site wide start article id.
 34      *
 35      * @return int
 36      */
 37     public static function getSiteStartArticleId()
 38     {
 39         return rex_addon::get('structure')->getProperty('start_article_id', 1);
 40     }
 41 
 42     /**
 43      * Return the site wide start article.
 44      *
 45      * @param int $clang
 46      *
 47      * @return self|null
 48      */
 49     public static function getSiteStartArticle($clang = null)
 50     {
 51         return self::get(self::getSiteStartArticleId(), $clang);
 52     }
 53 
 54     /**
 55      * Return the site wide notfound article id.
 56      *
 57      * @return int
 58      */
 59     public static function getNotfoundArticleId()
 60     {
 61         return rex_addon::get('structure')->getProperty('notfound_article_id', 1);
 62     }
 63 
 64     /**
 65      * Return the site wide notfound article.
 66      *
 67      * @param int $clang
 68      *
 69      * @return self
 70      */
 71     public static function getNotfoundArticle($clang = null)
 72     {
 73         return self::get(self::getNotfoundArticleId(), $clang);
 74     }
 75 
 76     /**
 77      * Return a list of top-level articles.
 78      *
 79      * @param bool $ignoreOfflines
 80      * @param int  $clang
 81      *
 82      * @return self[]
 83      */
 84     public static function getRootArticles($ignoreOfflines = false, $clang = null)
 85     {
 86         return self::getChildElements(0, 'alist', $ignoreOfflines, $clang);
 87     }
 88 
 89     /**
 90      * Returns the category id.
 91      *
 92      * @return int
 93      */
 94     public function getCategoryId()
 95     {
 96         return $this->isStartArticle() ? $this->getId() : $this->getParentId();
 97     }
 98 
 99     /**
100      * Returns the parent category.
101      *
102      * @return rex_category
103      */
104     public function getCategory()
105     {
106         return rex_category::get($this->getCategoryId(), $this->getClang());
107     }
108 
109     /**
110      * Returns the parent object of the article.
111      *
112      * @return self
113      */
114     public function getParent()
115     {
116         return self::get($this->parent_id, $this->clang_id);
117     }
118 
119     /**
120      * Returns the path of the category/article.
121      *
122      * @return string
123      */
124     public function getPath()
125     {
126         if ($this->isStartArticle()) {
127             return $this->path . $this->id . '|';
128         }
129 
130         return $this->path;
131     }
132 
133     /**
134      * {@inheritdoc}
135      */
136     public function getValue($value)
137     {
138         if ('category_id' === $value) {
139             // für die CatId hier den Getter verwenden,
140             // da dort je nach ArtikelTyp unterscheidungen getroffen werden müssen
141             return $this->getCategoryId();
142         }
143         return parent::getValue($value);
144     }
145 
146     /**
147      * @param string $value
148      *
149      * @return bool
150      */
151     public static function hasValue($value)
152     {
153         return parent::_hasValue($value, ['art_']);
154     }
155 
156     /**
157      * {@inheritdoc}
158      */
159     public function isPermitted()
160     {
161         return (bool) rex_extension::registerPoint(new rex_extension_point('ART_IS_PERMITTED', true, ['element' => $this]));
162     }
163 }
164