Completed
Pull Request — master (#29)
by Goffy
01:40
created

Catsubscr::getValuesCatsubscr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
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    GPL 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 Catsubscr
37
 */
38
class Catsubscr extends \XoopsObject
39
{
40
    public $helper = null;
41
    public $db;
42
43
    //Constructor
44
45 View Code Duplication
    public function __construct()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $this->helper = Helper::getInstance();
48
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
49
        $this->initVar('catsubscr_id', XOBJ_DTYPE_INT, null, false);
50
        $this->initVar('catsubscr_catid', XOBJ_DTYPE_INT, null, false);
51
        $this->initVar('catsubscr_subscrid', XOBJ_DTYPE_INT, null, false);
52
        $this->initVar('catsubscr_quited', XOBJ_DTYPE_INT, 0, false);
53
        $this->initVar('catsubscr_submitter', XOBJ_DTYPE_INT, null, false);
54
        $this->initVar('catsubscr_created', XOBJ_DTYPE_INT, time(), false);
55
    }
56
57
    /**
58
     * @param bool $action
59
     *
60
     * @return \XoopsThemeForm
61
     */
62
    public function getForm($action = false)
63
    {
64
        global $xoopsDB;
65
66
        if (false === $action) {
67
            $action = $_SERVER['REQUEST_URI'];
68
        }
69
70
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_CATSUBSCR_ADD) : sprintf(_AM_XNEWSLETTER_CATSUBSCR_EDIT);
71
72
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
73
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
74
        $form->setExtra('enctype="multipart/form-data"');
75
76
        $criteria = new \CriteriaCompo();
77
        $criteria->setSort('cat_id ASC, cat_name');
78
        $criteria->setOrder('ASC');
79
        $cat_select = new \XoopsFormSelect(_AM_XNEWSLETTER_CATSUBSCR_CATID, 'catsubscr_catid', $this->getVar('catsubscr_catid'));
80
        $cat_select->addOptionArray($this->helper->getHandler('Cat')->getList());
81
        $form->addElement($cat_select, true);
82
83
        $subscrCriteria = new \CriteriaCompo();
84
        $subscrCriteria->setSort('subscr_email ');
85
        $subscrCriteria->setOrder('ASC');
86
        $subscr_select = new \XoopsFormSelect(_AM_XNEWSLETTER_CATSUBSCR_SUBSCRID, 'catsubscr_subscrid', $this->getVar('catsubscr_subscrid'));
87
        $subscr_select->addOptionArray($this->helper->getHandler('Subscr')->getList($subscrCriteria));
88
        $form->addElement($subscr_select, true);
89
90
        $quited_tray = new \XoopsFormElementTray(_AM_XNEWSLETTER_CATSUBSCR_QUITED, '&nbsp;');
91
92
        $quit_now = new \XoopsFormRadio('', 'catsubscr_quit_now', _XNEWSLETTER_CATSUBSCR_QUIT_NO_VAL_NONE);
93
        $quit_now->addOptionArray([
94
                                      _XNEWSLETTER_CATSUBSCR_QUIT_NO_VAL_NONE   => _AM_XNEWSLETTER_CATSUBSCR_QUIT_NONE,
95
                                      _XNEWSLETTER_CATSUBSCR_QUIT_NO_VAL_NOW    => _AM_XNEWSLETTER_CATSUBSCR_QUIT_NOW,
96
                                      _XNEWSLETTER_CATSUBSCR_QUIT_NO_VAL_REMOVE => _AM_XNEWSLETTER_CATSUBSCR_QUIT_REMOVE,
97
                                  ]);
98
        $quited_tray->addElement($quit_now, false);
99
        $quited_tray->addElement(new \XoopsFormLabel('', $this->getVar('catsubscr_quited')));
100
        $form->addElement($quited_tray, false);
101
102
        $time = $this->isNew() ? time() : $this->getVar('catsubscr_created');
103
        $form->addElement(new \XoopsFormHidden('catsubscr_submitter', $GLOBALS['xoopsUser']->uid()));
104
        $form->addElement(new \XoopsFormHidden('catsubscr_created', $time));
105
106
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
107
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_CREATED, formatTimestamp($time, 's')));
108
109
        //$form->addElement(new \XoopsFormSelectUser(_AM_XNEWSLETTER_SUBMITTER, 'catsubscr_submitter', false, $this->getVar('catsubscr_submitter'), 1, false), true);
110
        //$form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_CREATED, 'catsubscr_created', '', $this->getVar('catsubscr_created')));
111
112
        $form->addElement(new \XoopsFormHidden('op', 'save_catsubscr'));
113
        $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
114
115
        return $form;
116
    }
117
118
    /**
119
     * Get Values
120
     * @param null $keys
121
     * @param string|null $format
122
     * @param int|null $maxDepth
123
     * @return array
124
     */
125
    public function getValuesCatsubscr($keys = null, $format = null, $maxDepth = null)
126
    {
127
        $ret = $this->getValues($keys, $format, $maxDepth);
128
        $ret['id']        = $this->getVar('catsubscr_id');
129
        $ret['catid']     = $this->getVar('catsubscr_catid');
130
        $ret['subscrid']  = $this->getVar('catsubscr_subscrid');
131
        $ret['quited']    = $this->getVar('catsubscr_quited');
132
        $ret['created']   = formatTimestamp($this->getVar('catsubscr_created'), 's');
133
        $ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('catsubscr_submitter'));
134
        return $ret;
135
    }
136
}
137