Passed
Push — master ( 81a23f...5fbe19 )
by Goffy
03:28
created

XoopsConfirm::getFormXoopsConfirm()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 23
nc 32
nop 0
dl 0
loc 36
rs 8.9297
c 1
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Modulebuilder\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
 * My Module module for xoops
17
 *
18
 * @copyright     2020 XOOPS Project (https://xooops.org)
19
 * @license        GPL 2.0 or later
20
 * @package        Modulebuilder
21
 * @since          1.0
22
 * @min_xoops      2.5.9
23
 * @author         Goffy - Email:<[email protected]> - Website:<http://xoops.org>
24
 */
25
26
use XoopsModules\Modulebuilder;
27
28
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
29
30
/**
31
 * Class Object XoopsConfirm
32
 */
33
class XoopsConfirm
34
{
35
    private $hiddens = [];
36
    private $action  = '';
37
    private $title   = '';
38
    private $label   = '';
39
    private $object  = '';
40
41
    /**
42
     * @public function constructor class
43
     * @param        $hiddens
44
     * @param        $action
45
     * @param        $object
46
     * @param string $title
47
     * @param string $label
48
     */
49
    public function __construct($hiddens, $action, $object, $title = '', $label = '')
50
    {
51
        $this->hiddens = $hiddens;
52
        $this->action  = $action;
53
        $this->object  = $object;
54
        $this->title   = $title;
55
        $this->label   = $label;
56
    }
57
58
    /**
59
     * @public function getXoopsConfirm
60
     * @return \XoopsThemeForm
61
     */
62
    public function getFormXoopsConfirm()
63
    {
64
        //in order to be accessable from user and admin area this should be place in language common.php
65
        if (!defined('CO_WGTRANSIFEX_DELETE_CONFIRM')) {
66
            \define('CO_WGTRANSIFEX_DELETE_CONFIRM', 'Confirm delete');
67
            \define('CO_WGTRANSIFEX_DELETE_LABEL', 'Do you really want to delete:');
68
        }
69
70
        // Get Theme Form
71
        if ('' === $this->action) {
72
            $this->action = \Xmf\Request::getString('REQUEST_URI', '', 'SERVER');
73
        }
74
        if ('' === $this->title) {
75
            $this->title = CO_MODULEBUILDER_DELETE_CONFIRM;
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Modulebuild...EBUILDER_DELETE_CONFIRM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
76
        }
77
        if ('' === $this->label) {
78
79
            $this->label = CO_MODULEBUILDER_DELETE_LABEL;
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Modulebuild...ULEBUILDER_DELETE_LABEL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
80
        }
81
82
        \xoops_load('XoopsFormLoader');
83
        $form = new \XoopsThemeForm($this->title, 'formXoopsConfirm', $this->action, 'post', true);
84
        $form->setExtra('enctype="multipart/form-data"');
85
        $form->addElement(new \XoopsFormLabel($this->label, $this->object));
86
        //hiddens
87
        foreach ($this->hiddens as $key => $value) {
88
            $form->addElement(new \XoopsFormHidden($key, $value));
89
        }
90
        $form->addElement(new \XoopsFormHidden('ok', 1));
91
        $buttonTray = new \XoopsFormElementTray('');
92
        $buttonTray->addElement(new \XoopsFormButton('', 'confirm_submit', _YES, 'submit'));
93
        $buttonBack = new \XoopsFormButton('', 'confirm_back', _NO, 'button');
94
        $buttonBack->setExtra('onclick="history.go(-1);return true;"');
95
        $buttonTray->addElement($buttonBack);
96
        $form->addElement($buttonTray);
97
        return $form;
98
    }
99
}