Issues (584)

class/Requests.php (3 issues)

1
<?php
2
3
namespace XoopsModules\Wggithub;
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
 * wgGitHub module for xoops
17
 *
18
 * @copyright      2020 XOOPS Project (https://xooops.org)
19
 * @license        GPL 2.0 or later
20
 * @package        wggithub
21
 * @since          1.0
22
 * @min_xoops      2.5.10
23
 * @author         TDM XOOPS - Email:<[email protected]> - Website:<https://wedega.com>
24
 */
25
26
use XoopsModules\Wggithub;
27
28
\defined('\XOOPS_ROOT_PATH') || die('Restricted access');
29
30
/**
31
 * Class Object Requests
32
 */
33
class Requests extends \XoopsObject
34
{
35
    /**
36
     * Constructor
37
     *
38
     * @param null
39
     */
40
    public function __construct()
41
    {
42
        $this->initVar('req_id', \XOBJ_DTYPE_INT);
43
        $this->initVar('req_request', \XOBJ_DTYPE_TXTBOX);
44
        $this->initVar('req_result', \XOBJ_DTYPE_TXTBOX);
45
        $this->initVar('req_datecreated', \XOBJ_DTYPE_INT);
46
        $this->initVar('req_submitter', \XOBJ_DTYPE_INT);
47
    }
48
49
    /**
50
     * @static function &getInstance
51
     *
52
     * @param null
53
     */
54
    public static function getInstance()
55
    {
56
        static $instance = false;
57
        if (!$instance) {
58
            $instance = new self();
59
        }
60
    }
61
62
    /**
63
     * The new inserted $Id
64
     * @return inserted id
65
     */
66
    public function getNewInsertedIdRequests()
67
    {
68
        $newInsertedId = $GLOBALS['xoopsDB']->getInsertId();
69
        return $newInsertedId;
70
    }
71
72
    /**
73
     * @public function getForm
74
     * @param bool $action
75
     * @return \XoopsThemeForm
76
     */
77
    public function getFormRequests($action = false)
78
    {
79
        if (!$action) {
80
            $action = $_SERVER['REQUEST_URI'];
81
        }
82
        // Title
83
        $title = $this->isNew() ? \sprintf(\_AM_WGGITHUB_REQUEST_ADD) : \sprintf(\_AM_WGGITHUB_REQUEST_EDIT);
84
        // Get Theme Form
85
        \xoops_load('XoopsFormLoader');
86
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
87
        $form->setExtra('enctype="multipart/form-data"');
88
        // Form Text reqRequest
89
        $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_REQUEST_REQUEST, 'req_request', 50, 255, $this->getVar('req_request')), true);
90
        // Form Text reqResult
91
        $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_REQUEST_RESULT, 'req_result', 50, 255, $this->getVar('req_result')));
92
        // Form Text Date Select reqDatecreated
93
        $reqDatecreated = $this->isNew() ?: $this->getVar('req_datecreated');
94
        $form->addElement(new \XoopsFormTextDateSelect(\_AM_WGGITHUB_REQUEST_DATECREATED, 'req_datecreated', '', $reqDatecreated));
95
        // Form Select User reqSubmitter
96
        $form->addElement(new \XoopsFormSelectUser(\_AM_WGGITHUB_REQUEST_SUBMITTER, 'req_submitter', false, $this->getVar('req_submitter')));
97
        // To Save
98
        $form->addElement(new \XoopsFormHidden('op', 'save'));
99
        $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
100
        return $form;
101
    }
102
103
    /**
104
     * Get Values
105
     * @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...
106
     * @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...
107
     * @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...
108
     * @return array
109
     */
110
    public function getValuesRequests($keys = null, $format = null, $maxDepth = null)
111
    {
112
        $ret = $this->getValues($keys, $format, $maxDepth);
113
        $ret['id']          = $this->getVar('req_id');
114
        $ret['request']     = $this->getVar('req_request');
115
        $ret['result']      = $this->getVar('req_result');
116
        $ret['datecreated'] = \formatTimestamp($this->getVar('req_datecreated'), 's');
117
        $ret['submitter']   = \XoopsUser::getUnameFromId($this->getVar('req_submitter'));
118
        return $ret;
119
    }
120
121
    /**
122
     * Returns an array representation of the object
123
     *
124
     * @return array
125
     */
126
    public function toArrayRequests()
127
    {
128
        $ret = [];
129
        $vars = $this->getVars();
130
        foreach (\array_keys($vars) as $var) {
131
            $ret[$var] = $this->getVar('"{$var}"');
132
        }
133
        return $ret;
134
    }
135
}
136