1: <?php
2:
3: if (!defined('XOOPS_ROOT_PATH')) exit();
4:
5: class UserMailjobObject extends XoopsSimpleObject
6: {
7: var $mUsers = array();
8: var $_mUsersLoadedFlag = false;
9: var $mUserCount = 0;
10: var $_mUserCountLoadedFlag = false;
11:
12: 13: 14:
15: var $mGetReplaceTitle = null;
16:
17: 18: 19:
20: var $mGetReplaceBody = null;
21:
22: 23: 24:
25: var $mSend = null;
26:
27: function UserMailjobObject()
28: {
29: static $initVars;
30: if (isset($initVars)) {
31: $this->mVars = $initVars;
32: } else {
33: $this->initVar('mailjob_id', XOBJ_DTYPE_INT, '', false);
34: $this->initVar('title', XOBJ_DTYPE_STRING, '', true, 255);
35: $this->initVar('body', XOBJ_DTYPE_TEXT, '', true);
36: $this->initVar('from_name', XOBJ_DTYPE_STRING, '', false, 255);
37: $this->initVar('from_email', XOBJ_DTYPE_STRING, '', false, 255);
38: $this->initVar('is_pm', XOBJ_DTYPE_BOOL, '0', true);
39: $this->initVar('is_mail', XOBJ_DTYPE_BOOL, '0', true);
40: $this->initVar('create_unixtime', XOBJ_DTYPE_INT, time(), true);
41: $initVars=$this->mVars;
42: }
43:
44: $this->mGetReplaceTitle =new XCube_Delegate();
45: $this->mGetReplaceTitle->register('UserMailjobObject.GetReplaceTitle');
46:
47: $this->mGetReplaceBody =new XCube_Delegate();
48: $this->mGetReplaceBody->register('UserMailjobObject.GetReplaceBody');
49:
50: $this->mSend =new XCube_Delegate();
51: $this->mSend->register('UserMailjobObject.Send');
52: }
53:
54: 55: 56:
57: function loadUserCount()
58: {
59: if (!$this->_mUserCountLoadedFlag)
60: {
61: $handler =& xoops_getmodulehandler('mailjob_link', 'user');
62: $this->mUserCount = $handler->getCount(new Criteria('mailjob_id', $this->get('mailjob_id')));
63: $this->_mUserCountLoadedFlag = true;
64: }
65: }
66:
67: 68: 69:
70: function loadUser()
71: {
72: if (!$this->_mUsersLoadedFlag) {
73: $handler =& xoops_getmodulehandler('mailjob_link', 'user');
74: $this->mUsers =& $handler->getObjects(new Criteria('mailjob_id', $this->get('mailjob_id')));
75: $this->_mUsersLoadedFlag = true;
76: }
77: }
78:
79: 80: 81: 82:
83: function &getUsers($retry)
84: {
85: $handler =& xoops_getmodulehandler('mailjob_link', 'user');
86:
87: $criteria =new CriteriaCompo();
88: $criteria->add(new Criteria('mailjob_id', $this->get('mailjob_id')));
89: $criteria->add(new Criteria('retry', $retry));
90:
91: $arr =& $handler->getObjects($criteria);
92:
93: return $arr;
94: }
95:
96: 97: 98: 99:
100: function getUserCount()
101: {
102: $this->loadUserCount();
103: return $this->mUserCount;
104: }
105:
106: function send($from_user)
107: {
108: $root =& XCube_Root::getSingleton();
109:
110: $userArr =& $this->getUsers($this->getCurrentRetry());
111: $handler =& xoops_getmodulehandler('mailjob_link', 'user');
112:
113: $userHandler =& xoops_gethandler('user');
114:
115: foreach (array_keys($userArr) as $key) {
116: $to_user =& $userHandler->get($userArr[$key]->get('uid'));
117:
118: $userArr[$key]->set('message', '');
119:
120: if (is_object($to_user)) {
121: $this->mSend->call(new XCube_Ref($userArr[$key]), new XCube_Ref($this), $to_user, $from_user);
122: }
123: else {
124: $userArr[$key]->set('message', 'This user does not exist.');
125: }
126:
127: if ($userArr[$key]->get('message') == '') {
128: $handler->delete($userArr[$key]);
129: }
130: else {
131: $userArr[$key]->set('retry', $userArr[$key]->get('retry') + 1);
132: $handler->insert($userArr[$key]);
133: }
134: }
135: }
136:
137: function getReplaceTitle(&$to_user, &$from_user)
138: {
139: return $this->get('title');
140: }
141:
142: function getReplaceBody(&$to_user, &$from_user)
143: {
144: $t_body = $this->get('body');
145:
146:
147:
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: function getCurrentRetry()
159: {
160: $handler =& xoops_getmodulehandler('mailjob_link', 'user');
161: return $handler->getCurrentRetry($this->get('mailjob_id'));
162: }
163: }
164:
165: class UserMailjobHandler extends XoopsObjectGenericHandler
166: {
167: var $mTable = "user_mailjob";
168: var $mPrimary = "mailjob_id";
169: var $mClass = "UserMailjobObject";
170: }
171:
172: ?>
173: