UserSearch::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 19
rs 9.7666
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 UserSearch.
31
 */
32
class UserSearch extends Files\CreateFile
33
{
34
    /**
35
     * @var mixed
36
     */
37
    private $usercode = null;
38
39
    /**
40
     * @var string
41
     */
42
    private $xoopscode = null;
43
44
    /**
45
     * @public function constructor
46
     * @param null
47
     */
48
    public function __construct()
49
    {
50
        parent::__construct();
51
        $this->xoopscode = 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 $xoopscode.

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...
52
        $this->phpcode   = 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 $phpcode.

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...
53
        $this->usercode  = UserXoopsCode::getInstance();
54
    }
55
56
    /**
57
     * @static function getInstance
58
     * @param null
59
     * @return UserSearch
60
     */
61
    public static function getInstance()
62
    {
63
        static $instance = false;
64
        if (!$instance) {
65
            $instance = new self();
66
        }
67
68
        return $instance;
69
    }
70
71
    /**
72
     * @public function write
73
     * @param string $module
74
     * @param mixed  $table
75
     * @param string $filename
76
     */
77
    public function write($module, $table, $filename)
78
    {
79
        $this->setModule($module);
80
        $this->setTable($table);
81
        $this->setFileName($filename);
82
    }
83
84
    /**
85
     * @private function getUserSearchHeader
86
     *
87
     * @param $moduleDirname
88
     *
89
     * @param $table
90
     * @param $fields
91
     * @return string
92
     */
93
    private function getUserSearchHeader($moduleDirname, $table, $fields)
94
    {
95
        $pc  = Tdmcreate\Files\CreatePhpCode::getInstance();
96
        $ret = $pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
97
        $ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
98
        $ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']);
99
        $ret .= $this->getInclude();
100
        foreach (array_keys($fields) as $f) {
101
            $fieldName = $fields[$f]->getVar('field_name');
102
            if (0 == $f) {
103
                $fieldId = $fieldName;
104
            }
105
            if (1 == $fields[$f]->getVar('field_parent')) {
106
                $fieldPid = $fieldName;
107
            }
108
        }
109
        if (1 == $table->getVar('table_category')) {
110
            $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...
111
            $ret        .= $this->xoopscode->getXcXoopsRequest($ccFieldPid, (string)$fieldPid, '0', 'Int');
112
        }
113
        $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...
114
        $ret       .= $this->xoopscode->getXcXoopsRequest($ccFieldId, (string)$fieldId, '0', 'Int');
115
        $ret       .= $this->usercode->getUserTplMain($moduleDirname);
116
        $ret       .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
117
        $ret       .= $this->getDashComment('Define Stylesheet');
118
        $ret       .= $this->xoopscode->getXcXoThemeAddStylesheet();
119
120
        return $ret;
121
    }
122
123
    /**
124
     * @public function getAdminPagesList
125
     * @param $moduleDirname
126
     * @param $tableName
127
     * @param $language
128
     * @return string
129
     */
130
    public function getUserSearch($moduleDirname, $tableName, $language)
0 ignored issues
show
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

130
    public function getUserSearch(/** @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...
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

130
    public function getUserSearch($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

130
    public function getUserSearch($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...
131
    {
132
        $ret = <<<'EOT'
133
134
EOT;
135
        $ret .= $this->getSimpleString('$keywords = array();');
136
137
        return $ret;
138
    }
139
140
    /**
141
     * @private function getUserSearchFooter
142
     *
143
     * @param $moduleDirname
144
     * @param $tableName
145
     * @param $language
146
     *
147
     * @return string
148
     */
149
    private function getUserSearchFooter($moduleDirname, $tableName, $language)
150
    {
151
        $stuModuleDirname = mb_strtoupper($moduleDirname);
152
        $stuTableName     = mb_strtoupper($tableName);
153
        $ret              = $this->getDashComment('Breadcrumbs');
154
        $ret              .= $this->usercode->getUserBreadcrumbs((string)$stuTableName, $language);
155
        $ret              .= $this->getDashComment('Keywords');
156
        $ret              .= $this->usercode->getUserMetaKeywords($moduleDirname);
157
        $ret              .= $this->phpcode->getPhpCodeUnset('keywords');
158
        $ret              .= $this->getDashComment('Description');
159
        $ret              .= $this->usercode->getUserMetaDesc($moduleDirname, 'DESC', $language);
160
        $ret              .= $this->xoopscode->getXcXoopsTplAssign('xoops_mpageurl', "{$stuModuleDirname}_URL.'/index.php'");
161
        $ret              .= $this->xoopscode->getXcXoopsTplAssign('xoops_icons32_url', 'XOOPS_ICONS32_URL');
162
        $ret              .= $this->xoopscode->getXcXoopsTplAssign("{$moduleDirname}_upload_url", "{$stuModuleDirname}_UPLOAD_URL");
163
        $ret              .= $this->getInclude('footer');
164
165
        return $ret;
166
    }
167
168
    /**
169
     * @public function render
170
     * @param null
171
     * @return bool|string
172
     */
173
    public function render()
174
    {
175
        $module        = $this->getModule();
176
        $table         = $this->getTable();
177
        $filename      = $this->getFileName();
178
        $moduleDirname = $module->getVar('mod_dirname');
179
        $tableId       = $table->getVar('table_id');
180
        $tableMid      = $table->getVar('table_mid');
181
        $tableName     = $table->getVar('table_name');
182
        $fields        = $this->getTableFields($tableMid, $tableId);
183
        $language      = $this->getLanguage($moduleDirname, 'MA');
184
        $content       = $this->getHeaderFilesComments($module);
185
        $content       .= $this->getUserSearchHeader($moduleDirname, $table, $fields);
186
        $content       .= $this->getUserSearch($moduleDirname, $tableName, $language);
187
        $content       .= $this->getUserSearchFooter($moduleDirname, $tableName, $language);
188
189
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
190
191
        return $this->renderFile();
192
    }
193
}
194