Completed
Push — master ( 48ecb4...5fe85d )
by Michael
01:45
created

InstructionInstruction::get_new_enreg()   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
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
class InstructionInstruction extends XoopsObject
10
{
11
    // constructor
12
    public function __construct()
13
    {
14
        //		$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...
15
        $this->initVar('instrid', XOBJ_DTYPE_INT, null, false, 11);
16
        $this->initVar('cid', XOBJ_DTYPE_INT, 0, false, 5);
17
        $this->initVar('uid', XOBJ_DTYPE_INT, 0, false, 11);
18
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', false);
19
        $this->initVar('status', XOBJ_DTYPE_INT, 0, false, 1);
20
        $this->initVar('pages', XOBJ_DTYPE_INT, 0, false, 11);
21
        $this->initVar('description', XOBJ_DTYPE_TXTAREA, null, false);
22
        $this->initVar('datecreated', XOBJ_DTYPE_INT, 0, false, 10);
23
        $this->initVar('dateupdated', XOBJ_DTYPE_INT, 0, false, 10);
24
        $this->initVar('metakeywords', XOBJ_DTYPE_TXTBOX, '', false);
25
        $this->initVar('metadescription', XOBJ_DTYPE_TXTBOX, '', false);
26
27
        // Нет в таблице
28
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
29
        $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false);
30
    }
31
32
    public function InstructionInstruction()
33
    {
34
        $this->__construct();
35
    }
36
37
    public function get_new_enreg()
38
    {
39
        $new_enreg = $GLOBALS['xoopsDB']->getInsertId();
40
        return $new_enreg;
41
    }
42
43
    // Получаем форму
44
    public function getForm($action = false)
45
    {
46
        global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
47
        // Если нет $action
48
        if (false === $action) {
49
            $action = xoops_getenv('REQUEST_URI');
50
        }
51
        // Подключаем формы
52
        include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
53
54
        // Название формы
55
        $title = $this->isNew() ? sprintf(_AM_INSTRUCTION_FORMADDINSTR) : sprintf(_AM_INSTRUCTION_FORMEDITINSTR);
56
57
        // Форма
58
        $form = new XoopsThemeForm($title, 'forminstr', $action, 'post', true);
59
        //$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...
60
        // Название инструкции
61
        $form->addElement(new XoopsFormText(_AM_INSTRUCTION_TITLEC, 'title', 50, 255, $this->getVar('title')), true);
62
        // Категория
63
        $instructioncatHandler = xoops_getModuleHandler('category', 'instruction');
64
        $criteria              = new CriteriaCompo();
65
        $criteria->setSort('weight ASC, title');
66
        $criteria->setOrder('ASC');
67
        $instructioncat_arr = $instructioncatHandler->getall($criteria);
68
        unset($criteria);
69
        // Подключаем трей
70
        include_once $GLOBALS['xoops']->path('class/tree.php');
71
        $mytree = new XoopsObjectTree($instructioncat_arr, 'cid', 'pid');
72
73
        // $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), 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...
74
        $moduleDirName = basename(__DIR__);
75
        if (false !== ($moduleHelper = Xmf\Module\Helper::getHelper($moduleDirName))) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
76
        } else {
77
            $moduleHelper = Xmf\Module\Helper::getHelper('system');
78
        }
79
        $module = $moduleHelper->getModule();
80
81 View Code Duplication
        if (InstructionUtility::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...
82
            $mytree_select = $mytree->makeSelectElement('cid', 'title', '--', $this->getVar('cid'), true, 0, '', _AM_INSTRUCTION_CATC);
83
            $form->addElement($mytree_select);
84
        } else {
85
            $form->addElement(new XoopsFormLabel(_AM_INSTRUCTION_CATC, $mytree->makeSelBox('cid', 'title', '--', $this->getVar('cid'), true)));
86
        }
87
88
        // Описание
89
        $form->addElement(InstructionUtility::getWysiwygForm(_AM_INSTRUCTION_DESCRIPTIONC, 'description', $this->getVar('description', 'e')), true);
90
        // Статус
91
        $form->addElement(new XoopsFormRadioYN(_AM_INSTRUCTION_ACTIVEC, 'status', $this->getVar('status')), false);
92
93
        // Теги
94
        if (is_dir('../../tag') || is_dir('../tag')) {
95
            $dir_tag_ok = true;
96
        } else {
97
            $dir_tag_ok = false;
98
        }
99
        // Если влючена поддержка тегов и есть модуль tag
100
        if (xoops_getModuleOption('usetag', 'instruction') && $dir_tag_ok) {
101
            $itemIdForTag = $this->isNew() ? 0 : $this->getVar('instrid');
102
            // Подключаем форму тегов
103
            include_once $GLOBALS['xoops']->path('modules/tag/include/formtag.php');
104
            // Добавляем элемент в форму
105
            $form->addElement(new XoopsFormTag('tag', 60, 255, $itemIdForTag, 0));
106
        }
107
108
        // Мета-теги ключевых слов
109
        $form->addElement(new XoopsFormText(_AM_INSTRUCTION_METAKEYWORDSC, 'metakeywords', 50, 255, $this->getVar('metakeywords')), false);
110
        // Мета-теги описания
111
        $form->addElement(new XoopsFormText(_AM_INSTRUCTION_METADESCRIPTIONC, 'metadescription', 50, 255, $this->getVar('metadescription')), false);
112
113
        // Если мы редактируем категорию
114
        if (!$this->isNew()) {
115
            $form->addElement(new XoopsFormHidden('instrid', $this->getVar('instrid')));
116
        }
117
        //
118
        $form->addElement(new XoopsFormHidden('op', 'saveinstr'));
119
        // Кнопка
120
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
121
        return $form;
122
    }
123
}
124
125
class InstructionInstructionHandler extends XoopsPersistableObjectHandler
126
{
127
    public function __construct($db)
128
    {
129
        parent::__construct($db, 'instruction_instr', 'InstructionInstruction', 'instrid', 'title');
130
    }
131
132
    // Обновление даты обновления инструкций
133 View Code Duplication
    public function updateDateupdated($instrid = 0, $time = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
134
    {
135
        // Если не передали время
136
        $time = null === $time ? time() : (int)$time;
137
        //
138
        $sql = sprintf('UPDATE `%s` SET `dateupdated` = %u WHERE `instrid` = %u', $this->table, $time, (int)$instrid);
139
        //
140
        return $this->db->query($sql);
141
    }
142
143
    // Обновление числа страниц
144
    public function updatePages($instrid = 0)
145
    {
146
        $inspageHandler = xoops_getModuleHandler('page', 'instruction');
147
        // Находим число активных страниц
148
        $criteria = new CriteriaCompo();
149
        $criteria->add(new Criteria('instrid', $instrid, '='));
150
        $criteria->add(new Criteria('status ', '0', '>'));
151
        // Число страниц
152
        $pages = $inspageHandler->getCount($criteria);
153
        unset($criteria);
154
155
        // Сохраняем это число
156
        $sql = sprintf('UPDATE `%s` SET `pages` = %u, `dateupdated` = %u WHERE `instrid` = %u', $this->table, $pages, time(), $instrid);
157
        //
158
        return $this->db->query($sql);
159
    }
160
}
161