XoopsModules25x /
xnewsletter
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 Protocol |
||
| 37 | */ |
||
| 38 | class Protocol extends \XoopsObject |
||
| 39 | { |
||
| 40 | public $helper = null; |
||
| 41 | public $db; |
||
| 42 | |||
| 43 | public $protocol_status_strs = [ |
||
| 44 | _XNEWSLETTER_PROTOCOL_STATUS_SAVED => _AM_XNEWSLETTER_PROTOCOL_STATUS_SAVED, |
||
| 45 | _XNEWSLETTER_PROTOCOL_STATUS_ERROR_CREATE_TASK => _AM_XNEWSLETTER_PROTOCOL_STATUS_ERROR_CREATE_TASK, |
||
| 46 | _XNEWSLETTER_PROTOCOL_STATUS_OK_SEND_TEST => _AM_XNEWSLETTER_PROTOCOL_STATUS_OK_SEND_TEST, |
||
| 47 | _XNEWSLETTER_PROTOCOL_STATUS_OK_SEND => _AM_XNEWSLETTER_PROTOCOL_STATUS_OK_SEND, |
||
| 48 | _XNEWSLETTER_PROTOCOL_STATUS_ERROR_SEND => _AM_XNEWSLETTER_PROTOCOL_STATUS_ERROR_SEND,// INPROGRESS |
||
| 49 | ]; |
||
| 50 | |||
| 51 | //Constructor |
||
| 52 | |||
| 53 | public function __construct() |
||
| 54 | { |
||
| 55 | $this->helper = Helper::getInstance(); |
||
| 56 | $this->db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 57 | $this->initVar('protocol_id', XOBJ_DTYPE_INT, null, false); |
||
| 58 | $this->initVar('protocol_letter_id', XOBJ_DTYPE_INT, null, false); |
||
| 59 | $this->initVar('protocol_subscriber_id', XOBJ_DTYPE_INT, null, false); |
||
| 60 | $this->initVar('protocol_status', XOBJ_DTYPE_TXTBOX, '', false, 200); // old style |
||
| 61 | $this->initVar('protocol_success', XOBJ_DTYPE_OTHER, null, false); // boolean |
||
| 62 | $this->initVar('protocol_submitter', XOBJ_DTYPE_INT, null, false); |
||
| 63 | $this->initVar('protocol_created', XOBJ_DTYPE_INT, null, false); |
||
| 64 | $this->initVar('protocol_status_str_id', XOBJ_DTYPE_TXTBOX, '', false); // new from v1.3 |
||
| 65 | $this->initVar('protocol_status_vars', XOBJ_DTYPE_ARRAY, [], false); // new from v1.3 |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param bool $action |
||
| 70 | * |
||
| 71 | * @return \XoopsThemeForm |
||
| 72 | */ |
||
| 73 | public function getForm($action = false) |
||
| 74 | { |
||
| 75 | global $xoopsDB; |
||
| 76 | |||
| 77 | if (false === $action) { |
||
| 78 | $action = $_SERVER['REQUEST_URI']; |
||
| 79 | } |
||
| 80 | |||
| 81 | $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_PROTOCOL_ADD) : sprintf(_AM_XNEWSLETTER_PROTOCOL_EDIT); |
||
| 82 | |||
| 83 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 84 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
| 85 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 86 | |||
| 87 | $letterCriteria = new \CriteriaCompo(); |
||
| 88 | $letterCriteria->setSort('letter_id'); |
||
| 89 | $letterCriteria->setOrder('DESC'); |
||
| 90 | $letter_select = new \XoopsFormSelect(_AM_XNEWSLETTER_PROTOCOL_LETTER_ID, 'protocol_letter_id', $this->getVar('protocol_letter_id')); |
||
| 91 | $letter_select->addOptionArray($this->helper->getHandler('Letter')->getList($letterCriteria)); |
||
| 92 | $form->addElement($letter_select, true); |
||
| 93 | |||
| 94 | $subscrCriteria = new \CriteriaCompo(); |
||
| 95 | $subscrCriteria->setSort('subscr_id'); |
||
| 96 | $subscrCriteria->setOrder('ASC'); |
||
| 97 | $subscr_select = new \XoopsFormSelect(_AM_XNEWSLETTER_PROTOCOL_SUBSCRIBER_ID, 'protocol_subscriber_id', $this->getVar('protocol_subscriber_id')); |
||
| 98 | $subscr_select->addOptionArray($this->helper->getHandler('Subscr')->getList($subscrCriteria)); |
||
| 99 | $form->addElement($subscr_select, true); |
||
| 100 | |||
| 101 | $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_PROTOCOL_STATUS, 'protocol_status', 50, 200, $this->getVar('protocol_status')), false); |
||
| 102 | |||
| 103 | $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_PROTOCOL_SUCCESS, 'protocol_success', 50, 255, $this->getVar('protocol_success')), false); |
||
| 104 | |||
| 105 | $form->addElement(new \XoopsFormSelectUser(_AM_XNEWSLETTER_SUBMITTER, 'protocol_submitter', false, $this->getVar('protocol_submitter'), 1, false), true); |
||
| 106 | |||
| 107 | $form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_CREATED, 'protocol_created', '', $this->getVar('protocol_created'))); |
||
| 108 | |||
| 109 | $form->addElement(new \XoopsFormHidden('op', 'save_protocol')); |
||
| 110 | $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
||
| 111 | |||
| 112 | return $form; |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get Values |
||
| 117 | * @param null $keys |
||
| 118 | * @param string|null $format |
||
| 119 | * @param int|null $maxDepth |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | public function getValuesProtocol($keys = null, $format = null, $maxDepth = null) |
||
| 123 | { |
||
| 124 | $ret['id'] = $this->getVar('protocol_id'); |
||
|
0 ignored issues
–
show
|
|||
| 125 | $ret['letter_id'] = $this->getVar('protocol_letter_id'); |
||
| 126 | $ret['subscriber_id'] = $this->getVar('protocol_subscriber_id'); |
||
| 127 | $ret['status'] = $this->getVar('protocol_status'); |
||
| 128 | $ret['success'] = $this->getVar('protocol_success'); |
||
| 129 | $ret['status_str_id'] = $this->getVar('protocol_status_str_id'); |
||
| 130 | $ret['status_vars'] = $this->getVar('protocol_status_vars'); |
||
| 131 | $ret['created'] = formatTimestamp($this->getVar('protocol_created'), 'L'); |
||
| 132 | $ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('protocol_submitter')); |
||
| 133 | return $ret; |
||
| 134 | } |
||
| 135 | } |
||
| 136 |
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:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.