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