Passed
Push — master ( 76a8b6...d71037 )
by Goffy
27:29
created

LanguageMailTpl::getTemplateTableNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 4
dl 0
loc 15
rs 9.9
c 0
b 0
f 0
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 LanguageMailTpl.
31
 */
32
class LanguageMailTpl extends Files\CreateFile
33
{
34
    /**
35
     * @public function constructor
36
     * @param null
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
     * @static function getInstance
45
     * @param null
46
     * @return LanguageMailTpl
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
     *
61
     * @param $module
62
     * @param $table
63
     * @param $filename
64
     */
65
    public function write($module, $table, $filename)
66
    {
67
        $this->setModule($module);
68
        $this->setTable($table);
69
        $this->setFileName($filename);
70
    }
71
72
    /**
73
     * @public function getTemplateDummy
74
     * @param $tableSoleName
75
     * @param $stuTableSoleName
76
     * @param $stuFieldMain
77
     * @param $line
78
     * @return string
79
     */
80
    public function getTemplateDummy($tableSoleName, $stuTableSoleName, $stuFieldMain, $line)
0 ignored issues
show
Unused Code introduced by
The parameter $stuFieldMain 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

80
    public function getTemplateDummy($tableSoleName, $stuTableSoleName, /** @scrutinizer ignore-unused */ $stuFieldMain, $line)

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...
Unused Code introduced by
The parameter $stuTableSoleName 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

80
    public function getTemplateDummy($tableSoleName, /** @scrutinizer ignore-unused */ $stuTableSoleName, $stuFieldMain, $line)

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...
81
    {
82
83
        $ret = $this->getSimpleString('Hello {X_UNAME},');
84
        $ret .= $this->getSimpleString('');
85
        $ret .= $this->getSimpleString('A new ' . $tableSoleName . ' "{ITEM_NAME}" has been added at {X_SITENAME}.');
86
        $ret .= $this->getSimpleString('');
87
        $ret .= $this->getSimpleString('You can view this ' . $tableSoleName . ' here:');
88
        $ret .= $this->getSimpleString('{ITEM_URL}');
89
        $ret .= $this->getSimpleString('');
90
        $ret .= $this->getSimpleString($line);
91
        $ret .= $this->getSimpleString('');
92
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when a new ' . $tableSoleName . ' is added to our site.');
93
        $ret .= $this->getSimpleString('');
94
95
        return $ret;
96
    }
97
98
    /**
99
     * @public function getTemplateTableModify
100
     * @param $tableSoleName
101
     * @param $stuTableSoleName
102
     * @param $stuFieldMain
103
     * @param $line
104
     * @return string
105
     */
106
    public function getTemplateTableModify($tableSoleName, $stuTableSoleName, $stuFieldMain, $line)
0 ignored issues
show
Unused Code introduced by
The parameter $stuTableSoleName 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

106
    public function getTemplateTableModify($tableSoleName, /** @scrutinizer ignore-unused */ $stuTableSoleName, $stuFieldMain, $line)

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...
Unused Code introduced by
The parameter $stuFieldMain 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

106
    public function getTemplateTableModify($tableSoleName, $stuTableSoleName, /** @scrutinizer ignore-unused */ $stuFieldMain, $line)

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...
107
    {
108
109
        $ret = $this->getSimpleString('Hello {X_UNAME},');
110
        $ret .= $this->getSimpleString('');
111
        $ret .= $this->getSimpleString('The ' . $tableSoleName . ' "{ITEM_NAME}" has been modified at {X_SITENAME}.');
112
        $ret .= $this->getSimpleString('');
113
        $ret .= $this->getSimpleString('You can view this ' . $tableSoleName . ' here:');
114
        $ret .= $this->getSimpleString('{ITEM_URL}');
115
        $ret .= $this->getSimpleString('');
116
        $ret .= $this->getSimpleString($line);
117
        $ret .= $this->getSimpleString('');
118
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when a ' . $tableSoleName . ' is modified on our site.');
119
120
        return $ret;
121
    }
122
123
    /**
124
     * @public function getTemplateTableDelete
125
     * @param $tableSoleName
126
     * @param $stuFieldMain
127
     * @param $line
128
     * @return string
129
     */
130
    public function getTemplateTableDelete($tableSoleName, $stuFieldMain, $line)
0 ignored issues
show
Unused Code introduced by
The parameter $stuFieldMain 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

130
    public function getTemplateTableDelete($tableSoleName, /** @scrutinizer ignore-unused */ $stuFieldMain, $line)

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...
131
    {
132
133
        $ret = $this->getSimpleString('Hello {X_UNAME},');
134
        $ret .= $this->getSimpleString('');
135
        $ret .= $this->getSimpleString('The ' . $tableSoleName . ' "{ITEM_NAME}" has been deleted from {X_SITENAME}.');
136
        $ret .= $this->getSimpleString('');
137
        $ret .= $this->getSimpleString($line);
138
        $ret .= $this->getSimpleString('');
139
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when a ' . $tableSoleName . ' is deleted from our site.');
140
141
        return $ret;
142
    }
143
144
    /**
145
     * @public function getTemplateTableApprove
146
     * @param $tableSoleName
147
     * @param $stuTableSoleName
148
     * @param $stuFieldMain
149
     * @param $line
150
     * @return string
151
     */
152
    public function getTemplateTableApprove($tableSoleName, $stuTableSoleName, $stuFieldMain, $line)
0 ignored issues
show
Unused Code introduced by
The parameter $stuTableSoleName 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

152
    public function getTemplateTableApprove($tableSoleName, /** @scrutinizer ignore-unused */ $stuTableSoleName, $stuFieldMain, $line)

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...
Unused Code introduced by
The parameter $stuFieldMain 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

152
    public function getTemplateTableApprove($tableSoleName, $stuTableSoleName, /** @scrutinizer ignore-unused */ $stuFieldMain, $line)

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...
153
    {
154
155
        $ret = $this->getSimpleString('Hello {X_UNAME},');
156
        $ret .= $this->getSimpleString('');
157
        $ret .= $this->getSimpleString('A new ' . $tableSoleName . ' "{ITEM_NAME}" is waiting for approval at {X_SITENAME}.');
158
        $ret .= $this->getSimpleString('');
159
        $ret .= $this->getSimpleString('You can view this ' . $tableSoleName . ' here:');
160
        $ret .= $this->getSimpleString('{ITEM_URL}');
161
        $ret .= $this->getSimpleString('');
162
        $ret .= $this->getSimpleString($line);
163
        $ret .= $this->getSimpleString('');
164
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when a ' . $tableSoleName . ' is waitung for approval on our site.');
165
166
        return $ret;
167
    }
168
169
    /**
170
     * @public function getTemplateTableApprove
171
     * @param $tableSoleName
172
     * @param $stuTableSoleName
173
     * @param $stuFieldMain
174
     * @param $line
175
     * @return string
176
     */
177
    public function getTemplateTableBroken($tableSoleName, $stuTableSoleName, $stuFieldMain, $line)
0 ignored issues
show
Unused Code introduced by
The parameter $stuTableSoleName 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

177
    public function getTemplateTableBroken($tableSoleName, /** @scrutinizer ignore-unused */ $stuTableSoleName, $stuFieldMain, $line)

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...
Unused Code introduced by
The parameter $stuFieldMain 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

177
    public function getTemplateTableBroken($tableSoleName, $stuTableSoleName, /** @scrutinizer ignore-unused */ $stuFieldMain, $line)

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...
178
    {
179
180
        $ret = $this->getSimpleString('Hello {X_UNAME},');
181
        $ret .= $this->getSimpleString('');
182
        $ret .= $this->getSimpleString('The ' . $tableSoleName . ' "{ITEM_NAME}" has been notified as broken at {X_SITENAME}.');
183
        $ret .= $this->getSimpleString('');
184
        $ret .= $this->getSimpleString('You can view this ' . $tableSoleName . ' here:');
185
        $ret .= $this->getSimpleString('{ITEM_URL}');
186
        $ret .= $this->getSimpleString('');
187
        $ret .= $this->getSimpleString($line);
188
        $ret .= $this->getSimpleString('');
189
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when a ' . $tableSoleName . ' is notified as broken on our site.');
190
191
        return $ret;
192
    }
193
194
    /**
195
     * @public function getTemplateGlobalNew
196
     * @param $line
197
     * @return string
198
     */
199
    public function getTemplateGlobalNew($line)
200
    {
201
202
        $ret = $this->getSimpleString('Hello {X_UNAME},');
203
        $ret .= $this->getSimpleString('');
204
        $ret .= $this->getSimpleString('A new item "{ITEM_NAME}" has been added at {X_SITENAME}.');
205
        $ret .= $this->getSimpleString('');
206
        $ret .= $this->getSimpleString('You can view this item here:');
207
        $ret .= $this->getSimpleString('{ITEM_URL}');
208
        $ret .= $this->getSimpleString('');
209
        $ret .= $this->getSimpleString($line);
210
        $ret .= $this->getSimpleString('');
211
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when a new item is added to our site.');
212
213
        return $ret;
214
    }
215
216
    /**
217
     * @public function getTemplateGlobalModify
218
     * @param $line
219
     * @return string
220
     */
221
    public function getTemplateGlobalModify($line)
222
    {
223
224
        $ret = $this->getSimpleString('Hello {X_UNAME},');
225
        $ret .= $this->getSimpleString('');
226
        $ret .= $this->getSimpleString('The item "{ITEM_NAME}" has been modified at {X_SITENAME}.');
227
        $ret .= $this->getSimpleString('');
228
        $ret .= $this->getSimpleString('You can view this item here:');
229
        $ret .= $this->getSimpleString('{ITEM_URL}');
230
        $ret .= $this->getSimpleString('');
231
        $ret .= $this->getSimpleString($line);
232
        $ret .= $this->getSimpleString('');
233
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when an item is modified on our site.');
234
235
        return $ret;
236
    }
237
238
    /**
239
     * @public function getTemplateGlobalDelete
240
     * @param $line
241
     * @return string
242
     */
243
    public function getTemplateGlobalDelete($line)
244
    {
245
246
        $ret = $this->getSimpleString('Hello {X_UNAME},');
247
        $ret .= $this->getSimpleString('');
248
        $ret .= $this->getSimpleString('The item "{ITEM_NAME}" has been deleted from {X_SITENAME}.');
249
        $ret .= $this->getSimpleString('');
250
        $ret .= $this->getSimpleString($line);
251
        $ret .= $this->getSimpleString('');
252
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when an item is deleted from our site.');
253
254
        return $ret;
255
    }
256
257
    /**
258
     * @public function getTemplateGlobalApprove
259
     * @param $line
260
     * @return string
261
     */
262
    public function getTemplateGlobalApprove($line)
263
    {
264
265
        $ret = $this->getSimpleString('Hello {X_UNAME},');
266
        $ret .= $this->getSimpleString('');
267
        $ret .= $this->getSimpleString('The item "{ITEM_NAME}" is waiting for approval at {X_SITENAME}.');
268
        $ret .= $this->getSimpleString('');
269
        $ret .= $this->getSimpleString('You can view this item here:');
270
        $ret .= $this->getSimpleString('{ITEM_URL}');
271
        $ret .= $this->getSimpleString('');
272
        $ret .= $this->getSimpleString($line);
273
        $ret .= $this->getSimpleString('');
274
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when an item is waitung for approval on our site.');
275
276
        return $ret;
277
    }
278
279
    /**
280
     * @public function getTemplateGlobalBroken
281
     * @param $line
282
     * @return string
283
     */
284
    public function getTemplateGlobalBroken($line)
285
    {
286
287
        $ret = $this->getSimpleString('Hello {X_UNAME},');
288
        $ret .= $this->getSimpleString('');
289
        $ret .= $this->getSimpleString('The item "{ITEM_NAME}" has been notified as broken at {X_SITENAME}.');
290
        $ret .= $this->getSimpleString('');
291
        $ret .= $this->getSimpleString('You can view this item here:');
292
        $ret .= $this->getSimpleString('{ITEM_URL}');
293
        $ret .= $this->getSimpleString('');
294
        $ret .= $this->getSimpleString($line);
295
        $ret .= $this->getSimpleString('');
296
        $ret .= $this->getSimpleString('You are receiving this message because you selected to be notified when an item is notified as broken on our site.');
297
298
        return $ret;
299
    }
300
    /**
301
     * @public function getTemplateTableApprove
302
     * @param $line
303
     * @return string
304
     */
305
    public function getTemplateTableFooter($line)
306
    {
307
308
        $ret = $this->getSimpleString('');
309
        $ret .= $this->getSimpleString('If this is an error or you wish not to receive further such notifications, please update your subscriptions by visiting the link below:');
310
        $ret .= $this->getSimpleString('{X_UNSUBSCRIBE_URL}');
311
        $ret .= $this->getSimpleString('');
312
        $ret .= $this->getSimpleString('Please do not reply to this message.');
313
        $ret .= $this->getSimpleString('');
314
        $ret .= $this->getSimpleString($line);
315
        $ret .= $this->getSimpleString('');
316
        $ret .= $this->getSimpleString('{X_SITENAME} ({X_SITEURL})');
317
        $ret .= $this->getSimpleString('webmaster');
318
        $ret .= $this->getSimpleString('{X_ADMINMAIL}');
319
        $ret .= $this->getSimpleString('');
320
        $ret .= $this->getSimpleString($line);
321
322
        return $ret;
323
    }
324
325
326
    /**
327
     * @public   function renderFile
328
     * @return bool|string
329
     */
330
    public function render()
331
    {
332
        $module        = $this->getModule();
333
        $filename      = $this->getFileName();
334
        $table         = $this->getTable();
335
        $moduleDirname = $module->getVar('mod_dirname');
336
        $tableSoleName = $table->getVar('table_solename');
337
        $stuTableSoleName = mb_strtoupper($tableSoleName);
338
        $fieldMain  = '';
339
        $fields    = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
340
        foreach (array_keys($fields) as $f) {
341
            $fieldName = $fields[$f]->getVar('field_name');
342
            if (1 == $fields[$f]->getVar('field_main')) {
343
                $fieldMain = $fieldName; // fieldMain = fields parameters main field
344
            }
345
        }
346
        $stuFieldMain = mb_strtoupper($fieldMain);
347
348
        $line = '------------------------------------------------------------------';
349
        $content = '';
350
        switch ($filename) {
351
            case 'category_new_notify.tpl':
352
                //$content .= $this->getTemplateCategoryNew('categories', 'CATEGORY', 'CATEGORY', $line);
353
                //break;
354
            case 'default':
355
            default:
356
                $content .= $this->getTemplateDummy('story', 'STORY', 'STORY_NAME', $line);
357
                break;
358
            case 'global_new_notify.tpl':
359
                $content .= $this->getTemplateGlobalNew($line);
360
                break;
361
            case'global_modify_notify.tpl':
362
                $content .= $this->getTemplateGlobalModify($line);
363
                break;
364
            case 'global_delete_notify.tpl':
365
                $content .= $this->getTemplateGlobalDelete($line);
366
                break;
367
            case 'global_approve_notify.tpl':
368
                $content .= $this->getTemplateGlobalApprove($line);
369
                break;
370
            case 'global_broken_notify.tpl':
371
                $content .= $this->getTemplateGlobalBroken($line);
372
                break;
373
            case $tableSoleName . '_modify_notify.tpl':
374
                $content .= $this->getTemplateTableModify($tableSoleName, $stuTableSoleName, $stuFieldMain, $line);
375
                break;
376
            case $tableSoleName . '_delete_notify.tpl':
377
                $content .= $this->getTemplateTableDelete($tableSoleName, $stuFieldMain, $line);
378
                break;
379
            case $tableSoleName . '_approve_notify.tpl':
380
                $content .= $this->getTemplateTableApprove($tableSoleName, $stuTableSoleName, $stuFieldMain, $line);
381
                break;
382
            case $tableSoleName . '_broken_notify.tpl':
383
                $content .= $this->getTemplateTableBroken($tableSoleName, $stuTableSoleName, $stuFieldMain, $line);
384
                break;
385
        }
386
        $content .= $this->getTemplateTableFooter($line);
387
388
        $this->create($moduleDirname, 'language/' . $GLOBALS['xoopsConfig']['language'] . '/mail_template', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED);
389
390
        return $this->renderFile();
391
    }
392
}
393