1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Xnewsletter; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* xnewsletter module for xoops |
17
|
|
|
* |
18
|
|
|
* @copyright The TXMod XOOPS Project http://sourceforge.net/projects/thmod/ |
19
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @package xnewsletter |
22
|
|
|
* @since 2.5.x |
23
|
|
|
* @author XOOPS Development Team ( [email protected] ) - ( https://xoops.org ) |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
//use XoopsModules\Xnewsletter; |
27
|
|
|
|
28
|
|
|
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined"); |
29
|
|
|
require_once dirname(__DIR__) . '/include/common.php'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class Task |
33
|
|
|
*/ |
34
|
|
|
class Task extends \XoopsObject |
35
|
|
|
{ |
36
|
|
|
public $helper = null; |
37
|
|
|
public $db; |
38
|
|
|
|
39
|
|
|
//Constructor |
40
|
|
|
|
41
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$this->helper = Helper::getInstance(); |
44
|
|
|
$this->db = \XoopsDatabaseFactory::getDatabaseConnection(); |
45
|
|
|
parent::__construct(); |
46
|
|
|
$this->initVar('task_id', XOBJ_DTYPE_INT, null, false); |
47
|
|
|
$this->initVar('task_letter_id', XOBJ_DTYPE_INT, null, false); |
48
|
|
|
$this->initVar('task_subscr_id', XOBJ_DTYPE_INT, null, false); |
49
|
|
|
$this->initVar('task_starttime', XOBJ_DTYPE_INT, null, false); |
50
|
|
|
$this->initVar('task_submitter', XOBJ_DTYPE_INT, null, false); |
51
|
|
|
$this->initVar('task_created', XOBJ_DTYPE_INT, time(), false); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param bool $action |
56
|
|
|
* |
57
|
|
|
* @return \XoopsThemeForm |
58
|
|
|
*/ |
59
|
|
|
public function getForm($action = false) |
60
|
|
|
{ |
61
|
|
|
global $xoopsDB; |
62
|
|
|
|
63
|
|
|
if (false === $action) { |
64
|
|
|
$action = $_SERVER['REQUEST_URI']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_TASK_ADD) : sprintf(_AM_XNEWSLETTER_TASK_EDIT); |
68
|
|
|
|
69
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
70
|
|
|
|
71
|
|
|
$form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
72
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
73
|
|
|
|
74
|
|
|
$letterCriteria = new \CriteriaCompo(); |
75
|
|
|
$letterCriteria->setSort('letter_id'); |
76
|
|
|
$letterCriteria->setOrder('DESC'); |
77
|
|
|
$letter_select = new \XoopsFormSelect(_AM_XNEWSLETTER_TASK_LETTER_ID, 'task_letter_id', $this->getVar('task_letter_id')); |
78
|
|
|
$letter_select->addOptionArray($this->helper->getHandler('Letter')->getList($letterCriteria)); |
79
|
|
|
$form->addElement($letter_select, true); |
80
|
|
|
|
81
|
|
|
$subscrCriteria = new \CriteriaCompo(); |
82
|
|
|
$subscrCriteria->setSort('subscr_id'); |
83
|
|
|
$subscrCriteria->setOrder('ASC'); |
84
|
|
|
$subscr_select = new \XoopsFormSelect(_AM_XNEWSLETTER_TASK_SUBSCR_ID, 'task_subscr_id', $this->getVar('task_subscr_id')); |
85
|
|
|
$subscr_select->addOptionArray($this->helper->getHandler('Subscr')->getList($subscrCriteria)); |
86
|
|
|
$form->addElement($subscr_select, true); |
87
|
|
|
|
88
|
|
|
$form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_TASK_STARTTIME, 'task_starttime', '', $this->getVar('task_starttime'))); |
89
|
|
|
|
90
|
|
|
$form->addElement(new \XoopsFormSelectUser(_AM_XNEWSLETTER_SUBMITTER, 'task_submitter', false, $this->getVar('task_submitter'), 1, false), true); |
91
|
|
|
|
92
|
|
|
$form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_CREATED, 'task_created', '', $this->getVar('task_created'))); |
93
|
|
|
|
94
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save_task')); |
95
|
|
|
$form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
96
|
|
|
|
97
|
|
|
return $form; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get Values |
102
|
|
|
* @param null $keys |
103
|
|
|
* @param string|null $format |
104
|
|
|
* @param int|null $maxDepth |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function getValuesTask($keys = null, $format = null, $maxDepth = null) |
108
|
|
|
{ |
109
|
|
|
$ret = $this->getValues($keys, $format, $maxDepth); |
110
|
|
|
$ret['id'] = $this->getVar('task_id'); |
111
|
|
|
$ret['letter_id'] = $this->getVar('task_letter_id'); |
112
|
|
|
$ret['letter_title'] = $this->helper->getHandler('Letter')->get($this->getVar('task_letter_id'))->getVar('letter_title'); |
113
|
|
|
$ret['subscr_id'] = $this->getVar('task_subscr_id'); |
114
|
|
|
$ret['subscr_email'] = $this->helper->getHandler('Subscr')->get($this->getVar('task_subscr_id'))->getVar('subscr_email'); |
115
|
|
|
$ret['starttime'] = formatTimestamp($this->getVar('task_starttime'), 'L'); |
116
|
|
|
$ret['created'] = formatTimestamp($this->getVar('task_created'), 'L'); |
117
|
|
|
$ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('task_submitter')); |
118
|
|
|
return $ret; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
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.