Passed
Push — master ( 0f0f99...fb91d6 )
by Michael
17s
created

TemplatesUserBroken::renderFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 17
nc 1
nop 1
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: TemplatesUserBroken.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserBroken.
27
 */
28
class TemplatesUserBroken extends TDMCreateFile
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
29
{
30
    /*
31
    * @var string
32
    */
33
    private $tdmcfile = null;
34
35
    /*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        parent::__construct();
45
        $this->tdmcfile = TDMCreateFile::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateFile::getInstance() of type object<TDMCreateFile> is incompatible with the declared type string of property $tdmcfile.

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...
46
        $this->htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateHtmlSmartyCodes::getInstance() of type object<TDMCreateHtmlSmartyCodes> is incompatible with the declared type string of property $htmlcode.

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...
47
    }
48
49
    /*
50
    *  @static function &getInstance
51
    *  @param null
52
    */
53
    /**
54
     * @return TemplatesUserBroken
55
     */
56
    public static function &getInstance()
57
    {
58
        static $instance = false;
59
        if (!$instance) {
60
            $instance = new self();
61
        }
62
63
        return $instance;
64
    }
65
66
    /*
67
    *  @public function write
68
    *  @param string $module
69
    *  @param string $table
70
    *  @param string $filename
71
    */
72
    /**
73
     * @param $module
74
     * @param $table
75
     */
76
    public function write($module, $table)
77
    {
78
        $this->setModule($module);
79
        $this->setTable($table);
80
    }
81
82
    /*
83
    *  @private function getTemplatesUserBrokenFileHeader
84
    *  @param string $moduleDirname
85
    */
86
    /**
87
     * @param $moduleDirname
88
     *
89
     * @return string
90
     */
91
    private function getTemplatesUserBrokenFileHeader($moduleDirname)
92
    {
93
        return $this->htmlcode->getSmartyIncludeFile($moduleDirname, 'header');
0 ignored issues
show
Bug introduced by
The method getSmartyIncludeFile cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
94
    }
95
96
    /*
97
    *  @private function getTemplatesUserBrokenTableHead
98
    *  @param string $moduleDirname
99
    *  @param string $table
100
    *  @param string $language
101
    */
102
    /**
103
     * @param $moduleDirname
104
     * @param $table
105
     * @param $language
106
     *
107
     * @return string
108
     */
109
    private function getTemplatesUserBrokenTableHead($tableMid, $tableId, $tableAutoincrement, $language)
110
    {
111
        $th = '';
112
        $fields = $this->getTableFields($tableMid, $tableId);
113
        foreach (array_keys($fields) as $f) {
114
            $fieldName = $fields[$f]->getVar('field_name');
115
            $stuFieldName = strtoupper($fieldName);
116
            if ((1 == $tableAutoincrement) || (1 == $fields[$f]->getVar('field_user'))) {
117
                $const = $this->htmlcode->getSmartyConst($language, $stuFieldName);
0 ignored issues
show
Bug introduced by
The method getSmartyConst cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
118
                $th .= $this->htmlcode->getHtmlTag('th', array('class' => 'center'), $const).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
119
            }
120
        }
121
        $tr = $this->htmlcode->getHtmlTag('tr', array('class' => 'head'), $th).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
122
123
        return $this->htmlcode->getHtmlTag('thead', array('class' => 'outer'), $tr).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTag cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
124
    }
125
126
    /*
127
    *  @private function getTemplatesUserBrokenBody
128
    *  @param string $moduleDirname
129
    *  @param string $table
130
    *  @param string $language
131
    */
132
    /**
133
     * @param $moduleDirname
134
     * @param $table
135
     * @param $language
136
     *
137
     * @return string
138
     */
139
    private function getTemplatesUserBrokenBody($moduleDirname, $tableMid, $tableId, $tableName, $tableSolename, $tableAutoincrement, $language)
0 ignored issues
show
Unused Code introduced by
The parameter $language is not used and could be removed.

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

Loading history...
140
    {
141
        $ret = '';
142
        $fields = $this->getTableFields($tableMid, $tableId);
143
        foreach (array_keys($fields) as $f) {
144
            $fieldName = $fields[$f]->getVar('field_name');
145
            $fieldElement = $fields[$f]->getVar('field_element');
146
            $rpFieldName = $this->tdmcfile->getRightString($fieldName);
0 ignored issues
show
Bug introduced by
The method getRightString cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
147
            if ((1 == $tableAutoincrement) || (1 == $fields[$f]->getVar('field_user'))) {
148
                switch ($fieldElement) {
149
                    case 9:
150
                        $span = $this->htmlcode->getHtmlSpan("<{\${$moduleDirname}_upload_url}>/images/{$tableName}/<{\${$tableSolename}.{$rpFieldName}}>", "#<{\${$tableSolename}.{$rpFieldName}}>").PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlSpan cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
151
                        $ret .= $this->htmlcode->getHtmlTableData($span, 'center').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableData cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
152
                        break;
153
                    case 10:
154
                        $img = $this->htmlcode->getHtmlImage("<{xoModuleIcons32}><{\${$tableSolename}.{$rpFieldName}}>", $tableName);
0 ignored issues
show
Bug introduced by
The method getHtmlImage cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
155
                        $ret .= $this->htmlcode->getHtmlTableData($img, 'center').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableData cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
156
                        break;
157
                    case 13:
158
                        $img = $this->htmlcode->getHtmlImage("<{\${$moduleDirname}_upload_url}>/images/{$tableName}/<{\${$tableSolename}.{$rpFieldName}}>", $tableName);
0 ignored issues
show
Bug introduced by
The method getHtmlImage cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
159
                        $ret .= $this->htmlcode->getHtmlTableData($img, 'center').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableData cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
160
                        break;
161
                    default:
162
                        $ret .= $this->htmlcode->getHtmlTableData("<{\${$tableSolename}.{$rpFieldName}}>", 'center').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableData cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
163
                        break;
164
                }
165
            }
166
        }
167
        $row = $this->htmlcode->getHtmlTableRow($ret, '<{cycle values="odd, even"}>').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableRow cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
168
        $foreach = $this->htmlcode->getSmartyForeach($tableSolename, $tableName, $row).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getSmartyForeach cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
169
170
        return $this->htmlcode->getHtmlTableTbody($foreach).PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTableTbody cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
171
    }
172
173
    /*
174
    *  @private function getTemplatesUserBrokenFileFooter
175
    *  @param string $moduleDirname
176
    */
177
    /**
178
     * @param $moduleDirname
179
     *
180
     * @return string
181
     */
182
    private function getTemplatesUserBrokenFileFooter($moduleDirname)
183
    {
184
        return $this->htmlcode->getSmartyIncludeFile($moduleDirname, 'footer');
0 ignored issues
show
Bug introduced by
The method getSmartyIncludeFile cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
185
    }
186
187
    /*
188
    *  @public function renderFile
189
    *  @param string $filename
190
    */
191
    /**
192
     * @param $filename
193
     *
194
     * @return bool|string
195
     */
196
    public function renderFile($filename)
197
    {
198
        $module = $this->getModule();
199
        $table = $this->getTable();
200
        $moduleDirname = $module->getVar('mod_dirname');
201
        $tableId = $table->getVar('table_id');
202
        $tableMid = $table->getVar('table_mid');
203
        $tableName = $table->getVar('table_name');
204
        $tableSolename = $table->getVar('table_solename');
205
        $tableAutoincrement = $table->getVar('table_autoincrement');
206
        $language = $this->getLanguage($moduleDirname, 'MA');
207
        $content = $this->getTemplatesUserBrokenFileHeader($moduleDirname).PHP_EOL;
208
        $contentTable = $this->getTemplatesUserBrokenTableHead($tableMid, $tableId, $tableAutoincrement, $language);
209
        $contentTable .= $this->getTemplatesUserBrokenBody($moduleDirname, $tableMid, $tableId, $tableName, $tableSolename, $tableAutoincrement, $language);
210
        $content .= $this->htmlcode->getHtmlTable($contentTable, 'table table-bordered').PHP_EOL;
0 ignored issues
show
Bug introduced by
The method getHtmlTable cannot be called on $this->htmlcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
211
        $content .= $this->getTemplatesUserBrokenFileFooter($moduleDirname);
212
        //
213
        $this->tdmcfile->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
0 ignored issues
show
Bug introduced by
The method create cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
214
215
        return $this->tdmcfile->renderFile();
0 ignored issues
show
Bug introduced by
The method renderFile cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
216
    }
217
}
218