Completed
Pull Request — master (#27)
by Michael
01:42
created

Template   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getForm() 0 49 4
1
<?php
2
3
namespace XoopsModules\Xnewsletter;
4
5
/**
6
 * ****************************************************************************
7
 *  - A Project by Developers TEAM For Xoops - ( https://xoops.org )
8
 * ****************************************************************************
9
 *  XNEWSLETTER - MODULE FOR XOOPS
10
 *  Copyright (c) 2007 - 2012
11
 *  Goffy ( wedega.com )
12
 *
13
 *  You may not change or alter any portion of this comment or credits
14
 *  of supporting developers from this source code or any supporting
15
 *  source code which is considered copyrighted (c) material of the
16
 *  original comment or credit authors.
17
 *
18
 *  This program is distributed in the hope that it will be useful,
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 *  GNU General Public License for more details.
22
 *  ---------------------------------------------------------------------------
23
 * @copyright  Goffy ( wedega.com )
24
 * @license    GNU General Public License 2.0
25
 * @package    xnewsletter
26
 * @author     Goffy ( [email protected] )
27
 *
28
 * ****************************************************************************
29
 */
30
31
//use XoopsModules\Xnewsletter;
32
33
require_once dirname(__DIR__) . '/include/common.php';
34
35
/**
36
 * Class Template
37
 */
38
class Template extends \XoopsObject
39
{
40
    public $helper = null;
41
42
    //Constructor
43
44
    public function __construct()
45
    {
46
        $this->helper = Helper::getInstance();
47
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
48
        $this->initVar('template_id', XOBJ_DTYPE_INT, null, false);
49
        $this->initVar('template_title', XOBJ_DTYPE_TXTBOX, '', true, 100);
50
        $this->initVar('template_description', XOBJ_DTYPE_TXTAREA, '', false);
51
        $this->initVar('template_content', XOBJ_DTYPE_TXTAREA, '', true);
52
        $this->initVar('template_submitter', XOBJ_DTYPE_INT, null, false);
53
        $this->initVar('template_created', XOBJ_DTYPE_INT, time(), false);
54
    }
55
56
    /**
57
     * @param bool $action
58
     *
59
     * @return \XoopsThemeForm
60
     */
61
    public function getForm($action = false)
62
    {
63
        global $xoopsDB;
64
65
        if (false === $action) {
66
            $action = $_SERVER['REQUEST_URI'];
67
        }
68
69
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
70
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_TEMPLATE_ADD) : sprintf(_AM_XNEWSLETTER_TEMPLATE_EDIT);
71
        $form  = new \XoopsThemeForm($title, 'form', $action, 'post', true);
72
        $form->setExtra('enctype="multipart/form-data"');
73
74
        // template_title
75
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_TEMPLATE_TITLE, 'template_title', 50, 255, $this->getVar('template_title', 'e')), true);
76
77
        // template_description
78
        $template_description_textarea = new \XoopsFormTextArea(_AM_XNEWSLETTER_TEMPLATE_DESCRIPTION, 'template_description', $this->getVar('template_description', 'e'), 5, 50);
79
        $template_description_textarea->setDescription(_AM_XNEWSLETTER_TEMPLATE_DESCRIPTION_DESC);
80
        $form->addElement($template_description_textarea, false);
81
82
        // template_content
83
        $editor_configs           = [];
84
        $editor_configs['name']   = 'template_content';
85
        $editor_configs['value']  = $this->getVar('template_content', 'e');
86
        $editor_configs['rows']   = 40;
87
        $editor_configs['cols']   = 80;
88
        $editor_configs['width']  = '100%';
89
        $editor_configs['height'] = '800px';
90
        $editor_configs['editor'] = $this->helper->getConfig('template_editor');
91
        $template_content_editor  = new \XoopsFormEditor(_AM_XNEWSLETTER_TEMPLATE_CONTENT, 'template_content', $editor_configs);
92
        $template_content_editor->setDescription(_AM_XNEWSLETTER_TEMPLATE_CONTENT_DESC);
93
        $form->addElement($template_content_editor, true);
94
95
        $time = $this->isNew() ? time() : $this->getVar('template_created');
96
        $form->addElement(new \XoopsFormHidden('template_submitter', $GLOBALS['xoopsUser']->uid()));
97
        $form->addElement(new \XoopsFormHidden('template_created', $time));
98
99
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_TEMPLATE_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
100
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_TEMPLATE_CREATED, formatTimestamp($time, 's')));
101
102
        //$form->addElement(new \XoopsFormSelectUser(_AM_XNEWSLETTER_TEMPLATE_SUBMITTER, "template_submitter", false, $this->getVar("template_submitter"), 1, false), true);
103
        //$form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_TEMPLATE_CREATED, "template_created", "", $this->getVar("template_created")));
104
105
        $form->addElement(new \XoopsFormHidden('op', 'save_template'));
106
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
107
108
        return $form;
109
    }
110
}
111