1: <?php
2:
3: /**
4: * This file contains the select box class for the plugin content allocation.
5: *
6: * @package Plugin
7: * @subpackage ContentAllocation
8: * @author Marco Jahn
9: * @copyright four for business AG <www.4fb.de>
10: * @license http://www.contenido.org/license/LIZENZ.txt
11: * @link http://www.4fb.de
12: * @link http://www.contenido.org
13: */
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: plugin_include('repository', 'custom/FrontendNavigation.php');
18:
19: /**
20: * Select box class for content allocation
21: *
22: * @package Plugin
23: * @subpackage ContentAllocation
24: */
25: class pApiContentAllocationSelectBox extends pApiTree {
26:
27: /**
28: * @var bool
29: */
30: protected $_idSetter = true;
31:
32: /**
33: * @var array
34: */
35: protected $_load = array();
36:
37: /**
38: * pApiContentAllocationSelectBox constructor
39: *
40: * @param string $uuid
41: *
42: * @throws cDbException
43: * @throws cException
44: */
45: public function __construct($uuid) {
46: parent::__construct($uuid);
47: }
48:
49: /**
50: * Old constructor
51: *
52: * @deprecated [2016-02-11]
53: * This method is deprecated and is not needed any longer. Please use __construct() as constructor function.
54: *
55: * @param string $uuid
56: *
57: * @return pApiContentAllocationSelectBox
58: * @throws cDbException
59: * @throws cException
60: */
61: public function pApiContentAllocationSelectBox($uuid) {
62: cDeprecated('This method is deprecated and is not needed any longer. Please use __construct() as constructor function.');
63: return $this->__construct($uuid);
64: }
65:
66: /**
67: * Builed an render tree
68: *
69: * @param $tree
70: * @return string
71: */
72: protected function _buildRenderTree($tree) {
73:
74: $this->_idSetter = false;
75: $result = '';
76:
77: foreach ($tree as $item_tmp) {
78: $spacer = '|-';
79: $spacer = str_pad($spacer, (($item_tmp['level'] + 1) * 2), "--", STR_PAD_RIGHT);
80:
81: $result .= '<option value="'.$item_tmp['idpica_alloc'].'_'.$item_tmp['level'].'">'.$spacer . $item_tmp['name'].'</option>';
82:
83: if ($item_tmp['children']) {
84: $children = $this->_buildRenderTree($item_tmp['children']);
85: $result .= $children;
86: }
87: }
88:
89: return $result;
90: }
91:
92: /**
93: * Old function
94: *
95: * @deprecated [2016-02-11]
96: * This method is deprecated and is not needed any longer. *
97: * @param null $load
98: * @return bool
99: */
100: public function setChecked($load = null) {
101: cDeprecated('This method is deprecated and is not needed any longer.');
102: return false;
103: }
104:
105: /**
106: * Render tree
107: *
108: * @param bool $return
109: * @param mixed $parentId
110: * @param bool $useTreeStatus (if true use expand/collapsed status of the tree, otherwise not)
111: *
112: * @return bool|object
113: * @throws cDbException
114: */
115: public function renderTree($return = true, $parentId = false, $useTreeStatus = false) {
116:
117: $tree = $this->fetchTree($parentId, 0, $useTreeStatus);
118:
119: if ($tree === false) {
120: return false;
121: }
122:
123: $tree = $this->_buildRenderTree($tree);
124:
125: if ($return === true) {
126: return $tree;
127: } else {
128: echo $tree;
129: }
130: }
131: }
132: