XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
mailjob.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
8{
9 public $mUsers = [];
10 public $_mUsersLoadedFlag = false;
11 public $mUserCount = 0;
12 public $_mUserCountLoadedFlag = false;
13
17 public $mGetReplaceTitle = null;
18
22 public $mGetReplaceBody = null;
23
27 public $mSend = null;
28
29 public function __construct()
30 {
31 static $initVars;
32 if (isset($initVars)) {
33 $this->mVars = $initVars;
34 } else {
35 $this->initVar('mailjob_id', XOBJ_DTYPE_INT, '', false);
36 $this->initVar('title', XOBJ_DTYPE_STRING, '', true, 191);
37 $this->initVar('body', XOBJ_DTYPE_TEXT, '', true);
38 $this->initVar('from_name', XOBJ_DTYPE_STRING, '', false, 191);
39 $this->initVar('from_email', XOBJ_DTYPE_STRING, '', false, 191);
40 $this->initVar('is_pm', XOBJ_DTYPE_BOOL, '0', true);
41 $this->initVar('is_mail', XOBJ_DTYPE_BOOL, '0', true);
42 $this->initVar('create_unixtime', XOBJ_DTYPE_INT, time(), true);
43 $initVars = $this->mVars;
44 }
45
46 $this->mGetReplaceTitle = new XCube_Delegate();
47 $this->mGetReplaceTitle->register('UserMailjobObject.GetReplaceTitle');
48
49 $this->mGetReplaceBody = new XCube_Delegate();
50 $this->mGetReplaceBody->register('UserMailjobObject.GetReplaceBody');
51
52 $this->mSend = new XCube_Delegate();
53 $this->mSend->register('UserMailjobObject.Send');
54 }
55
59 public function loadUserCount()
60 {
61 if (!$this->_mUserCountLoadedFlag) {
62 $handler = &xoops_getmodulehandler('mailjob_link', 'user');
63 $this->mUserCount = $handler->getCount(new Criteria('mailjob_id', $this->get('mailjob_id')));
64 $this->_mUserCountLoadedFlag = true;
65 }
66 }
67
71 public function loadUser()
72 {
73 if (!$this->_mUsersLoadedFlag) {
74 $handler = &xoops_getmodulehandler('mailjob_link', 'user');
75 $this->mUsers = &$handler->getObjects(new Criteria('mailjob_id', $this->get('mailjob_id')));
76 $this->_mUsersLoadedFlag = true;
77 }
78 }
79
85 public function &getUsers($retry)
86 {
87 $handler = &xoops_getmodulehandler('mailjob_link', 'user');
88
89 $criteria = new CriteriaCompo();
90 $criteria->add(new Criteria('mailjob_id', $this->get('mailjob_id')));
91 $criteria->add(new Criteria('retry', $retry));
92
93 $arr = &$handler->getObjects($criteria);
94
95 return $arr;
96 }
97
102 public function getUserCount()
103 {
104 $this->loadUserCount();
105 return $this->mUserCount;
106 }
107
108 public function send($from_user)
109 {
110 $root = &XCube_Root::getSingleton();
111
112 $userArr = &$this->getUsers($this->getCurrentRetry());
113 $handler = &xoops_getmodulehandler('mailjob_link', 'user');
114
115 $userHandler = &xoops_gethandler('user');
116
117 foreach (array_keys($userArr) as $key) {
118 $to_user = &$userHandler->get($userArr[$key]->get('uid'));
119
120 $userArr[$key]->set('message', '');
121
122 if (is_object($to_user)) {
123 $this->mSend->call(new XCube_Ref($userArr[$key]), new XCube_Ref($this), $to_user, $from_user);
124 } else {
125 $userArr[$key]->set('message', 'This user does not exist.');
126 }
127
128 if ('' == $userArr[$key]->get('message')) {
129 $handler->delete($userArr[$key]);
130 } else {
131 $userArr[$key]->set('retry', $userArr[$key]->get('retry') + 1);
132 $handler->insert($userArr[$key]);
133 }
134 }
135 }
136
137 public function getReplaceTitle(&$to_user, &$from_user)
138 {
139 return $this->get('title');
140 }
141
142 public function getReplaceBody(&$to_user, &$from_user)
143 {
144 $t_body = $this->get('body');
145
146 //
147 // TODO {X_UACTLINK}
148 //
149 $t_body = str_replace('{X_UID}', $to_user->get('uid'), $t_body);
150 $t_body = str_replace('{X_UNAME}', $to_user->get('uname'), $t_body);
151 $t_body = str_replace('{X_UEMAIL}', $to_user->get('email'), $t_body);
152
153 $this->mGetReplaceBody->call(new XCube_Ref($t_body), $to_user, $from_user);
154
155 return $t_body;
156 }
157
158 public function getCurrentRetry()
159 {
160 $handler = &xoops_getmodulehandler('mailjob_link', 'user');
161 return $handler->getCurrentRetry($this->get('mailjob_id'));
162 }
163}
164
166{
167 public $mTable = 'user_mailjob';
168 public $mPrimary = 'mailjob_id';
169 public $mClass = 'UserMailjobObject';
170}
& getUsers($retry)
Definition mailjob.php:85
[Final] Used for the simple mechanism for common delegation in XCube.