editCardealerPart()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 20
nc 6
nop 1
dl 0
loc 28
rs 9.6
c 1
b 0
f 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
/**
14
 * Module: cardealer
15
 *
16
 * @category        Module
17
 * @package         cardealer
18
 * @author          XOOPS Development Team <[email protected]> - <https://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 XoopsModules\Cardealer;
26
27
/**
28
 * @param $options
29
 *
30
 * @return array
31
 */
32
function showCardealerPart($options)
33
{
34
35
    $block     = [];
36
    $blockType = $options[0];
37
    $partCount = $options[1];
38
    //$titleLenght = $options[2];
39
40
    /** @var \XoopsPersistableObjectHandler $partHandler */
41
    $partHandler = new Cardealer\PartHandler($GLOBALS['xoopsDB']);
42
    $criteria    = new \CriteriaCompo();
43
    array_shift($options);
44
    array_shift($options);
45
    array_shift($options);
46
    if ($blockType) {
47
        $criteria->add(new \Criteria('partnum', 0, '!='));
48
        $criteria->setSort('partnum');
49
        $criteria->setOrder('ASC');
50
    }
51
52
    $criteria->setLimit($partCount);
53
    $partArray = $partHandler->getAll($criteria);
54
    foreach (array_keys($partArray) as $i) {
55
    }
56
57
    return $block;
58
}
59
60
/**
61
 * @param $options
62
 *
63
 * @return string
64
 */
65
function editCardealerPart($options)
66
{
67
68
    $form = MB_CARDEALER_DISPLAY;
0 ignored issues
show
Bug introduced by
The constant MB_CARDEALER_DISPLAY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
69
    $form .= "<input type='hidden' name='options[0]' value='" . $options[0] . "' />";
70
    $form .= "<input name='options[1]' size='5' maxlength='255' value='" . $options[1] . "' type='text' />&nbsp;<br>";
71
    $form .= MB_CARDEALER_TITLELENGTH . " : <input name='options[2]' size='5' maxlength='255' value='" . $options[2] . "' type='text' /><br><br>";
0 ignored issues
show
Bug introduced by
The constant MB_CARDEALER_TITLELENGTH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
72
73
    /** @var \XoopsPersistableObjectHandler $partHandler */
74
    $partHandler = new Cardealer\PartHandler($GLOBALS['xoopsDB']);
75
76
    $criteria = new \CriteriaCompo();
77
    array_shift($options);
78
    array_shift($options);
79
    array_shift($options);
80
    $criteria->add(new Criteria('partnum', 0, '!='));
81
    $criteria->setSort('partnum');
82
    $criteria->setOrder('ASC');
83
    $partArray = $partHandler->getAll($criteria);
84
    $form      .= MB_CARDEALER_CATTODISPLAY . "<br><select name='options[]' multiple='multiple' size='5'>";
0 ignored issues
show
Bug introduced by
The constant MB_CARDEALER_CATTODISPLAY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
85
    $form      .= "<option value='0' " . (false === in_array(0, $options) ? '' : "selected='selected'") . '>' . MB_CARDEALER_ALLCAT . '</option>';
0 ignored issues
show
Bug introduced by
The constant MB_CARDEALER_ALLCAT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
86
    foreach (array_keys($partArray) as $i) {
87
        $partnum = $partArray[$i]->getVar('partnum');
88
        $form    .= "<option value='" . $partnum . "' " . (false === in_array($partnum, $options) ? '' : "selected='selected'") . '>' . $partArray[$i]->getVar('title') . '</option>';
89
    }
90
    $form .= '</select>';
91
92
    return $form;
93
}
94