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
|
|
|
* Pedigree module for XOOPS |
13
|
|
|
* |
14
|
|
|
* @copyright {@link http://xoops.org/ The XOOPS Project} |
15
|
|
|
* @license GPL 2.0 or later |
16
|
|
|
* @package pedigree |
17
|
|
|
* @author XOOPS Module Dev Team |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class PedigreeFields |
24
|
|
|
*/ |
25
|
|
|
class PedigreeFields extends XoopsObject |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Constructor |
29
|
|
|
*/ |
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
$this->initVar('Id', XOBJ_DTYPE_INT, null, false, 2); |
34
|
|
|
$this->initVar('isActive', XOBJ_DTYPE_INT, 1, false, 1); |
35
|
|
|
$this->initVar('fieldName', XOBJ_DTYPE_TXTBOX, null, false, 50); |
36
|
|
|
$this->initVar('fieldType', XOBJ_DTYPE_ENUM, 'textbox', false); |
37
|
|
|
$this->initVar('lookupTable', XOBJ_DTYPE_INT, 0, false, 1); |
38
|
|
|
$this->initVar('defaultValue', XOBJ_DTYPE_TXTBOX, null, false, 50); |
39
|
|
|
$this->initVar('fieldExplanation', XOBJ_DTYPE_TXTAREA, null, false); |
40
|
|
|
$this->initVar('hasSearch', XOBJ_DTYPE_INT, 0, false, 1); |
41
|
|
|
$this->initVar('litter', XOBJ_DTYPE_INT, 0, false, 1); |
42
|
|
|
$this->initVar('generalLitter', XOBJ_DTYPE_INT, 1, false, 1); |
43
|
|
|
$this->initVar('searchName', XOBJ_DTYPE_TXTBOX, null, false, 50); |
44
|
|
|
$this->initVar('searchExplanation', XOBJ_DTYPE_TXTAREA, null, false); |
45
|
|
|
$this->initVar('viewInPedigree', XOBJ_DTYPE_INT, 1, false, 1); |
46
|
|
|
$this->initVar('viewInAdvanced', XOBJ_DTYPE_INT, 1, false, 1); |
47
|
|
|
$this->initVar('viewInPie', XOBJ_DTYPE_INT, 1, false, 1); |
48
|
|
|
$this->initVar('viewInList', XOBJ_DTYPE_INT, 1, false, 1); |
49
|
|
|
$this->initVar('locked', XOBJ_DTYPE_INT, 0, false, 1); |
50
|
|
|
$this->initVar('order', XOBJ_DTYPE_INT, 0, false, 3); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param bool $action |
55
|
|
|
* |
56
|
|
|
* @todo refactor to eliminate XoopsObjectTree since it's not structured to |
57
|
|
|
* handle this type of object |
58
|
|
|
* |
59
|
|
|
* @return object {@see XoopsThemeForm} |
60
|
|
|
*/ |
61
|
|
|
public function getForm($action = false) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
if ($action === false) { |
64
|
|
|
$action = $_SERVER['REQUEST_URI']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$title = $this->isNew() ? sprintf(_AM_PEDIGREE_PEDIGREE_CONFIG_ADD) : sprintf(_AM_PEDIGREE_PEDIGREE_CONFIG_EDIT); |
68
|
|
|
|
69
|
|
|
include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
70
|
|
|
|
71
|
|
|
$form = new XoopsThemeForm($title, 'form', $action, 'post', true); |
72
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
73
|
|
|
|
74
|
|
|
$form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDNAME, 'fieldName', 50, 255, $this->getVar('FieldName')), true); |
75
|
|
|
$form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_ISACTIVE, 'isActive', (int)$this->getVar('isActive')), false); |
76
|
|
|
$fieldTypes = new XoopsFormSelect(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDTYPE, 'fieldType', $this->getVar('FieldType'), false); |
77
|
|
|
$fieldTypes->addOptionArray(array('DataSelect' => 'DataSelect', 'Picture' => 'Picture', 'radiobutton' => 'radiobutton', 'selectbox' => 'selectbox', 'textarea' => 'textarea', 'textbox' => 'textbox', 'urlfield' => 'urlfield')); |
78
|
|
|
$form->addElement($fieldTypes); |
79
|
|
|
// $form->addElement(new XoopsFormTextArea(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDTYPE, "FieldType", $this->getVar("FieldType"), 4, 47), false); |
|
|
|
|
80
|
|
|
$form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_LOOKUPTABLE, 'lookupTable', 50, 255, $this->getVar('LookupTable')), false); |
81
|
|
|
$form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_DEFAULTVALUE, 'defaultValue', 50, 255, $this->getVar('DefaultValue')), false); |
82
|
|
|
$form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDEXPLANATION, 'fieldExplanation', 50, 255, $this->getVar('FieldExplanation')), false); |
83
|
|
|
$form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_HASSEARCH, 'hasSearch', (int)$this->getVar('HasSearch')), false); |
84
|
|
|
/* @todo: should be single select for either General Litter or Litter, can't have both */ |
85
|
|
|
$currentType = $this->getVar('litter') ? 'litter' : 'generallitter'; |
86
|
|
|
$litterRadio = new XoopsFormRadio(_AM_PEDIGREE_PEDIGREE_CONFIG_LITTER_TYPE, 'litterType', $currentType); |
87
|
|
|
$litterRadio->addOptionArray(array('litter' => _AM_PEDIGREE_PEDIGREE_CONFIG_LITTER, 'generallitter' => _AM_PEDIGREE_PEDIGREE_CONFIG_GENERALLITTER)); |
88
|
|
|
$form->addElement($litterRadio, false); |
89
|
|
|
// $form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_LITTER, "Litter", $this->getVar("Litter")), false); |
|
|
|
|
90
|
|
|
// $form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_GENERALLITTER, "Generallitter", $this->getVar("Generallitter")), false); |
|
|
|
|
91
|
|
|
$form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_SEARCHNAME, 'searchName', 50, 255, $this->getVar('SearchName')), false); |
92
|
|
|
$form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_SEARCHEXPLANATION, 'searchExplanation', 50, 255, $this->getVar('SearchExplanation')), false); |
93
|
|
|
$form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINPEDIGREE, 'viewInPedigree', (int)$this->getVar('ViewInPedigree')), false); |
94
|
|
|
$form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINADVANCED, 'viewInAdvanced', (int)$this->getVar('ViewInAdvanced')), false); |
95
|
|
|
$form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINPIE, 'viewInPie', (int)$this->getVar('ViewInPie')), false); |
96
|
|
|
$form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINLIST, 'viewInList', (int)$this->getVar('ViewInList')), false); |
97
|
|
|
$form->addElement(new XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, 'locked', (int)$this->getVar('locked')), false); |
98
|
|
|
$form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_ORDER, 'order', 3, 8, (int)$this->getVar('order')), false); |
99
|
|
|
// include_once(XOOPS_ROOT_PATH."/class/tree.php"); |
|
|
|
|
100
|
|
|
// $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsDB']->getVar("dirname")); |
|
|
|
|
101
|
|
|
// $criteria = new CriteriaCompo(); |
|
|
|
|
102
|
|
|
// $criteria->setSort('_id'); |
|
|
|
|
103
|
|
|
// $criteria->setOrder('ASC'); |
|
|
|
|
104
|
|
|
// $_arr = $Handler->getall(); |
|
|
|
|
105
|
|
|
// $mytree = new XoopsObjectTree($_arr, "_id", "_pid"); |
|
|
|
|
106
|
|
|
// $form->addElement(new XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, $mytree->makeSelBox("_pid", "_title","--", $this->getVar("_pid"),false))); |
|
|
|
|
107
|
|
|
// |
108
|
|
|
// include_once(XOOPS_ROOT_PATH."/class/tree.php"); |
|
|
|
|
109
|
|
|
// $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsModule']->getVar("dirname")); |
|
|
|
|
110
|
|
|
// $criteria = new CriteriaCompo(); |
|
|
|
|
111
|
|
|
// $criteria->setSort('_id'); |
|
|
|
|
112
|
|
|
// $criteria->setOrder('ASC'); |
|
|
|
|
113
|
|
|
// $_arr = $Handler->getall(); |
|
|
|
|
114
|
|
|
// $mytree = new XoopsObjectTree($_arr, "_id", "_pid"); |
|
|
|
|
115
|
|
|
// $form->addElement(new XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_ORDER, $mytree->makeSelBox("_pid", "_title","--", $this->getVar("_pid"),false))); |
|
|
|
|
116
|
|
|
/* |
|
|
|
|
117
|
|
|
include_once $GLOBALS['xoops']->path("class/tree.php"); |
118
|
|
|
// $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsModule']->getVar("dirname")); |
119
|
|
|
$Handler = xoops_getModuleHandler('fields', 'pedigree'); |
120
|
|
|
// $Handler = & $pedigreeFieldsHandler; |
121
|
|
|
$criteria = new CriteriaCompo(); |
122
|
|
|
$criteria->setSort('Id'); |
123
|
|
|
$criteria->setOrder('ASC'); |
124
|
|
|
$_arr = $Handler->getAll(); |
125
|
|
|
$mytree = new XoopsObjectTree($_arr, "ID", "_pid"); |
126
|
|
|
$form->addElement(new XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, $mytree->makeSelBox("_pid", "_title", "--", $this->getVar("_pid"), false))); |
127
|
|
|
*/ |
128
|
|
|
$form->addElement(new XoopsFormHidden('op', 'save_pedigree_config')); |
129
|
|
|
|
130
|
|
|
//Submit buttons |
131
|
|
|
$form->addElement(new XoopsFormButtonTray('fieldButtons', _SUBMIT, 'submit')); |
132
|
|
|
/* |
|
|
|
|
133
|
|
|
$button_tray = new XoopsFormElementTray("", ""); |
134
|
|
|
$submit_button = new XoopsFormButton("", "submit", _SUBMIT, "submit"); |
135
|
|
|
$button_tray->addElement($submit_button); |
136
|
|
|
|
137
|
|
|
$cancel_button = new XoopsFormButton("", "", _CANCEL, "cancel"); |
138
|
|
|
$cancel_button->setExtra('onclick="history.go(-1)"'); |
139
|
|
|
$button_tray->addElement($cancel_button); |
140
|
|
|
|
141
|
|
|
$form->addElement($button_tray); |
142
|
|
|
*/ |
143
|
|
|
return $form; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return bool |
148
|
|
|
*/ |
149
|
|
|
public function isActive() |
150
|
|
|
{ |
151
|
|
|
return (1 == $this->getVar('isActive'));// ? true : false; |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return bool |
156
|
|
|
*/ |
157
|
|
|
public function inAdvanced() |
158
|
|
|
{ |
159
|
|
|
return (1 == $this->getVar('ViewInAdvanced'));// ? true : false; |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return bool |
164
|
|
|
*/ |
165
|
|
|
public function isLocked() |
166
|
|
|
{ |
167
|
|
|
return (1 == $this->getVar('Locked'));// ? true : false; |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return bool |
172
|
|
|
*/ |
173
|
|
|
public function hasSearch() |
174
|
|
|
{ |
175
|
|
|
return (1 == $this->getVar('HasSearch'));// ? true : false; |
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return bool |
180
|
|
|
*/ |
181
|
|
|
public function addLitter() |
182
|
|
|
{ |
183
|
|
|
return (1 == $this->getVar('Litter'));// ? true : false; |
|
|
|
|
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return bool |
188
|
|
|
*/ |
189
|
|
|
public function generalLitter() |
190
|
|
|
{ |
191
|
|
|
return (1 == $this->getVar('Generallitter'));// ? true : false; |
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return bool |
196
|
|
|
*/ |
197
|
|
|
public function hasLookup() |
198
|
|
|
{ |
199
|
|
|
return (1 == $this->getVar('LookupTable'));// ? true : false; |
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
|
|
public function getSearchString() |
206
|
|
|
{ |
207
|
|
|
return '&o=naam&p'; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return bool |
212
|
|
|
*/ |
213
|
|
|
public function inPie() |
214
|
|
|
{ |
215
|
|
|
return (1 == $this->getVar('ViewInPie'));// ? true : false; |
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return bool |
220
|
|
|
*/ |
221
|
|
|
public function inPedigree() |
222
|
|
|
{ |
223
|
|
|
return (1 == $this->getVar('ViewInPedigree'));// ? true : false; |
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return bool |
228
|
|
|
*/ |
229
|
|
|
public function inList() |
230
|
|
|
{ |
231
|
|
|
return (1 == $this->getVar('ViewInList'));// ? true : false; |
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return int|mixed |
236
|
|
|
*/ |
237
|
|
|
public function getId() |
238
|
|
|
{ |
239
|
|
|
$id = $this->getVar('Id'); |
240
|
|
|
|
241
|
|
|
return !empty($id) ? $id : 0; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @deprecated |
246
|
|
|
* @param $setting |
247
|
|
|
* |
248
|
|
|
* @return mixed |
249
|
|
|
*/ |
250
|
|
|
public function getSetting($setting) |
251
|
|
|
{ |
252
|
|
|
return isset($this->$setting) ? $this->setting : null; |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Class PedigreeFieldsHandler |
258
|
|
|
* |
259
|
|
|
* @param object $db reference to the {@link XoopsDatabase} object |
260
|
|
|
* |
261
|
|
|
* @return void |
262
|
|
|
*/ |
263
|
|
|
class PedigreeFieldsHandler extends XoopsPersistableObjectHandler |
|
|
|
|
264
|
|
|
{ |
265
|
|
|
/** |
266
|
|
|
* @param null|object|XoopsDatabase $db |
267
|
|
|
*/ |
268
|
|
|
public function __construct(XoopsDatabase $db) |
269
|
|
|
{ |
270
|
|
|
parent::__construct($db, 'pedigree_fields', 'PedigreeFields', 'Id', 'FieldName'); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @todo table pedigree_lookup doesn't exist in dB this function will FAIL if called |
275
|
|
|
* |
276
|
|
|
* @param $fieldnumber |
277
|
|
|
* |
278
|
|
|
* @return array |
279
|
|
|
*/ |
280
|
|
View Code Duplication |
public function lookupField($fieldnumber) |
|
|
|
|
281
|
|
|
{ |
282
|
|
|
$ret = array(); |
283
|
|
|
$SQL = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_lookup' . $fieldnumber) . " ORDER BY 'order'"; |
284
|
|
|
$result = $GLOBALS['xoopsDB']->query($SQL); |
285
|
|
|
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
286
|
|
|
$ret[] = array('id' => $row['Id'], 'value' => $row['value']); |
287
|
|
|
} |
288
|
|
|
//array_multisort($ret,SORT_ASC); |
|
|
|
|
289
|
|
|
return $ret; |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
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.