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 Newsletter Collection 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: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: /**
 18:  * Newsletter Collection class.
 19:  *
 20:  * @package Plugin
 21:  * @subpackage Newsletter
 22:  * @method NewsletterRecipient createNewItem
 23:  * @method NewsletterRecipient next
 24:  */
 25: class NewsletterRecipientCollection extends ItemCollection {
 26:     /**
 27:      * Constructor Function
 28:      *
 29:      * @throws cInvalidArgumentException
 30:      */
 31:     public function __construct() {
 32:         global $cfg;
 33:         parent::__construct($cfg["tab"]["news_rcp"], "idnewsrcp");
 34:         $this->_setItemClass("NewsletterRecipient");
 35:     }
 36: 
 37:     /**
 38:      * Creates a new recipient
 39:      *
 40:      * @param string $sEMail       Specifies the e-mail adress
 41:      * @param string $sName        Specifies the recipient name (optional)
 42:      * @param int    $iConfirmed   Specifies, if the recipient is confirmed
 43:      *                             (optional)
 44:      * @param string $sJoinID      Specifies additional recipient group ids to join
 45:      *                             (optional, e.g. 47,12,...)
 46:      * @param int    $iMessageType Specifies the message type for the recipient (0 = text, 1 = html)
 47:      *
 48:      * @return Item
 49:      * @throws cDbException
 50:      * @throws cException
 51:      * @throws cInvalidArgumentException
 52:      */
 53:     public function create($sEMail, $sName = "", $iConfirmed = 0, $sJoinID = "", $iMessageType = 0) {
 54:         global $client, $lang, $auth;
 55: 
 56:         /* Check if the e-mail adress already exists */
 57:         $email = cString::toLowerCase($sEMail); // e-mail always lower case
 58:         $this->setWhere("idclient", $client);
 59:         $this->setWhere("idlang", $lang);
 60:         $this->setWhere("email", $email);
 61:         $this->query();
 62: 
 63:         if ($this->next()) {
 64:             return $this->create($email . "_" . cString::getPartOfString(md5(rand()), 0, 10), $sName, 0, $sJoinID, $iMessageType); // 0:
 65:                                                                                                             // Deactivate
 66:                                                                                                             // 'confirmed'
 67:         }
 68:         $oItem = $this->createNewItem();
 69:         $oItem->set("idclient", $client);
 70:         $oItem->set("idlang", $lang);
 71:         $oItem->set("name", $sName);
 72:         $oItem->set("email", $email);
 73:         $oItem->set("hash", cString::getPartOfString(md5(rand()), 0, 17) . uniqid("")); // Generating
 74:                                                                     // UID, 30
 75:                                                                     // characters
 76:         $oItem->set("confirmed", $iConfirmed);
 77:         $oItem->set("news_type", $iMessageType);
 78: 
 79:         if ($iConfirmed) {
 80:             $oItem->set("confirmeddate", date("Y-m-d H:i:s"), false);
 81:         }
 82:         $oItem->set("deactivated", 0);
 83:         $oItem->set("created", date('Y-m-d H:i:s'), false);
 84:         $oItem->set("author", $auth->auth["uid"]);
 85:         $oItem->store();
 86: 
 87:         $iIDRcp = $oItem->get("idnewsrcp"); // Getting internal id of new
 88:                                             // recipient
 89: 
 90:         // Add this recipient to the default recipient group (if available)
 91:         $oGroups = new NewsletterRecipientGroupCollection();
 92:         $oGroupMembers = new NewsletterRecipientGroupMemberCollection();
 93: 
 94:         $oGroups->setWhere("idclient", $client);
 95:         $oGroups->setWhere("idlang", $lang);
 96:         $oGroups->setWhere("defaultgroup", 1);
 97:         $oGroups->query();
 98: 
 99:         while ($oGroup = $oGroups->next()) {
100:             $iIDGroup = $oGroup->get("idnewsgroup");
101:             $oGroupMembers->create($iIDGroup, $iIDRcp);
102:         }
103: 
104:         // Add to other recipient groups as well? Do so!
105:         if ($sJoinID != "") {
106:             $aJoinID = explode(",", $sJoinID);
107: 
108:             if (count($aJoinID) > 0) {
109:                 foreach ($aJoinID as $iIDGroup) {
110:                     $oGroupMembers->create($iIDGroup, $iIDRcp);
111:                 }
112:             }
113:         }
114: 
115:         return $oItem;
116:     }
117: 
118:     /**
119:      * Overridden delete method to remove recipient from groupmember table
120:      * before deleting recipient
121:      *
122:      * @param $itemID int specifies the recipient
123:      *
124:      * @throws cDbException
125:      * @throws cException
126:      * @throws cInvalidArgumentException
127:      */
128:     public function delete($itemID) {
129:         $oAssociations = new NewsletterRecipientGroupMemberCollection();
130:         $oAssociations->setWhere("idnewsrcp", $itemID);
131:         $oAssociations->query();
132: 
133:         While ($oItem = $oAssociations->next()) {
134:             $oAssociations->delete($oItem->get("idnewsgroupmember"));
135:         }
136:         parent::delete($itemID);
137:     }
138: 
139:     /**
140:      * Purge method to delete recipients which hasn't been confirmed since over
141:      * a month
142:      *
143:      * @param $timeframe int Days after creation a not confirmed recipient will
144:      *                   be removed
145:      *
146:      * @return int Count of deleted recipients
147:      * @throws cDbException
148:      * @throws cException
149:      * @throws cInvalidArgumentException
150:      */
151:     public function purge($timeframe) {
152:         global $client, $lang;
153: 
154:         $oRecipientCollection = new NewsletterRecipientCollection();
155: 
156:         // DATEDIFF(created, NOW()) > 30 would be better, but it's only
157:         // available in MySQL V4.1.1 and above
158:         // Note, that, TO_DAYS or NOW may not be available in other database
159:         // systems than MySQL
160:         $oRecipientCollection->setWhere("idclient", $client);
161:         $oRecipientCollection->setWhere("idlang", $lang);
162:         $oRecipientCollection->setWhere("confirmed", 0);
163:         $oRecipientCollection->setWhere("(TO_DAYS(NOW()) - TO_DAYS(created))", $timeframe, ">");
164:         $oRecipientCollection->query();
165: 
166:         while ($oItem = $oRecipientCollection->next()) {
167:             $oRecipientCollection->delete($oItem->get("idnewsrcp"));
168:         }
169:         return $oRecipientCollection->count();
170:     }
171: 
172:     /**
173:      * checkEMail returns true, if there is no recipient with the same e-mail
174:      * address; otherwise false
175:      *
176:      * @param $sEmail string e-mail
177:      *
178:      * @return NewsletterRecipient|false recpient item if item with e-mail exists, false otherwise
179:      * @throws cException
180:      */
181:     public function emailExists($sEmail) {
182:         global $client, $lang;
183: 
184:         $oRecipientCollection = new NewsletterRecipientCollection();
185:         $oRecipientCollection->setWhere("idclient", $client);
186:         $oRecipientCollection->setWhere("idlang", $lang);
187:         $oRecipientCollection->setWhere("email", cString::toLowerCase($sEmail));
188:         $oRecipientCollection->query();
189: 
190:         if ($oItem = $oRecipientCollection->next()) {
191:             return $oItem;
192:         } else {
193:             return false;
194:         }
195:     }
196: 
197:     /**
198:      * Sets a key for all recipients without key or an old key (len(key) <> 30)
199:      *
200:      * @return int
201:      * @throws cDbException
202:      * @throws cException
203:      */
204:     public function updateKeys() {
205:         $this->setWhere("LENGTH(hash)", 30, "<>");
206:         $this->query();
207: 
208:         $iUpdated = $this->count();
209:         while ($oItem = $this->next()) {
210:             $oItem->set("hash", cString::getPartOfString(md5(rand()), 0, 17) . uniqid("")); /*
211:                                                                          *
212:                                                                          * Generating
213:                                                                          * UID,
214:                                                                          * 30
215:                                                                          * characters
216:                                                                          */
217:             $oItem->store();
218:         }
219: 
220:         return $iUpdated;
221:     }
222: 
223: }
224: 
225: /**
226:  * Single Recipient Item
227:  */
228: class NewsletterRecipient extends Item {
229:     /**
230:      * Constructor Function
231:      *
232:      * @param mixed $mId Specifies the ID of item to load
233:      *
234:      * @throws cDbException
235:      * @throws cException
236:      */
237:     public function __construct($mId = false) {
238:         global $cfg;
239:         parent::__construct($cfg["tab"]["news_rcp"], "idnewsrcp");
240:         if ($mId !== false) {
241:             $this->loadByPrimaryKey($mId);
242:         }
243:     }
244: 
245:     /**
246:      * @return bool
247:      * @throws cDbException
248:      * @throws cException
249:      */
250:     public function store() {
251:         global $auth;
252: 
253:         $this->set("lastmodified", date('Y-m-d H:i:s'), false);
254:         $this->set("modifiedby", $auth->auth["uid"]);
255:         $success = parent::store();
256: 
257:         // @todo do update below only if code from abve was successfull
258: 
259:         // Update name, email and newsletter type for recipients in pending
260:         // newsletter jobs
261:         $sName = $this->get("name");
262:         $sEmail = $this->get("email");
263:         if ($sName == "") {
264:             $sName = $sEmail;
265:         }
266:         $iNewsType = $this->get("news_type");
267: 
268:         $oLogs = new NewsletterLogCollection();
269:         $oLogs->setWhere("idnewsrcp", $this->get($this->getPrimaryKeyName()));
270:         $oLogs->setWhere("status", "pending");
271:         $oLogs->query();
272: 
273:         while ($oLog = $oLogs->next()) {
274:             $oLog->set("rcpname", $sName);
275:             $oLog->set("rcpemail", $sEmail);
276:             $oLog->set("rcpnewstype", $iNewsType);
277:             $oLog->store();
278:         }
279: 
280:         return $success;
281:     }
282: 
283:     /**
284:      * Userdefined setter for newsletter recipients fields.
285:      *
286:      * @param string $name
287:      * @param mixed  $value
288:      * @param bool   $bSafe Flag to run defined inFilter on passed value
289:      *
290:      * @return bool
291:      */
292:     public function setField($name, $value, $bSafe = true) {
293:         switch ($name) {
294:             case 'confirmed':
295:                 $value = (int) $value;
296:                 break;
297:             case 'news_type':
298:                 $value = (int) $value;
299:                 break;
300:         }
301: 
302:         return parent::setField($name, $value, $bSafe);
303:     }
304: 
305: }
306: 
307: ?>
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0