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

Page   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 176
Duplicated Lines 3.41 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 6
loc 176
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 1
A Page() 0 4 1
A get_new_enreg() 0 5 1
D getForm() 6 116 8
A getInstrid() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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');
8
9
/**
10
 * Class Page
11
 * @package Xoopsmodules\instruction
12
 */
13
class Page extends \XoopsObject
14
{
15
    // constructor
16
    public function __construct()
17
    {
18
        //	$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...
19
        $this->initVar('pageid', XOBJ_DTYPE_INT, null, false, 11);
20
        $this->initVar('pid', XOBJ_DTYPE_INT, 0, false, 11);
21
        $this->initVar('instrid', XOBJ_DTYPE_INT, 0, false, 11);
22
        $this->initVar('uid', XOBJ_DTYPE_INT, 0, false, 11);
23
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false, 255);
24
        $this->initVar('status', XOBJ_DTYPE_INT, 1, false, 1);
25
        $this->initVar('type', XOBJ_DTYPE_INT, 1, false, 1);
26
        $this->initVar('hometext', XOBJ_DTYPE_TXTAREA, null, false);
27
        $this->initVar('footnote', XOBJ_DTYPE_TXTAREA, '', false);
28
        $this->initVar('weight', XOBJ_DTYPE_INT, 0, false, 11);
29
        $this->initVar('keywords', XOBJ_DTYPE_TXTBOX, '', false, 255);
30
        $this->initVar('description', XOBJ_DTYPE_TXTBOX, '', false, 255);
31
        $this->initVar('comments', XOBJ_DTYPE_INT, 0, false, 11);
32
        $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10);
33
        $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10);
34
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false, 1);
35
        $this->initVar('dosmiley', XOBJ_DTYPE_INT, 0, false, 1);
36
        $this->initVar('doxcode', XOBJ_DTYPE_INT, 1, false, 1);
37
        $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false, 1);
38
    }
39
40
    public function Page()
41
    {
42
        $this->__construct();
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function get_new_enreg()
49
    {
50
        $new_enreg = $GLOBALS['xoopsDB']->getInsertId();
51
        return $new_enreg;
52
    }
53
54
    // Получаем форму
55
56
    /**
57
     * @param bool|null|string $action
58
     * @param int  $instrid
59
     * @return \XoopsThemeForm
60
     */
61
    public function getForm($action = false, $instrid = 0)
62
    {
63
        // Если нет $action
64
        if (false === $action) {
65
            $action = xoops_getenv('REQUEST_URI');
66
        }
67
68
        // Подключаем формы
69
        include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
70
        // Подключаем типы страниц
71
        $pagetypes = include $GLOBALS['xoops']->path('modules/instruction/include/pagetypes.inc.php');
72
73
        // Название формы
74
        $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDPAGE) : sprintf(_AM_INSTRUCTION_FORMEDITPAGE);
75
76
        // Форма
77
        $form = new \XoopsThemeForm($title, 'instr_form_page', $action, 'post', true);
78
        // Название
79
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true);
80
81
        // Родительская страница
82
        //        $pageHandler = xoops_getModuleHandler('page', '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...
83
        $criteria = new \CriteriaCompo();
84
        // ID инструкции в которой данная страница
85
        $instrid_page = $this->isNew() ? $instrid : $this->getVar('instrid');
86
        // Находим все страницы данной инструкции
87
        $criteria->add(new \Criteria('instrid', $instrid_page, '='));
88
        // Если мы редактируем, то убрать текущую страницу из списка выбора родительской
89
        if (!$this->isNew()) {
90
            $criteria->add(new \Criteria('pageid', $this->getVar('pageid'), '<>'));
91
        }
92
        $criteria->setSort('weight');
93
        $criteria->setOrder('ASC');
94
        $inspage_arr = $pageHandler->getall($criteria);
0 ignored issues
show
Bug introduced by
The variable $pageHandler does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
95
        unset($criteria);
96
        // Подключаем трей
97
        include_once $GLOBALS['xoops']->path('class/tree.php');
98
        $mytree = new \XoopsObjectTree($inspage_arr, 'pageid', 'pid');
99
100
        // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $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...
101
        $helper = Helper::getInstance();
102
        $module = $helper->getModule();
103
104 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...
105
            $mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PPAGEC);
106
            $form->addElement($mytree_select);
107
        } else {
108
            $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true)));
109
        }
110
111
        // Вес
112
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true);
113
        // Основной текст
114
        $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_HOMETEXTC, 'hometext', $this->getVar('hometext', 'e')), true);
115
        // Сноска
116
        $form_footnote = new \XoopsFormTextArea(_AM_INSTRUCTION_FOOTNOTEC, 'footnote', $this->getVar('footnote', 'e'));
117
        $form_footnote->setDescription(_AM_INSTRUCTION_FOOTNOTE_DSC);
118
        $form->addElement($form_footnote, false);
119
        unset($form_footnote);
120
        // Статус
121
        $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false);
122
        // Тип страницы
123
        $form_type = new \XoopsFormSelect(_AM_INSTR_PAGETYPEC, 'type', $this->getVar('type'));
124
        $form_type->setDescription(_AM_INSTR_PAGETYPEC_DESC);
125
        $form_type->addOptionArray($pagetypes);
126
        $form->addElement($form_type, false);
127
        // Мета-теги ключевых слов
128
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'keywords', 50, 255, $this->getVar('keywords')), false);
129
        // Мета-теги описания
130
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'description', 50, 255, $this->getVar('description')), false);
131
132
        // Настройки
133
        $option_tray = new \XoopsFormElementTray(_OPTIONS, '<br>');
134
        // HTML
135
        $html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml'));
136
        $html_checkbox->addOption(1, _AM_INSTR_DOHTML);
137
        $option_tray->addElement($html_checkbox);
138
        // Смайлы
139
        $smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley'));
140
        $smiley_checkbox->addOption(1, _AM_INSTR_DOSMILEY);
141
        $option_tray->addElement($smiley_checkbox);
142
        // ББ коды
143
        $xcode_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode'));
144
        $xcode_checkbox->addOption(1, _AM_INSTR_DOXCODE);
145
        $option_tray->addElement($xcode_checkbox);
146
        //
147
        $br_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr'));
148
        $br_checkbox->addOption(1, _AM_INSTR_DOAUTOWRAP);
149
        $option_tray->addElement($br_checkbox);
150
        //
151
        $form->addElement($option_tray);
152
153
        // Если мы редактируем страницу
154
        if (!$this->isNew()) {
155
            $form->addElement(new \XoopsFormHidden('pageid', $this->getVar('pageid')));
156
        } else {
157
            $form->addElement(new \XoopsFormHidden('pageid', 0));
158
        }
159
        // ID инструкции
160
        if ($instrid) {
161
            $form->addElement(new \XoopsFormHidden('instrid', $instrid));
162
        } else {
163
            $form->addElement(new \XoopsFormHidden('instrid', 0));
164
        }
165
        //
166
        $form->addElement(new \XoopsFormHidden('op', 'savepage'));
167
        // Кнопка
168
        $button_tray = new \XoopsFormElementTray('', '');
169
        $button_tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
170
        $save_btn = new \XoopsFormButton('', 'cancel', _AM_INSTR_SAVEFORM);
171
        $save_btn->setExtra('onclick="instrSavePage();"');
172
        $button_tray->addElement($save_btn);
173
        $form->addElement($button_tray);
174
175
        return $form;
176
    }
177
178
    //
179
180
    /**
181
     * @return mixed
182
     */
183
    public function getInstrid()
184
    {
185
        // Возвращаем ID инструкции
186
        return $this->getVar('instrid');
187
    }
188
}
189