Completed
Push — master ( c8eead...62889a )
by Michael
04:13
created

PedigreeFields   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 111
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 1
A getForm() 0 75 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 24.

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.

Loading history...
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
 * animal module for xoops
13
 *
14
 * @copyright       The TXMod XOOPS Project http://sourceforge.net/projects/thmod/
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GPL 2.0 or later
17
 * @package         animal
18
 * @since           2.5.x
19
 * @author          XOOPS Development Team ( [email protected] ) - ( http://xoops.org )
20
 * @version         $Id: const_entete.php 9860 2012-07-13 10:41:41Z txmodxoops $
21
 */
22
23
if (!defined("XOOPS_ROOT_PATH")) {
24
    die("XOOPS root path not defined");
25
}
26
27
/**
28
 * Class PedigreeFields
29
 */
30
class PedigreeFields extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
31
{
32
    //Constructor
33
    /**
34
     *
35
     */
36
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
    {
38
        parent::__construct();
39
        $this->initVar("ID", XOBJ_DTYPE_INT, null, false, 2);
40
        $this->initVar("isActive", XOBJ_DTYPE_INT, null, false, 1);
41
        $this->initVar("FieldName", XOBJ_DTYPE_TXTBOX, null, false, 50);
42
        $this->initVar("FieldType", XOBJ_DTYPE_ENUM, null, false);
43
        $this->initVar("LookupTable", XOBJ_DTYPE_INT, null, false, 1);
44
        $this->initVar("DefaultValue", XOBJ_DTYPE_TXTBOX, null, false, 50);
45
        $this->initVar("FieldExplenation", XOBJ_DTYPE_TXTAREA, null, false);
46
        $this->initVar("HasSearch", XOBJ_DTYPE_INT, null, false, 1);
47
        $this->initVar("Litter", XOBJ_DTYPE_INT, null, false, 1);
48
        $this->initVar("Generallitter", XOBJ_DTYPE_INT, null, false, 1);
49
        $this->initVar("SearchName", XOBJ_DTYPE_TXTBOX, null, false, 50);
50
        $this->initVar("SearchExplenation", XOBJ_DTYPE_TXTAREA, null, false);
51
        $this->initVar("ViewInPedigree", XOBJ_DTYPE_INT, null, false, 1);
52
        $this->initVar("ViewInAdvanced", XOBJ_DTYPE_INT, null, false, 1);
53
        $this->initVar("ViewInPie", XOBJ_DTYPE_INT, null, false, 1);
54
        $this->initVar("ViewInList", XOBJ_DTYPE_INT, null, false, 1);
55
        $this->initVar("locked", XOBJ_DTYPE_INT, null, false, 1);
56
        $this->initVar("order", XOBJ_DTYPE_INT, null, false, 3);
57
58
    }
59
60
    /**
61
     * @param bool $action
62
     *
63
     * @return XoopsThemeForm
64
     */
65
    function getForm($action = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
getForm uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
66
    {
67
        global $xoopsDB, $xoopsModuleConfig, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
68
69
        if ($action === false) {
70
            $action = $_SERVER["REQUEST_URI"];
71
        }
72
73
        $title = $this->isNew() ? sprintf(_AM_PEDIGREE_PEDIGREE_CONFIG_ADD) : sprintf(_AM_PEDIGREE_PEDIGREE_CONFIG_EDIT);
74
75
        include_once(XOOPS_ROOT_PATH . "/class/xoopsformloader.php");
76
77
        $form = new XoopsThemeForm($title, "form", $action, "post", true);
78
        $form->setExtra('enctype="multipart/form-data"');
79
80
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_ISACTIVE, "isActive", 50, 255, $this->getVar("isActive")), false);
81
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDNAME, "FieldName", 50, 255, $this->getVar("FieldName")), false);
82
        $form->addElement(new XoopsFormTextArea(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDTYPE, "FieldType", $this->getVar("FieldType"), 4, 47), false);
83
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_LOOKUPTABLE, "LookupTable", 50, 255, $this->getVar("LookupTable")), false);
84
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_DEFAULTVALUE, "DefaultValue", 50, 255, $this->getVar("DefaultValue")), false);
85
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDEXPLENATION, "FieldExplenation", 50, 255, $this->getVar("FieldExplenation")), false);
86
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_HASSEARCH, "HasSearch", 50, 255, $this->getVar("HasSearch")), false);
87
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_LITTER, "Litter", 50, 255, $this->getVar("Litter")), false);
88
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_GENERALLITTER, "Generallitter", 50, 255, $this->getVar("Generallitter")), false);
89
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_SEARCHNAME, "SearchName", 50, 255, $this->getVar("SearchName")), false);
90
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_SEARCHEXPLENATION, "SearchExplenation", 50, 255, $this->getVar("SearchExplenation")), false);
91
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINPEDIGREE, "ViewInPedigree", 50, 255, $this->getVar("ViewInPedigree")), false);
92
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINADVANCED, "ViewInAdvanced", 50, 255, $this->getVar("ViewInAdvanced")), false);
93
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINPIE, "ViewInPie", 50, 255, $this->getVar("ViewInPie")), false);
94
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINLIST, "ViewInList", 50, 255, $this->getVar("ViewInList")), false);
95
96
//			include_once(XOOPS_ROOT_PATH."/class/tree.php");
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
//			$Handler =& xoops_getModuleHandler("animal_", $xoopsModule->getVar("dirname"));
98
//			$criteria = new CriteriaCompo();
99
//            $criteria->setSort('_id');
100
//            $criteria->setOrder('ASC');
101
//			$_arr = $Handler->getall();
102
//			$mytree = new XoopsObjectTree($_arr, "_id", "_pid");
103
//			$form->addElement(new XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, $mytree->makeSelBox("_pid", "_title","--", $this->getVar("_pid"),false)));
104
//
105
//			include_once(XOOPS_ROOT_PATH."/class/tree.php");
106
//			$Handler =& xoops_getModuleHandler("animal_", $xoopsModule->getVar("dirname"));
107
//			$criteria = new CriteriaCompo();
108
//            $criteria->setSort('_id');
109
//            $criteria->setOrder('ASC');
110
//			$_arr = $Handler->getall();
111
//			$mytree = new XoopsObjectTree($_arr, "_id", "_pid");
112
//			$form->addElement(new XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_ORDER, $mytree->makeSelBox("_pid", "_title","--", $this->getVar("_pid"),false)));
113
114
        include_once(XOOPS_ROOT_PATH . "/class/tree.php");
115
//      $Handler =& xoops_getModuleHandler("animal_", $xoopsModule->getVar("dirname"));
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
116
        $Handler =& xoops_getModuleHandler('fields', $xoopsModule->getVar("dirname"));
117
//        $Handler = & $pedigreeFieldsHandler;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
118
        $criteria = new CriteriaCompo();
119
        $criteria->setSort('_id');
120
        $criteria->setOrder('ASC');
121
        $_arr   = $Handler->getall();
122
        $mytree = new XoopsObjectTree($_arr, "_id", "_pid");
123
        $form->addElement(new XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, $mytree->makeSelBox("_pid", "_title", "--", $this->getVar("_pid"), false)));
124
125
        $form->addElement(new XoopsFormHidden("op", "save_pedigree_config"));
126
127
        //Submit buttons
128
        $button_tray   = new XoopsFormElementTray("", "");
129
        $submit_button = new XoopsFormButton("", "submit", _SUBMIT, "submit");
130
        $button_tray->addElement($submit_button);
131
132
        $cancel_button = new XoopsFormButton("", "", _CANCEL, "cancel");
133
        $cancel_button->setExtra('onclick="history.go(-1)"');
134
        $button_tray->addElement($cancel_button);
135
136
        $form->addElement($button_tray);
137
138
        return $form;
139
    }
140
}
141
142
/**
143
 * Class PedigreeFieldsHandler
144
 */
145
class PedigreeFieldsHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
146
{
147
    /**
148
     * @param null|object $db
149
     */
150
    function __construct(&$db)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
151
    {
152
        parent::__construct($db, "pedigree_fields", "PedigreeFields", "ID", "isActive");
153
    }
154
}
155