|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
/** |
|
12
|
|
|
* WfdownloadsObjectTree |
|
13
|
|
|
* |
|
14
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
15
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
|
16
|
|
|
* @author lucio <[email protected]> |
|
17
|
|
|
* @package Wfdownloads |
|
18
|
|
|
* @since 3.23 |
|
19
|
|
|
* @version $Id:$ |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
defined('XOOPS_ROOT_PATH') || die('XOOPS root path not defined'); |
|
23
|
|
|
|
|
24
|
|
|
//xoops_load('XoopsObjectTree'); |
|
25
|
|
|
include_once XOOPS_ROOT_PATH . '/class/tree.php'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Form element that ... |
|
29
|
|
|
*/ |
|
30
|
|
|
class WfdownloadsObjectTree extends XoopsObjectTree |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Make options for a select box from |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $fieldName Name of the member variable from the node objects that should be used as the title for the options. |
|
36
|
|
|
* @param int $key ID of the object to display as the root of select options |
|
37
|
|
|
* @param string $optionsArray (reference to a string when called from outside) Result from previous recursions |
|
38
|
|
|
* @param string $prefix_orig String to indent items at deeper levels |
|
39
|
|
|
* @param string $prefix_curr String to indent the current item |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
@access private |
|
43
|
|
|
*/ |
|
44
|
|
|
public function makeSelBoxOptionsArray($fieldName, $key, &$optionsArray, $prefix_orig, $prefix_curr = '') |
|
45
|
|
|
{ |
|
46
|
|
|
if ($key > 0) { |
|
47
|
|
|
$value = $this->_tree[$key]['obj']->getVar($this->_myId); |
|
48
|
|
|
$optionsArray[$value] = $prefix_curr . $this->_tree[$key]['obj']->getVar($fieldName); |
|
49
|
|
|
$prefix_curr .= $prefix_orig; |
|
50
|
|
|
} |
|
51
|
|
|
if (isset($this->_tree[$key]['child']) && !empty($this->_tree[$key]['child'])) { |
|
52
|
|
|
foreach ($this->_tree[$key]['child'] as $childkey) { |
|
53
|
|
|
$this->makeSelBoxOptionsArray($fieldName, $childkey, $optionsArray, $prefix_orig, $prefix_curr); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $optionsArray; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Make a select box with options from the tree |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $fieldName Name of the member variable from the node objects that should be used as the title for the options. |
|
64
|
|
|
* @param string $prefix String to indent deeper levels |
|
65
|
|
|
* @param bool $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy |
|
66
|
|
|
* @param integer $key ID of the object to display as the root of select options |
|
67
|
|
|
* |
|
68
|
|
|
* @return array $optionsArray Associative array of value->name pairs, useful for {@link XoopsFormSelect}->addOptionArray method |
|
|
|
|
|
|
69
|
|
|
*/ |
|
70
|
|
|
public function makeSelBox($fieldName, $prefix = '-', $addEmptyOption = false, $key = 0) |
|
71
|
|
|
{ |
|
72
|
|
|
$optionsArray = array(); |
|
73
|
|
|
if ($addEmptyOption) { |
|
74
|
|
|
$optionsArray[0] = ''; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $this->makeSelBoxOptionsArray($fieldName, $key, $optionsArray, $prefix); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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.