Completed
Push — master ( 692213...d4ec0d )
by Goffy
03:18 queued 01:37
created

class/catsubscr.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ****************************************************************************
4
 *  - A Project by Developers TEAM For Xoops - ( http://www.xoops.org )
5
 * ****************************************************************************
6
 *  XNEWSLETTER - MODULE FOR XOOPS
7
 *  Copyright (c) 2007 - 2012
8
 *  Goffy ( wedega.com )
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
12
 *  source code which is considered copyrighted (c) material of the
13
 *  original comment or credit authors.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *  ---------------------------------------------------------------------------
20
 *
21
 * @copyright  Goffy ( wedega.com )
22
 * @license    GPL 2.0
23
 * @package    xnewsletter
24
 * @author     Goffy ( [email protected] )
25
 *
26
 *  Version : $Id $
27
 * ****************************************************************************
28
 */
29
30
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined");
31
include_once dirname(__DIR__) . '/include/common.php';
32
33
/**
34
 * Class XnewsletterCatsubscr
35
 */
36
class XnewsletterCatsubscr extends XoopsObject
37
{
38
    public $xnewsletter = null;
39
40
    //Constructor
41
    /**
42
     *
43
     */
44 View Code Duplication
    public function __construct()
0 ignored issues
show
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...
45
    {
46
        $this->xnewsletter = xnewsletterxnewsletter::getInstance();
47
        $this->db          = XoopsDatabaseFactory::getDatabaseConnection();
48
        $this->initVar("catsubscr_id", XOBJ_DTYPE_INT, null, false, 8);
49
        $this->initVar("catsubscr_catid", XOBJ_DTYPE_INT, null, false, 8);
50
        $this->initVar("catsubscr_subscrid", XOBJ_DTYPE_INT, null, false, 8);
51
        $this->initVar("catsubscr_quited", XOBJ_DTYPE_INT, null, false, 10);
52
        $this->initVar("catsubscr_submitter", XOBJ_DTYPE_INT, null, false, 10);
53
        $this->initVar("catsubscr_created", XOBJ_DTYPE_INT, null, false, 10);
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 ($action === false) {
66
            $action = $_SERVER["REQUEST_URI"];
67
        }
68
69
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_CATSUBSCR_ADD) : sprintf(_AM_XNEWSLETTER_CATSUBSCR_EDIT);
70
71
        include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
72
        $form = new XoopsThemeForm($title, "form", $action, "post", true);
73
        $form->setExtra('enctype="multipart/form-data"');
74
75
        $criteria = new CriteriaCompo();
76
        $criteria->setSort('cat_id ASC, cat_name');
77
        $criteria->setOrder('ASC');
78
        $cat_select = new XoopsFormSelect(_AM_XNEWSLETTER_CATSUBSCR_CATID, "catsubscr_catid", $this->getVar("catsubscr_catid"));
79
        $cat_select->addOptionArray($this->xnewsletter->getHandler('cat')->getList());
80
        $form->addElement($cat_select, true);
81
82
        $subscrCriteria = new CriteriaCompo();
83
        $subscrCriteria->setSort('subscr_email ');
84
        $subscrCriteria->setOrder('ASC');
85
        $subscr_select = new XoopsFormSelect(_AM_XNEWSLETTER_CATSUBSCR_SUBSCRID, "catsubscr_subscrid", $this->getVar("catsubscr_subscrid"));
86
        $subscr_select->addOptionArray($this->xnewsletter->getHandler('subscr')->getList($subscrCriteria));
87
        $form->addElement($subscr_select, true);
88
89
        $quited_tray = new XoopsFormElementTray(_AM_XNEWSLETTER_CATSUBSCR_QUITED, "&nbsp;");
90
91
        $quit_now = new XoopsFormRadio("", "catsubscr_quit_now", 0);
92
        $quit_now->addOption(0, _AM_XNEWSLETTER_CATSUBSCR_QUIT_NONE);
93
        $quit_now->addOption(1, _AM_XNEWSLETTER_CATSUBSCR_QUIT_NOW);
94
        $quit_now->addOption(2, _AM_XNEWSLETTER_CATSUBSCR_QUIT_REMOVE);
95
        $quited_tray->addElement($quit_now, false);
96
        $quited_tray->addElement(new XoopsFormLabel("", $this->getVar("catsubscr_quited")));
97
        $form->addElement($quited_tray, false);
98
99
        $time = ($this->isNew()) ? time() : $this->getVar("catsubscr_created");
100
        $form->addElement(new XoopsFormHidden("catsubscr_submitter", $GLOBALS['xoopsUser']->uid()));
101
        $form->addElement(new XoopsFormHidden("catsubscr_created", $time));
102
103
        $form->addElement(new XoopsFormLabel(_AM_XNEWSLETTER_CATSUBSCR_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
104
        $form->addElement(new XoopsFormLabel(_AM_XNEWSLETTER_CATSUBSCR_CREATED, formatTimestamp($time, 's')));
105
106
        //$form->addElement(new XoopsFormSelectUser(_AM_XNEWSLETTER_CATSUBSCR_SUBMITTER, "catsubscr_submitter", false, $this->getVar("catsubscr_submitter"), 1, false), true);
107
        //$form->addElement(new XoopsFormTextDateSelect(_AM_XNEWSLETTER_CATSUBSCR_CREATED, "catsubscr_created", "", $this->getVar("catsubscr_created")));
108
109
        $form->addElement(new XoopsFormHidden("op", "save_catsubscr"));
110
        $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
111
112
        return $form;
113
    }
114
}
115
116
/**
117
 * Class XnewsletterCatsubscrHandler
118
 */
119 View Code Duplication
class XnewsletterCatsubscrHandler extends XoopsPersistableObjectHandler
120
{
121
    /**
122
     * @var xnewsletterxnewsletter
123
     * @access public
124
     */
125
    public $xnewsletter = null;
126
127
    /**
128
     * @param null|object $db
129
     */
130
    public function __construct(&$db)
131
    {
132
        parent::__construct($db, "xnewsletter_catsubscr", "XnewsletterCatsubscr", "catsubscr_id", "catsubscr_catid");
133
        $this->xnewsletter = xnewsletterxnewsletter::getInstance();
134
    }
135
}
136