Completed
Push — master ( d5e38f...a385a9 )
by Richard
16:37 queued 09:02
created

SystemuserrankHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User ranks class manager
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
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
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @author              Gregory Mage (AKA Mage)
15
 * @package             system
16
 */
17
18
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
19
20
/**
21
 * System User ranks
22
 *
23
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
24
 * @package             system
25
 */
26
class SystemUserrank extends XoopsObject
27
{
28
    /**
29
     *
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
        $this->initVar('rank_id', XOBJ_DTYPE_INT, null, false, 5);
35
        $this->initVar('rank_title', XOBJ_DTYPE_TXTBOX, null, false);
36
        $this->initVar('rank_min', XOBJ_DTYPE_INT, null, false, 8);
37
        $this->initVar('rank_max', XOBJ_DTYPE_INT, null, false, 8);
38
        $this->initVar('rank_special', XOBJ_DTYPE_INT, null, false, 1);
39
        $this->initVar('rank_image', XOBJ_DTYPE_TXTBOX, null, false);
40
    }
41
42
    /**
43
     * @param bool $action
44
     *
45
     * @return XoopsThemeForm
46
     */
47
    public function getForm($action = false)
48
    {
49 View Code Duplication
        if ($this->isNew()) {
50
            $blank_img = 'blank.gif';
51
        } else {
52
            $blank_img = str_replace('ranks/', '', $this->getVar('rank_image', 'e'));
53
        }
54
        if ($action === false) {
55
            $action = $_SERVER['REQUEST_URI'];
56
        }
57
58
        $title = $this->isNew() ? sprintf(_AM_SYSTEM_USERRANK_ADD) : sprintf(_AM_SYSTEM_USERRANK_EDIT);
59
60
        $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
61
        $form->setExtra('enctype="multipart/form-data"');
62
63
        $form->addElement(new XoopsFormText(_AM_SYSTEM_USERRANK_TITLE, 'rank_title', 50, 50, $this->getVar('rank_title'), true));
0 ignored issues
show
Unused Code introduced by
The call to XoopsFormText::__construct() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
64
        $form->addElement(new XoopsFormText(_AM_SYSTEM_USERRANK_MINPOST, 'rank_min', 10, 10, $this->getVar('rank_min')));
65
        $form->addElement(new XoopsFormText(_AM_SYSTEM_USERRANK_MAXPOST, 'rank_max', 10, 10, $this->getVar('rank_max')));
66
67
        $imgtray_img     = new XoopsFormElementTray(_AM_SYSTEM_USERRANK_IMAGE, '<br>');
68
        $imgpath_img     = sprintf(_AM_SYSTEM_USERRANK_IMAGE_PATH, XOOPS_UPLOAD_PATH . '/ranks/');
69
        $imageselect_img = new XoopsFormSelect($imgpath_img, 'rank_image', $blank_img);
70
        $image_array_img = XoopsLists::getImgListAsArray(XOOPS_UPLOAD_PATH . '/ranks');
71
        $imageselect_img->addOption("$blank_img", $blank_img);
72
        foreach ($image_array_img as $image_img) {
73
            $imageselect_img->addOption("$image_img", $image_img);
74
        }
75
        $imageselect_img->setExtra("onchange='showImgSelected(\"xo-ranks-img\", \"rank_image\", \"ranks\", \"\", \"" . XOOPS_UPLOAD_URL . "\")'");
76
        $imgtray_img->addElement($imageselect_img, false);
77
        $imgtray_img->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_UPLOAD_URL . '/ranks/' . $blank_img . "' name='image_img' id='xo-ranks-img' alt='' />"));
78
79
        $fileseltray_img = new XoopsFormElementTray('<br>', '<br><br>');
80
        $fileseltray_img->addElement(new XoopsFormFile(_AM_SYSTEM_USERRANK_UPLOAD, 'rank_image', 500000), false);
81
        $fileseltray_img->addElement(new XoopsFormLabel(''), false);
82
        $imgtray_img->addElement($fileseltray_img);
83
        $form->addElement($imgtray_img);
84
85
        $rank_special = 0;
86
        if (!$this->isNew()) {
87
            $rank_special = $this->getVar('rank_special');
88
        }
89
90
        $special_tray = new XoopsFormElementTray(_AM_SYSTEM_USERRANK_SPECIAL, '<br>');
91
        $special_tray->setDescription(_AM_SYSTEM_USERRANK_SPECIAL_CAN);
92
        $special_tray->addElement(new XoopsFormRadioYN('', 'rank_special', $rank_special));
93
        $form->addElement($special_tray);
94
        if (!$this->isNew()) {
95
            $form->addElement(new XoopsFormHidden('rank_id', $this->getVar('rank_id')));
96
        }
97
        $form->addElement(new XoopsFormHidden('op', 'userrank_save'));
98
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
99
100
        return $form;
101
    }
102
}
103
104
/**
105
 * System user ranks handler class. (Singelton)
106
 *
107
 * This class is responsible for providing data access mechanisms to the data source
108
 * of XOOPS block class objects.
109
 *
110
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
111
 * @package             system
112
 * @subpackage          avatar
113
 */
114
class SystemuserrankHandler 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...
115
{
116
    /**
117
     * @param null|XoopsDatabase $db
118
     */
119
    public function __construct(XoopsDatabase $db)
120
    {
121
        parent::__construct($db, 'ranks', 'SystemUserrank', 'rank_id', 'rank_title');
122
    }
123
}
124