Passed
Pull Request — master (#81)
by Michael
02:53
created

VisitorsForm   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 37
c 1
b 0
f 0
dl 0
loc 70
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 59 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Yogurt\Form;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 * Module: Yogurt
19
 *
20
 * @category        Module
21
 * @package         yogurt
22
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
23
 * @copyright       {@link https://xoops.org/ XOOPS Project}
24
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
25
 */
26
27
use Xmf\Module\Helper\Permission;
28
use XoopsFormButton;
29
use XoopsFormHidden;
30
use XoopsFormLabel;
31
use XoopsFormSelectUser;
32
use XoopsFormText;
33
use XoopsFormTextDateSelect;
34
use XoopsModules\Yogurt;
35
use XoopsThemeForm;
36
37
require_once \dirname(__DIR__, 2) . '/include/common.php';
38
39
$moduleDirName = \basename(\dirname(__DIR__, 2));
40
//$helper = Yogurt\Helper::getInstance();
41
$permHelper = new Permission();
42
43
\xoops_load('XoopsFormLoader');
44
45
/**
46
 * Class VisitorsForm
47
 */
48
class VisitorsForm extends XoopsThemeForm
49
{
50
    public $targetObject;
51
52
    public $helper;
53
54
    /**
55
     * Constructor
56
     *
57
     * @param $target
58
     */
59
    public function __construct($target)
60
    {
61
        $this->helper       = $target->helper;
62
        $this->targetObject = $target;
63
64
        $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_VISITORS_ADD) : \sprintf(\AM_YOGURT_VISITORS_EDIT);
65
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
66
        $this->setExtra('enctype="multipart/form-data"');
67
68
        //include ID field, it's needed so the module knows if it is a new form or an edited form
69
70
        $hidden = new XoopsFormHidden(
71
            'cod_visit', $this->targetObject->getVar(
72
            'cod_visit'
73
        )
74
        );
75
        $this->addElement($hidden);
76
        unset($hidden);
77
78
        // Cod_visit
79
        $this->addElement(
80
            new XoopsFormLabel(\AM_YOGURT_VISITORS_COD_VISIT, $this->targetObject->getVar('cod_visit'), 'cod_visit')
81
        );
82
        // Uid_owner
83
        $this->addElement(
84
            new XoopsFormSelectUser(
85
                \AM_YOGURT_VISITORS_UID_OWNER, 'uid_owner', false, $this->targetObject->getVar(
86
                'uid_owner'
87
            ), 1, false
88
            ),
89
            false
90
        );
91
        // Uid_visitor
92
        $this->addElement(
93
            new XoopsFormSelectUser(
94
                \AM_YOGURT_VISITORS_UID_VISITOR, 'uid_visitor', false, $this->targetObject->getVar(
95
                'uid_visitor'
96
            ), 1, false
97
            ),
98
            false
99
        );
100
        // Uname_visitor
101
        $this->addElement(
102
            new XoopsFormText(
103
                \AM_YOGURT_VISITORS_UNAME_VISITOR, 'uname_visitor', 50, 255, $this->targetObject->getVar(
104
                'uname_visitor'
105
            )
106
            ),
107
            false
108
        );
109
        // Datetime
110
        $this->addElement(
111
            new XoopsFormTextDateSelect(
112
                \AM_YOGURT_VISITORS_DATETIME, 'date_visited', 0, formatTimestamp($this->targetObject->getVar('date_visited'), 's')
0 ignored issues
show
Bug introduced by
formatTimestamp($this->t...r('date_visited'), 's') of type string is incompatible with the type integer expected by parameter $value 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

112
                \AM_YOGURT_VISITORS_DATETIME, 'date_visited', 0, /** @scrutinizer ignore-type */ formatTimestamp($this->targetObject->getVar('date_visited'), 's')
Loading history...
113
            )
114
        );
115
116
        $this->addElement(new XoopsFormHidden('op', 'save'));
117
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
118
    }
119
}
120