Passed
Pull Request — master (#8)
by Michael
11:33
created

myiframe_iframe.php ➔ b_myiframe_iframe_show()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 26
nc 2
nop 1
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * ****************************************************************************
5
 * MYIFRAME - MODULE FOR XOOPS
6
 * Copyright (c) Hervé Thouzard of Instant Zero (https://www.instant-zero.com)
7
 * ****************************************************************************
8
 */
9
require_once XOOPS_ROOT_PATH . '/modules/myiframe/include/functions.php';
10
11
/**
12
 * @param $options
13
 * @return array
14
 */
15
function b_myiframe_iframe_show($options)
16
{
17
    $block         = [];
18
    $tblalign      = [
19
        'top',
20
        'middle',
21
        'bottom',
22
        'left',
23
        'rigth',
24
    ];
25
    $tblscrolling  = [
26
        'yes',
27
        'no',
28
        'auto',
29
    ];
30
    $iframeHandler = $helper->getHandler('MyiframeBase');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $helper seems to be never defined.
Loading history...
31
    $frame         = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $frame is dead and can be removed.
Loading history...
32
    $frame         = $iframeHandler->get($options[0]);
33
34
    if (is_object($frame)) {
35
        $block['longdesc']     = $frame->getVar('frame_description');
36
        $block['width']        = $frame->getVar('frame_width');
37
        $block['height']       = $frame->getVar('frame_height');
38
        $block['align']        = $tblalign[$frame->getVar('frame_align') - 1];
39
        $block['frameborder']  = $frame->getVar('frame_frameborder');
40
        $block['marginwidth']  = $frame->getVar('frame_marginwidth');
41
        $block['marginheight'] = $frame->getVar('frame_marginheight');
42
        $block['scrolling']    = $tblscrolling[$frame->getVar('frame_scrolling') - 1];
43
        $block['url']          = $frame->getVar('frame_url');
44
    }
45
46
    return $block;
47
}
48
49
/**
50
 * @param $options
51
 * @return string
52
 */
53
function b_myiframe_iframe_edit($options)
54
{
55
    /** @var \MyiframeBaseHandler $iframeHandler */
56
    $iframeHandler = $helper->getHandler('MyiframeBase');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $helper seems to be never defined.
Loading history...
57
    $frarray       = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $frarray is dead and can be removed.
Loading history...
58
    $critere       = new \Criteria('1', '1', '=');
59
    $critere->setSort('frame_description');
60
    $frarray = $iframeHandler->getObjects($critere);
61
62
    $form = '' . _MB_MYIFRAME_IFRAME . "&nbsp;<select name='options[0]'>";
63
    /** @var Myiframe $oneframe */
64
    foreach ($frarray as $oneframe) {
65
        $form .= "<option value='" . $oneframe->getVar('frame_frameid') . "'";
66
        if ($options[0] == $oneframe->getVar('frame_frameid')) {
67
            $form .= " selected='selected'";
68
        }
69
        $form .= '>' . $oneframe->getVar('frame_description') . '</option>';
70
    }
71
    $form .= "</select>\n";
72
73
    return $form;
74
}
75
76
/**
77
 * @param $options
78
 */
79
function b_myiframe_iframe_onthefly($options): void
80
{
81
    $options = explode('|', $options);
82
    $block   = b_myiframe_iframe_show($options);
83
84
    $tpl = new \XoopsTpl();
85
    $tpl->assign('block', $block);
86
    $tpl->display('db:myiframe_block_show.tpl');
87
}
88