UserSearch::write()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
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: UserSearch.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class UserSearch.
30
 */
31
class UserSearch extends Files\CreateFile
32
{
33
    /**
34
     * @var mixed
35
     */
36
    private $usercode = null;
37
38
    /**
39
     * @var string
40
     */
41
    private $xoopscode = null;
42
43
    /**
44
     *  @public function constructor
45
     *  @param null
46
     */
47
    public function __construct()
48
    {
49
        parent::__construct();
50
        $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...
51
        $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...
52
        $this->usercode = UserXoopsCode::getInstance();
53
    }
54
55
    /**
56
     *  @static function getInstance
57
     *  @param null
58
     * @return UserSearch
59
     */
60
    public static function getInstance()
61
    {
62
        static $instance = false;
63
        if (!$instance) {
64
            $instance = new self();
65
        }
66
67
        return $instance;
68
    }
69
70
    /**
71
     *  @public function write
72
     *  @param string $module
73
     *  @param mixed $table
74
     *  @param string $filename
75
     */
76
    public function write($module, $table, $filename)
77
    {
78
        $this->setModule($module);
79
        $this->setTable($table);
80
        $this->setFileName($filename);
81
    }
82
83
    /**
84
     * @private function getUserSearchHeader
85
     *
86
     * @param $moduleDirname
87
     *
88
     * @param $table
89
     * @param $fields
90
     * @return string
91
     */
92
    private function getUserSearchHeader($moduleDirname, $table, $fields)
93
    {
94
        $ret = $this->getInclude();
95
        foreach (array_keys($fields) as $f) {
96
            $fieldName = $fields[$f]->getVar('field_name');
97
            if (0 == $f) {
98
                $fieldId = $fieldName;
99
            }
100
            if (1 == $fields[$f]->getVar('field_parent')) {
101
                $fieldPid = $fieldName;
102
            }
103
        }
104
        if (1 == $table->getVar('table_category')) {
105
            $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...
106
            $ret .= $this->xoopscode->getXoopsCodeXoopsRequest($ccFieldPid, (string)$fieldPid, '0', 'Int');
107
        }
108
        $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...
109
        $ret .= $this->xoopscode->getXoopsCodeXoopsRequest($ccFieldId, (string)$fieldId, '0', 'Int');
110
        $ret .= $this->usercode->getUserTplMain($moduleDirname);
111
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
112
        $ret .= $this->getCommentLine('Define Stylesheet');
0 ignored issues
show
Bug introduced by
The method getCommentLine() does not exist on XoopsModules\Tdmcreate\Files\User\UserSearch. ( Ignorable by Annotation )

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

112
        $ret .= $this->/** @scrutinizer ignore-call */ getCommentLine('Define Stylesheet');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
113
        $ret .= $this->xoopscode->getXoopsCodeAddStylesheet();
114
115
        return $ret;
116
    }
117
118
    /**
119
     *  @public function getAdminPagesList
120
     * @param $moduleDirname
121
     * @param $tableName
122
     * @param $language
123
     * @return string
124
     */
125
    public function getUserSearch($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

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

125
    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

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