UserSubmit   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 214
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 101
dl 0
loc 214
rs 10
c 0
b 0
f 0
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserSubmitForm() 0 20 1
A getUserSubmitFooter() 0 10 1
A __construct() 0 3 1
A getInstance() 0 8 2
A getUserSubmitSwitch() 0 10 1
A getUserSubmitHeader() 0 22 1
A write() 0 5 1
A getUserSubmitSave() 0 27 3
A render() 0 27 2
1
<?php namespace XoopsModules\Tdmcreate\Files\User;
2
3
use XoopsModules\Tdmcreate;
4
use XoopsModules\Tdmcreate\Files;
5
6
/*
7
 You may not change or alter any portion of this comment or credits
8
 of supporting developers from this source code or any supporting source code
9
 which is considered copyrighted (c) material of the original comment or credit authors.
10
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
/**
16
 * tdmcreate module.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.0
22
 *
23
 * @author          Txmod Xoops http://www.txmodxoops.org
24
 *
25
 * @version         $Id: UserSubmit.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class UserSubmit.
30
 */
31
class UserSubmit extends Files\CreateFile
32
{
33
    /**
34
     *  @public function constructor
35
     *  @param null
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /**
43
     *  @static function getInstance
44
     *  @param null
45
     * @return UserSubmit
46
     */
47
    public static function getInstance()
48
    {
49
        static $instance = false;
50
        if (!$instance) {
51
            $instance = new self();
52
        }
53
54
        return $instance;
55
    }
56
57
    /**
58
     *  @public function write
59
     *  @param string $module
60
     *  @param mixed $table
61
     *  @param string $filename
62
     */
63
    public function write($module, $table, $filename)
64
    {
65
        $this->setModule($module);
66
        $this->setTable($table);
67
        $this->setFileName($filename);
68
    }
69
70
    /**
71
     * @public function getUserSubmitHeader
72
     * @param $moduleDirname
73
     *
74
     * @return string
75
     */
76
    public function getUserSubmitHeader($moduleDirname)
77
    {
78
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
79
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
80
        $uc = UserXoopsCode::getInstance();
81
        $t = "\t";
82
        $ret = $this->getInclude();
83
        $ret .= $xc->getXcLoadLanguage('admin', '', $moduleDirname);
84
        $ret .= $pc->getPhpCodeCommentLine('It recovered the value of argument op in URL$');
85
        $ret .= $xc->getXcXoopsRequest('op', 'op', 'form');
86
        $ret .= $pc->getPhpCodeCommentLine('Template');
87
        $ret .= $uc->getUserTplMain($moduleDirname, 'submit');
88
        $ret .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
89
        $ret .= $xc->getXcAddStylesheet();
90
        $ret .= "\$permSubmit = \$gpermHandler->checkRight('{$moduleDirname}_ac', 4, \$groups, \$GLOBALS['xoopsModule']->getVar('mid')) ? true : false;\n";
91
        $ret .= $pc->getPhpCodeCommentLine('Redirection if not permissions');
92
        $condIf = $xc->getXcRedirectHeader('index', '', '2', '_NOPERM', true, $t);
93
        $condIf .= $this->getSimpleString('exit();', $t);
94
95
        $ret .= $pc->getPhpCodeConditions('$permSubmit', ' === ', 'false', $condIf, false);
96
97
        return $ret;
98
    }
99
100
    /**
101
     * @public function getAdminPagesList
102
     * @param        $tableName
103
     * @param        $language
104
     * @param string $t
105
     * @return string
106
     */
107
    public function getUserSubmitForm($tableName, $language, $t = '')
108
    {
109
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
110
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
111
        $uc = UserXoopsCode::getInstance();
112
        $ret = $pc->getPhpCodeCommentLine('Navigation');
113
        $ret .= $xc->getXcEqualsOperator('$navigation', "{$language}SUBMIT_PROPOSER", '', false, $t . "\t");
114
        $ret .= $xc->getXcTplAssign('navigation', '$navigation', true, $t . "\t");
115
        $ret .= $pc->getPhpCodeCommentLine('Title of page', null, $t . "\t");
116
        $ret .= $xc->getXcEqualsOperator('$title', "{$language}SUBMIT_PROPOSER . '&nbsp;-&nbsp;'", '', false, $t . "\t");
117
        $ret .= $xc->getXcEqualsOperator('$title', "\$GLOBALS['xoopsModule']->name()", '.', false, $t . "\t");
118
        $ret .= $xc->getXcTplAssign('xoops_pagetitle', '$title', true, $t . "\t");
119
        $ret .= $pc->getPhpCodeCommentLine('Description', null, $t . "\t");
120
        $ret .= $uc->getUserAddMeta('description', $language, 'SUBMIT_PROPOSER', $t . "\t");
121
        $ret .= $pc->getPhpCodeCommentLine('Form Create', null, $t . "\t");
122
        $ret .= $xc->getXcObjHandlerCreate($tableName, $t . "\t");
123
        $ret .= $xc->getXcGetForm('form', $tableName, 'Obj', $t . "\t");
124
        $ret .= $xc->getXcTplAssign('form', '$form->render()', true, $t . "\t");
125
126
        return $ret;
127
    }
128
129
    /**
130
     *  @public function getUserSubmitSave
131
     *  @param string $moduleDirname
132
     * @param        $fields
133
     *  @param string $tableName
134
     * @param        $tableSoleName
135
     * @param        $tableSubmit
136
     * @param        $tableAutoincrement
137
     * @param        $language
138
     * @param string $t
139
     * @return string
140
     */
141
    public function getUserSubmitSave($moduleDirname, $fields, $tableName, $tableSoleName, $tableSubmit, $tableAutoincrement, $language, $t = '')
142
    {
143
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
144
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
145
        $ucfTableName = ucfirst($tableName);
0 ignored issues
show
Unused Code introduced by
The assignment to $ucfTableName is dead and can be removed.
Loading history...
146
        $ret = $pc->getPhpCodeCommentLine('Security Check');
147
        $xoopsSecurityCheck = $xc->getXcSecurityCheck();
148
        $securityError = $xc->getXcSecurityErrors();
149
        $implode = $pc->getPhpCodeImplode(',', $securityError);
150
        $redirectError = $xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t");
151
        $ret .= $pc->getPhpCodeConditions('!' . $xoopsSecurityCheck, '', '', $redirectError, false, $t);
152
        $ret .= $xc->getXcObjHandlerCreate($tableName, $t);
153
        $autoincrement = in_array(1, $tableAutoincrement) ? $tableAutoincrement : 0;
154
        if (in_array(1, $tableSubmit)) {
155
            $ret .= $xc->getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $autoincrement, $fields, $t);
156
        }
157
        $ret .= $pc->getPhpCodeCommentLine('Insert Data', null, $t);
158
        $insert = $xc->getXcInsert($tableName, $tableName, 'Obj', 'Handler');
159
        $confirmOk = $xc->getXcRedirectHeader('index', '', '2', "{$language}FORM_OK", true, $t . "\t");
160
        $ret .= $pc->getPhpCodeConditions($insert, '', '', $confirmOk, false, $t);
161
162
        $ret .= $pc->getPhpCodeCommentLine('Get Form Error', null, $t);
163
        $ret .= $xc->getXcTplAssign('error', "\${$tableName}Obj->getHtmlErrors()", true, $t);
164
        $ret .= $xc->getXcGetForm('form', $tableName, 'Obj', $t);
165
        $ret .= $xc->getXcTplAssign('form', '$form->display()', true, $t);
166
167
        return $ret;
168
    }
169
170
    /**
171
     * @public function getUserSubmitFooter
172
     * @param $moduleDirname
173
     * @param $language
174
     * @return string
175
     */
176
    public function getUserSubmitFooter($moduleDirname, $language)
177
    {
178
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
179
        $uc = UserXoopsCode::getInstance();
180
        $stuModuleDirname = mb_strtoupper($moduleDirname);
0 ignored issues
show
Unused Code introduced by
The assignment to $stuModuleDirname is dead and can be removed.
Loading history...
181
        $ret = $pc->getPhpCodeCommentLine('Breadcrumbs');
182
        $ret .= $uc->getUserBreadcrumbs($language, 'SUBMIT');
183
        $ret .= $this->getInclude('footer');
184
185
        return $ret;
186
    }
187
188
    /**
189
     * @private function getUserSubmitSwitch
190
     * @param $moduleDirname
191
     * @param $tableId
192
     * @param $tableMid
193
     * @param $tableName
194
     * @param $tableSoleName
195
     * @param $tableSubmit
196
     * @param $tableAutoincrement
197
     * @param $language
198
     * @param $t
199
     * @return string
200
     */
201
    private function getUserSubmitSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableSubmit, $tableAutoincrement, $language, $t)
202
    {
203
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
204
        $fields = $this->getTableFields($tableMid, $tableId);
205
        $cases = [
206
            'form' => [$this->getUserSubmitForm($tableName, $language, $t)],
207
            'save' => [$this->getUserSubmitSave($moduleDirname, $fields, $tableName, $tableSoleName, $tableSubmit, $tableAutoincrement, $language, $t . "\t")],
208
        ];
209
210
        return $xc->getXcSwitch('op', $cases, true, false, $t);
211
    }
212
213
    /**
214
     *  @public function render
215
     *  @param null
216
     * @return bool|string
217
     */
218
    public function render()
219
    {
220
        $module = $this->getModule();
221
        $table = $this->getTable();
0 ignored issues
show
Unused Code introduced by
The assignment to $table is dead and can be removed.
Loading history...
222
        $filename = $this->getFileName();
223
        $moduleDirname = $module->getVar('mod_dirname');
224
        $tables = $this->getTableTables($module->getVar('mod_id'));
225
        $tableSoleName = '';
226
        $tableSubmit = [];
227
        $tableAutoincrement = [];
228
        foreach (array_keys($tables) as $t) {
229
            $tableId = $tables[$t]->getVar('table_id');
230
            $tableMid = $tables[$t]->getVar('table_mid');
231
            $tableName = $tables[$t]->getVar('table_name');
232
            $tableSoleName = $tables[$t]->getVar('table_solename');
233
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
234
            $tableAutoincrement[] = $tables[$t]->getVar('table_autoincrement');
235
        }
236
        $language = $this->getLanguage($moduleDirname, 'MA');
237
        $content = $this->getHeaderFilesComments($module, $filename);
238
        $content .= $this->getUserSubmitHeader($moduleDirname);
239
        $content .= $this->getUserSubmitSwitch($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableSubmit, $tableAutoincrement, $language, "\t");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tableName seems to be defined by a foreach iteration on line 228. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
Comprehensibility Best Practice introduced by
The variable $tableId seems to be defined by a foreach iteration on line 228. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
Comprehensibility Best Practice introduced by
The variable $tableMid seems to be defined by a foreach iteration on line 228. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
240
        $content .= $this->getUserSubmitFooter($moduleDirname, $language);
241
242
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
243
244
        return $this->renderFile();
245
    }
246
}
247