Passed
Push — master ( 664846...354237 )
by Goffy
03:12
created

Directories::getValuesDirectories()   B

Complexity

Conditions 7
Paths 48

Size

Total Lines 26
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 48
nop 3
dl 0
loc 26
rs 8.6186
c 0
b 0
f 0
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         Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com>
24
 */
25
26
use XoopsModules\Wggithub;
27
use XoopsModules\Wggithub\Constants;
28
29
\defined('\XOOPS_ROOT_PATH') || die('Restricted access');
30
31
/**
32
 * Class Object Directories
33
 */
34
class Directories extends \XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject 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...
35
{
36
    /**
37
     * Constructor
38
     *
39
     * @param null
40
     */
41
    public function __construct()
42
    {
43
        $this->initVar('dir_id', \XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
44
        $this->initVar('dir_name', \XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
45
        $this->initVar('dir_descr', XOBJ_DTYPE_OTHER);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Wggithub\XOBJ_DTYPE_OTHER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
46
        $this->initVar('dir_type', \XOBJ_DTYPE_INT);
47
        $this->initVar('dir_content', \XOBJ_DTYPE_INT);
48
        $this->initVar('dir_autoupdate', XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Wggithub\XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
49
        $this->initVar('dir_online', XOBJ_DTYPE_INT);
50
        $this->initVar('dir_filterrelease', XOBJ_DTYPE_INT);
51
        $this->initVar('dir_datecreated', \XOBJ_DTYPE_INT);
52
        $this->initVar('dir_submitter', \XOBJ_DTYPE_INT);
53
    }
54
55
    /**
56
     * @static function &getInstance
57
     *
58
     * @param null
59
     */
60
    public static function getInstance()
61
    {
62
        static $instance = false;
63
        if (!$instance) {
64
            $instance = new self();
65
        }
66
    }
67
68
    /**
69
     * The new inserted $Id
70
     * @return inserted id
0 ignored issues
show
Bug introduced by
The type XoopsModules\Wggithub\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...
71
     */
72
    public function getNewInsertedIdDirectories()
73
    {
74
        $newInsertedId = $GLOBALS['xoopsDB']->getInsertId();
75
        return $newInsertedId;
76
    }
77
78
    /**
79
     * @public function getForm
80
     * @param bool $action
81
     * @param int  $start
82
     * @param int  $limit
83
     * @return \XoopsThemeForm
84
     */
85
    public function getFormDirectories($action = false, $start = 0, $limit = 0)
86
    {
87
        $helper = \XoopsModules\Wggithub\Helper::getInstance();
88
        if (!$action) {
89
            $action = $_SERVER['REQUEST_URI'];
90
        }
91
        $isAdmin = $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid());
92
93
        // Title
94
        $title = $this->isNew() ? \sprintf(\_AM_WGGITHUB_DIRECTORY_ADD) : \sprintf(\_AM_WGGITHUB_DIRECTORY_EDIT);
95
        // Get Theme Form
96
        \xoops_load('XoopsFormLoader');
0 ignored issues
show
Bug introduced by
The function xoops_load was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

96
        /** @scrutinizer ignore-call */ 
97
        \xoops_load('XoopsFormLoader');
Loading history...
97
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm 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...
98
        $form->setExtra('enctype="multipart/form-data"');
99
        // Form Text dirName
100
        $form->addElement(new \XoopsFormText(\_AM_WGGITHUB_DIRECTORY_NAME, 'dir_name', 50, 255, $this->getVar('dir_name')), true);
0 ignored issues
show
Bug introduced by
The type XoopsFormText 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...
101
        // Form Editor DhtmlTextArea dirDescr
102
        $editorConfigs = [];
103
        if ($isAdmin) {
104
            $editor = $helper->getConfig('editor_admin');
105
        } else {
106
            $editor = $helper->getConfig('editor_user');
107
        }
108
        $editorConfigs['name'] = 'dir_descr';
109
        $editorConfigs['value'] = $this->getVar('dir_descr', 'e');
110
        $editorConfigs['rows'] = 5;
111
        $editorConfigs['cols'] = 40;
112
        $editorConfigs['width'] = '100%';
113
        $editorConfigs['height'] = '400px';
114
        $editorConfigs['editor'] = $editor;
115
        $form->addElement(new \XoopsFormEditor(_AM_WGGITHUB_DIRECTORY_DESCR, 'dir_descr', $editorConfigs));
0 ignored issues
show
Bug introduced by
The type XoopsFormEditor 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...
116
        // Form Select dirType
117
        $dirTypeSelect = new \XoopsFormSelect(\_AM_WGGITHUB_DIRECTORY_TYPE, 'dir_type', $this->getVar('dir_type'), 5);
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect 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...
118
        $dirTypeSelect->addOption(Constants::DIRECTORY_TYPE_USER, \_AM_WGGITHUB_DIRECTORY_TYPE_USER);
119
        $dirTypeSelect->addOption(Constants::DIRECTORY_TYPE_ORG, \_AM_WGGITHUB_DIRECTORY_TYPE_ORG);
120
        $form->addElement($dirTypeSelect, true);
121
        // Form Select dirContent
122
        $dirContentSelect = new \XoopsFormSelect(\_AM_WGGITHUB_DIRECTORY_CONTENT, 'dir_content', $this->getVar('dir_content'), 3);
123
        $dirContentSelect->addOption(Constants::DIRECTORY_CONTENT_ALL, \_AM_WGGITHUB_DIRECTORY_CONTENT_ALL);
124
        $dirContentSelect->addOption(Constants::DIRECTORY_CONTENT_OWN, \_AM_WGGITHUB_DIRECTORY_CONTENT_OWN);
125
        $form->addElement($dirContentSelect, true);
126
        // Form Radio Yes/No dirAutoupdate
127
        $dirAutoupdate = $this->isNew() ?: $this->getVar('dir_autoupdate');
128
        $form->addElement(new \XoopsFormRadioYN(_AM_WGGITHUB_DIRECTORY_AUTOUPDATE, 'dir_autoupdate', $dirAutoupdate));
0 ignored issues
show
Bug introduced by
The type XoopsFormRadioYN 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...
129
        // Form Radio Yes/No dirOnline
130
        $dirOnline = $this->isNew() ?: $this->getVar('dir_online');
131
        $form->addElement(new \XoopsFormRadioYN(_AM_WGGITHUB_DIRECTORY_ONLINE, 'dir_online', $dirOnline));
132
        // Form Radio Yes/No dirFilterrelease
133
        $dirFilterrelease = $this->isNew() ?: $this->getVar('dir_filterrelease');
134
        $form->addElement(new \XoopsFormRadioYN(_AM_WGGITHUB_DIRECTORY_FILTERRELEASE, 'dir_filterrelease', $dirFilterrelease));
135
        // Form Text Date Select dirDatecreated
136
        $dirDatecreated = $this->isNew() ?: $this->getVar('dir_datecreated');
137
        $form->addElement(new \XoopsFormTextDateSelect(\_AM_WGGITHUB_DIRECTORY_DATECREATED, 'dir_datecreated', '', $dirDatecreated));
0 ignored issues
show
Bug introduced by
The type XoopsFormTextDateSelect 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...
138
        // Form Select User dirSubmitter
139
        $form->addElement(new \XoopsFormSelectUser(\_AM_WGGITHUB_DIRECTORY_SUBMITTER, 'dir_submitter', false, $this->getVar('dir_submitter')));
0 ignored issues
show
Bug introduced by
The type XoopsFormSelectUser 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...
140
        // To Save
141
        $form->addElement(new \XoopsFormHidden('op', 'save'));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden 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...
142
        $form->addElement(new \XoopsFormHidden('start', $start));
143
        $form->addElement(new \XoopsFormHidden('limit', $limit));
144
        $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Wggithub\_SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The type XoopsFormButtonTray 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...
145
        return $form;
146
    }
147
148
    /**
149
     * Get Values
150
     * @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...
151
     * @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...
152
     * @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...
153
     * @return array
154
     */
155
    public function getValuesDirectories($keys = null, $format = null, $maxDepth = null)
156
    {
157
        $ret = $this->getValues($keys, $format, $maxDepth);
158
        $ret['id']          = $this->getVar('dir_id');
159
        $ret['name']        = $this->getVar('dir_name');
160
        $ret['descr']        = $this->getVar('dir_descr');
161
        $ret['type']        = $this->getVar('dir_type');
162
        $ret['type_text']   = Constants::DIRECTORY_TYPE_USER == $this->getVar('dir_type') ? \_AM_WGGITHUB_DIRECTORY_TYPE_USER : \_AM_WGGITHUB_DIRECTORY_TYPE_ORG;
163
        $content            = $this->getVar('dir_content');
164
        $ret['content']      = $content;
165
        switch ($content) {
166
            case Constants::DIRECTORY_CONTENT_ALL:
167
            default:
168
                $content_text = \_AM_WGGITHUB_DIRECTORY_CONTENT_ALL;
169
                break;
170
            case Constants::DIRECTORY_CONTENT_OWN:
171
                $content_text = \_AM_WGGITHUB_DIRECTORY_CONTENT_OWN;
172
                break;
173
        }
174
        $ret['content_shorttext'] = Utility::truncateHtml($content_text);
175
        $ret['autoupdate']  = (int)$this->getVar('dir_autoupdate') > 0 ? _YES : _NO;
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Wggithub\_YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant XoopsModules\Wggithub\_NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
176
        $ret['online']      = (int)$this->getVar('dir_online') > 0 ? _YES : _NO;
177
        $ret['filterrelease'] = (int)$this->getVar('dir_filterrelease') > 0 ? _YES : _NO;
178
        $ret['datecreated'] = \formatTimestamp($this->getVar('dir_datecreated'), 's');
0 ignored issues
show
Bug introduced by
The function formatTimestamp was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

178
        $ret['datecreated'] = /** @scrutinizer ignore-call */ \formatTimestamp($this->getVar('dir_datecreated'), 's');
Loading history...
179
        $ret['submitter']   = \XoopsUser::getUnameFromId($this->getVar('dir_submitter'));
0 ignored issues
show
Bug introduced by
The type XoopsUser 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...
180
        return $ret;
181
    }
182
183
    /**
184
     * Returns an array representation of the object
185
     *
186
     * @return array
187
     */
188
    public function toArrayDirectories()
189
    {
190
        $ret = [];
191
        $vars = $this->getVars();
192
        foreach (\array_keys($vars) as $var) {
193
            $ret[$var] = $this->getVar('"{$var}"');
194
        }
195
        return $ret;
196
    }
197
}
198