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
|
|
|
/** |
14
|
|
|
* Module: Equipment |
15
|
|
|
* |
16
|
|
|
* @category Module |
17
|
|
|
* @package equipment |
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <http://xoops.org> |
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @link https://xoops.org/ |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use Xmf\Language; |
26
|
|
|
|
27
|
|
|
// comment callback functions |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param $category |
31
|
|
|
* @param $item_id |
32
|
|
|
* @return null |
33
|
|
|
*/ |
34
|
|
|
function equipment_notify_iteminfo($category, $item_id) |
35
|
|
|
{ |
36
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
37
|
|
|
|
38
|
|
|
if (empty($GLOBALS['xoopsModule']) || $GLOBALS['xoopsModule']->getVar('dirname') !== 'equipment') { |
39
|
|
|
/** @var XoopsModuleHandler $moduleHandler */ |
40
|
|
|
$moduleHandler = xoops_getHandler('module'); |
41
|
|
|
$module = $moduleHandler->getByDirname('equipment'); |
42
|
|
|
/** @var XoopsConfigHandler $configHandler */ |
43
|
|
|
$configHandler = xoops_getHandler('config'); |
44
|
|
|
$config =& $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
45
|
|
|
} else { |
46
|
|
|
$module = $GLOBALS['xoopsModule']; |
47
|
|
|
$config = $GLOBALS['xoopsModuleConfig']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
Language::load('main', $moduleDirName); |
51
|
|
|
|
52
|
|
|
if ('global' === $category) { |
53
|
|
|
$item['name'] = ''; |
|
|
|
|
54
|
|
|
$item['url'] = ''; |
55
|
|
|
|
56
|
|
|
return $item; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ('category' === $category) { |
60
|
|
|
// Assume we have a valid category id |
61
|
|
|
$sql = 'SELECT _title FROM ' . $GLOBALS['xoopsDB']->prefix('equipment_cat') . ' WHERE _cid = ' . $item_id; |
62
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql); // TODO: error check |
63
|
|
|
$resultArrayay = $GLOBALS['xoopsDB']->fetchArray($result); |
64
|
|
|
$item['name'] = $resultArrayay['_title']; |
|
|
|
|
65
|
|
|
$item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/cat_view.php?_cid=' . $item_id; |
66
|
|
|
|
67
|
|
|
return $item; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if ('' == $category) { |
71
|
|
|
// Assume we have a valid link id |
72
|
|
|
$sql = 'SELECT _cid, _title FROM ' . $GLOBALS['xoopsDB']->prefix('equipment_rentals') . ' WHERE _lid = ' . $item_id; |
73
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql); // TODO: error check |
74
|
|
|
$resultArrayay = $GLOBALS['xoopsDB']->fetchArray($result); |
75
|
|
|
$item['name'] = $resultArrayay['title']; |
|
|
|
|
76
|
|
|
$item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/equipment_visit.php?_cid=' . $resultArrayay['_cid'] . '&_lid=' . $item_id; |
77
|
|
|
|
78
|
|
|
return $item; |
79
|
|
|
} |
80
|
|
|
return null; |
81
|
|
|
} |
82
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.