UserSingle   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 65
dl 0
loc 146
rs 10
c 0
b 0
f 0
wmc 12

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A getUserSingleFooter() 0 20 1
A getUserSingleBody() 0 8 1
A getUserSingleHeader() 0 27 5
A __construct() 0 3 1
A write() 0 5 1
A render() 0 18 1
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: UserSingle.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class UserSingle.
30
 */
31
class UserSingle 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 UserSingle
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
     * @private function getUserSingleHeader
72
     * @param $moduleDirname
73
     * @param $table
74
     * @param $fields
75
     * @return string
76
     */
77
    private function getUserSingleHeader($moduleDirname, $table, $fields)
78
    {
79
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
80
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
81
        $uc = UserXoopsCode::getInstance();
82
        $ret = $this->getInclude();
83
        foreach (array_keys($fields) as $f) {
84
            $fieldName = $fields[$f]->getVar('field_name');
85
            if (0 == $f) {
86
                $fieldId = $fieldName;
87
            }
88
            if (1 == $fields[$f]->getVar('field_parent')) {
89
                $fieldPid = $fieldName;
90
            }
91
        }
92
        if (1 == $table->getVar('table_category')) {
93
            $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...
94
            $ret .= $xc->getXcXoopsRequest($ccFieldPid, (string)$fieldPid, '0', 'Int');
95
        }
96
        $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...
97
        $ret .= $xc->getXcXoopsRequest($ccFieldId, (string)$fieldId, '0', 'Int');
98
        $ret .= $uc->getUserTplMain($moduleDirname, 'single');
99
        $ret .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
100
        $ret .= $pc->getPhpCodeCommentLine('Define Stylesheet');
101
        $ret .= $xc->getXcAddStylesheet();
102
103
        return $ret;
104
    }
105
106
    /**
107
     * @public function getUserSingleBody
108
     * @param $moduleDirname
109
     * @param $tableName
110
     * @param $language
111
     *
112
     * @return string
113
     */
114
    public function getUserSingleBody($moduleDirname, $tableName, $language)
0 ignored issues
show
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

114
    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 $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

114
    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 $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

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