Passed
Push — master ( 123922...c30da6 )
by Goffy
09:11 queued 04:26
created

LanguageMain::getLanguageMain()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 65
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 57
nc 3
nop 2
dl 0
loc 65
rs 8.9381
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\Tdmcreate\Files\Language;
4
5
use XoopsModules\Tdmcreate;
6
use XoopsModules\Tdmcreate\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
 * tdmcreate 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 $defines = null;
38
39
    /**
40
     * @public function constructor
41
     * @param null
42
     */
43
    public function __construct()
44
    {
45
        parent::__construct();
46
        $this->defines = LanguageDefines::getInstance();
47
    }
48
49
    /**
50
     * @static function getInstance
51
     * @param null
52
     * @return LanguageMain
53
     */
54
    public static function getInstance()
55
    {
56
        static $instance = false;
57
        if (!$instance) {
58
            $instance = new self();
59
        }
60
61
        return $instance;
62
    }
63
64
    /**
65
     * @public function write
66
     * @param string $module
67
     * @param mixed  $tables
68
     * @param string $filename
69
     */
70
    public function write($module, $tables, $filename)
71
    {
72
        $this->setModule($module);
73
        $this->setFileName($filename);
74
        $this->setTables($tables);
75
    }
76
77
    /**
78
     * @private function getLanguageMain
79
     * @param string $module
80
     * @param string $language
81
     *
82
     * @return string
83
     */
84
    private function getLanguageMain($module, $language)
85
    {
86
        /** @var \XoopsModules\Tdmcreate\Utility $utility */
87
        $utility = new \XoopsModules\Tdmcreate\Utility();
88
89
        $moduleName = $module->getVar('mod_name');
90
        $tables     = $this->getTables();
91
        $ret        = $this->defines->getBlankLine();
92
        $ret        .= $this->defines->getAboveHeadDefines('Main');
93
        $ret        .= $this->defines->getDefine($language, 'INDEX', 'Home');
94
        $ret        .= $this->defines->getDefine($language, 'TITLE', (string)$module->getVar('mod_name'));
95
        $ret        .= $this->defines->getDefine($language, 'DESC', (string)$module->getVar('mod_description'));
96
        $ret        .= $this->defines->getDefine(
97
            $language,
98
            'INDEX_DESC',
99
            "Welcome to the homepage of your new module {$moduleName}!<br>
100
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 TDMCreate, 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 TDMCreate 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 TDMCreate 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.",
101
            true
102
        );
103
        $ret        .= $this->defines->getDefine($language, 'NO_PDF_LIBRARY', 'Libraries TCPDF not there yet, upload them in root/Frameworks');
104
        $ret        .= $this->defines->getDefine($language, 'NO', 'No');
105
        $ret        .= $this->defines->getAboveHeadDefines('Contents');
106
        $ucfTableName     = '';
107
        $ucfTableSoleName = '';
108
        $stuTableSoleName = '';
109
        $tableSoleName    = '';
110
        foreach (array_keys($tables) as $i) {
111
            $tableName        = $tables[$i]->getVar('table_name');
112
            $tableSoleName    = $tables[$i]->getVar('table_solename');
113
            $stuTableName     = mb_strtoupper($tableName);
114
            $stuTableSoleName = mb_strtoupper($tableSoleName);
115
            $ucfTableName     = $utility::UcFirstAndToLower($tableName);
116
            $ucfTableSoleName = $utility::UcFirstAndToLower($tableSoleName);
117
            $ret              .= $this->defines->getAboveDefines($ucfTableSoleName);
118
            $ret              .= $this->defines->getDefine($language, $stuTableSoleName, $ucfTableSoleName);
119
            $ret              .= $this->defines->getDefine($language, $stuTableName, $ucfTableName);
120
            $ret              .= $this->defines->getDefine($language, "{$stuTableName}_TITLE", "{$ucfTableName} title");
121
            $ret              .= $this->defines->getDefine($language, "{$stuTableName}_DESC", "{$ucfTableName} description");
122
            $ret              .= $this->defines->getAboveDefines("Caption of {$ucfTableSoleName}");
123
            $fields           = $this->getTableFields($tables[$i]->getVar('table_mid'), $tables[$i]->getVar('table_id'));
124
            foreach (array_keys($fields) as $f) {
125
                $fieldName     = $fields[$f]->getVar('field_name');
126
                $rpFieldName   = $this->getRightString($fieldName);
127
                $fieldNameDesc = ucfirst($rpFieldName);
128
                $ret           .= $this->defines->getDefine($language, $stuTableSoleName . '_' . $rpFieldName, $fieldNameDesc);
129
            }
130
        }
131
        $ret .= $this->defines->getDefine($language, 'INDEX_THEREARE', "There are %s {$ucfTableName}");
132
        $ret .= $this->defines->getDefine($language, 'INDEX_LATEST_LIST', "Last {$module->getVar('mod_name')}");
133
        $ret .= $this->defines->getAboveDefines('Submit');
134
        $ret .= $this->defines->getDefine($language, 'SUBMIT', 'Submit');
135
        $ret .= $this->defines->getDefine($language, "SUBMIT_{$stuTableSoleName}", "Submit {$ucfTableSoleName}");
136
        $ret .= $this->defines->getDefine($language, 'SUBMIT_ALLPENDING', "All {$tableSoleName}/script information are posted pending verification.");
137
        $ret .= $this->defines->getDefine($language, 'SUBMIT_DONTABUSE', 'Username and IP are recorded, so please do not abuse the system.');
138
        $ret .= $this->defines->getDefine($language, 'SUBMIT_ISAPPROVED', "Your {$tableSoleName} has been approved");
139
        $ret .= $this->defines->getDefine($language, 'SUBMIT_PROPOSER', "Submit a {$tableSoleName}");
140
        $ret .= $this->defines->getDefine($language, 'SUBMIT_RECEIVED', "We have received your {$tableSoleName} info. Thank you !");
141
        $ret .= $this->defines->getDefine($language, 'SUBMIT_SUBMITONCE', "Submit your {$tableSoleName}/script only once.");
142
        $ret .= $this->defines->getDefine($language, 'SUBMIT_TAKEDAYS', "This will take many days to see your {$tableSoleName}/script added successfully in our database.");
143
        $ret .= $this->defines->getAboveDefines('Form');
144
        $ret .= $this->defines->getDefine($language, 'FORM_OK', 'Successfully saved');
145
        $ret .= $this->defines->getDefine($language, 'FORM_DELETE_OK', 'Successfully deleted');
146
        $ret .= $this->defines->getDefine($language, 'FORM_SURE_DELETE', "Are you sure to delete: <b><span style='color : Red;'>%s </span></b>", true);
147
        $ret .= $this->defines->getDefine($language, 'FORM_SURE_RENEW', "Are you sure to update: <b><span style='color : Red;'>%s </span></b>", true);
148
        return $ret;
149
    }
150
151
    /**
152
     * @private function getLanguageMainFooter
153
     * @param string $language
154
     *
155
     * @return string
156
     */
157
    private function getLanguageMainFooter($language)
158
    {
159
        $ret = $this->defines->getAboveDefines('Admin link');
160
        $ret .= $this->defines->getDefine($language, 'ADMIN', 'Admin');
161
        $ret .= $this->defines->getBelowDefines('End');
162
        $ret .= $this->defines->getBlankLine();
163
164
        return $ret;
165
    }
166
167
    /**
168
     * @public function render
169
     * @param null
170
     * @return bool|string
171
     */
172
    public function render()
173
    {
174
        $module        = $this->getModule();
175
        $filename      = $this->getFileName();
176
        $moduleDirname = $module->getVar('mod_dirname');
177
        $language      = $this->getLanguage($moduleDirname, 'MA');
178
        $content       = $this->getHeaderFilesComments($module);
179
        $content       .= $this->getLanguageMain($module, $language);
180
        $content       .= $this->getLanguageMainFooter($language);
181
182
        $this->create($moduleDirname, 'language/' . $GLOBALS['xoopsConfig']['language'], $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
183
184
        return $this->renderFile();
185
    }
186
}
187