Passed
Push — master ( 0648fb...5a286b )
by Goffy
03:25
created

Confirm::getFormConfirm()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 38
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 25
c 1
b 0
f 0
nc 32
nop 0
dl 0
loc 38
rs 8.8977
1
<?php
2
3
namespace XoopsModules\Wggithub\Common;
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
 * Custom form confirm for XOOPS modules
17
 *
18
 * @copyright     2020 XOOPS Project (https://xoops.org)
19
 * @license        GPL 2.0 or later
20
 * @package        general
21
 * @since          1.0
22
 * @min_xoops      2.5.9
23
 * @author         Goffy - Email:<[email protected]> - Website:<https://xoops.org>
24
 *
25
 *
26
 * Example:
27
    $customConfirm = new Common\Confirm(
28
        ['ok' => 1, 'item_id' => $itemId, 'op' => 'delete'],
29
        $_SERVER['REQUEST_URI'],
30
        \sprintf(\_MA_MYMODULE_FORM_SURE_DELETE,
31
        $itemsObj->getCaption()));
32
    $form = $customConfirm->getFormConfirm();
33
    $GLOBALS['xoopsTpl']->assign('form', $form->render());
34
 */
35
36
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
37
38
/**
39
 * Class Object Confirm
40
 */
41
class Confirm
42
{
43
    private $hiddens = [];
44
    private $action  = '';
45
    private $title   = '';
46
    private $label   = '';
47
    private $object  = '';
48
49
    /**
50
     * @public function constructor class
51
     * @param        $hiddens
52
     * @param        $action
53
     * @param        $object
54
     * @param string $title
55
     * @param string $label
56
     */
57
    public function __construct($hiddens, $action, $object, $title = '', $label = '')
58
    {
59
        $this->hiddens = $hiddens;
60
        $this->action  = $action;
61
        $this->object  = $object;
62
        $this->title   = $title;
63
        $this->label   = $label;
64
    }
65
66
    /**
67
     * @public function getFormConfirm
68
     * @return \XoopsThemeForm
69
     */
70
    public function getFormConfirm()
71
    {
72
        $moduleDirName      = \basename(__DIR__);
73
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
74
        //in order to be accessable from user and admin area this should be place in language common.php
75
        if (!\defined('CO_' . $moduleDirNameUpper . '_DELETE_CONFIRM')) {
76
            \define('CO_' . $moduleDirNameUpper . '_DELETE_CONFIRM', 'Confirm delete');
77
            \define('CO_' . $moduleDirNameUpper . '_DELETE_LABEL', 'Do you really want to delete:');
78
        }
79
80
        // Get Theme Form
81
        if ('' === $this->action) {
82
            $this->action = \Xmf\Request::getString('REQUEST_URI', '', 'SERVER');
0 ignored issues
show
Bug introduced by
The type Xmf\Request 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...
83
        }
84
        if ('' === $this->title) {
85
            $this->title = \constant('CO_' . $moduleDirNameUpper . '_DELETE_CONFIRM');
86
        }
87
        if ('' === $this->label) {
88
89
            $this->label = \constant('CO_' . $moduleDirNameUpper . '_DELETE_LABEL');
90
        }
91
92
        \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

92
        /** @scrutinizer ignore-call */ 
93
        \xoops_load('XoopsFormLoader');
Loading history...
93
        $form = new \XoopsThemeForm($this->title, 'formConfirm', $this->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...
94
        $form->setExtra('enctype="multipart/form-data"');
95
        $form->addElement(new \XoopsFormLabel($this->label, $this->object));
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel 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...
96
        //hiddens
97
        foreach ($this->hiddens as $key => $value) {
98
            $form->addElement(new \XoopsFormHidden($key, $value));
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...
99
        }
100
        $form->addElement(new \XoopsFormHidden('ok', 1));
101
        $buttonTray = new \XoopsFormElementTray('');
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray 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...
102
        $buttonTray->addElement(new \XoopsFormButton('', 'confirm_submit', \_YES, 'submit'));
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The type XoopsFormButton 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...
103
        $buttonBack = new \XoopsFormButton('', 'confirm_back', \_NO, 'button');
0 ignored issues
show
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
104
        $buttonBack->setExtra('onclick="history.go(-1);return true;"');
105
        $buttonTray->addElement($buttonBack);
106
        $form->addElement($buttonTray);
107
        return $form;
108
    }
109
}
110