1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
14
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License |
15
|
|
|
* @package Mymenus |
16
|
|
|
* @since 1.0 |
17
|
|
|
* @author trabis <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
21
|
|
|
|
22
|
|
|
include_once dirname(__DIR__) . '/include/common.php'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class MymenusMenus |
26
|
|
|
*/ |
27
|
|
|
class MymenusMenus extends XoopsObject |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var MymenusMenus |
31
|
|
|
* @access private |
32
|
|
|
*/ |
33
|
|
|
private $mymenus = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* constructor |
37
|
|
|
*/ |
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
$this->mymenus = MymenusMymenus::getInstance(); |
41
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
42
|
|
|
$this->initVar('id', XOBJ_DTYPE_INT); |
43
|
|
|
$this->initVar('title', XOBJ_DTYPE_TXTBOX); |
44
|
|
|
$this->initVar('css', XOBJ_DTYPE_TXTBOX); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get {@link XoopsThemeForm} for adding/editing items |
49
|
|
|
* |
50
|
|
|
* @param bool|string $action |
51
|
|
|
* @return XoopsThemeForm {@link XoopsThemeForm} |
52
|
|
|
*/ |
53
|
|
|
public function getForm($action = false) |
54
|
|
|
{ |
55
|
|
|
// $grouppermHandler = xoops_gethandler('groupperm'); |
|
|
|
|
56
|
|
|
// |
57
|
|
|
xoops_load('XoopsFormLoader'); |
58
|
|
|
// |
59
|
|
|
if ($action === false) { |
60
|
|
|
// $action = $_SERVER['REQUEST_URI']; |
|
|
|
|
61
|
|
|
$action = XoopsRequest::getString('REQUEST_URI', '', 'SERVER'); |
62
|
|
|
} |
63
|
|
|
// |
64
|
|
|
// $isAdmin = mymenusUserIsAdmin(); |
|
|
|
|
65
|
|
|
// $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : array(0 => XOOPS_GROUP_ANONYMOUS); |
|
|
|
|
66
|
|
|
// |
67
|
|
|
$title = $this->isNew() ? _AM_MYMENUS_MENUS_ADD : _AM_MYMENUS_MENUS_EDIT; |
68
|
|
|
// |
69
|
|
|
$form = new XoopsThemeForm($title, 'moneusform', $action, 'post', true); |
70
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
71
|
|
|
// menus: title |
72
|
|
|
$menusTitleText = new XoopsFormText(_AM_MYMENUS_MENU_TITLE, 'title', 50, 255, $this->getVar('title', 'e')); |
73
|
|
|
$menusTitleText->setDescription(_AM_MYMENUS_MENU_TITLE_DESC); |
74
|
|
|
$form->addElement($menusTitleText, true); |
75
|
|
|
// menus: css |
76
|
|
|
$menusCssText = new XoopsFormText(_AM_MYMENUS_MENU_CSS, 'css', 50, 255, $this->getVar('css', 'e')); |
77
|
|
|
$menusCssText->setDescription(_AM_MYMENUS_MENU_CSS_DESC); |
78
|
|
|
$form->addElement($menusCssText, false); |
79
|
|
|
// form: button tray |
80
|
|
|
$buttonTray = new XoopsFormElementTray('', ''); |
81
|
|
|
$buttonTray->addElement(new XoopsFormHidden('op', 'save')); |
82
|
|
|
// |
83
|
|
|
$buttonSubmit = new XoopsFormButton('', '', _SUBMIT, 'submit'); |
84
|
|
|
$buttonSubmit->setExtra('onclick="this.form.elements.op.value=\'save\'"'); |
85
|
|
|
$buttonTray->addElement($buttonSubmit); |
86
|
|
|
if ($this->isNew()) { |
|
|
|
|
87
|
|
|
// NOP |
88
|
|
|
} else { |
89
|
|
|
$form->addElement(new XoopsFormHidden('id', (int)$this->getVar('id'))); |
90
|
|
|
// |
91
|
|
|
$buttonDelete = new XoopsFormButton('', '', _DELETE, 'submit'); |
92
|
|
|
$buttonDelete->setExtra('onclick="this.form.elements.op.value=\'delete\'"'); |
93
|
|
|
$buttonTray->addElement($buttonDelete); |
94
|
|
|
} |
95
|
|
|
$buttonReset = new XoopsFormButton('', '', _RESET, 'reset'); |
96
|
|
|
$buttonTray->addElement($buttonReset); |
97
|
|
|
// |
98
|
|
|
$buttonCancel = new XoopsFormButton('', '', _CANCEL, 'button'); |
99
|
|
|
$buttonCancel->setExtra('onclick="history.go(-1)"'); |
100
|
|
|
$buttonTray->addElement($buttonCancel); |
101
|
|
|
// |
102
|
|
|
$form->addElement($buttonTray); |
103
|
|
|
|
104
|
|
|
// |
105
|
|
|
return $form; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Class MymenusMenusHandler |
111
|
|
|
*/ |
112
|
|
|
class MymenusMenusHandler extends XoopsPersistableObjectHandler |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
/** |
115
|
|
|
* @var MymenusMymenus |
116
|
|
|
* @access private |
117
|
|
|
*/ |
118
|
|
|
private $mymenus = null; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param null|XoopsDatabase $db |
122
|
|
|
*/ |
123
|
|
|
public function __construct(XoopsDatabase $db) |
124
|
|
|
{ |
125
|
|
|
parent::__construct($db, 'mymenus_menus', 'MymenusMenus', 'id', 'title', 'css'); |
126
|
|
|
$this->mymenus = MymenusMymenus::getInstance(); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.