Utility   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A renderIconLinks() 0 25 6
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopsfaq;
4
5
/*
6
 Xoopsfaq Utility Class Definition
7
8
 You may not change or alter any portion of this comment or credits of
9
 supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit
11
 authors.
12
13
 This program is distributed in the hope that it will be useful, but
14
 WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
18
/**
19
 * Module:  myQuiz
20
 *
21
 * @license      https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
22
 * @copyright    https://xoops.org 2001-2017 &copy; XOOPS Project
23
 * @author       ZySpec <[email protected]>
24
 * @author       Mamba <[email protected]>
25
 * @since        ::      File available since version 4.10
26
 */
27
28
use Xmf\Module\Admin;
29
use XoopsModules\Xoopsfaq\{
30
    Common
31
};
32
33
/**
34
 * Class Utility
35
 */
36
class Utility extends Common\SysUtility
37
{
38
    //--------------- Custom module methods -----------------------------
39
    /**
40
     * Render the icon links
41
     *
42
     * @param array $icon_array contains operation=>icon_name as key=>value
43
     * @param mixed $param      HTML parameter
44
     * @param mixed $value      HTML parameter value to set
45
     * @param mixed $extra      are any additional HTML attributes desired for the <a> tag
46
     */
47
    public static function renderIconLinks(array $icon_array, $param, $value = null, $extra = null): string
48
    {
49
        $moduleDirName = \basename(\dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
50
        //        \xoops_loadLanguage('admin', $moduleDirName);
51
        $ret = '';
52
        if (null !== $value) {
53
            foreach ($icon_array as $_op => $icon) {
54
                if (false !== \mb_strpos((string)$icon, '.')) {
55
                    $iconName = \mb_substr((string)$icon, 0, \mb_strlen((string)$icon) - \mb_strrchr((string)$icon, '.'));
56
                    $iconExt  = \mb_substr(\mb_strrchr((string)$icon, '.'), 1);
57
                } else {
58
                    $iconName = $icon;
59
                    $iconExt  = 'png';
60
                }
61
                $url = (!\is_numeric($_op)) ? $_op . '?' . $param . '=' . $value : \xoops_getenv('SCRIPT_NAME') . '?op=' . $iconName . '&amp;' . $param . '=' . $value;
62
                if (null !== $extra) {
63
                    $url .= ' ' . $extra;
64
                }
65
                $title = \constant(\htmlspecialchars(mb_strtoupper('_XO_LA_' . $iconName), \ENT_QUOTES | \ENT_HTML5));
66
                $img   = '<img src="' . Admin::iconUrl($iconName . '.' . $iconExt, '16') . '"' . ' title ="' . $title . '"' . ' alt = "' . $title . '"' . ' class="bnone middle">';
67
                $ret   .= '<a href="' . $url . '"' . $extra . '>' . $img . '</a>';
68
            }
69
        }
70
71
        return $ret;
72
    }
73
}
74