1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: 17: 18: 19: 20: 21: 22: 23:
24: class NewsletterRecipientGroupCollection extends ItemCollection {
25: 26: 27: 28: 29:
30: public function __construct() {
31: global $cfg;
32: parent::__construct($cfg["tab"]["news_groups"], "idnewsgroup");
33: $this->_setItemClass("NewsletterRecipientGroup");
34: }
35:
36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
46: public function create($groupname, $defaultgroup = 0) {
47: global $client, $lang;
48:
49: $group = new NewsletterRecipientGroup();
50:
51:
52:
53: $mangledGroupName = $group->_inFilter($groupname);
54: $this->setWhere("idclient", $client);
55: $this->setWhere("idlang", $lang);
56: $this->setWhere("groupname", $mangledGroupName);
57: $this->query();
58:
59: if ($obj = $this->next()) {
60: $groupname = $groupname . md5(rand());
61: }
62:
63: $item = $this->createNewItem();
64: $item->set("idclient", $client);
65: $item->set("idlang", $lang);
66: $item->set("groupname", $groupname);
67: $item->set("defaultgroup", $defaultgroup);
68: $item->store();
69:
70: return $item;
71: }
72:
73: 74: 75: 76: 77: 78: 79: 80: 81: 82:
83: public function delete($itemID) {
84: $oAssociations = new NewsletterRecipientGroupMemberCollection();
85: $oAssociations->setWhere("idnewsgroup", $itemID);
86: $oAssociations->query();
87:
88: while ($oItem = $oAssociations->next()) {
89: $oAssociations->delete($oItem->get("idnewsgroupmember"));
90: }
91: parent::delete($itemID);
92: }
93:
94: }
95:
96: 97: 98:
99: class NewsletterRecipientGroup extends Item {
100: 101: 102: 103: 104: 105: 106: 107:
108: public function __construct($mId = false) {
109: global $cfg;
110: parent::__construct($cfg["tab"]["news_groups"], "idnewsgroup");
111: if ($mId !== false) {
112: $this->loadByPrimaryKey($mId);
113: }
114: }
115:
116: 117: 118: 119: 120:
121: public function store() {
122: global $client, $lang;
123:
124: $client = cSecurity::toInteger($client);
125: $lang = cSecurity::toInteger($lang);
126:
127: if ($this->get("defaultgroup") == 1) {
128: $oItems = new NewsletterRecipientGroupCollection();
129: $oItems->setWhere("idclient", $client);
130: $oItems->setWhere("idlang", $lang);
131: $oItems->setWhere("defaultgroup", 1);
132: $oItems->setWhere("idnewsgroup", $this->get("idnewsgroup"), "<>");
133: $oItems->query();
134:
135: while ($oItem = $oItems->next()) {
136: $oItem->set("defaultgroup", 0);
137: $oItem->store();
138: }
139: }
140: return parent::store();
141: }
142:
143: 144: 145: 146: 147: 148: 149: 150: 151:
152: public function setField($name, $value, $bSafe = true) {
153: switch ($name) {
154: case 'idclient':
155: $value = (int) $value;
156: break;
157: case 'idlang':
158: $value = (int) $value;
159: break;
160: }
161:
162: return parent::setField($name, $value, $bSafe);
163: }
164:
165: }
166:
167: 168: 169: 170: 171: 172:
173: class NewsletterRecipientGroupMemberCollection extends ItemCollection {
174: 175: 176: 177: 178:
179: public function __construct() {
180: global $cfg;
181: parent::__construct($cfg["tab"]["news_groupmembers"], "idnewsgroupmember");
182: $this->_setJoinPartner('NewsletterRecipientGroupCollection');
183: $this->_setJoinPartner('NewsletterRecipientCollection');
184: $this->_setItemClass("NewsletterRecipientGroupMember");
185: }
186:
187: 188: 189: 190: 191: 192: 193: 194: 195: 196:
197: public function create($idrecipientgroup, $idrecipient) {
198:
199: $this->setWhere("idnewsgroup", $idrecipientgroup);
200: $this->setWhere("idnewsrcp", $idrecipient);
201: $this->query();
202:
203: if ($this->next()) {
204: return false;
205: }
206:
207: $oItem = parent::createNewItem();
208:
209: $oItem->set("idnewsrcp", $idrecipient);
210: $oItem->set("idnewsgroup", $idrecipientgroup);
211: $oItem->store();
212:
213: return $oItem;
214: }
215:
216: 217: 218: 219: 220: 221: 222: 223: 224: 225:
226: public function remove($idrecipientgroup, $idrecipient) {
227: $idrecipientgroup = cSecurity::toInteger($idrecipientgroup);
228: $idrecipient = cSecurity::toInteger($idrecipient);
229:
230: $this->setWhere("idnewsgroup", $idrecipientgroup);
231: $this->setWhere("idnewsrcp", $idrecipient);
232: $this->query();
233:
234: if ($oItem = $this->next()) {
235: $this->delete($oItem->get("idnewsgroupmember"));
236: }
237: }
238:
239: 240: 241: 242: 243: 244: 245: 246: 247:
248: public function removeRecipientFromGroups($idrecipient) {
249: $idrecipient = cSecurity::toInteger($idrecipient);
250:
251: $this->setWhere("idnewsrcp", $idrecipient);
252: $this->query();
253:
254: while ($oItem = $this->next()) {
255: $this->delete($oItem->get("idnewsgroupmember"));
256: }
257: }
258:
259: 260: 261: 262: 263: 264: 265: 266: 267:
268: public function removeGroup($idgroup) {
269: $idgroup = cSecurity::toInteger($idgroup);
270:
271: $this->setWhere("idnewsgroup", $idgroup);
272: $this->query();
273:
274: while ($oItem = $this->next()) {
275: $this->delete($oItem->get("idnewsgroupmember"));
276: }
277: }
278:
279: 280: 281: 282: 283: 284: 285: 286: 287: 288:
289: public function getRecipientsInGroup($idrecipientgroup, $asObjects = true) {
290: $idrecipientgroup = cSecurity::toInteger($idrecipientgroup);
291:
292: $this->setWhere("idnewsgroup", $idrecipientgroup);
293: $this->query();
294:
295: $aObjects = array();
296:
297: while ($oItem = $this->next()) {
298: if ($asObjects) {
299: $oRecipient = new NewsletterRecipient();
300: $oRecipient->loadByPrimaryKey($oItem->get("idnewsrcp"));
301:
302: $aObjects[] = $oRecipient;
303: } else {
304: $aObjects[] = $oItem->get("idnewsrcp");
305: }
306: }
307:
308: return ($aObjects);
309: }
310:
311: }
312:
313: 314: 315:
316: class NewsletterRecipientGroupMember extends Item {
317: 318: 319: 320: 321: 322: 323: 324:
325: public function __construct($mId = false) {
326: global $cfg;
327: parent::__construct($cfg["tab"]["news_groupmembers"], "idnewsgroupmember");
328: if ($mId !== false) {
329: $this->loadByPrimaryKey($mId);
330: }
331: }
332:
333: 334: 335: 336: 337: 338: 339: 340: 341:
342: public function setField($name, $value, $bSafe = true) {
343: switch ($name) {
344: case 'idnewsgroup':
345: $value = (int) $value;
346: break;
347: case 'idnewsrcp':
348: $value = (int) $value;
349: break;
350: }
351:
352: return parent::setField($name, $value, $bSafe);
353: }
354:
355: }
356:
357: ?>