UserSingle::getUserSingleHeader()   A
last analyzed

Complexity

Conditions 5
Paths 10

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 23
nc 10
nop 3
dl 0
loc 30
rs 9.2408
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 UserSingle.
31
 */
32
class UserSingle extends Files\CreateFile
33
{
34
    /**
35
     * @public function constructor
36
     * @param null
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
     * @static function getInstance
45
     * @param null
46
     * @return UserSingle
47
     */
48
    public static function getInstance()
49
    {
50
        static $instance = false;
51
        if (!$instance) {
52
            $instance = new self();
53
        }
54
55
        return $instance;
56
    }
57
58
    /**
59
     * @public function write
60
     * @param string $module
61
     * @param mixed  $table
62
     * @param string $filename
63
     */
64
    public function write($module, $table, $filename)
65
    {
66
        $this->setModule($module);
67
        $this->setTable($table);
68
        $this->setFileName($filename);
69
    }
70
71
    /**
72
     * @private function getUserSingleHeader
73
     * @param $moduleDirname
74
     * @param $table
75
     * @param $fields
76
     * @return string
77
     */
78
    private function getUserSingleHeader($moduleDirname, $table, $fields)
79
    {
80
        $xc  = Tdmcreate\Files\CreateXoopsCode::getInstance();
81
        $pc  = Tdmcreate\Files\CreatePhpCode::getInstance();
82
        $uxc = UserXoopsCode::getInstance();
83
        $ret = $pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
84
        $ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
85
        $ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']);
86
        $ret .= $this->getInclude();
87
        foreach (array_keys($fields) as $f) {
88
            $fieldName = $fields[$f]->getVar('field_name');
89
            if (0 == $f) {
90
                $fieldId = $fieldName;
91
            }
92
            if (1 == $fields[$f]->getVar('field_parent')) {
93
                $fieldPid = $fieldName;
94
            }
95
        }
96
        if (1 == $table->getVar('table_category')) {
97
            $ccFieldPid = $this->getCamelCase($fieldPid, false, true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldPid does not seem to be defined for all execution paths leading up to this point.
Loading history...
98
            $ret        .= $xc->getXcXoopsRequest($ccFieldPid, (string)$fieldPid, '0', 'Int');
99
        }
100
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldId does not seem to be defined for all execution paths leading up to this point.
Loading history...
101
        $ret       .= $xc->getXcXoopsRequest($ccFieldId, (string)$fieldId, '0', 'Int');
102
        $ret       .= $uxc->getUserTplMain($moduleDirname, 'single');
103
        $ret       .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
104
        $ret       .= $pc->getPhpCodeCommentLine('Define Stylesheet');
105
        $ret       .= $xc->getXcXoThemeAddStylesheet();
106
107
        return $ret;
108
    }
109
110
    /**
111
     * @public function getUserSingleBody
112
     * @param $moduleDirname
113
     * @param $tableName
114
     * @param $language
115
     *
116
     * @return string
117
     */
118
    public function getUserSingleBody($moduleDirname, $tableName, $language)
0 ignored issues
show
Unused Code introduced by
The parameter $language is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

118
    public function getUserSingleBody($moduleDirname, $tableName, /** @scrutinizer ignore-unused */ $language)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $tableName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

118
    public function getUserSingleBody($moduleDirname, /** @scrutinizer ignore-unused */ $tableName, $language)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $moduleDirname is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

118
    public function getUserSingleBody(/** @scrutinizer ignore-unused */ $moduleDirname, $tableName, $language)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
119
    {
120
        $ret = <<<'EOT'
121
122
EOT;
123
        $ret .= $this->getSimpleString('$keywords = array();');
124
125
        return $ret;
126
    }
127
128
    /**
129
     * @private function getUserSingleFooter
130
     * @param $moduleDirname
131
     * @param $tableName
132
     * @param $language
133
     *
134
     * @return string
135
     */
136
    private function getUserSingleFooter($moduleDirname, $tableName, $language)
137
    {
138
        $xc               = Tdmcreate\Files\CreateXoopsCode::getInstance();
139
        $pc               = Tdmcreate\Files\CreatePhpCode::getInstance();
140
        $uxc              = UserXoopsCode::getInstance();
141
        $stuModuleDirname = mb_strtoupper($moduleDirname);
142
        $stuTableName     = mb_strtoupper($tableName);
143
        $ret              = $pc->getPhpCodeCommentLine('Breadcrumbs');
144
        $ret              .= $uxc->getUserBreadcrumbs($language, $stuTableName);
145
        $ret              .= $pc->getPhpCodeCommentLine('Keywords');
146
        $ret              .= $uxc->getUserMetaKeywords($moduleDirname);
147
        $ret              .= $pc->getPhpCodeUnset('keywords');
148
        $ret              .= $pc->getPhpCodeCommentLine('Description');
149
        $ret              .= $uxc->getUserMetaDesc($moduleDirname, $language, $stuTableName);
150
        $ret              .= $xc->getXcXoopsTplAssign('xoops_mpageurl', "{$stuModuleDirname}_URL.'/index.php'");
151
        $ret              .= $xc->getXcXoopsTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL');
152
        $ret              .= $xc->getXcXoopsTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL");
153
        $ret              .= $this->getInclude('footer');
154
155
        return $ret;
156
    }
157
158
    /**
159
     * @public function render
160
     * @param null
161
     * @return bool|string
162
     */
163
    public function render()
164
    {
165
        $module        = $this->getModule();
166
        $table         = $this->getTable();
167
        $filename      = $this->getFileName();
168
        $moduleDirname = $module->getVar('mod_dirname');
169
        $tableId       = $table->getVar('table_id');
170
        $tableMid      = $table->getVar('table_mid');
171
        $tableName     = $table->getVar('table_name');
172
        $fields        = $this->getTableFields($tableMid, $tableId);
173
        $language      = $this->getLanguage($moduleDirname, 'MA');
174
        $content       = $this->getHeaderFilesComments($module);
175
        $content       .= $this->getUserSingleHeader($moduleDirname, $table, $fields);
176
        $content       .= $this->getUserSingleBody($module, $tableName, $language);
177
        $content       .= $this->getUserSingleFooter($moduleDirname, $tableName, $language);
178
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
179
180
        return $this->renderFile();
181
    }
182
}
183