Passed
Push — master ( b847d6...d6d54c )
by Michael
09:34 queued 05:00
created

class/Animal.php (1 issue)

Labels
Severity
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;
0 ignored issues
show
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Pedigree. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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