Completed
Pull Request — master (#126)
by Gino
03:40
created

IncludeCommentFunctions::renderFile()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 30
rs 8.8571
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: IncludeCommentFunctions.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class IncludeCommentFunctions.
27
 */
28
class IncludeCommentFunctions extends TDMCreateFile
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
29
{
30
    /*
31
    *  @public function constructor
32
    *  @param null
33
    */
34
    /**
35
     *
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /*
43
    *  @static function getInstance
44
    *  @param null
45
    */
46
    /**
47
     * @return IncludeCommentFunctions
48
     */
49
    public static function getInstance()
50
    {
51
        static $instance = false;
52
        if (!$instance) {
53
            $instance = new self();
54
        }
55
56
        return $instance;
57
    }
58
59
    /*
60
    *  @public function write
61
    *  @param string $module
62
    *  @param mixed $table
63
    */
64
    /**
65
     * @param $module
66
     * @param $table
67
     * @param $filename
68
     */
69
    public function write($module, $table, $filename)
70
    {
71
        $this->setModule($module);
72
        $this->setTable($table);
73
        $this->setFileName($filename);
74
    }
75
76
    /*
77
    *  @public function render
78
    *  @param null
79
    */
80
    /**
81
     * @return bool|string
82
     */
83
    public function render()
84
    {
85
        $module = $this->getModule();
86
        $table = $this->getTable();
87
        $moduleDirname = $module->getVar('mod_dirname');
88
        $tableName = $table->getVar('table_name');
89
        $ucfModuleDirname = ucfirst($moduleDirname);
90
        $ucfTableName = ucfirst($tableName);
91
        $filename = $this->getFileName();
92
        $content = $this->getHeaderFilesComments($module, $filename);
93
        $content .= <<<EOT
94
95
function {$moduleDirname}CommentsUpdate(\$itemId, \$itemNumb) {
96
    \$itemId = (int) (\$itemId);
97
    \$itemNumb = (int) (\$itemNumb);
98
    \$article = new {$ucfModuleDirname}{$ucfTableName}(\$itemId);
99
    if (!\$article->updateComments(\$itemNumb)) {
100
        return false;
101
    }
102
    return true;
103
}
104
105
function {$moduleDirname}CommentsApprove(&\$comment){
106
    // notification mail here
107
}
108
EOT;
109
        $this->create($moduleDirname, 'include', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
110
111
        return $this->renderFile();
112
    }
113
}
114