Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • Newsletter
  • NewsletterCollection
  • NewsletterJob
  • NewsletterJobCollection
  • NewsletterLog
  • NewsletterLogCollection
  • NewsletterRecipient
  • NewsletterRecipientCollection
  • NewsletterRecipientGroup
  • NewsletterRecipientGroupCollection
  • NewsletterRecipientGroupMember
  • NewsletterRecipientGroupMemberCollection
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the Recipient groups class.
  4:  *
  5:  * @package Plugin
  6:  * @subpackage Newsletter
  7:  * @author Bjoern Behrens
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Recipient group management class.
 18:  *
 19:  * @package Plugin
 20:  * @subpackage Newsletter
 21:  * @method NewsletterRecipientGroup createNewItem
 22:  * @method NewsletterRecipientGroup next
 23:  */
 24: class NewsletterRecipientGroupCollection extends ItemCollection {
 25:     /**
 26:      * Constructor Function
 27:      *
 28:      * @throws cInvalidArgumentException
 29:      */
 30:     public function __construct() {
 31:         global $cfg;
 32:         parent::__construct($cfg["tab"]["news_groups"], "idnewsgroup");
 33:         $this->_setItemClass("NewsletterRecipientGroup");
 34:     }
 35: 
 36:     /**
 37:      * Creates a new group
 38:      *
 39:      * @param $groupname    string Specifies the groupname
 40:      * @param $defaultgroup integer Specfies, if group is default group
 41:      *                      (optional)
 42:      *
 43:      * @return Item
 44:      * @throws cException
 45:      */
 46:     public function create($groupname, $defaultgroup = 0) {
 47:         global $client, $lang;
 48: 
 49:         $group = new NewsletterRecipientGroup();
 50: 
 51:         // _arrInFilters = array('urlencode', 'htmlspecialchars', 'addslashes');
 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:      * Overridden delete method to remove groups from groupmember table
 75:      * before deleting group
 76:      *
 77:      * @param $itemID int specifies the newsletter recipient group
 78:      *
 79:      * @throws cDbException
 80:      * @throws cException
 81:      * @throws cInvalidArgumentException
 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:  * Single RecipientGroup Item
 98:  */
 99: class NewsletterRecipientGroup extends Item {
100:     /**
101:      * Constructor Function
102:      *
103:      * @param mixed $mId Specifies the ID of item to load
104:      *
105:      * @throws cDbException
106:      * @throws cException
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:      * Overriden store() method to ensure, that there is only one default group
118:      *
119:      * @throws cException
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:      * Userdefined setter for newsletter recipient group fields.
145:      *
146:      * @param string $name
147:      * @param mixed  $value
148:      * @param bool   $bSafe Flag to run defined inFilter on passed value
149:      *
150:      * @return bool
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:  * Recipient group member management class
169:  * 
170:  * @method NewsletterRecipientGroupMember createNewItem
171:  * @method NewsletterRecipientGroupMember next
172:  */
173: class NewsletterRecipientGroupMemberCollection extends ItemCollection {
174:     /**
175:      * Constructor Function
176:      *
177:      * @throws cInvalidArgumentException
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:      * Creates a new association
189:      *
190:      * @param $idrecipientgroup int specifies the newsletter group
191:      * @param $idrecipient      int specifies the newsletter user
192:      *
193:      * @return bool|Item
194:      * @throws cDbException
195:      * @throws cException
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:      * Removes an association
218:      *
219:      * @param $idrecipientgroup int specifies the newsletter group
220:      * @param $idrecipient      int specifies the newsletter user
221:      *
222:      * @throws cDbException
223:      * @throws cException
224:      * @throws cInvalidArgumentException
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:      * Removes all associations from any newsletter group
241:      *
242:      * @param $idrecipient int specifies the newsletter recipient
243:      *
244:      * @throws cDbException
245:      * @throws cException
246:      * @throws cInvalidArgumentException
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:      * Removes all associations of a newsletter group
261:      *
262:      * @param $idgroup int specifies the newsletter recipient group
263:      *
264:      * @throws cDbException
265:      * @throws cException
266:      * @throws cInvalidArgumentException
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:      * Returns all recipients in a single group
281:      *
282:      * @param $idrecipientgroup int specifies the newsletter group
283:      * @param $asObjects        boolean specifies if the function should return objects
284:      *
285:      * @return array RecipientRecipient items
286:      * @throws cDbException
287:      * @throws cException
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:  * Single RecipientGroup Item
315:  */
316: class NewsletterRecipientGroupMember extends Item {
317:     /**
318:      * Constructor Function
319:      *
320:      * @param mixed $mId Specifies the ID of item to load
321:      *
322:      * @throws cDbException
323:      * @throws cException
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:      * Userdefined setter for newsletter recipient group member fields.
335:      *
336:      * @param string $name
337:      * @param mixed  $value
338:      * @param bool   $bSafe Flag to run defined inFilter on passed value
339:      *
340:      * @return bool
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: ?>
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0