UserPrint::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Tdmcreate\Files\User;
4
5
use XoopsModules\Tdmcreate;
6
use XoopsModules\Tdmcreate\Files;
7
8
/*
9
 You may not change or alter any portion of this comment or credits
10
 of supporting developers from this source code or any supporting source code
11
 which is considered copyrighted (c) material of the original comment or credit authors.
12
13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/**
18
 * tdmcreate module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops http://www.txmodxoops.org
26
 *
27
 */
28
29
/**
30
 * Class UserPrint.
31
 */
32
class UserPrint extends Files\CreateFile
33
{
34
    /**
35
     * @var mixed
36
     */
37
    private $uxc = null;
38
39
    /**
40
     * @var string
41
     */
42
    private $xc = null;
43
	
44
	/**
45
     * @var string
46
     */
47
    private $pc = null;
48
49
    /**
50
     * @public function constructor
51
     * @param null
52
     */
53
    public function __construct()
54
    {
55
        parent::__construct();
56
        $this->xc      = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like XoopsModules\Tdmcreate\F...oopsCode::getInstance() of type XoopsModules\Tdmcreate\Files\CreateXoopsCode is incompatible with the declared type string of property $xc.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like XoopsModules\Tdmcreate\F...ePhpCode::getInstance() of type XoopsModules\Tdmcreate\Files\CreatePhpCode is incompatible with the declared type string of property $pc.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
        $this->uxc      = UserXoopsCode::getInstance();
59
    }
60
61
    /**
62
     * @static function getInstance
63
     * @param null
64
     * @return UserPrint
65
     */
66
    public static function getInstance()
67
    {
68
        static $instance = false;
69
        if (!$instance) {
70
            $instance = new self();
71
        }
72
73
        return $instance;
74
    }
75
76
    /**
77
     * @public function write
78
     * @param string $module
79
     * @param mixed  $table
80
     * @param string $filename
81
     */
82
    public function write($module, $table, $filename)
83
    {
84
        $this->setModule($module);
85
        $this->setTable($table);
86
        $this->setFileName($filename);
87
    }
88
89
    /**
90
     * @public function getUserPrint
91
     * @param string $moduleDirname
92
     * @param string $language
93
     *
94
     * @return string
95
     */
96
    public function getUserPrint($moduleDirname, $language)
97
    {
98
        $pc               = Tdmcreate\Files\CreatePhpCode::getInstance();
99
        $stuModuleDirname = mb_strtoupper($moduleDirname);
100
        $table            = $this->getTable();
101
        $tableName        = $table->getVar('table_name');
102
        $tableSoleName    = $table->getVar('table_solename');
103
        $fields           = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
104
        $fieldId          = '';
105
        $fieldMain        = '';
106
        $ucfFieldName     = '';
107
        foreach (array_keys($fields) as $f) {
108
            $fieldName   = $fields[$f]->getVar('field_name');
109
            if ((0 == $f) && (1 == $this->table->getVar('table_autoincrement'))) {
110
                $fieldId = $fieldName;
111
            } else {
112
                if (1 == $fields[$f]->getVar('field_main')) {
113
                    $fieldMain = $fieldName; // fieldMain = fields parameters main field
114
                }
115
            }
116
            $ucfFieldName = ucfirst($fieldName);
117
        }
118
        $ccFieldId      = $this->getCamelCase($fieldId, false, true);
119
        $stuLpFieldName = mb_strtoupper($ccFieldId);
120
        $ret            = $pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
121
        $ret            .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
122
        $ret            .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']);
123
        $ret            .= $this->getInclude();
124
        $ret            .= $this->xc->getXcXoopsRequest($ccFieldId, (string)$fieldId, '', 'Int');
125
        $ret            .= $this->pc->getPhpCodeCommentLine('Define Stylesheet');
126
        $ret            .= $this->xc->getXcXoThemeAddStylesheet();
127
        $redirectHeader = $this->xc->getXcRedirectHeader("{$stuModuleDirname}_URL . '/index.php'", '', '2', "{$language}NO{$stuLpFieldName}", false, "\t");
128
        $ret            .= $this->pc->getPhpCodeConditions("empty(\${$ccFieldId})", '', '', $redirectHeader);
129
130
        $ret            .= $this->pc->getPhpCodeCommentLine('Get Instance of Handler');
131
        $ret            .= $this->xc->getXcHandlerLine($tableName);
132
133
        $ret            .= $this->pc->getPhpCodeCommentLine('Verify that the article is published');
134
        if (false !== mb_strpos($fieldName, 'published')) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldName seems to be defined by a foreach iteration on line 107. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
135
            $ret            .= $this->pc->getPhpCodeCommentLine('Not yet', $fieldName);
136
            $redirectHeader .= $this->getSimpleString('exit();');
137
            $ret            .= $this->pc->getPhpCodeConditions("\${$tableName}Handler->getVar('{$fieldName}') == 0 || \${$tableName}Handler->getVar('{$fieldName}') > time()", '', '', $redirectHeader);
138
        }
139
        if (false !== mb_strpos($fieldName, 'expired')) {
140
            $ret            .= $this->pc->getPhpCodeCommentLine('Expired', $ucfFieldName);
141
            $redirectHeader .= $this->getSimpleString('exit();');
142
            $ret            .= $this->pc->getPhpCodeConditions("\${$tableName}Handler->getVar('{$fieldName}') != 0 && \${$tableName}Handler->getVar('{$fieldName}') < time()", '', '', $redirectHeader);
143
        }
144
        if (false !== mb_strpos($fieldName, 'date')) {
145
            $ret            .= $this->pc->getPhpCodeCommentLine('Date', $ucfFieldName);
146
            $redirectHeader .= $this->getSimpleString('exit();');
147
            $ret            .= $this->pc->getPhpCodeConditions("\${$tableName}Handler->getVar('{$fieldName}') != 0 && \${$tableName}Handler->getVar('{$fieldName}') < time()", '', '', $redirectHeader);
148
        }
149
        if (false !== mb_strpos($fieldName, 'time')) {
150
            $ret            .= $this->pc->getPhpCodeCommentLine('Time', $ucfFieldName);
151
            $redirectHeader .= $this->getSimpleString('exit();');
152
            $ret            .= $this->pc->getPhpCodeConditions("\${$tableName}Handler->getVar('{$fieldName}') != 0 && \${$tableName}Handler->getVar('{$fieldName}') < time()", '', '', $redirectHeader);
153
        }
154
        $ret            .= $this->xc->getXcHandlerGet($tableName, $ccFieldId, '', $tableName . 'Handler',false);
155
        $gperm          = $this->xc->getXcCheckRight('!$grouppermHandler', "{$moduleDirname}_view", "\${$ccFieldId}->getVar('{$fieldId}')", '$groups', "\$GLOBALS['xoopsModule']->getVar('mid')", true);
156
        $ret            .= $this->pc->getPhpCodeCommentLine('Verify permissions');
157
        $noPerm         = $this->xc->getXcRedirectHeader("{$stuModuleDirname}_URL . '/index.php'", '', '3', '_NOPERM', false, "\t");
158
        $noPerm         .= $this->getSimpleString('exit();', "\t");
159
        $ret            .= $this->pc->getPhpCodeConditions($gperm, '', '', $noPerm);
160
        $ret            .= $this->xc->getXcGetValues($tableName, $tableSoleName, '', true);
161
        $contentForeach = $this->xc->getXcXoopsTplAppend('"{$k}"', '$v', "\t");
162
        $ret            .= $this->pc->getPhpCodeForeach($tableSoleName, false, 'k', 'v', $contentForeach);
163
        $ret            .= $this->xc->getXcXoopsTplAssign('xoops_sitename', "\$GLOBALS['xoopsConfig']['sitename']");
164
        $getVar         = $this->xc->getXcGetVar('', $tableSoleName, $fieldMain, true);
165
        $stripTags      = $this->pc->getPhpCodeStripTags('', $getVar . ' - ' . "{$language}PRINT" . ' - ' . "\$GLOBALS['xoopsModule']->name()", true);
166
        $ret            .= $this->xc->getXcXoopsTplAssign('xoops_pagetitle', $stripTags);
167
        $ret            .= $this->xc->getXcXoopsTplDisplay($tableName . '_print.tpl', '', false);
168
169
        return $ret;
170
    }
171
172
    /**
173
     * @public function render
174
     * @param null
175
     * @return bool|string
176
     */
177
    public function render()
178
    {
179
        $module        = $this->getModule();
180
        $filename      = $this->getFileName();
181
        $moduleDirname = $module->getVar('mod_dirname');
182
        $language      = $this->getLanguage($moduleDirname, 'MA');
183
        $content       = $this->getHeaderFilesComments($module);
184
        $content       .= $this->getUserPrint($moduleDirname, $language);
185
186
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
187
188
        return $this->renderFile();
189
    }
190
}
191