Answerhist   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 56
c 0
b 0
f 0
dl 0
loc 93
rs 10
wmc 13

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 5 2
A __construct() 0 13 1
B getValuesAnswerhists() 0 52 10
1
<?php declare(strict_types=1);
2
3
4
namespace XoopsModules\Wgevents;
5
6
/*
7
 You may not change or alter any portion of this comment or credits
8
 of supporting developers from this source code or any supporting source code
9
 which is considered copyrighted (c) material of the original comment or credit authors.
10
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
*/
15
16
/**
17
 * wgEvents module for xoops
18
 *
19
 * @copyright    2021 XOOPS Project (https://xoops.org)
20
 * @license      GPL 2.0 or later
21
 * @package      wgevents
22
 * @since        1.0.0
23
 * @min_xoops    2.5.11 Beta1
24
 * @author       Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com
25
 */
26
27
use XoopsModules\Wgevents;
28
29
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
30
31
/**
32
 * Class Object Answerhist
33
 */
34
class Answerhist extends \XoopsObject
35
{
36
    /**
37
     * Constructor
38
     *
39
     */
40
    public function __construct()
41
    {
42
        $this->initVar('hist_id', \XOBJ_DTYPE_INT);
43
        $this->initVar('hist_info', \XOBJ_DTYPE_TXTBOX);
44
        $this->initVar('hist_datecreated', \XOBJ_DTYPE_INT);
45
        $this->initVar('hist_submitter', \XOBJ_DTYPE_INT);
46
        $this->initVar('id', \XOBJ_DTYPE_INT);
47
        $this->initVar('regid', \XOBJ_DTYPE_INT);
48
        $this->initVar('queid', \XOBJ_DTYPE_INT);
49
        $this->initVar('evid', \XOBJ_DTYPE_INT);
50
        $this->initVar('text', \XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('datecreated', \XOBJ_DTYPE_INT);
52
        $this->initVar('submitter', \XOBJ_DTYPE_INT);
53
    }
54
55
    /**
56
     * @static function &getInstance
57
     *
58
     */
59
    public static function getInstance()
60
    {
61
        static $instance = false;
62
        if (!$instance) {
63
            $instance = new self();
64
        }
65
    }
66
67
    /**
68
     * Get Values
69
     * @param array $questionsArr
70
     * @param null  $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
71
     * @param null  $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
72
     * @param null  $maxDepth
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $maxDepth is correct as it would always require null to be passed?
Loading history...
73
     * @return array
74
     */
75
    public function getValuesAnswerhists($questionsArr, $keys = null, $format = null, $maxDepth = null)
76
    {
77
        $helper  = \XoopsModules\Wgevents\Helper::getInstance();
78
        $ret = $this->getValues($keys, $format, $maxDepth);
79
        $ret['hist_datecreated_text'] = \formatTimestamp($this->getVar('hist_datecreated'), 's');
80
        $ret['hist_submitter_text']   = \XoopsUser::getUnameFromId($this->getVar('hist_submitter'));
81
        $questionHandler = $helper->getHandler('Question');
82
        $questionObj = $questionHandler->get($this->getVar('queid'));
83
        $queCaption = '';
84
        if (\is_object($questionObj)) {
85
            $queCaption = $questionObj->getVar('caption');
86
        }
87
        $ret['quecaption'] = $queCaption;
88
        $queItem = $questionsArr[$this->getVar('queid')];
89
        $ansText = $this->getVar('text', 'n');
90
        if (Constants::FIELD_RADIOYN == $queItem['type']) {
91
            if ((bool)$ansText) {
92
                $ansText = \_YES;
93
            } else {
94
                $ansText = \_NO;
95
            }
96
        }
97
        if (Constants::FIELD_CHECKBOX == $queItem['type'] ||
98
            Constants::FIELD_COMBOBOX == $queItem['type']) {
99
            $queValues = \unserialize($queItem['values'], ['allowed_classes' => false]);
100
            $ansItems = \unserialize($ansText, ['allowed_classes' => false]);
101
            $ansText = '';
102
            foreach ($ansItems as $ansItem) {
103
                $ansText .= $queValues[(int)$ansItem] . ' <br>';
104
            }
105
        }
106
        if (Constants::FIELD_SELECTBOX == $queItem['type']) {
107
            $queValues = \unserialize($queItem['values'], ['allowed_classes' => false]);
108
            $ansItem = (string)\unserialize($ansText, ['allowed_classes' => false]);
109
            $ansText = $queValues[(int)$ansItem];
110
        }
111
        if (Constants::FIELD_RADIO == $queItem['type']) {
112
            $queValues = \unserialize($queItem['values']);
113
            $ansText = $queValues[$ansText];
114
        }
115
        $ret['text_text'] = $ansText;
116
        $eventHandler = $helper->getHandler('Event');
117
        $eventObj = $eventHandler->get($this->getVar('evid'));
118
        $evName = 'invalid event';
119
        if (\is_object($eventObj)) {
120
            $evName = $eventObj->getVar('name');
121
        }
122
        $ret['eventname']        = $evName;
123
        $ret['datecreated_text'] = \formatTimestamp($this->getVar('datecreated'), 's');
124
        $ret['submitter_text']   = \XoopsUser::getUnameFromId($this->getVar('submitter'));
125
126
        return $ret;
127
    }
128
}
129