Passed
Push — master ( d71037...1531a2 )
by Goffy
03:41
created

CheckData::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files;
4
5
use XoopsModules\Modulebuilder;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
/**
17
 * modulebuilder module.
18
 *
19
 * @copyright       XOOPS Project (https://xoops.org)
20
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21
 *
22
 * @since           2.5.0
23
 *
24
 * @author          Txmod Xoops http://www.txmodxoops.org
25
 *
26
 */
27
28
//include dirname(__DIR__) . '/autoload.php';
29
30
/**
31
 * Class CheckData.
32
 */
33
class CheckData
34
{
35
    /**
36
     * @public function constructor class
37
     *
38
     * @param null
39
     */
40
    public function __construct()
41
    {
42
        //parent::__construct();
43
    }
44
45
    /**
46
     * @static function getInstance
47
     *
48
     * @param null
49
     *
50
     * @return Modulebuilder\Files\CheckData
51
     */
52
    public static function getInstance()
53
    {
54
        static $instance = false;
55
        if (!$instance) {
56
            $instance = new self();
57
        }
58
59
        return $instance;
60
    }
61
62
    /**
63
     * @public function getCheckResult
64
     *
65
     * @param $module
66
     * @return array
67
     */
68
    public function getCheckPreBuilding($module)
69
    {
70
        $cf     = Modulebuilder\Files\CreateFile::getInstance();
71
72
        $modId  = $module->getVar('mod_id');
73
        $tables = $cf->getTableTables($modId);
74
        $infos = [];
75
76
        foreach (array_keys($tables) as $t) {
77
            if (1 == $tables[$t]->getVar('table_broken')) {
78
                $tableId = $tables[$t]->getVar('table_id');
79
                $tableName = $tables[$t]->getVar('table_name');
80
                $fields = $cf->getTableFields($modId, $tableId);
81
                $fieldSatus = '';
82
83
                foreach (array_keys($fields) as $f) {
84
                    $fieldName = $fields[$f]->getVar('field_name');
85
                    if (16 == $fields[$f]->getVar('field_element')) {
86
                        $fieldSatus = $fieldName;
87
                    }
88
                }
89
                // check whether each table with handling "broken" has also a field "status"
90
                if ('' == $fieldSatus) {
91
                    $info = str_replace('%t', $tableName, _AM_MODULEBUILDER_CHECKPREBUILD_BROKEN1);
92
                    $infos[] = ['icon' => 'error', 'info' => $info];
93
                }
94
            }
95
        }
96
97
        foreach (array_keys($tables) as $t) {
98
            $tableId = $tables[$t]->getVar('table_id');
99
            $tableName = $tables[$t]->getVar('table_name');
100
            $fields = $cf->getTableFields($modId, $tableId);
101
102
            foreach (array_keys($fields) as $f) {
103
                $fieldName = $fields[$f]->getVar('field_name');
104
                // check fields for parameters
105
                if ($f > 0) {
106
                    $fieldParams = (int)$fields[$f]->getVar('field_parent') + (int)$fields[$f]->getVar('field_admin') + (int)$fields[$f]->getVar('field_inlist') + (int)$fields[$f]->getVar('field_inform')
107
                        + (int)$fields[$f]->getVar('field_user') + (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot')
108
                        + (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot') + (int)$fields[$f]->getVar('field_block')
109
                        + (int)$fields[$f]->getVar('field_main') + (int)$fields[$f]->getVar('field_search') + (int)$fields[$f]->getVar('field_required');
110
                    if (0 == $fieldParams) {
111
                        $info = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS1);
112
                        $infos[] = ['icon' => 'error', 'info' => $info];
113
                    }
114
                }
115
            }
116
        }
117
118
        //check user file no usage in index or item
119
        foreach (array_keys($tables) as $t) {
120
            $tableId = $tables[$t]->getVar('table_id');
121
            $tableName = $tables[$t]->getVar('table_name');
122
            $fields = $cf->getTableFields($modId, $tableId);
123
124
            foreach (array_keys($fields) as $f) {
125
                $fieldName = $fields[$f]->getVar('field_name');
126
                if (1 == $fields[$f]->getVar('field_user')) {
127
                    // check fields for parameters
128
                    if ($f > 0) {
129
                        $fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot')
130
                            + (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot');
131
                        if (0 == $fieldParams) {
132
                            $info = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS2);
133
                            $infos[] = ['icon' => 'warning', 'info' => $info];
134
                        }
135
                    }
136
                }
137
            }
138
        }
139
        //check user file index multiple usage
140
        //check user file item multiple usage
141
        foreach (array_keys($tables) as $t) {
142
            $tableId = $tables[$t]->getVar('table_id');
143
            $tableName = $tables[$t]->getVar('table_name');
144
            $fields = $cf->getTableFields($modId, $tableId);
145
146
            foreach (array_keys($fields) as $f) {
147
                $fieldName = $fields[$f]->getVar('field_name');
148
                if (1 == $fields[$f]->getVar('field_user')) {
149
                    // check fields for parameters
150
                    if ($f > 0) {
151
                        $fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot');
152
                        if ($fieldParams > 1) {
153
                            $info = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS3);
154
                            $infos[] = ['icon' => 'warning', 'info' => $info];
155
                        }
156
                        $fieldParams = (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot');
157
                        if ($fieldParams > 1) {
158
                            $info = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS3);
159
                            $infos[] = ['icon' => 'warning', 'info' => $info];
160
                        }
161
                    }
162
                }
163
            }
164
        }
165
166
        //use in block but not field selected
167
        foreach (array_keys($tables) as $t) {
168
            $tableId = $tables[$t]->getVar('table_id');
169
            $tableName = $tables[$t]->getVar('table_name');
170
            $fields = $cf->getTableFields($modId, $tableId);
171
            $count = 0;
172
            if (1 == $tables[$t]->getVar('table_blocks')) {
173
                foreach (array_keys($fields) as $f) {
174
                    if (1 == $fields[$f]->getVar('field_block')) {
175
                        $count++;
176
                    }
177
                }
178
                if (0 == $count) {
179
                    $info = str_replace(['%t'], [$tableName], _AM_MODULEBUILDER_CHECKPREBUILD_BLOCK1);
180
                    $infos[] = ['icon' => 'warning', 'info' => $info];
181
                }
182
            }
183
        }
184
        //use in block but not field date
185
        foreach (array_keys($tables) as $t) {
186
            $tableId = $tables[$t]->getVar('table_id');
187
            $tableName = $tables[$t]->getVar('table_name');
188
189
            $count = 0;
190
            if (1 == $tables[$t]->getVar('table_blocks')) {
191
                $fields = $cf->getTableFields($modId, $tableId);
192
                foreach (array_keys($fields) as $f) {
193
                    if (15 == $fields[$f]->getVar('field_element') || 21 == $fields[$f]->getVar('field_element')) {
194
                        $count++;
195
                    }
196
                }
197
                if (0 == $count) {
198
                    $info = str_replace(['%t'], [$tableName], _AM_MODULEBUILDER_CHECKPREBUILD_BLOCK2);
199
                    $infos[] = ['icon' => 'warning', 'info' => $info];
200
                }
201
            }
202
        }
203
        //use comments in multiple tables
204
        $count         = 0;
205
        $tableComments = [];
206
        foreach (array_keys($tables) as $t) {
207
            if (1 == $tables[$t]->getVar('table_comments')) {
208
                $count++;
209
                $tableComments[] = $tables[$t]->getVar('table_name');
210
            }
211
        }
212
        if ($count > 1) {
213
            $tablesComments = implode(', ', $tableComments);
214
            $info = str_replace('%t', $tablesComments, _AM_MODULEBUILDER_CHECKPREBUILD_COMMENTS1);
215
            $infos[] = ['icon' => 'error', 'info' => $info];
216
        }
217
218
        foreach (array_keys($tables) as $t) {
219
            if (1 == $tables[$t]->getVar('table_comments')) {
220
                $tableId = $tables[$t]->getVar('table_id');
221
                $tableName = $tables[$t]->getVar('table_name');
222
                $fields = $cf->getTableFields($modId, $tableId);
223
                $fieldComments = '';
224
225
                foreach (array_keys($fields) as $f) {
226
                    $fieldName = $fields[$f]->getVar('field_name');
227
                    if ($fieldName == $tables[$t]->getVar('table_fieldname') . '_comments') {
228
                        $fieldComments = $fieldName;
229
                    }
230
                }
231
                // check whether each table with handling "broken" has also a field "status"
232
                if ('' == $fieldComments) {
233
                    $info = str_replace(['%f', '%t'], [$tables[$t]->getVar('table_fieldname') . '_comments', $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_COMMENTS2);
234
                    $infos[] = ['icon' => 'warning', 'info' => $info];
235
                }
236
            }
237
        }
238
239
        return $infos;
240
    }
241
}
242