1 | <?php |
||
2 | |||
3 | namespace XoopsModules\Wggithub; |
||
4 | |||
5 | /* |
||
6 | You may not change or alter any portion of this comment or credits |
||
7 | of supporting developers from this source code or any supporting source code |
||
8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
9 | |||
10 | This program is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
13 | */ |
||
14 | |||
15 | /** |
||
16 | * wgGitHub module for xoops |
||
17 | * |
||
18 | * @copyright 2020 XOOPS Project (https://xooops.org) |
||
19 | * @license GPL 2.0 or later |
||
20 | * @package wggithub |
||
21 | * @since 1.0 |
||
22 | * @min_xoops 2.5.10 |
||
23 | * @author Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com> |
||
24 | */ |
||
25 | |||
26 | use XoopsModules\Wggithub; |
||
27 | |||
28 | \defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
||
29 | |||
30 | /** |
||
31 | * Class Object Settings |
||
32 | */ |
||
33 | class Settings extends \XoopsObject |
||
34 | { |
||
35 | /** |
||
36 | * Constructor |
||
37 | * |
||
38 | * @param null |
||
39 | */ |
||
40 | public function __construct() |
||
41 | { |
||
42 | $this->initVar('set_id', \XOBJ_DTYPE_INT); |
||
43 | $this->initVar('set_username', \XOBJ_DTYPE_TXTBOX); |
||
44 | $this->initVar('set_token', \XOBJ_DTYPE_TXTBOX); |
||
45 | $this->initVar('set_options', \XOBJ_DTYPE_TXTAREA); |
||
46 | $this->initVar('set_primary', \XOBJ_DTYPE_INT); |
||
47 | $this->initVar('set_date', \XOBJ_DTYPE_INT); |
||
48 | $this->initVar('set_submitter', \XOBJ_DTYPE_INT); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @static function &getInstance |
||
53 | * |
||
54 | * @param null |
||
55 | */ |
||
56 | public static function getInstance() |
||
57 | { |
||
58 | static $instance = false; |
||
59 | if (!$instance) { |
||
60 | $instance = new self(); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * The new inserted $Id |
||
66 | * @return inserted id |
||
67 | */ |
||
68 | public function getNewInsertedIdSettings() |
||
69 | { |
||
70 | $newInsertedId = $GLOBALS['xoopsDB']->getInsertId(); |
||
71 | return $newInsertedId; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @public function getForm |
||
76 | * @param bool $action |
||
77 | * @param int $start |
||
78 | * @param int $limit |
||
79 | * @return \XoopsThemeForm |
||
80 | */ |
||
81 | public function getFormSettings($action = false, $start = 0, $limit = 0) |
||
82 | { |
||
83 | if (!$action) { |
||
84 | $action = $_SERVER['REQUEST_URI']; |
||
85 | } |
||
86 | // Title |
||
87 | $title = $this->isNew() ? \sprintf(\_AM_WGGITHUB_SETTING_ADD) : \sprintf(\_AM_WGGITHUB_SETTING_EDIT); |
||
88 | // Get Theme Form |
||
89 | \xoops_load('XoopsFormLoader'); |
||
90 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
91 | $form->setExtra('enctype="multipart/form-data"'); |
||
92 | // Form Text setUsername |
||
93 | $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_SETTING_USERNAME, 'set_username', 50, 255, $this->getVar('set_username')), true); |
||
94 | // Form Text setToken |
||
95 | $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_SETTING_TOKEN, 'set_token', 50, 255, $this->getVar('set_token')), true); |
||
96 | // Form Editor TextArea setOptions |
||
97 | $form->addElement(new \XoopsFormTextArea(\_AM_WGGITHUB_SETTING_OPTIONS, 'set_options', $this->getVar('set_options', 'e'), 4, 47)); |
||
98 | // Form Radio Yes/No setPrimary |
||
99 | $setPrimary = $this->isNew() ?: $this->getVar('set_primary'); |
||
100 | $form->addElement(new \XoopsFormRadioYN(\_AM_WGGITHUB_SETTING_PRIMARY, 'set_primary', $setPrimary)); |
||
101 | // Form Text Date Select setDate |
||
102 | $setDate = $this->isNew() ?: $this->getVar('set_date'); |
||
103 | $form->addElement(new \XoopsFormTextDateSelect(\_AM_WGGITHUB_SETTING_DATE, 'set_date', '', $setDate)); |
||
104 | // Form Select User setSubmitter |
||
105 | $form->addElement(new \XoopsFormSelectUser(\_AM_WGGITHUB_SETTING_SUBMITTER, 'set_submitter', false, $this->getVar('set_submitter'))); |
||
106 | // To Save |
||
107 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
108 | $form->addElement(new \XoopsFormHidden('start', $start)); |
||
109 | $form->addElement(new \XoopsFormHidden('limit', $limit)); |
||
110 | $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
||
111 | return $form; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get Values |
||
116 | * @param null $keys |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
117 | * @param null $format |
||
0 ignored issues
–
show
|
|||
118 | * @param null $maxDepth |
||
0 ignored issues
–
show
|
|||
119 | * @return array |
||
120 | */ |
||
121 | public function getValuesSettings($keys = null, $format = null, $maxDepth = null) |
||
122 | { |
||
123 | $helper = \XoopsModules\Wggithub\Helper::getInstance(); |
||
124 | $utility = new \XoopsModules\Wggithub\Utility(); |
||
125 | $ret = $this->getValues($keys, $format, $maxDepth); |
||
126 | $ret['id'] = $this->getVar('set_id'); |
||
127 | $ret['username'] = $this->getVar('set_username'); |
||
128 | $ret['token'] = $this->getVar('set_token'); |
||
129 | $ret['options'] = \strip_tags($this->getVar('set_options', 'e')); |
||
130 | $editorMaxchar = $helper->getConfig('editor_maxchar'); |
||
131 | $ret['options_short'] = $utility::truncateHtml($ret['options'], $editorMaxchar); |
||
132 | $ret['primary'] = (int)$this->getVar('set_primary') > 0 ? _YES : _NO; |
||
133 | $ret['date'] = \formatTimestamp($this->getVar('set_date'), 's'); |
||
134 | $ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('set_submitter')); |
||
135 | return $ret; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Returns an array representation of the object |
||
140 | * |
||
141 | * @return array |
||
142 | */ |
||
143 | public function toArraySettings() |
||
144 | { |
||
145 | $ret = []; |
||
146 | $vars = $this->getVars(); |
||
147 | foreach (\array_keys($vars) as $var) { |
||
148 | $ret[$var] = $this->getVar('"{$var}"'); |
||
149 | } |
||
150 | return $ret; |
||
151 | } |
||
152 | } |
||
153 |