CategoriesForm   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 59
c 1
b 0
f 0
dl 0
loc 101
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 91 7
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Adslight\Form;
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
 * Module: Adslight
17
 *
18
 * @category        Module
19
 * @author          XOOPS Development Team <https://xoops.org>
20
 * @copyright       {@link https://xoops.org/ XOOPS Project}
21
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
22
 */
23
24
use Xmf\Request;
25
use XoopsModules\Adslight;
26
27
require_once \dirname(__DIR__, 2) . '/include/common.php';
28
29
$moduleDirName = \basename(\dirname(__DIR__, 2));
30
//$helper = Adslight\Helper::getInstance();
31
$permHelper = new \Xmf\Module\Helper\Permission();
32
33
\xoops_load('XoopsFormLoader');
34
35
/**
36
 * Class CategoriesForm
37
 */
38
class CategoriesForm extends \XoopsThemeForm
39
{
40
    public $targetObject;
41
    public $helper;
42
43
    /**
44
     * Constructor
45
     *
46
     * @param $target
47
     */
48
    public function __construct($target)
49
    {
50
        $this->helper       = $target->helper;
51
        $this->targetObject = $target;
52
53
        $title = $this->targetObject->isNew() ? \AM_ADSLIGHT_CATEGORIES_ADD : \AM_ADSLIGHT_CATEGORIES_EDIT;
54
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
55
        $this->setExtra('enctype="multipart/form-data"');
56
57
        //include ID field, it's needed so the module knows if it is a new form or an edited form
58
59
        $hidden = new \XoopsFormHidden('cid', $this->targetObject->getVar('cid'));
60
        $this->addElement($hidden);
61
        unset($hidden);
62
63
        // Cid
64
        $this->addElement(new \XoopsFormLabel(\AM_ADSLIGHT_CATEGORIES_CID, $this->targetObject->getVar('cid'), 'cid'));
65
        // Pid
66
        require_once XOOPS_ROOT_PATH . '/class/tree.php';
67
        //$categoriesHandler = xoops_getModuleHandler('categories', 'adslight' );
68
        //$db     = \XoopsDatabaseFactory::getDatabaseConnection();
69
        /** @var \XoopsPersistableObjectHandler $categoriesHandler */
70
        $categoriesHandler = $this->helper->getHandler('Categories');
71
72
        $criteria      = new \CriteriaCompo();
73
        $categoryArray = $categoriesHandler->getObjects($criteria);
74
        if (!empty($categoryArray)) {
75
            $categoryTree = new \XoopsObjectTree($categoryArray, 'cid', 'pid');
76
77
            // if (Adslight\Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) {
78
            $categoriesPid = $categoryTree->makeSelectElement('pid', 'title', '--', $this->targetObject->getVar('pid'), true, 0, '', \AM_ADSLIGHT_CATEGORIES_PID);
79
            $this->addElement($categoriesPid);
80
            //  } else {
81
            //      $categoriesPid = $categoryTree->makeSelBox( 'pid', 'title','--', $this->targetObject->getVar('pid', 'e' ), true );
82
            //      $this->addElement( new \XoopsFormLabel ( AM_ADSLIGHT_CATEGORIES_PID, $categoriesPid ) );
83
            //  }
84
        }
85
        // Title
86
        $this->addElement(new \XoopsFormText(\AM_ADSLIGHT_CATEGORIES_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')), false);
87
        // Cat_desc
88
        if (\class_exists('XoopsFormEditor')) {
89
            $editorOptions           = [];
90
            $editorOptions['name']   = 'cat_desc';
91
            $editorOptions['value']  = $this->targetObject->getVar('cat_desc', 'e');
92
            $editorOptions['rows']   = 5;
93
            $editorOptions['cols']   = 40;
94
            $editorOptions['width']  = '100%';
95
            $editorOptions['height'] = '400px';
96
            //$editorOptions['editor'] = xoops_getModuleOption('adslight_editor', 'adslight');
97
            //$this->addElement( new \XoopsFormEditor(AM_ADSLIGHT_CATEGORIES_CAT_DESC, 'cat_desc', $editorOptions), false  );
98
            if ($this->helper->isUserAdmin()) {
99
                $descEditor = new \XoopsFormEditor(\AM_ADSLIGHT_CATEGORIES_CAT_DESC, $this->helper->getConfig('adslightEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea');
100
            } else {
101
                $descEditor = new \XoopsFormEditor(\AM_ADSLIGHT_CATEGORIES_CAT_DESC, $this->helper->getConfig('adslightEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea');
102
            }
103
        } else {
104
            $descEditor = new \XoopsFormDhtmlTextArea(\AM_ADSLIGHT_CATEGORIES_CAT_DESC, 'description', $this->targetObject->getVar('description', 'e'), 5, 50);
105
        }
106
        $this->addElement($descEditor);
107
        // Cat_keywords
108
        $this->addElement(new \XoopsFormText(\AM_ADSLIGHT_CATEGORIES_CAT_KEYWORDS, 'cat_keywords', 50, 255, $this->targetObject->getVar('cat_keywords')), false);
109
        // Img
110
        $img = $this->targetObject->getVar('img') ?: 'blank.png';
111
112
        $uploadDir   = '/uploads/adslight/categories/';
113
        $imgtray     = new \XoopsFormElementTray(\AM_ADSLIGHT_CATEGORIES_IMG, '<br>');
114
        $imgpath     = \sprintf(\AM_ADSLIGHT_FORMIMAGE_PATH, $uploadDir);
115
        $imageselect = new \XoopsFormSelect($imgpath, 'img', $img);
116
        $imageArray  = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDir);
117
        foreach ($imageArray as $image) {
118
            $imageselect->addOption($image, $image);
119
        }
120
        $imageselect->setExtra("onchange='showImgSelected(\"image_img\", \"img\", \"" . $uploadDir . '", "", "' . XOOPS_URL . "\")'");
121
        $imgtray->addElement($imageselect);
122
        $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadDir . '/' . $img . "' name='image_img' id='image_img' alt='' style='max-width:300px' >"));
123
        $fileseltray = new \XoopsFormElementTray('', '<br>');
124
        $fileseltray->addElement(new \XoopsFormFile(\AM_ADSLIGHT_FORMUPLOAD, 'img', $this->helper->getConfig('maxsize')));
125
        $fileseltray->addElement(new \XoopsFormLabel(''));
126
        $imgtray->addElement($fileseltray);
127
        $this->addElement($imgtray);
128
        // Cat_order
129
        $this->addElement(new \XoopsFormText(\AM_ADSLIGHT_CATEGORIES_CAT_ORDER, 'cat_order', 50, 255, $this->targetObject->getVar('cat_order')), false);
130
        // Affprice
131
        $this->addElement(new \XoopsFormText(\AM_ADSLIGHT_CATEGORIES_AFFPRICE, 'affprice', 50, 255, $this->targetObject->getVar('affprice')), false);
132
        // Cat_moderate
133
        $this->addElement(new \XoopsFormSelectUser(\AM_ADSLIGHT_CATEGORIES_CAT_MODERATE, 'cat_moderate', false, $this->targetObject->getVar('cat_moderate'), 1, false), false);
134
        // Moderate_subcat
135
        $this->addElement(new \XoopsFormSelectUser(\AM_ADSLIGHT_CATEGORIES_MODERATE_SUBCAT, 'moderate_subcat', false, $this->targetObject->getVar('moderate_subcat'), 1, false), false);
136
137
        $this->addElement(new \XoopsFormHidden('op', 'save'));
138
        $this->addElement(new \XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
139
    }
140
}
141