LanguageBlocks::getLanguageBlock()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
nc 3
nop 2
dl 0
loc 27
rs 9.6333
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: LanguageBlocks.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class LanguageBlocks.
30
 */
31
class LanguageBlocks 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 LanguageBlocks
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 getLanguageBlock
73
     *  @param string $language
74
     *  @param string $module
75
     *
76
     * @return string
77
     */
78
    private function getLanguageBlock($module, $language)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

78
    private function getLanguageBlock(/** @scrutinizer ignore-unused */ $module, $language)

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

Loading history...
79
    {
80
        $tables = $this->getTables();
81
        $ret = $this->defines->getAboveDefines('Admin Edit');
82
        $ret .= $this->defines->getDefine($language, 'DISPLAY', 'How Many Tables to Display');
83
        $ret .= $this->defines->getDefine($language, 'TITLE_LENGTH', 'Title Length');
84
        $ret .= $this->defines->getDefine($language, 'CATTODISPLAY', 'Categories to Display');
85
        $ret .= $this->defines->getDefine($language, 'ALLCAT', 'All Categories');
86
        foreach (array_keys($tables) as $t) {
87
            $tableName = $tables[$t]->getVar('table_name');
88
            $ucfTableName = ucfirst($tableName);
89
            $ret .= $this->defines->getAboveDefines($ucfTableName);
90
            $fields = $this->getTableFields($tables[$t]->getVar('table_mid'), $tables[$t]->getVar('table_id'));
91
            foreach (array_keys($fields) as $f) {
92
                $fieldName = $fields[$f]->getVar('field_name');
93
                $stuFieldName = mb_strtoupper($fieldName);
94
95
                $rpFieldName = $this->getRightString($fieldName);
96
                $lpFieldName = mb_substr($fieldName, 0, mb_strpos($fieldName, '_'));
0 ignored issues
show
Unused Code introduced by
The assignment to $lpFieldName is dead and can be removed.
Loading history...
97
98
                $fieldNameDesc = ucfirst($rpFieldName);
99
100
                $ret .= $this->defines->getDefine($language, $stuFieldName, $fieldNameDesc);
101
            }
102
        }
103
104
        return $ret;
105
    }
106
107
    /**
108
     *  @private function getFooter
109
     *  @param null
110
     * @return string
111
     */
112
    private function getLanguageFooter()
113
    {
114
        $ret = $this->defines->getBelowDefines('End');
115
116
        return $ret;
117
    }
118
119
    /**
120
     *  @public function render
121
     *  @param null
122
     * @return bool|string
123
     */
124
    public function render()
125
    {
126
        $module = $this->getModule();
127
        $filename = $this->getFileName();
128
        $moduleDirname = $module->getVar('mod_dirname');
129
        $language = $this->getLanguage($moduleDirname, 'MB');
130
        $content = $this->getHeaderFilesComments($module, $filename);
131
        $content .= $this->getLanguageBlock($module, $language);
132
        $content .= $this->getLanguageFooter();
133
134
        $this->create($moduleDirname, 'language/' . $GLOBALS['xoopsConfig']['language'], $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
135
136
        return $this->renderFile();
137
    }
138
}
139