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
    • 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:  */
 22: class NewsletterRecipientGroupCollection extends ItemCollection {
 23: 
 24:     /**
 25:      * Constructor Function
 26:      *
 27:      * @param none
 28:      */
 29:     public function __construct() {
 30:         global $cfg;
 31:         parent::__construct($cfg["tab"]["news_groups"], "idnewsgroup");
 32:         $this->_setItemClass("NewsletterRecipientGroup");
 33:     }
 34: 
 35:     /**
 36:      * Creates a new group
 37:      *
 38:      * @param $groupname string Specifies the groupname
 39:      * @param $defaultgroup integer Specfies, if group is default group
 40:      *        (optional)
 41:      */
 42:     public function create($groupname, $defaultgroup = 0) {
 43:         global $client, $lang;
 44: 
 45:         $group = new NewsletterRecipientGroup();
 46: 
 47:         // _arrInFilters = array('urlencode', 'htmlspecialchars', 'addslashes');
 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:      * Overridden delete method to remove groups from groupmember table
 72:      * before deleting group
 73:      *
 74:      * @param $itemID int specifies the newsletter recipient group
 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:  * Single RecipientGroup Item
 91:  */
 92: class NewsletterRecipientGroup extends Item {
 93: 
 94:     /**
 95:      * Constructor Function
 96:      *
 97:      * @param mixed $mId Specifies the ID of item to load
 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:      * Overriden store() method to ensure, that there is only one default group
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:      * Userdefined setter for newsletter recipient group fields.
134:      *
135:      * @param string $name
136:      * @param mixed $value
137:      * @param bool $bSafe Flag to run defined inFilter on passed value
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:  * Recipient group member management class
156:  */
157: class NewsletterRecipientGroupMemberCollection extends ItemCollection {
158: 
159:     /**
160:      * Constructor Function
161:      *
162:      * @param none
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:      * Creates a new association
174:      *
175:      * @param $idrecipientgroup int specifies the newsletter group
176:      * @param $idrecipient int specifies the newsletter user
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:      * Removes an association
199:      *
200:      * @param $idrecipientgroup int specifies the newsletter group
201:      * @param $idrecipient int specifies the newsletter user
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:      * Removes all associations from any newsletter group
218:      *
219:      * @param $idrecipient int specifies the newsletter recipient
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:      * Removes all associations of a newsletter group
234:      *
235:      * @param $idgroup int specifies the newsletter recipient group
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:      * Returns all recipients in a single group
250:      *
251:      * @param $idrecipientgroup int specifies the newsletter group
252:      * @param $asObjects boolean specifies if the function should return objects
253:      * @return array RecipientRecipient items
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:  * Single RecipientGroup Item
281:  */
282: class NewsletterRecipientGroupMember extends Item {
283: 
284:     /**
285:      * Constructor Function
286:      *
287:      * @param mixed $mId Specifies the ID of item to load
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:      * Userdefined setter for newsletter recipient group member fields.
299:      *
300:      * @param string $name
301:      * @param mixed $value
302:      * @param bool $bSafe Flag to run defined inFilter on passed value
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: ?>
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0