UserSearch::getUserSearch()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\User;
4
5
use XoopsModules\Modulebuilder;
6
use XoopsModules\Modulebuilder\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
 * modulebuilder module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops https://xoops.org 
26
 *                  Goffy https://myxoops.org
27
 *
28
 */
29
30
/**
31
 * Class UserSearch.
32
 */
33
class UserSearch extends Files\CreateFile
34
{
35
    /**
36
     * @var mixed
37
     */
38
    private $uxc = null;
39
    /**
40
     * @var mixed
41
     */
42
    private $xc = null;
43
    /**
44
     * @var mixed
45
     */
46
    private $pc = null;
47
48
    /**
49
     * @public function constructor
50
     * @param null
51
     */
52
    public function __construct()
53
    {
54
        parent::__construct();
55
        $this->xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
56
        $this->pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
57
        $this->uxc = UserXoopsCode::getInstance();
58
    }
59
60
    /**
61
     * @static function getInstance
62
     * @param null
63
     * @return UserSearch
64
     */
65
    public static function getInstance()
66
    {
67
        static $instance = false;
68
        if (!$instance) {
69
            $instance = new self();
70
        }
71
72
        return $instance;
73
    }
74
75
    /**
76
     * @public function write
77
     * @param string $module
78
     * @param mixed  $table
79
     * @param string $filename
80
     */
81
    public function write($module, $table, $filename)
82
    {
83
        $this->setModule($module);
84
        $this->setTable($table);
85
        $this->setFileName($filename);
86
    }
87
88
    /**
89
     * @private function getUserSearchHeader
90
     *
91
     * @param $moduleDirname
92
     *
93
     * @param $table
94
     * @param $fields
95
     * @return string
96
     */
97
    private function getUserSearchHeader($moduleDirname, $table, $fields)
98
    {
99
        $ret      = $this->pc->getPhpCodeUseNamespace(['Xmf', 'Request'], '', '');
100
        $ret      .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname], '', '');
101
        $ret      .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Constants']);
102
        $ret      .= $this->getRequire();
103
        $fieldId  = 0;
104
        $fieldPid = 0;
105
        foreach (\array_keys($fields) as $f) {
106
            $fieldName = $fields[$f]->getVar('field_name');
107
            if (0 == $f) {
108
                $fieldId = $fieldName;
109
            }
110
            if (1 == $fields[$f]->getVar('field_parent')) {
111
                $fieldPid = $fieldName;
112
            }
113
        }
114
        if (1 == $table->getVar('table_category')) {
115
            $ccFieldPid = $this->getCamelCase($fieldPid, false, true);
116
            $ret        .= $this->xc->getXcXoopsRequest($ccFieldPid, (string)$fieldPid, '0', 'Int');
117
        }
118
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
119
        $ret       .= $this->xc->getXcXoopsRequest($ccFieldId, (string)$fieldId, '0', 'Int');
120
        $ret       .= $this->uxc->getUserTplMain($moduleDirname);
121
        $ret       .= $this->phpcode->getPhpCodeIncludeDir('\XOOPS_ROOT_PATH', 'header', true);
122
        $ret       .= $this->getDashComment('Define Stylesheet');
123
        $ret       .= $this->xc->getXcXoThemeAddStylesheet();
124
125
        return $ret;
126
    }
127
128
    /**
129
     * @public function getAdminPagesList
130
     * @param $moduleDirname
131
     * @param $tableName
132
     * @param $language
133
     * @return string
134
     */
135
    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

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

135
    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...
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

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