LanguageMain::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
1
<?php namespace XoopsModules\Tdmcreate\Files\Language;
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: LanguageMain.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class LanguageMain.
30
 */
31
class LanguageMain extends Files\CreateFile
32
{
33
    /**
34
     *  @public function constructor
35
     *  @param null
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
        $this->defines = LanguageDefines::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property defines does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
41
    }
42
43
    /**
44
     *  @static function getInstance
45
     *  @param null
46
     * @return LanguageMain
47
     */
48
    public static function getInstance()
49
    {
50
        static $instance = false;
51
        if (!$instance) {
52
            $instance = new self();
53
        }
54
55
        return $instance;
56
    }
57
58
    /**
59
     *  @public function write
60
     *  @param string $module
61
     *  @param mixed $tables
62
     *  @param string $filename
63
     */
64
    public function write($module, $tables, $filename)
65
    {
66
        $this->setModule($module);
67
        $this->setFileName($filename);
68
        $this->setTables($tables);
69
    }
70
71
    /**
72
     *  @private function geLanguagetMain
73
     *  @param string $module
74
     *  @param string $language
75
     *
76
     * @return string
77
     */
78
    private function geLanguagetMain($module, $language)
79
    {
80
        /** @var \XoopsModules\Tdmcreate\Utility $utility */
81
        $utility = new \XoopsModules\Tdmcreate\Utility();
82
83
        $moduleName = $module->getVar('mod_name');
84
        $tables = $this->getTables();
85
        $ret = $this->defines->getAboveHeadDefines('Main');
86
        $ret .= $this->defines->getDefine($language, 'INDEX', 'Home');
87
        $ret .= $this->defines->getDefine($language, 'TITLE', (string)$module->getVar('mod_name'));
88
        $ret .= $this->defines->getDefine($language, 'DESC', (string)$module->getVar('mod_description'));
89
        $ret .= $this->defines->getDefine($language, 'INDEX_DESC', "Welcome to the homepage of your new module {$moduleName}!<br>
90
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.", true);
91
        $ret .= $this->defines->getDefine($language, 'NO_PDF_LIBRARY', 'Libraries TCPDF not there yet, upload them in root/Frameworks');
92
        $ret .= $this->defines->getDefine($language, 'NO', 'No');
93
        $ret .= $this->defines->getAboveHeadDefines('Contents');
94
        foreach (array_keys($tables) as $i) {
95
            $tableName = $tables[$i]->getVar('table_name');
96
            $tableSoleName = $tables[$i]->getVar('table_solename');
97
            $stuTableName = mb_strtoupper($tableName);
98
            $stuTableSoleName = mb_strtoupper($tableSoleName);
99
            $ucfTableName = $utility::UcFirstAndToLower($tableName);
100
            $ucfTableSoleName = $utility::UcFirstAndToLower($tableSoleName);
101
            $ret .= $this->defines->getAboveDefines($ucfTableSoleName);
102
            $ret .= $this->defines->getDefine($language, $stuTableSoleName, $ucfTableSoleName);
103
            $ret .= $this->defines->getDefine($language, $stuTableName, $ucfTableName);
104
            $ret .= $this->defines->getDefine($language, "{$stuTableName}_TITLE", "{$ucfTableName} title");
105
            $ret .= $this->defines->getDefine($language, "{$stuTableName}_DESC", "{$ucfTableName} description");
106
            $ret .= $this->defines->getAboveDefines("Caption of {$ucfTableSoleName}");
107
            $fields = $this->getTableFields($tables[$i]->getVar('table_mid'), $tables[$i]->getVar('table_id'));
108
            foreach (array_keys($fields) as $f) {
109
                $fieldName = $fields[$f]->getVar('field_name');
110
                $rpFieldName = $this->getRightString($fieldName);
111
                $fieldNameDesc = ucfirst($rpFieldName);
112
                $ret .= $this->defines->getDefine($language, $stuTableSoleName . '_' . $rpFieldName, $fieldNameDesc);
113
            }
114
        }
115
        $ret .= $this->defines->getDefine($language, 'INDEX_THEREARE', "There are %s {$ucfTableName}");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ucfTableName seems to be defined by a foreach iteration on line 94. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
116
        $ret .= $this->defines->getDefine($language, 'INDEX_LATEST_LIST', "Last {$module->getVar('mod_name')}");
117
        $ret .= $this->defines->getAboveDefines('Submit');
118
        $ret .= $this->defines->getDefine($language, 'SUBMIT', 'Submit');
119
        $ret .= $this->defines->getDefine($language, "SUBMIT_{$stuTableSoleName}", "Submit {$ucfTableSoleName}");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ucfTableSoleName seems to be defined by a foreach iteration on line 94. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
Comprehensibility Best Practice introduced by
The variable $stuTableSoleName seems to be defined by a foreach iteration on line 94. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
120
        $ret .= $this->defines->getDefine($language, 'SUBMIT_ALLPENDING', "All {$tableSoleName}/script information are posted pending verification.");
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tableSoleName seems to be defined by a foreach iteration on line 94. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
121
        $ret .= $this->defines->getDefine($language, 'SUBMIT_DONTABUSE', 'Username and IP are recorded, so please do not abuse the system.');
122
        $ret .= $this->defines->getDefine($language, 'SUBMIT_ISAPPROVED', "Your {$tableSoleName} has been approved");
123
        $ret .= $this->defines->getDefine($language, 'SUBMIT_PROPOSER', "Submit a {$tableSoleName}");
124
        $ret .= $this->defines->getDefine($language, 'SUBMIT_RECEIVED', "We have received your {$tableSoleName} info. Thank you !");
125
        $ret .= $this->defines->getDefine($language, 'SUBMIT_SUBMITONCE', "Submit your {$tableSoleName}/script only once.");
126
        $ret .= $this->defines->getDefine($language, 'SUBMIT_TAKEDAYS', "This will take many days to see your {$tableSoleName}/script added successfully in our database.");
127
128
        return $ret;
129
    }
130
131
    /**
132
     *  @private function geLanguagetMainFooter
133
     *  @param string $language
134
     *
135
     * @return string
136
     */
137
    private function geLanguagetMainFooter($language)
138
    {
139
        $ret = $this->defines->getAboveDefines('Admin link');
140
        $ret .= $this->defines->getDefine($language, 'ADMIN', 'Admin');
141
        $ret .= $this->defines->getBelowDefines('End');
142
143
        return $ret;
144
    }
145
146
    /**
147
     *  @public function render
148
     *  @param null
149
     * @return bool|string
150
     */
151
    public function render()
152
    {
153
        $module = $this->getModule();
154
        $filename = $this->getFileName();
155
        $moduleDirname = $module->getVar('mod_dirname');
156
        $language = $this->getLanguage($moduleDirname, 'MA');
157
        $content = $this->getHeaderFilesComments($module, $filename);
158
        $content .= $this->geLanguagetMain($module, $language);
159
        $content .= $this->geLanguagetMainFooter($language);
160
161
        $this->create($moduleDirname, 'language/' . $GLOBALS['xoopsConfig']['language'], $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
162
163
        return $this->renderFile();
164
    }
165
}
166