1 <?php
 2 
 3 /**
 4  * REX_CATEGORY[xzy]
 5  * REX_CATEGORY[field=xzy]
 6  * REX_CATEGORY[field=xzy id=3]
 7  * REX_CATEGORY[field=xzy id=3 clang=2].
 8  *
 9  * Attribute:
10  *   - field    => Feld der Kategorie, das ausgegeben werden soll
11  *   - clang    => ClangId der Kategorie
12  *
13  * @package redaxo\structure
14  */
15 class rex_var_category extends rex_var
16 {
17     /**
18      * Werte für die Ausgabe.
19      */
20     protected function getOutput()
21     {
22         $field = $this->getParsedArg('field');
23         if (!$field) {
24             return false;
25         }
26 
27         $category_id = $this->getParsedArg('id', '$this->getValue(\'category_id\')');
28         $clang = $this->getParsedArg('clang', 'null');
29 
30         return self::class . '::getCategoryValue(' . $category_id . ', ' . $field . ', ' . $clang . ')';
31     }
32 
33     public static function getCategoryValue($id, $field, $clang = null)
34     {
35         if ($clang === null) {
36             $clang = rex_clang::getCurrentId();
37         }
38         $cat = rex_category::get($id, $clang);
39         if ($cat) {
40             return rex_escape($cat->getValue($field));
41         }
42     }
43 }
44