Completed
Push — master ( a4e09c...825da9 )
by Michael
01:51
created

Category::getForm()   F

Complexity

Conditions 9
Paths 256

Size

Total Lines 146
Code Lines 72

Duplication

Lines 27
Ratio 18.49 %

Importance

Changes 0
Metric Value
cc 9
eloc 72
nc 256
nop 1
dl 27
loc 146
rs 3.1304
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace Xoopsmodules\instruction;
2
3
//if (!defined("XOOPS_ROOT_PATH")) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
4
//	die("XOOPS root path not defined");
5
//}
6
7
//include_once $GLOBALS['xoops']->path('include/common.php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
8
9
//include_once __DIR__ . '/Utility.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
10
//include_once __DIR__ . '/CategoryHandler.php';
11
//include_once __DIR__ . '/Helper.php';
12
13
/**
14
 * Class Category
15
 * @package Xoopsmodules\instruction
16
 */
17
class Category extends \XoopsObject
18
{
19
    // constructor
20
    public function __construct()
21
    {
22
        //		$this->XoopsObject();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
23
        $this->initVar('cid', XOBJ_DTYPE_INT, null, false, 5);
24
        $this->initVar('pid', XOBJ_DTYPE_INT, 0, false, 5);
25
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false);
26
        $this->initVar('imgurl', XOBJ_DTYPE_TXTBOX, '', false);
27
        $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false);
28
        $this->initVar('weight', XOBJ_DTYPE_INT, 0, false, 11);
29
        $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10);
30
        $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10);
31
        $this->initVar('metakeywords', XOBJ_DTYPE_TXTBOX, '', false);
32
        $this->initVar('metadescription', XOBJ_DTYPE_TXTBOX, '', false);
33
    }
34
35
    /**
36
     * @return mixed
37
     */
38
    public function get_new_enreg()
39
    {
40
        $new_enreg = $GLOBALS['xoopsDB']->getInsertId();
41
        return $new_enreg;
42
    }
43
44
    // Получаем форму
45
46
    /**
47
     * @param bool|null|string $action
48
     * @return \XoopsThemeForm
49
     */
50
    public function getForm($action = false)
51
    {
52
        //global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
53
        require_once __DIR__ . '/../include/common.php';
54
        // Если нет $action
55
        if (false === $action) {
56
            $action = xoops_getenv('REQUEST_URI');
57
        }
58
        // Подключаем формы
59
        include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
60
61
        // Название формы
62
        $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDCAT) : sprintf(_AM_INSTRUCTION_FORMEDITCAT);
63
64
        // Форма
65
        $form = new \XoopsThemeForm($title, 'formcat', $action, 'post', true);
66
        //$form->setExtra('enctype="multipart/form-data"');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
67
        // Название категории
68
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true);
69
        // Редактор
70
        $form->addElement(new \XoopsFormTextArea(_AM_INSTRUCTION_DSCC, 'description', $this->getVar('description', 'e')), true);
71
        //image
72
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
73
        $downloadscat_img = $this->getVar('imgurl') ? $this->getVar('imgurl') : 'blank.gif';
74
        $uploadirectory='/uploads/tdmdownloads/images/cats';
75
        $imgtray = new \XoopsFormElementTray(_AM_TDMDOWNLOADS_FORMIMG,'<br>');
76
        $imgpath=sprintf(_AM_TDMDOWNLOADS_FORMPATH, $uploadirectory );
77
        $imageselect= new \XoopsFormSelect($imgpath, 'downloadscat_img',$downloadscat_img);
78
        $topics_array = XoopsLists :: getImgListAsArray( XOOPS_ROOT_PATH . $uploadirectory );
79
        foreach( $topics_array as $image ) {
80
            $imageselect->addOption("$image", $image);
81
        }
82
        $imageselect->setExtra( "onchange='showImgSelected(\"image3\", \"downloadscat_img\", \"" . $uploadirectory . "\", \"\", \"" . XOOPS_URL . "\")'" );
83
        $imgtray->addElement($imageselect,false);
84
        $imgtray -> addElement( new \XoopsFormLabel( '', "<br><img src='" . XOOPS_URL . "/" . $uploadirectory . "/" . $downloadscat_img . "' name='image3' id='image3' alt='' />" ) );
85
        $fileseltray= new \XoopsFormElementTray('','<br>');
86
        $fileseltray->addElement(new \XoopsFormFile(_AM_TDMDOWNLOADS_FORMUPLOAD , 'attachedfile', $xoopsModuleConfig['maxuploadsize']), false);
87
        $fileseltray->addElement(new \XoopsFormLabel('' ), false);
88
        $imgtray->addElement($fileseltray);
89
        $form->addElement($imgtray);
90
        */
91
        // Родительская категория
92
        //        $categoryHandler = xoops_getModuleHandler('category', 'instruction');
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
93
        $criteria = new \CriteriaCompo();
94
        // Если мы редактируем, то убрать текущую категорию из списка выбора родительской
95
        if (!$this->isNew()) {
96
            $criteria->add(new \Criteria('cid', $this->getVar('cid'), '<>'));
97
        }
98
        $criteria->setSort('weight ASC, title');
99
        $criteria->setOrder('ASC');
100
101
        $db              = \XoopsDatabaseFactory::getDatabase();
102
        $categoryHandler = new CategoryHandler($db);
103
104
        $instructioncat_arr = $categoryHandler->getall($criteria);
105
        unset($criteria);
106
        // Подключаем трей
107
        include_once $GLOBALS['xoops']->path('class/tree.php');
108
        $mytree = new \XoopsObjectTree($instructioncat_arr, 'cid', 'pid');
109
110
        // $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PCATC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true)));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
111
112
        $helper = Helper::getInstance();
113
        $module = $helper->getModule();
114
115 View Code Duplication
        if (Utility::checkVerXoops($module, '2.5.9')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
            $mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PCATC);
117
            $form->addElement($mytree_select);
118
        } else {
119
            $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PCATC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true)));
120
        }
121
122
        // Вес
123
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true);
124
        // Мета-теги ключевых слов
125
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false);
126
        // Мета-теги описания
127
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false);
128
129
        // ==========================================================
130
        // ==========================================================
131
132
        // Права
133
        $memberHandler = xoops_getHandler('member');
134
        $group_list    = $memberHandler->getGroupList();
135
        $gpermHandler  = xoops_getHandler('groupperm');
136
        $full_list     = array_keys($group_list);
137
138
        // Права на просмотр
139
        $groups_ids = [];
0 ignored issues
show
Unused Code introduced by
$groups_ids is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
140
        // Если мы редактируем
141 View Code Duplication
        if (!$this->isNew()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
            $groups_ids        = $gpermHandler->getGroupIds('instruction_view', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid'));
143
            $groups_ids        = array_values($groups_ids);
144
            $groups_instr_view = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_VIEW, 'groups_instr_view', $groups_ids);
145
        } else {
146
            $groups_instr_view = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_VIEW, 'groups_instr_view', $full_list);
147
        }
148
        $groups_instr_view->addOptionArray($group_list);
149
        $form->addElement($groups_instr_view);
150
151
        // Права на отправку
152
        $groups_ids = [];
0 ignored issues
show
Unused Code introduced by
$groups_ids is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
153 View Code Duplication
        if (!$this->isNew()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
154
            $groups_ids          = $gpermHandler->getGroupIds('instruction_submit', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid'));
155
            $groups_ids          = array_values($groups_ids);
156
            $groups_instr_submit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_SUBMIT, 'groups_instr_submit', $groups_ids);
157
        } else {
158
            $groups_instr_submit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_SUBMIT, 'groups_instr_submit', $full_list);
159
        }
160
        $groups_instr_submit->addOptionArray($group_list);
161
        $form->addElement($groups_instr_submit);
162
163
        // Права на редактирование
164
        $groups_ids = [];
0 ignored issues
show
Unused Code introduced by
$groups_ids is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
165 View Code Duplication
        if (!$this->isNew()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
            $groups_ids        = $gpermHandler->getGroupIds('instruction_edit', $this->getVar('cid'), $GLOBALS['xoopsModule']->getVar('mid'));
167
            $groups_ids        = array_values($groups_ids);
168
            $groups_instr_edit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_EDIT, 'groups_instr_edit', $groups_ids);
169
        } else {
170
            $groups_instr_edit = new \XoopsFormCheckBox(_AM_INSTRUCTION_PERM_EDIT, 'groups_instr_edit', $full_list);
171
        }
172
        $groups_instr_edit->addOptionArray($group_list);
173
        $form->addElement($groups_instr_edit);
174
175
        // ==========================================================
176
        // ==========================================================
177
178
        // Если мы редактируем категорию
179
        if (!$this->isNew()) {
180
            $form->addElement(new \XoopsFormHidden('cid', $this->getVar('cid')));
181
            //$form->addElement( new \XoopsFormHidden( 'catmodify', true));
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
182
        }
183
        //
184
        $form->addElement(new \XoopsFormHidden('op', 'savecat'));
185
        // Кнопка
186
        $button_tray = new \XoopsFormElementTray('', '');
187
        $submit_btn  = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit');
188
        $button_tray->addElement($submit_btn);
189
        $cancel_btn = new \XoopsFormButton('', 'cancel', _CANCEL, 'cancel');
190
        $cancel_btn->setExtra('onclick="javascript:history.go(-1);"');
191
        $button_tray->addElement($cancel_btn);
192
        $form->addElement($button_tray);
193
194
        return $form;
195
    }
196
}
197
198