Entries::getForm()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 25
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 38
rs 9.52
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Gbook;
6
7
/**
8
 * ****************************************************************************
9
 *  GBOOK - MODULE FOR XOOPS
10
 *  Copyright (c) 2007 - 2012
11
 *  Ingo H. de Boer (http://www.winshell.org)
12
 *
13
 *  This program is free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 2 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  You may not change or alter any portion of this comment or credits
19
 *  of supporting developers from this source code or any supporting
20
 *  source code which is considered copyrighted (c) material of the
21
 *  original comment or credit authors.
22
 *
23
 *  This program is distributed in the hope that it will be useful,
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 *  GNU General Public License for more details.
27
 *  ---------------------------------------------------------------------------
28
 *
29
 * @copyright       Ingo H. de Boer (http://www.winshell.org)
30
 * @license         GNU General Public License (GPL)
31
 * @package         GBook
32
 * @author          Ingo H. de Boer ([email protected])
33
 *
34
 * ****************************************************************************
35
 */
36
37
use Xmf\Request;
38
use XoopsFormButton;
39
use XoopsFormHidden;
40
use XoopsFormText;
41
use XoopsModules\Gbook;
42
use XoopsObject;
43
use XoopsThemeForm;
44
45
46
47
48
49
/**
50
 * @package   kernel
51
 * @copyright copyright &copy; 2000 XOOPS.org
52
 */
53
class Entries extends XoopsObject
54
{
55
    /**
56
     * Constructor
57
     */
58
    public function __construct()
59
    {
60
        $this->initVar('id', \XOBJ_DTYPE_INT, null, true);
61
        $this->initVar('name', \XOBJ_DTYPE_TXTBOX);
62
        $this->initVar('email', \XOBJ_DTYPE_TXTBOX);
63
        $this->initVar('url', \XOBJ_DTYPE_TXTBOX);
64
        $this->initVar('message', \XOBJ_DTYPE_TXTAREA);
65
        $this->initVar('note', \XOBJ_DTYPE_TXTAREA);
66
        $this->initVar('time', \XOBJ_DTYPE_INT);
67
        $this->initVar('date', \XOBJ_DTYPE_TXTBOX);
68
        $this->initVar('ip', \XOBJ_DTYPE_TXTBOX);
69
        $this->initVar('admin', \XOBJ_DTYPE_TXTBOX);
70
71
        $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false);
72
        $this->initVar('dosmiley', \XOBJ_DTYPE_INT, 1, false);
73
        $this->initVar('doxcode', \XOBJ_DTYPE_INT, 1, false);
74
        $this->initVar('doimage', \XOBJ_DTYPE_INT, 1, false);
75
        $this->initVar('dobr', \XOBJ_DTYPE_INT, 1, false);
76
    }
77
78
    /**
79
     * Get {@link XoopsThemeForm} for adding/editing categories
80
     *
81
     * @param mixed $action URL to submit to or false for $_SERVER['REQUEST_URI']
82
     *
83
     * @return \XoopsThemeForm
84
     */
85
    public function getForm($action = false): XoopsThemeForm
86
    {
87
        if (false === $action) {
88
            $action = Request::getString('REQUEST_URI', '', 'SERVER');
89
        }
90
        $title = _AM_GBOOK_ENTRY_EDIT;
91
        $helper  = Gbook\Helper::getInstance();
92
        $utility = new Gbook\Utility();
93
94
        require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
95
96
        $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
97
98
        $form->addElement(new XoopsFormText(_AM_GBOOK_NAME, 'name', 35, 255, $this->getVar('name')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('name') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

98
        $form->addElement(new XoopsFormText(_AM_GBOOK_NAME, 'name', 35, 255, /** @scrutinizer ignore-type */ $this->getVar('name')));
Loading history...
99
        $form->addElement(new XoopsFormText(_AM_GBOOK_EMAIL, 'email', 35, 255, $this->getVar('email')));
100
        $form->addElement(new XoopsFormText(_AM_GBOOK_URL, 'url', 35, 255, $this->getVar('url')));
101
102
        //set Editor options
103
        $options['name']   = 'message';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.
Loading history...
104
        $options['value']  = $this->getVar('message', 'e');
105
        $options['rows']   = 25;
106
        $options['cols']   = '100%';
107
        $options['width']  = '100%';
108
        $options['height'] = '400px';
109
110
        $messageEditor = $utility::getEditor($helper, $options);
111
        $form->addElement($messageEditor);
112
113
        $options['name']  = 'note';
114
        $options['value'] = $this->getVar('note', 'e');
115
116
        $noteEditor = $utility::getEditor($helper, $options);
117
        $form->addElement($noteEditor);
118
119
        $form->addElement(new XoopsFormHidden('op', 'save'));
120
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
121
122
        return $form;
123
    }
124
}
125