Completed
Push — master ( 825da9...adb11b )
by Michael
02:15
created

Page::getNewInstertId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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
    /**
41
     * @return mixed
42
     */
43
    public function getNewInstertId()
44
    {
45
        $newEnreg = $GLOBALS['xoopsDB']->getInsertId();
46
        return $newEnreg;
47
    }
48
49
    // Получаем форму
50
51
    /**
52
     * @param bool|null|string $action
53
     * @param int  $instrid
54
     * @return \XoopsThemeForm
55
     */
56
    public function getForm($action = false, $instrid = 0)
57
    {
58
        // Если нет $action
59
        if (false === $action) {
60
            $action = xoops_getenv('REQUEST_URI');
61
        }
62
63
        // Подключаем формы
64
        include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
65
        // Подключаем типы страниц
66
        $pagetypes = include $GLOBALS['xoops']->path('modules/instruction/include/pagetypes.inc.php');
67
68
        // Название формы
69
        $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDPAGE) : sprintf(_AM_INSTRUCTION_FORMEDITPAGE);
70
71
        // Форма
72
        $form = new \XoopsThemeForm($title, 'instr_form_page', $action, 'post', true);
73
        // Название
74
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true);
75
76
        // Родительская страница
77
        //        $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...
78
        $criteria = new \CriteriaCompo();
79
        // ID инструкции в которой данная страница
80
        $instrid_page = $this->isNew() ? $instrid : $this->getVar('instrid');
81
        // Находим все страницы данной инструкции
82
        $criteria->add(new \Criteria('instrid', $instrid_page, '='));
83
        // Если мы редактируем, то убрать текущую страницу из списка выбора родительской
84
        if (!$this->isNew()) {
85
            $criteria->add(new \Criteria('pageid', $this->getVar('pageid'), '<>'));
86
        }
87
        $criteria->setSort('weight');
88
        $criteria->setOrder('ASC');
89
        $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...
90
        unset($criteria);
91
        // Подключаем трей
92
        include_once $GLOBALS['xoops']->path('class/tree.php');
93
        $mytree = new \XoopsObjectTree($inspage_arr, 'pageid', 'pid');
94
95
        // $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...
96
        $helper = Helper::getInstance();
97
        $module = $helper->getModule();
98
99 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...
100
            $mytree_select = $mytree->makeSelectElement('pid', 'title', '--', $this->getVar('pid'), true, 0, '', _AM_INSTRUCTION_PPAGEC);
101
            $form->addElement($mytree_select);
102
        } else {
103
            $form->addElement(new \XoopsFormLabel(_AM_INSTRUCTION_PPAGEC, $mytree->makeSelBox('pid', 'title', '--', $this->getVar('pid'), true)));
104
        }
105
106
        // Вес
107
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_WEIGHTC, 'weight', 5, 5, $this->getVar('weight')), true);
108
        // Основной текст
109
        $form->addElement(Utility::getWysiwygForm(_AM_INSTRUCTION_HOMETEXTC, 'hometext', $this->getVar('hometext', 'e')), true);
110
        // Сноска
111
        $form_footnote = new \XoopsFormTextArea(_AM_INSTRUCTION_FOOTNOTEC, 'footnote', $this->getVar('footnote', 'e'));
112
        $form_footnote->setDescription(_AM_INSTRUCTION_FOOTNOTE_DSC);
113
        $form->addElement($form_footnote, false);
114
        unset($form_footnote);
115
        // Статус
116
        $form->addElement(new \XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false);
117
        // Тип страницы
118
        $form_type = new \XoopsFormSelect(_AM_INSTR_PAGETYPEC, 'type', $this->getVar('type'));
119
        $form_type->setDescription(_AM_INSTR_PAGETYPEC_DESC);
120
        $form_type->addOptionArray($pagetypes);
121
        $form->addElement($form_type, false);
122
        // Мета-теги ключевых слов
123
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'keywords', 50, 255, $this->getVar('keywords')), false);
124
        // Мета-теги описания
125
        $form->addElement(new \XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'description', 50, 255, $this->getVar('description')), false);
126
127
        // Настройки
128
        $option_tray = new \XoopsFormElementTray(_OPTIONS, '<br>');
129
        // HTML
130
        $html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml'));
131
        $html_checkbox->addOption(1, _AM_INSTR_DOHTML);
132
        $option_tray->addElement($html_checkbox);
133
        // Смайлы
134
        $smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley'));
135
        $smiley_checkbox->addOption(1, _AM_INSTR_DOSMILEY);
136
        $option_tray->addElement($smiley_checkbox);
137
        // ББ коды
138
        $xcode_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode'));
139
        $xcode_checkbox->addOption(1, _AM_INSTR_DOXCODE);
140
        $option_tray->addElement($xcode_checkbox);
141
        //
142
        $br_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr'));
143
        $br_checkbox->addOption(1, _AM_INSTR_DOAUTOWRAP);
144
        $option_tray->addElement($br_checkbox);
145
        //
146
        $form->addElement($option_tray);
147
148
        // Если мы редактируем страницу
149
        if (!$this->isNew()) {
150
            $form->addElement(new \XoopsFormHidden('pageid', $this->getVar('pageid')));
151
        } else {
152
            $form->addElement(new \XoopsFormHidden('pageid', 0));
153
        }
154
        // ID инструкции
155
        if ($instrid) {
156
            $form->addElement(new \XoopsFormHidden('instrid', $instrid));
157
        } else {
158
            $form->addElement(new \XoopsFormHidden('instrid', 0));
159
        }
160
        //
161
        $form->addElement(new \XoopsFormHidden('op', 'savepage'));
162
        // Кнопка
163
        $button_tray = new \XoopsFormElementTray('', '');
164
        $button_tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
165
        $save_btn = new \XoopsFormButton('', 'cancel', _AM_INSTR_SAVEFORM);
166
        $save_btn->setExtra('onclick="instrSavePage();"');
167
        $button_tray->addElement($save_btn);
168
        $form->addElement($button_tray);
169
170
        return $form;
171
    }
172
173
    //
174
175
    /**
176
     * @return mixed
177
     */
178
    public function getInstrid()
179
    {
180
        // Возвращаем ID инструкции
181
        return $this->getVar('instrid');
182
    }
183
}
184