10 public $_mUsersLoadedFlag =
false;
11 public $mUserCount = 0;
12 public $_mUserCountLoadedFlag =
false;
17 public $mGetReplaceTitle =
null;
22 public $mGetReplaceBody =
null;
29 public function __construct()
32 if (isset($initVars)) {
33 $this->mVars = $initVars;
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;
47 $this->mGetReplaceTitle->register(
'UserMailjobObject.GetReplaceTitle');
50 $this->mGetReplaceBody->register(
'UserMailjobObject.GetReplaceBody');
53 $this->mSend->register(
'UserMailjobObject.Send');
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;
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;
87 $handler = &xoops_getmodulehandler(
'mailjob_link',
'user');
90 $criteria->add(
new Criteria(
'mailjob_id', $this->
get(
'mailjob_id')));
91 $criteria->add(
new Criteria(
'retry', $retry));
93 $arr = &$handler->getObjects($criteria);
105 return $this->mUserCount;
108 public function send($from_user)
110 $root = &XCube_Root::getSingleton();
112 $userArr = &$this->
getUsers($this->getCurrentRetry());
113 $handler = &xoops_getmodulehandler(
'mailjob_link',
'user');
115 $userHandler = &xoops_gethandler(
'user');
117 foreach (array_keys($userArr) as $key) {
118 $to_user = &$userHandler->get($userArr[$key]->
get(
'uid'));
120 $userArr[$key]->set(
'message',
'');
122 if (is_object($to_user)) {
123 $this->mSend->call(
new XCube_Ref($userArr[$key]),
new XCube_Ref($this), $to_user, $from_user);
125 $userArr[$key]->set(
'message',
'This user does not exist.');
128 if (
'' == $userArr[$key]->
get(
'message')) {
129 $handler->delete($userArr[$key]);
131 $userArr[$key]->set(
'retry', $userArr[$key]->
get(
'retry') + 1);
132 $handler->insert($userArr[$key]);
137 public function getReplaceTitle(&$to_user, &$from_user)
139 return $this->
get(
'title');
142 public function getReplaceBody(&$to_user, &$from_user)
144 $t_body = $this->
get(
'body');
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);
153 $this->mGetReplaceBody->call(
new XCube_Ref($t_body), $to_user, $from_user);
158 public function getCurrentRetry()
160 $handler = &xoops_getmodulehandler(
'mailjob_link',
'user');
161 return $handler->getCurrentRetry($this->
get(
'mailjob_id'));