Log   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 5 2
A getValuesLogs() 0 6 1
B getForm() 0 28 8
A __construct() 0 6 1
A getNewInsertedId() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Wgevents;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * wgEvents module for xoops
17
 *
18
 * @copyright    2021 XOOPS Project (https://xoops.org)
19
 * @license      GPL 2.0 or later
20
 * @package      wgevents
21
 * @since        1.0.0
22
 * @min_xoops    2.5.11 Beta1
23
 * @author       Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com
24
 */
25
26
use XoopsModules\Wgevents;
27
28
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
29
30
/**
31
 * Class Object Log
32
 */
33
class Log extends \XoopsObject
34
{
35
    /**
36
     * @var int
37
     */
38
    public $start = 0;
39
40
    /**
41
     * @var int
42
     */
43
    public $limit = 0;
44
45
    /**
46
     * Constructor
47
     *
48
     */
49
    public function __construct()
50
    {
51
        $this->initVar('id', \XOBJ_DTYPE_INT);
52
        $this->initVar('text', \XOBJ_DTYPE_TXTBOX);
53
        $this->initVar('datecreated', \XOBJ_DTYPE_INT);
54
        $this->initVar('submitter', \XOBJ_DTYPE_INT);
55
    }
56
57
    /**
58
     * @static function &getInstance
59
     *
60
     */
61
    public static function getInstance()
62
    {
63
        static $instance = false;
64
        if (!$instance) {
65
            $instance = new self();
66
        }
67
    }
68
69
    /**
70
     * The new inserted $Id
71
     * @return inserted id
0 ignored issues
show
Bug introduced by
The type XoopsModules\Wgevents\inserted was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
     */
73
    public function getNewInsertedId()
74
    {
75
        return $GLOBALS['xoopsDB']->getInsertId();
76
    }
77
78
    /**
79
     * @public function getForm
80
     * @param bool $action
81
     * @return \XoopsThemeForm
82
     */
83
    public function getForm($action = false)
84
    {
85
        $helper = \XoopsModules\Wgevents\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
86
        if (!$action) {
87
            $action = $_SERVER['REQUEST_URI'];
88
        }
89
        $isAdmin = (\is_object($GLOBALS['xoopsUser']) && \is_object($GLOBALS['xoopsModule'])) ? $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid()) : false;
0 ignored issues
show
Unused Code introduced by
The assignment to $isAdmin is dead and can be removed.
Loading history...
90
        // Title
91
        $title = $this->isNew() ? \_AM_WGEVENTS_ADD_LOG : \_AM_WGEVENTS_EDIT_LOG;
92
        // Get Theme Form
93
        \xoops_load('XoopsFormLoader');
94
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
95
        $form->setExtra('enctype="multipart/form-data"');
96
        // Form Text logText
97
        $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_LOG_TEXT, 'text', 50, 255, $this->getVar('text')), true);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('text') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
        $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_LOG_TEXT, 'text', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('text')), true);
Loading history...
98
        // Form Text Date Select logDatecreated
99
        $logDatecreated = $this->isNew() ? \time() : $this->getVar('datecreated');
100
        $form->addElement(new \XoopsFormTextDateSelect(\_MA_WGEVENTS_DATECREATED, 'datecreated', '', $logDatecreated));
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type integer expected by parameter $size of XoopsFormTextDateSelect::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

100
        $form->addElement(new \XoopsFormTextDateSelect(\_MA_WGEVENTS_DATECREATED, 'datecreated', /** @scrutinizer ignore-type */ '', $logDatecreated));
Loading history...
101
        // Form Select User logSubmitter
102
        $uidCurrent = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0;
103
        $logSubmitter = $this->isNew() ? $uidCurrent : $this->getVar('submitter');
104
        $form->addElement(new \XoopsFormSelectUser(\_MA_WGEVENTS_SUBMITTER, 'submitter', false, $logSubmitter));
105
        // To Save
106
        $form->addElement(new \XoopsFormHidden('op', 'save'));
107
        $form->addElement(new \XoopsFormHidden('start', $this->start));
108
        $form->addElement(new \XoopsFormHidden('limit', $this->limit));
109
        $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));
110
        return $form;
111
    }
112
113
    /**
114
     * Get Values
115
     * @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...
116
     * @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...
117
     * @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...
118
     * @return array
119
     */
120
    public function getValuesLogs($keys = null, $format = null, $maxDepth = null)
121
    {
122
        $ret = $this->getValues($keys, $format, $maxDepth);
123
        $ret['datecreated_text'] = \formatTimestamp($this->getVar('datecreated'), 'm');
124
        $ret['submitter_text']   = \XoopsUser::getUnameFromId($this->getVar('submitter'));
125
        return $ret;
126
    }
127
128
    /**
129
     * Returns an array representation of the object
130
     *
131
     * @return array
132
     */
133
    /*
134
    public function toArray()
135
    {
136
        $ret = [];
137
        $vars = $this->getVars();
138
        foreach (\array_keys($vars) as $var) {
139
            $ret[$var] = $this->getVar($var);
140
        }
141
        return $ret;
142
    }
143
    */
144
}
145