|
1
|
|
|
<?php namespace XoopsModules\Pedigree; |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
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
|
|
|
/** |
|
13
|
|
|
* Pedigree module for XOOPS |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright {@link http://sourceforge.net/projects/xoops/ The XOOPS Project} |
|
16
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
|
17
|
|
|
* @package pedigree |
|
18
|
|
|
* @subpackage class |
|
19
|
|
|
* @since 1.3.1 |
|
20
|
|
|
* @author XOOPS Module Dev Team |
|
21
|
|
|
* @author ZySpec <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
use XoopsModules\Pedigree; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* |
|
30
|
|
|
* Animal Class |
|
31
|
|
|
* |
|
32
|
|
|
*/ |
|
33
|
|
|
class Animal |
|
34
|
|
|
{ |
|
35
|
|
|
protected $myTree = []; |
|
36
|
|
|
protected $fields = []; |
|
37
|
|
|
protected $configValues = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* class constructor |
|
41
|
|
|
* |
|
42
|
|
|
* initializes the tree array |
|
43
|
|
|
* @param integer|null $id |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct($id = null) |
|
46
|
|
|
{ |
|
47
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
|
|
|
|
|
48
|
|
|
$id = null !== $id ? (int)$id : 1; |
|
49
|
|
|
$myTreeHandler = Pedigree\Helper::getInstance()->getHandler('Tree'); |
|
50
|
|
|
|
|
51
|
|
|
$criteria = new \CriteriaCompo(); |
|
52
|
|
|
$criteria->add(new \Criteria('id', $id)); |
|
53
|
|
|
$criteria->setLimit(1); |
|
54
|
|
|
$this->myTree = $myTreeHandler->getAll($criteria, null, false); |
|
55
|
|
|
/* |
|
|
|
|
|
|
56
|
|
|
$SQL = "SELECT * FROM " . $GLOBALS['xoopsDB']->prefix("pedigree_tree") . " WHERE id = {$id}"; |
|
57
|
|
|
$result = $GLOBALS['xoopsDB']->query($SQL); |
|
58
|
|
|
$row = $GLOBALS['xoopsDB']->fetchRow($result); |
|
59
|
|
|
$numfields = mysqli_num_fields($result); |
|
60
|
|
|
for ($i = 0; $i < $numfields; ++$i) { |
|
61
|
|
|
$key =$GLOBALS['xoopsDB']->getFieldName($result, $i); |
|
62
|
|
|
$this->$key = $row[$i]; |
|
63
|
|
|
} |
|
64
|
|
|
*/ |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* |
|
69
|
|
|
* Number of Fields |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getNumOfFields() |
|
73
|
|
|
{ |
|
74
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
|
|
|
|
|
75
|
|
|
$fieldsHandler = Pedigree\Helper::getInstance()->getHandler('Fields'); |
|
76
|
|
|
$criteria = new \CriteriaCompo(); |
|
77
|
|
|
$criteria->setSort('`order`'); |
|
78
|
|
|
$criteria->setOrder('ASC'); |
|
79
|
|
|
$this->fields = $fieldsHandler->getIds($criteria); //get all object IDs |
|
80
|
|
|
$this->configValues = $fieldsHandler->getAll($criteria, null, false); //get objects as arrays |
|
81
|
|
|
if (empty($this->configValues)) { |
|
82
|
|
|
$this->configValues = ''; |
|
83
|
|
|
} |
|
84
|
|
|
/* |
|
|
|
|
|
|
85
|
|
|
$SQL = "SELECT * FROM " . $GLOBALS['xoopsDB']->prefix("pedigree_fields") . " ORDER BY `order`"; |
|
86
|
|
|
$result = $GLOBALS['xoopsDB']->query($SQL); |
|
87
|
|
|
$fields = array(); |
|
88
|
|
|
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
|
89
|
|
|
$fields[] = $row['id']; |
|
90
|
|
|
$configValues[] = $row; |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
$this->configValues = isset($configValues) ? $configValues : ''; |
|
94
|
|
|
//print_r ($this->configValues); die(); |
|
95
|
|
|
*/ |
|
96
|
|
|
unset($fieldsHandler, $criteria); |
|
97
|
|
|
|
|
98
|
|
|
return $this->fields; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return array |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getConfig() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->configValues; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
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.