Completed
Push — master ( 819fc9...f42eea )
by Goffy
18s queued 11s
created

Bmh::getValuesBmh()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 22
rs 9.568
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    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
xoops_loadLanguage('admin', 'xnewsletter');
35
36
/**
37
 * Class Bmh
38
 */
39
class Bmh extends \XoopsObject
40
{
41
    public $helper = null;
42
    public $db;
43
44
    //Constructor
45
46
    public function __construct()
47
    {
48
        $this->helper = Helper::getInstance();
49
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
50
        $this->initVar('bmh_id', XOBJ_DTYPE_INT, null, false);
51
        $this->initVar('bmh_rule_no', XOBJ_DTYPE_TXTBOX, null, false, 10);
52
        $this->initVar('bmh_rule_cat', XOBJ_DTYPE_TXTBOX, null, false, 50);
53
        $this->initVar('bmh_bouncetype', XOBJ_DTYPE_TXTBOX, null, false, 50);
54
        $this->initVar('bmh_remove', XOBJ_DTYPE_TXTBOX, null, false, 50);
55
        $this->initVar('bmh_email', XOBJ_DTYPE_TXTBOX, null, false, 100);
56
        $this->initVar('bmh_subject', XOBJ_DTYPE_TXTBOX, null, false, 100);
57
        $this->initVar('bmh_measure', XOBJ_DTYPE_INT, null, false);
58
        $this->initVar('bmh_submitter', XOBJ_DTYPE_INT, null, false);
59
        $this->initVar('bmh_created', XOBJ_DTYPE_INT, time(), false);
60
    }
61
62
    /**
63
     * @param bool $action
64
     *
65
     * @return \XoopsThemeForm
66
     */
67
    public function getForm($action = false)
68
    {
69
        global $xoopsDB;
70
71
        if (false === $action) {
72
            $action = $_SERVER['REQUEST_URI'];
73
        }
74
75
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_BMH_ADD) : sprintf(_AM_XNEWSLETTER_BMH_EDIT);
76
77
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
78
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
79
        $form->setExtra('enctype="multipart/form-data"');
80
81
        $account_default = $this->getVar('bmh_accounts_id');
82
        $accontsCriteria = new \CriteriaCompo();
83
        $accontsCriteria->setSort('accounts_id');
84
        $accontsCriteria->setOrder('ASC');
85
        $opt_accounts = new \XoopsFormSelect(_AM_XNEWSLETTER_BMH_ACCOUNTS_ID, 'bmh_accounts_id', $account_default);
86
        $opt_accounts->addOptionArray($this->helper->getHandler('Accounts')->getList($accontsCriteria));
87
        $form->addElement($opt_accounts, false);
88
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_BMH_RULE_NO, 'bmh_rule_no', 50, 255, $this->getVar('bmh_rule_no')), true);
89
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_BMH_RULE_CAT, 'bmh_rule_cat', 50, 255, $this->getVar('bmh_rule_cat')), true);
90
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_BMH_BOUNCETYPE, 'bmh_bouncetype', 50, 255, $this->getVar('bmh_bouncetype')), true);
91
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_BMH_REMOVE, 'bmh_remove', 50, 255, $this->getVar('bmh_remove')), true);
92
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_BMH_EMAIL, 'bmh_email', 50, 255, $this->getVar('bmh_email')), true);
93
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_BMH_SUBJECT, 'bmh_subject', 50, 255, $this->getVar('bmh_subject')), false);
94
95
        $measure_select = new \XoopsFormSelect(_AM_XNEWSLETTER_BMH_MEASURE, 'bmh_measure', $this->getVar('bmh_measure'));
96
        $measure_select->addOption(_XNEWSLETTER_BMH_MEASURE_VAL_PENDING, _AM_XNEWSLETTER_BMH_MEASURE_PENDING);
97
        $measure_select->addOption(_XNEWSLETTER_BMH_MEASURE_VAL_NOTHING, _AM_XNEWSLETTER_BMH_MEASURE_NOTHING);
98
        $measure_select->addOption(_XNEWSLETTER_BMH_MEASURE_VAL_QUIT, _AM_XNEWSLETTER_BMH_MEASURE_QUIT);
99
        $form->addElement($measure_select, true);
100
101
        $time = $this->isNew() ? time() : $this->getVar('bmh_created');
102
        $form->addElement(new \XoopsFormHidden('bmh_submitter', $GLOBALS['xoopsUser']->uid()));
103
        $form->addElement(new \XoopsFormHidden('bmh_created', $time));
104
105
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_SUBMITTER, $GLOBALS['xoopsUser']->uname()));
106
        $form->addElement(new \XoopsFormLabel(_AM_XNEWSLETTER_CREATED, formatTimestamp($time, 's')));
107
108
        //$form->addElement(new \XoopsFormSelectUser(_AM_XNEWSLETTER_SUBMITTER, "bmh_submitter", false, $this->getVar("bmh_submitter"), 1, false), true);
109
        //$form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_CREATED, "bmh_created", "", $this->getVar("bmh_created")));
110
111
        $form->addElement(new \XoopsFormHidden('op', 'save_bmh'));
112
        $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
113
114
        return $form;
115
    }
116
117
    /**
118
     * Get Values
119
     * @param null $keys
120
     * @param string|null $format
121
     * @param int|null $maxDepth
122
     * @return array
123
     */
124
    public function getValuesBmh($keys = null, $format = null, $maxDepth = null)
125
    {
126
        $arr_measure_type = [
127
            _XNEWSLETTER_BMH_MEASURE_VAL_ALL     => _AM_XNEWSLETTER_BMH_MEASURE_ALL,
128
            _XNEWSLETTER_BMH_MEASURE_VAL_PENDING => _AM_XNEWSLETTER_BMH_MEASURE_PENDING,
129
            _XNEWSLETTER_BMH_MEASURE_VAL_NOTHING => _AM_XNEWSLETTER_BMH_MEASURE_NOTHING,
130
            _XNEWSLETTER_BMH_MEASURE_VAL_QUIT    => _AM_XNEWSLETTER_BMH_MEASURE_QUITED,
131
            _XNEWSLETTER_BMH_MEASURE_VAL_DELETE  => _AM_XNEWSLETTER_BMH_MEASURE_DELETED,
132
        ];
133
        $ret['id']           = $this->getVar('bmh_id');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
134
        $ret['rule_no']      = $this->getVar('bmh_rule_no');
135
        $ret['rule_cat']     = $this->getVar('bmh_rule_cat');
136
        $ret['bouncetype']   = $this->getVar('bmh_bouncetype');
137
        $ret['remove']       = $this->getVar('bmh_remove') == '0' ? '' : $this->getVar('bmh_remove');
138
        $ret['email']        = $this->getVar('bmh_email');
139
        $ret['subject']      = $this->getVar('bmh_subject');
140
        $ret['measure']      = $this->getVar('bmh_measure');
141
        $ret['measure_text'] = $arr_measure_type[$this->getVar('bmh_measure')];
142
        $ret['created']      = formatTimestamp($this->getVar('bmh_created'), 'L');
143
        $ret['submitter']    = \XoopsUser::getUnameFromId($this->getVar('bmh_submitter'));
144
        return $ret;
145
    }
146
}
147