Passed
Push — master ( 48d769...5ccf6e )
by Michael
07:14
created

Animal::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
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);
0 ignored issues
show
Bug introduced by
The method getAll() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoUserHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        /** @scrutinizer ignore-call */ 
55
        $this->myTree = $myTreeHandler->getAll($criteria, null, false);
Loading history...
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__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
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
0 ignored issues
show
Bug introduced by
The method getIds() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
        /** @scrutinizer ignore-call */ 
80
        $this->fields       = $fieldsHandler->getIds($criteria); //get all object IDs
Loading history...
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