XoopsModules25x /
oledrion
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | /** |
||
| 3 | * XOOPS tree class |
||
| 4 | * |
||
| 5 | * You may not change or alter any portion of this comment or credits |
||
| 6 | * of supporting developers from this source code or any supporting source code |
||
| 7 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 8 | * This program is distributed in the hope that it will be useful, |
||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 11 | * |
||
| 12 | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
||
| 13 | * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) |
||
| 14 | * @package kernel |
||
| 15 | * @since 2.0.0 |
||
| 16 | * @author Kazumi Ono (http://www.myweb.ne.jp/, http://jp.xoops.org/) |
||
| 17 | */ |
||
| 18 | |||
| 19 | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
||
| 20 | |||
| 21 | require_once __DIR__ . '/../../../class/tree.php'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * A tree structures with {@link XoopsObject}s as nodes |
||
| 25 | * |
||
| 26 | * @package kernel |
||
| 27 | * @subpackage core |
||
| 28 | * @author Kazumi Ono <[email protected]> |
||
| 29 | */ |
||
| 30 | class Oledrion_XoopsObjectTree extends XoopsObjectTree |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 31 | { |
||
| 32 | /** |
||
| 33 | * @access private |
||
| 34 | */ |
||
| 35 | protected $parentId; |
||
| 36 | protected $myId; |
||
| 37 | protected $rootId; |
||
| 38 | protected $tree = array(); |
||
| 39 | protected $objects; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Constructor |
||
| 43 | * |
||
| 44 | * @param array $objectArr Array of {@link XoopsObject}s |
||
| 45 | * @param string $myId field name of object ID |
||
| 46 | * @param string $parentId field name of parent object ID |
||
| 47 | * @param string $rootId field name of root object ID |
||
| 48 | */ |
||
| 49 | public function __construct($objectArr, $myId, $parentId, $rootId = null) |
||
| 50 | { |
||
| 51 | parent::__construct($objectArr, $myId, $parentId, $rootId); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Make a select box with options from the tree |
||
| 56 | * |
||
| 57 | * @param string $name Name of the select box |
||
| 58 | * @param string $fieldName Name of the member variable from the |
||
| 59 | * node objects that should be used as the title for the options. |
||
| 60 | * @param string $prefix String to indent deeper levels |
||
| 61 | * @param string $selected Value to display as selected |
||
| 62 | * @param bool|string $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy |
||
| 63 | * @param integer $key ID of the object to display as the root of select options |
||
| 64 | * @param string $additional |
||
| 65 | * @return string HTML select box |
||
| 66 | * |
||
| 67 | * @deprecated since 2.5.9, please use makeSelectElement() |
||
| 68 | */ |
||
| 69 | public function makeSelBox( |
||
| 70 | $name, |
||
| 71 | $fieldName, |
||
| 72 | $prefix = '-', |
||
| 73 | $selected = '', |
||
| 74 | $addEmptyOption = '', |
||
| 75 | $key = 0, |
||
| 76 | $additional = '' |
||
| 77 | ) { |
||
| 78 | $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
||
| 79 | trigger_error("makeSelBox() is deprecated since 2.5.9, please use makeSelectElement(), accessed from {$trace[0]['file']} line {$trace[0]['line']},"); |
||
| 80 | |||
| 81 | $ret2 = '<select name="' . $name . '" id="' . $name . '" ' . $additional . '>'; //mb needs to test |
||
| 82 | if (false !== (bool)$addEmptyOption) { |
||
| 83 | $ret2 .= '<option value="0"></option>'; |
||
| 84 | } |
||
| 85 | |||
| 86 | $ret = "<select id='" . $name . "' name='" . $name . "'"; |
||
| 87 | if ($additional != '') { |
||
| 88 | $ret .= $additional; |
||
| 89 | } |
||
| 90 | $ret .= '>'; |
||
| 91 | if ($addEmptyOption != '') { |
||
| 92 | $tmpSelected = ''; |
||
| 93 | if ($selected == 0) { |
||
| 94 | $tmpSelected = ' selected'; |
||
| 95 | } |
||
| 96 | $ret .= '<option' . $tmpSelected . ' value="0">' . $addEmptyOption . '</option>'; |
||
| 97 | } |
||
| 98 | |||
| 99 | $this->makeSelBoxOptions($fieldName, $selected, $key, $ret, $prefix); |
||
| 100 | |||
| 101 | return $ret . '</select>'; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Magic __get method |
||
| 106 | * |
||
| 107 | * Some modules did not respect the leading underscore is private convention and broke |
||
| 108 | * when code was modernized. This will keep them running for now. |
||
| 109 | * |
||
| 110 | * @param string $name unknown variable name requested |
||
| 111 | * currently only '_tree' is supported |
||
| 112 | * |
||
| 113 | * @return mixed value |
||
| 114 | */ |
||
| 115 | public function __get($name) |
||
| 116 | { |
||
| 117 | $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
||
| 118 | if ($name === '_tree') { |
||
| 119 | trigger_error("XoopsObjectTree::\$_tree is deprecated, accessed from {$trace[0]['file']} line {$trace[0]['line']},"); |
||
| 120 | |||
| 121 | return $this->tree; |
||
| 122 | } |
||
| 123 | trigger_error('Undefined property: XoopsObjectTree::$' . $name . " in {$trace[0]['file']} line {$trace[0]['line']}, ", E_USER_NOTICE); |
||
| 124 | |||
| 125 | return null; |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Internal function used by makeTreeAsArray |
||
| 130 | * @param $fieldName |
||
| 131 | * @param $key |
||
| 132 | * @param $ret |
||
| 133 | * @param $prefix_orig |
||
| 134 | * @param string $prefix_curr |
||
| 135 | */ |
||
| 136 | public function _recursiveMakeTreeAsArray($fieldName, $key, &$ret, $prefix_orig, $prefix_curr = '') |
||
| 137 | { |
||
| 138 | if ($key > 0) { |
||
| 139 | $value = $this->tree[$key]['obj']->getVar($this->myId); |
||
| 140 | $ret[$value] = $prefix_curr . $this->tree[$key]['obj']->getVar($fieldName); |
||
| 141 | $prefix_curr .= $prefix_orig; |
||
| 142 | } |
||
| 143 | if (isset($this->tree[$key]['child']) && !empty($this->tree[$key]['child'])) { |
||
| 144 | foreach ($this->tree[$key]['child'] as $childkey) { |
||
| 145 | $this->_recursiveMakeTreeAsArray($fieldName, $childkey, $ret, $prefix_orig, $prefix_curr); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Identical function as makeSelBox but returns an array |
||
| 152 | * |
||
| 153 | * @param string $fieldName Name of the member variable from the node objects that should be used as the title for the options. |
||
| 154 | * @param string $prefix String to indent deeper levels |
||
| 155 | * @param integer $key ID of the object to display as the root of select options |
||
| 156 | * @param null $empty |
||
| 157 | * @return array key = object ID, value = $fieldName |
||
| 158 | */ |
||
| 159 | public function makeTreeAsArray($fieldName, $prefix = '-', $key = 0, $empty = null) |
||
| 160 | { |
||
| 161 | $ret = array(); |
||
| 162 | if ($empty != null) { |
||
| 163 | $ret[0] = $empty; |
||
| 164 | } |
||
| 165 | $this->_recursiveMakeTreeAsArray($fieldName, $key, $ret, $prefix); |
||
| 166 | |||
| 167 | return $ret; |
||
| 168 | } |
||
| 169 | } |
||
| 170 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.