Passed
Push — master ( c14394...753352 )
by Goffy
04:41
created

LanguageMain::getLanguageMain()   C

Complexity

Conditions 9
Paths 102

Size

Total Lines 117
Code Lines 103

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 103
nc 102
nop 2
dl 0
loc 117
rs 6.4311
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\Language;
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 (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 LanguageMain.
31
 */
32
class LanguageMain extends Files\CreateFile
33
{
34
    /**
35
     * @var mixed
36
     */
37
    private $ld = null;
38
39
    /**
40
     * @var mixed
41
     */
42
    private $pc = null;
43
44
    /**
45
     * @public function constructor
46
     * @param null
47
     */
48
    public function __construct()
49
    {
50
        parent::__construct();
51
        $this->ld = LanguageDefines::getInstance();
52
        $this->pc = Modulebuilder\Files\CreatePhpCode::getInstance();
53
    }
54
55
    /**
56
     * @static function getInstance
57
     * @param null
58
     * @return LanguageMain
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  $tables
74
     * @param string $filename
75
     */
76
    public function write($module, $tables, $filename)
77
    {
78
        $this->setModule($module);
79
        $this->setFileName($filename);
80
        $this->setTables($tables);
81
    }
82
83
    /**
84
     * @private function getLanguageMain
85
     * @param string $module
86
     * @param string $language
87
     *
88
     * @return string
89
     */
90
    private function getLanguageMain($module, $language)
91
    {
92
        /** @var \XoopsModules\Modulebuilder\Utility $utility */
93
        $utility = new \XoopsModules\Modulebuilder\Utility();
94
95
        $moduleName = $module->getVar('mod_name');
96
        $tables     = $this->getTables();
97
        $ret        = $this->ld->getBlankLine();
98
        $ret        .= $this->pc->getPhpCodeIncludeDir('__DIR__', 'admin', true);
99
        $ret        .= $this->ld->getBlankLine();
100
        $ret        .= $this->ld->getAboveHeadDefines('Main');
101
        $ret        .= $this->ld->getDefine($language, 'INDEX', 'Home');
102
        $ret        .= $this->ld->getDefine($language, 'TITLE', (string)$module->getVar('mod_name'));
103
        $ret        .= $this->ld->getDefine($language, 'DESC', (string)$module->getVar('mod_description'));
104
        $ret        .= $this->ld->getDefine(
105
            $language,
106
            'INDEX_DESC',
107
            "Welcome to the homepage of your new module {$moduleName}!<br>
108
As you can see, you have created a page with a list of links at the top to navigate between the pages of your module. This description is only visible on the homepage of this module, the other pages you will see the content you created when you built this module with the module ModuleBuilder, and after creating new content in admin of this module. In order to expand this module with other resources, just add the code you need to extend the functionality of the same. The files are grouped by type, from the header to the footer to see how divided the source code.<br><br>If you see this message, it is because you have not created content for this module. Once you have created any type of content, you will not see this message.<br><br>If you liked the module ModuleBuilder and thanks to the long process for giving the opportunity to the new module to be created in a moment, consider making a donation to keep the module ModuleBuilder and make a donation using this button <a href='http://www.txmodxoops.org/modules/xdonations/index.php' title='Donation To Txmod Xoops'><img src='https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif' alt='Button Donations' /></a><br>Thanks!<br><br>Use the link below to go to the admin and create content.",
109
            true
110
        );
111
        $ret        .= $this->ld->getDefine($language, 'NO_PDF_LIBRARY', 'Libraries TCPDF not there yet, upload them in root/Frameworks');
112
        $ret        .= $this->ld->getDefine($language, 'NO', 'No');
113
        $ret        .= $this->ld->getDefine($language, 'DETAILS', 'Show details');
114
        $ret        .= $this->ld->getDefine($language, 'BROKEN', 'Notify broken');
115
        $ret        .= $this->ld->getAboveHeadDefines('Contents');
116
        $ucfTableName     = '';
117
        $ucfTableSoleName = '';
118
        $stuTableSoleName = '';
119
        $tableSoleName    = '';
120
        $tableSubmit      = 0;
121
        $tableBroken      = 0;
122
        $tableRate        = 0;
123
        foreach (array_keys($tables) as $i) {
124
            $tableName        = $tables[$i]->getVar('table_name');
125
            $tableSoleName    = $tables[$i]->getVar('table_solename');
126
            if (1 === (int)$tables[$i]->getVar('table_submit')) {
127
                $tableSubmit = 1;
128
            }
129
            if (1 === (int)$tables[$i]->getVar('table_broken')) {
130
                $tableBroken = 1;
131
            }
132
            if (1 === (int)$tables[$i]->getVar('table_rate')) {
133
                $tableRate = 1;
134
            }
135
            $stuTableName     = mb_strtoupper($tableName);
136
            $stuTableSoleName = mb_strtoupper($tableSoleName);
137
            $ucfTableName     = $utility::UcFirstAndToLower($tableName);
138
            $ucfTableSoleName = $utility::UcFirstAndToLower($tableSoleName);
139
            $ret              .= $this->ld->getAboveDefines($ucfTableSoleName);
140
            $ret              .= $this->ld->getDefine($language, $stuTableSoleName, $ucfTableSoleName);
141
            $ret              .= $this->ld->getDefine($language, $stuTableName, $ucfTableName);
142
            $ret              .= $this->ld->getDefine($language, "{$stuTableName}_TITLE", "{$ucfTableName} title");
143
            $ret              .= $this->ld->getDefine($language, "{$stuTableName}_DESC", "{$ucfTableName} description");
144
            $ret              .= $this->ld->getDefine($language, "{$stuTableName}_LIST", "List of {$ucfTableName}");
145
            $ret              .= $this->ld->getAboveDefines("Caption of {$ucfTableSoleName}");
146
            $fields           = $this->getTableFields($tables[$i]->getVar('table_mid'), $tables[$i]->getVar('table_id'));
147
            foreach (array_keys($fields) as $f) {
148
                $fieldName     = $fields[$f]->getVar('field_name');
149
                $rpFieldName   = $this->getRightString($fieldName);
150
                $fieldNameDesc = ucfirst($rpFieldName);
151
                $ret           .= $this->ld->getDefine($language, $stuTableSoleName . '_' . $rpFieldName, $fieldNameDesc);
152
            }
153
        }
154
        $ret .= $this->ld->getDefine($language, 'INDEX_THEREARE', "There are %s {$ucfTableName}");
155
        $ret .= $this->ld->getDefine($language, 'INDEX_LATEST_LIST', "Last {$module->getVar('mod_name')}");
156
        $ret .= $this->ld->getAboveDefines('Submit');
157
        $ret .= $this->ld->getDefine($language, 'SUBMIT', 'Submit');
158
        $ret .= $this->ld->getDefine($language, "SUBMIT_{$stuTableSoleName}", "Submit {$ucfTableSoleName}");
159
        $ret .= $this->ld->getDefine($language, 'SUBMIT_ALLPENDING', "All {$tableSoleName}/script information are posted pending verification.");
160
        $ret .= $this->ld->getDefine($language, 'SUBMIT_DONTABUSE', 'Username and IP are recorded, so please do not abuse the system.');
161
        $ret .= $this->ld->getDefine($language, 'SUBMIT_ISAPPROVED', "Your {$tableSoleName} has been approved");
162
        $ret .= $this->ld->getDefine($language, 'SUBMIT_PROPOSER', "Submit a {$tableSoleName}");
163
        $ret .= $this->ld->getDefine($language, 'SUBMIT_RECEIVED', "We have received your {$tableSoleName} info. Thank you !");
164
        $ret .= $this->ld->getDefine($language, 'SUBMIT_SUBMITONCE', "Submit your {$tableSoleName}/script only once.");
165
        $ret .= $this->ld->getDefine($language, 'SUBMIT_TAKEDAYS', "This will take many days to see your {$tableSoleName}/script added successfully in our database.");
166
        if (1 === $tableSubmit) {
167
            $ret .= $this->ld->getAboveDefines('Form');
168
            $ret .= $this->ld->getDefine($language, 'FORM_OK', 'Successfully saved');
169
            $ret .= $this->ld->getDefine($language, 'FORM_DELETE_OK', 'Successfully deleted');
170
            $ret .= $this->ld->getDefine($language, 'FORM_SURE_DELETE', "Are you sure to delete: <b><span style='color : Red;'>%s </span></b>", true);
171
            $ret .= $this->ld->getDefine($language, 'FORM_SURE_RENEW', "Are you sure to update: <b><span style='color : Red;'>%s </span></b>", true);
172
            if (1 === $tableBroken) {
173
                $ret .= $this->ld->getDefine($language, 'FORM_SURE_BROKEN', "Are you sure to notify as broken: <b><span style='color : Red;'>%s </span></b>", true);
174
            }
175
            $ret .= $this->ld->getDefine($language, 'INVALID_PARAM', "Invalid parameter", true);
176
        }
177
        if (1 === $tableRate) {
178
            $ret .= $this->ld->getAboveHeadDefines('Ratings');
179
            $ret .= $this->ld->getDefine($language, 'RATING_CURRENT_1', 'Rating: %c / %m (%t rating totally)');
180
            $ret .= $this->ld->getDefine($language, 'RATING_CURRENT_X', 'Rating: %c / %m (%t ratings totally)');
181
            $ret .= $this->ld->getDefine($language, 'RATING_CURRENT_SHORT_1', '%c (%t rating)');
182
            $ret .= $this->ld->getDefine($language, 'RATING_CURRENT_SHORT_X', '%c (%t ratings)');
183
            $ret .= $this->ld->getDefine($language, 'RATING1', '1 of 5');
184
            $ret .= $this->ld->getDefine($language, 'RATING2', '2 of 5');
185
            $ret .= $this->ld->getDefine($language, 'RATING3', '3 of 5');
186
            $ret .= $this->ld->getDefine($language, 'RATING4', '4 of 5');
187
            $ret .= $this->ld->getDefine($language, 'RATING5', '5 of 5');
188
            $ret .= $this->ld->getDefine($language, 'RATING_10_1', '1 of 10');
189
            $ret .= $this->ld->getDefine($language, 'RATING_10_2', '2 of 10');
190
            $ret .= $this->ld->getDefine($language, 'RATING_10_3', '3 of 10');
191
            $ret .= $this->ld->getDefine($language, 'RATING_10_4', '4 of 10');
192
            $ret .= $this->ld->getDefine($language, 'RATING_10_5', '5 of 10');
193
            $ret .= $this->ld->getDefine($language, 'RATING_10_6', '6 of 10');
194
            $ret .= $this->ld->getDefine($language, 'RATING_10_7', '7 of 10');
195
            $ret .= $this->ld->getDefine($language, 'RATING_10_8', '8 of 10');
196
            $ret .= $this->ld->getDefine($language, 'RATING_10_9', '9 of 10');
197
            $ret .= $this->ld->getDefine($language, 'RATING_10_10', '10 of 10');
198
            $ret .= $this->ld->getDefine($language, 'RATING_VOTE_BAD', 'Invalid vote');
199
            $ret .= $this->ld->getDefine($language, 'RATING_VOTE_ALREADY', 'You have already voted');
200
            $ret .= $this->ld->getDefine($language, 'RATING_VOTE_THANKS', 'Thank you for rating');
201
            $ret .= $this->ld->getDefine($language, 'RATING_NOPERM', "Sorry, you don't have permission to rate items", true);
202
            $ret .= $this->ld->getDefine($language, 'RATING_LIKE', 'Like');
203
            $ret .= $this->ld->getDefine($language, 'RATING_DISLIKE', 'Dislike');
204
            $ret .= $this->ld->getDefine($language, 'RATING_ERROR1', 'Error: update base table failed!');
205
        }
206
        return $ret;
207
    }
208
209
    /**
210
     * @private function getLanguageMainFooter
211
     * @param string $language
212
     *
213
     * @return string
214
     */
215
    private function getLanguageMainFooter($language)
216
    {
217
        $ret = $this->ld->getAboveDefines('Admin link');
218
        $ret .= $this->ld->getDefine($language, 'ADMIN', 'Admin');
219
        $ret .= $this->ld->getBelowDefines('End');
220
        $ret .= $this->ld->getBlankLine();
221
222
        return $ret;
223
    }
224
225
    /**
226
     * @public function render
227
     * @param null
228
     * @return bool|string
229
     */
230
    public function render()
231
    {
232
        $module        = $this->getModule();
233
        $filename      = $this->getFileName();
234
        $moduleDirname = $module->getVar('mod_dirname');
235
        $language      = $this->getLanguage($moduleDirname, 'MA');
236
        $content       = $this->getHeaderFilesComments($module);
237
        $content       .= $this->getLanguageMain($module, $language);
238
        $content       .= $this->getLanguageMainFooter($language);
239
240
        $this->create($moduleDirname, 'language/' . $GLOBALS['xoopsConfig']['language'], $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED);
241
242
        return $this->renderFile();
243
    }
244
}
245