IncludeInstall::getInstallImagesFolder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php namespace XoopsModules\Tdmcreate\Files\Includes;
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: IncludeInstall.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class IncludeInstall.
30
 */
31
class IncludeInstall extends Files\CreateFile
32
{
33
    /**
34
    *  @public function constructor
35
    *  @param null
36
    */
37
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
    *  @static function getInstance
45
    *  @param null
46
     * @return IncludeInstall
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        $table
62
     * @param mixed  $tables
63
     * @param string $filename
64
     */
65
    public function write($module, $table, $tables, $filename)
66
    {
67
        $this->setModule($module);
68
        $this->setTable($table);
69
        $this->setTables($tables);
70
        $this->setFileName($filename);
71
    }
72
73
    /**
74
     * @private function getInstallDirectory
75
     *
76
     * @param $dirname
77
     *
78
     * @return string
79
     */
80
    private function getInstallDirectory($dirname)
81
    {
82
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property pc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
83
        $contentIf = $this->pc->getPhpCodeMkdir((string)$dirname, '0777', "\t");
84
        $contentIf .= $this->pc->getPhpCodeChmod((string)$dirname, '0777', "\t");
85
        $ret = $this->pc->getPhpCodeConditions("!is_dir(\${$dirname})", '', '', $contentIf);
86
        $ret .= $this->pc->getPhpCodeCopy('$indexFile', "\${$dirname}.'/index.html'");
87
88
        return $ret;
89
    }
90
91
    /**
92
     *  @private function getInstallModuleFolder
93
     *
94
     *  @param $moduleDirname
95
     *
96
     * @return string
97
     */
98
    private function getInstallModuleFolder($moduleDirname)
99
    {
100
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property pc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
101
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property xc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
102
        $ret = $this->pc->getPhpCodeCommentLine('Copy base file');
103
        $ret .= $this->xc->getXcEqualsOperator('$indexFile', "XOOPS_UPLOAD_PATH.'/index.html'");
104
        $ret .= $this->xc->getXcEqualsOperator('$blankFile', "XOOPS_UPLOAD_PATH.'/blank.gif'");
105
        $ret .= $this->pc->getPhpCodeCommentLine("Making of uploads/{$moduleDirname} folder");
106
        $ret .= $this->xc->getXcEqualsOperator("\${$moduleDirname}", "XOOPS_UPLOAD_PATH.'/{$moduleDirname}'");
107
        $ret .= $this->getInstallDirectory($moduleDirname);
108
109
        return $ret;
110
    }
111
112
    /**
113
     *  @private function getHeaderTableFolder
114
     *
115
     *  @param $moduleDirname
116
     *  @param $tableName
117
     *
118
     * @return string
119
     */
120
    private function getInstallTableFolder($moduleDirname, $tableName)
121
    {
122
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property pc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
123
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property xc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
124
        $ret = $this->pc->getPhpCodeCommentLine("Making of {$tableName} uploads folder");
125
        $ret .= $this->xc->getXcEqualsOperator("\${$tableName}", "\${$moduleDirname}.'/{$tableName}'");
126
        $ret .= $this->getInstallDirectory($tableName);
127
128
        return $ret;
129
    }
130
131
    /**
132
    *  @private function getInstallImagesFolder
133
    *  @param string $moduleDirname
134
     *
135
     * @return string
136
     */
137
    private function getInstallImagesFolder($moduleDirname)
138
    {
139
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property pc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
140
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property xc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
141
        $ret = $this->pc->getPhpCodeCommentLine('Making of images folder');
142
        $ret .= $this->xc->getXcEqualsOperator('$images', "\${$moduleDirname}.'/images'");
143
        $ret .= $this->getInstallDirectory('images');
144
        $ret .= $this->pc->getPhpCodeCopy('$blankFile', "\$images.'/blank.gif'");
145
146
        return $ret;
147
    }
148
149
    /**
150
     * @private function getInstallImagesShotsFolder
151
     *
152
     * @param $moduleDirname
153
     *
154
     * @return string
155
     */
156
    private function getInstallImagesShotsFolder($moduleDirname)
157
    {
158
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property pc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
159
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property xc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
160
        $ret = $this->pc->getPhpCodeCommentLine('Making of shots folder');
161
        $ret .= $this->xc->getXcEqualsOperator('$shots', "\${$moduleDirname}.'/shots'");
162
        $ret .= $this->getInstallDirectory('shots');
163
        $ret .= $this->pc->getPhpCodeCopy('$blankFile', "\$shots.'/blank.gif'");
164
165
        return $ret;
166
    }
167
168
    /**
169
     *  @private function getInstallTableImagesFolder
170
     *
171
     *  @param $tableName
172
     *
173
     * @return string
174
     */
175
    private function getInstallTableImagesFolder($tableName)
176
    {
177
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property pc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
178
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property xc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
179
        $ret = $this->pc->getPhpCodeCommentLine("Making of images/{$tableName} folder");
180
        $ret .= $this->xc->getXcEqualsOperator("\${$tableName}", "\$images.'/{$tableName}'");
181
        $ret .= $this->getInstallDirectory($tableName);
182
        $ret .= $this->pc->getPhpCodeCopy('$blankFile', "\${$tableName}.'/blank.gif'");
183
184
        return $ret;
185
    }
186
187
    /**
188
     *  @private function getInstallFilesFolder
189
     *
190
     *  @param $moduleDirname
191
     *
192
     * @return string
193
     */
194
    private function getInstallFilesFolder($moduleDirname)
195
    {
196
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property pc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
197
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property xc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
198
        $ret = $this->pc->getPhpCodeCommentLine('Making of files folder');
199
        $ret .= $this->xc->getXcEqualsOperator('$files', "\${$moduleDirname}.'/files'");
200
        $ret .= $this->getInstallDirectory('files');
201
202
        return $ret;
203
    }
204
205
    /**
206
    *  @private function getInstallTableFilesFolder
207
    *  @param string $tableName
208
     *
209
     * @return string
210
     */
211
    private function getInstallTableFilesFolder($tableName)
212
    {
213
        $this->pc = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property pc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
214
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Bug Best Practice introduced by
The property xc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
215
        $ret = $this->pc->getPhpCodeCommentLine("Making of {$tableName} files folder");
216
        $ret .= $this->xc->getXcEqualsOperator("\${$tableName}", "\$files.'/{$tableName}'");
217
        $ret .= $this->getInstallDirectory($tableName);
218
219
        return $ret;
220
    }
221
222
    /**
223
    *  @private function getInstallFooter
224
    *  @param null
225
     * @return string
226
     */
227
    private function getInstallFooter()
228
    {
229
        return $this->getDashComment('Install Footer');
230
    }
231
232
    /**
233
    *  @public function render
234
    *  @param null
235
     * @return bool|string
236
     */
237
    public function render()
238
    {
239
        $module = $this->getModule();
240
        $moduleDirname = $module->getVar('mod_dirname');
241
        $table = $this->getTable();
0 ignored issues
show
Unused Code introduced by
The assignment to $table is dead and can be removed.
Loading history...
242
        $tables = $this->getTables();
243
        $filename = $this->getFileName();
244
        $content = $this->getHeaderFilesComments($module, $filename);
245
        $content .= $this->getInstallModuleFolder($moduleDirname);
246
        foreach (array_keys($tables) as $t) {
247
            $tableId = $tables[$t]->getVar('table_id');
248
            $tableMid = $tables[$t]->getVar('table_mid');
249
            $tableName = $tables[$t]->getVar('table_name');
250
            $tableInstall = $tables[$t]->getVar('table_install');
251
            if (1 == $tableInstall) {
252
                $content .= $this->getInstallTableFolder($moduleDirname, $tableName);
253
                $fields = $this->getTableFields($tableMid, $tableId);
254
                foreach (array_keys($fields) as $f) {
255
                    $fieldElement = $fields[$f]->getVar('field_element');
256
                    // All fields elements selected
257
                    switch ($fieldElement) {
258
                        case 13:
259
                            $content .= $this->getInstallImagesFolder($moduleDirname);
260
                            $content .= $this->getInstallTableImagesFolder($tableName);
261
                            break;
262
                        case 11:
263
                            $content .= $this->getInstallImagesShotsFolder($moduleDirname);
264
                            break;
265
                        case 12:
266
                        case 14:
267
                            $content .= $this->getInstallFilesFolder($moduleDirname);
268
                            $content .= $this->getInstallTableFilesFolder($tableName);
269
                            break;
270
                    }
271
                }
272
            }
273
        }
274
        $content .= $this->getInstallFooter();
275
276
        $this->create($moduleDirname, 'include', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
277
278
        return $this->renderFile();
279
    }
280
}
281