Rating::getForm()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 38
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 31
nc 4
nop 2
dl 0
loc 38
rs 9.424
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Tdmdownloads;
6
7
/**
8
 * TDMDownload
9
 *
10
 * You may not change or alter any portion of this comment or credits
11
 * of supporting developers from this source code or any supporting source code
12
 * which is considered copyrighted (c) material of the original comment or credit authors.
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 *
17
 * @copyright   Gregory Mage (Aka Mage)
18
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
19
 * @author      Gregory Mage (Aka Mage)
20
 */
21
22
/**
23
 * Class Rating
24
 * @package XoopsModules\Tdmdownloads
25
 */
26
class Rating extends \XoopsObject
27
{
28
    // constructor
29
    public function __construct()
30
    {
31
        $this->initVar('ratingid', \XOBJ_DTYPE_INT, null, false, 11);
32
        $this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 11);
33
        $this->initVar('ratinguser', \XOBJ_DTYPE_INT, null, false, 11);
34
        $this->initVar('rating', \XOBJ_DTYPE_OTHER, null, false, 3);
35
        $this->initVar('ratinghostname', \XOBJ_DTYPE_TXTBOX, null, false);
36
        $this->initVar('ratingtimestamp', \XOBJ_DTYPE_INT, null, false, 10);
37
    }
38
39
    /**
40
     * @param      $lid
41
     * @param bool $action
42
     *
43
     * @return \XoopsThemeForm
44
     */
45
    public function getForm($lid, $action = false)
46
    {
47
        //        global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
48
        if (!$action) {
49
            $action = $_SERVER['REQUEST_URI'];
0 ignored issues
show
Unused Code introduced by
The assignment to $action is dead and can be removed.
Loading history...
50
        }
51
        if (!$this->isNew()) {
52
            $rating = 11;
53
        } else {
54
            $rating = $this->getVar('rating');
55
        }
56
        $form = new \XoopsThemeForm(_MD_TDMDOWNLOADS_SINGLEFILE_RATHFILE, 'rateform', 'ratefile.php', 'post');
57
        $form->setExtra('enctype="multipart/form-data"');
58
        $rating  = new \XoopsFormSelect(_MD_TDMDOWNLOADS_RATEFILE_VOTE, 'rating', $rating);
59
        $options = [
60
            '11' => '--',
61
            '10' => '10',
62
            '9'  => '9',
63
            '8'  => '8',
64
            '7'  => '7',
65
            '6'  => '6',
66
            '5'  => '5',
67
            '4'  => '4',
68
            '3'  => '3',
69
            '2'  => '2',
70
            '1'  => '1',
71
            '0'  => '0',
72
        ];
73
        $rating->addOptionArray($options);
74
        $form->addElement($rating, true);
75
        $form->addElement(new \XoopsFormCaptcha(), true);
76
        $form->addElement(new \XoopsFormHidden('op', 'save'));
77
        $form->addElement(new \XoopsFormHidden('lid', $lid));
78
        // Submit button
79
        $buttonTray = new \XoopsFormElementTray('', '');
80
        $buttonTray->addElement(new \XoopsFormButton('', 'post', _MD_TDMDOWNLOADS_RATEFILE_RATE, 'submit'));
81
        $form->addElement($buttonTray);
82
        return $form;
83
    }
84
}
85