Completed
Push — master ( 9d11bc...606015 )
by Gino
05:18 queued 02:03
created

TemplatesUserSubmit::renderFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4285
cc 1
eloc 11
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: TemplatesUserSubmit.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserSubmit.
27
 */
28
class TemplatesUserSubmit 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
{    
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
30
    /*
31
    *  @public function constructor
32
    *  @param null
33
    */
34
    /**
35
     *
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();        
40
    }
41
42
    /*
43
    *  @static function &getInstance
44
    *  @param null
45
    */
46
    /**
47
     * @return TemplatesUserSubmit
48
     */
49
    public static function &getInstance()
50
    {
51
        static $instance = false;
52
        if (!$instance) {
53
            $instance = new self();
54
        }
55
56
        return $instance;
57
    }
58
59
    /*
60
    *  @public function write
61
    *  @param string $module
62
    *  @param string $table
63
    *  @param string $filename
64
    */
65
    /**
66
     * @param $module
67
     * @param $table
68
     */
69
    public function write($module, $table, $filename)
70
    {
71
        $this->setModule($module);
72
        $this->setTable($table);
73
		$this->setFileName($filename);
74
    }
75
76
    /*
77
    *  @private function getTemplatesUserSubmitHeader
78
    *  @param string $moduleDirname
79
    *  @param string $table
80
    *  @param string $language
81
    */
82
    /**
83
     * @param $moduleDirname
84
     * @param $table
85
     * @param $language
86
     *
87
     * @return string
88
     */
89
    private function getTemplatesUserSubmitHeader($moduleDirname)
90
    {
91
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
92
		return $htmlcode->getSmartyIncludeFile($moduleDirname, 'header').PHP_EOL;
93
    }
94
95
    /*
96
    *  @private function getTemplatesUserSubmit
97
    *  @param string $moduleDirname
98
    *  @param string $language
99
    */
100
    /**
101
     * @param $moduleDirname
102
     * @param $language
103
     *
104
     * @return string
105
     */
106
    private function getTemplatesUserSubmit($moduleDirname, $language)
107
    {
108
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
109
		$const = $htmlcode->getSmartyConst($language, 'SUBMIT_SUBMITONCE');
110
        $li = $htmlcode->getHtmlLi($const).PHP_EOL;
111
        $const = $htmlcode->getSmartyConst($language, 'SUBMIT_ALLPENDING');
112
        $li .= $htmlcode->getHtmlLi($const).PHP_EOL;
113
        $const = $htmlcode->getSmartyConst($language, 'SUBMIT_DONTABUSE');
114
        $li .= $htmlcode->getHtmlLi($const).PHP_EOL;
115
        $const = $htmlcode->getSmartyConst($language, 'SUBMIT_TAKEDAYS');
116
        $li .= $htmlcode->getHtmlLi($const).PHP_EOL;
117
        $ul = $htmlcode->getHtmlUl($li).PHP_EOL;
118
        $ret = $htmlcode->getHtmlDiv($ul, $moduleDirname.'-tips').PHP_EOL;
119
120
        $single = $htmlcode->getSmartySingleVar('message_error').PHP_EOL;
121
        $divError = $htmlcode->getHtmlDiv($single, 'errorMsg').PHP_EOL;
122
        $ret .= $htmlcode->getSmartyConditions('message_error', ' != ', '\'\'', $divError).PHP_EOL;
123
        $single = $htmlcode->getSmartySingleVar('form').PHP_EOL;
124
        $ret .= $htmlcode->getHtmlDiv($single, $moduleDirname.'-submitform').PHP_EOL;
125
126
        return $ret;
127
    }
128
129
    /*
130
    *  @private function getTemplatesUserSubmitFooter
131
    *  @param string $moduleDirname
132
    */
133
    /**
134
     * @param $moduleDirname
135
     *
136
     * @return string
137
     */
138
    private function getTemplatesUserSubmitFooter($moduleDirname)
139
    {
140
        $htmlcode = TDMCreateHtmlSmartyCodes::getInstance();
141
		return $htmlcode->getSmartyIncludeFile($moduleDirname, 'footer');
142
    }
143
144
    /*
145
    *  @public function render
146
    *  @param null
147
    */
148
    /**
149
     * @param null
150
     *
151
     * @return bool|string
152
     */
153
    public function render()
154
    {
155
        $module = $this->getModule();
156
        $table = $this->getTable();
157
        $moduleDirname = $module->getVar('mod_dirname');
158
		$filename = $this->getFileName();
159
        $tableFieldname = $table->getVar('table_fieldname');
0 ignored issues
show
Unused Code introduced by
$tableFieldname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
160
        $language = $this->getLanguage($moduleDirname, 'MA');
161
        $content = $this->getTemplatesUserSubmitHeader($moduleDirname);
162
        $content .= $this->getTemplatesUserSubmit($moduleDirname, $language);
163
        $content .= $this->getTemplatesUserSubmitFooter($moduleDirname);
164
        //
165
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
166
167
        return $this->renderFile();
168
    }
169
}
170