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