Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Bjoern Behrens
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  *
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: /**
 20:  * Newsletter Collection class.
 21:  *
 22:  * @package Plugin
 23:  * @subpackage Newsletter
 24:  */
 25: class NewsletterRecipientCollection extends ItemCollection {
 26: 
 27:     /**
 28:      * Constructor Function
 29:      *
 30:      * @param none
 31:      */
 32:     public function __construct() {
 33:         global $cfg;
 34:         parent::__construct($cfg["tab"]["news_rcp"], "idnewsrcp");
 35:         $this->_setItemClass("NewsletterRecipient");
 36:     }
 37: 
 38:     /**
 39:      * Creates a new recipient
 40:      *
 41:      * @param string $sEMail Specifies the e-mail adress
 42:      * @param string $sName Specifies the recipient name (optional)
 43:      * @param int $iConfirmed Specifies, if the recipient is confirmed
 44:      *            (optional)
 45:      * @param string $sJoinID Specifies additional recipient group ids to join
 46:      *            (optional, e.g. 47,12,...)
 47:      * @param int $iMessageType Specifies the message type for the recipient (0
 48:      *            = text, 1 = html)
 49:      */
 50:     public function create($sEMail, $sName = "", $iConfirmed = 0, $sJoinID = "", $iMessageType = 0) {
 51:         global $client, $lang, $auth;
 52: 
 53:         $iConfirmed = (int) $iConfirmed;
 54:         $iMessageType = (int) $iMessageType;
 55: 
 56:         /* Check if the e-mail adress already exists */
 57:         $email = strtolower($email); // e-mail always lower case
 58:         $this->setWhere("idclient", $client);
 59:         $this->setWhere("idlang", $lang);
 60:         $this->setWhere("email", $sEMail);
 61:         $this->query();
 62: 
 63:         if ($this->next()) {
 64:             return $this->create($sEMail . "_" . substr(md5(rand()), 0, 10), $sName, 0, $sJoinID, $iMessageType); // 0:
 65:                                                                                                             // Deactivate
 66:                                                                                                             // 'confirmed'
 67:         }
 68:         $oItem = parent::createNewItem();
 69:         $oItem->set("idclient", $client);
 70:         $oItem->set("idlang", $lang);
 71:         $oItem->set("name", $sName);
 72:         $oItem->set("email", $sEMail);
 73:         $oItem->set("hash", substr(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:     public function delete($itemID) {
125:         $oAssociations = new NewsletterRecipientGroupMemberCollection();
126:         $oAssociations->setWhere("idnewsrcp", $itemID);
127:         $oAssociations->query();
128: 
129:         While ($oItem = $oAssociations->next()) {
130:             $oAssociations->delete($oItem->get("idnewsgroupmember"));
131:         }
132:         parent::delete($itemID);
133:     }
134: 
135:     /**
136:      * Purge method to delete recipients which hasn't been confirmed since over
137:      * a month
138:      *
139:      * @param $timeframe int Days after creation a not confirmed recipient will
140:      *            be removed
141:      * @return int Count of deleted recipients
142:      */
143:     public function purge($timeframe) {
144:         global $client, $lang;
145: 
146:         $oRecipientCollection = new NewsletterRecipientCollection();
147: 
148:         // DATEDIFF(created, NOW()) > 30 would be better, but it's only
149:         // available in MySQL V4.1.1 and above
150:         // Note, that, TO_DAYS or NOW may not be available in other database
151:         // systems than MySQL
152:         $oRecipientCollection->setWhere("idclient", $client);
153:         $oRecipientCollection->setWhere("idlang", $lang);
154:         $oRecipientCollection->setWhere("confirmed", 0);
155:         $oRecipientCollection->setWhere("(TO_DAYS(NOW()) - TO_DAYS(created))", $timeframe, ">");
156:         $oRecipientCollection->query();
157: 
158:         while ($oItem = $oRecipientCollection->next()) {
159:             $oRecipientCollection->delete($oItem->get("idnewsrcp"));
160:         }
161:         return $oRecipientCollection->count();
162:     }
163: 
164:     /**
165:      * checkEMail returns true, if there is no recipient with the same e-mail
166:      * address; otherwise false
167:      *
168:      * @param $email string e-mail
169:      * @return recpient item if item with e-mail exists, false otherwise
170:      */
171:     public function emailExists($sEmail) {
172:         global $client, $lang;
173: 
174:         $oRecipientCollection = new NewsletterRecipientCollection();
175: 
176:         $oRecipientCollection->setWhere("idclient", $client);
177:         $oRecipientCollection->setWhere("idlang", $lang);
178:         $oRecipientCollection->setWhere("email", strtolower($sEmail));
179:         $oRecipientCollection->query();
180: 
181:         if ($oItem = $oRecipientCollection->next()) {
182:             return $oItem;
183:         } else {
184:             return false;
185:         }
186:     }
187: 
188:     /**
189:      * Sets a key for all recipients without key or an old key (len(key) <> 30)
190:      *
191:      * @param none
192:      */
193:     public function updateKeys() {
194:         $this->setWhere("LENGTH(hash)", 30, "<>");
195:         $this->query();
196: 
197:         $iUpdated = $this->count();
198:         while ($oItem = $this->next()) {
199:             $oItem->set("hash", substr(md5(rand()), 0, 17) . uniqid("")); /*
200:                                                                          *
201:                                                                          * Generating
202:                                                                          * UID,
203:                                                                          * 30
204:                                                                          * characters
205:                                                                          */
206:             $oItem->store();
207:         }
208: 
209:         return $iUpdated;
210:     }
211: 
212: }
213: 
214: /**
215:  * Single Recipient Item
216:  */
217: class NewsletterRecipient extends Item {
218: 
219:     /**
220:      * Constructor Function
221:      *
222:      * @param mixed $mId Specifies the ID of item to load
223:      */
224:     public function __construct($mId = false) {
225:         global $cfg;
226:         parent::__construct($cfg["tab"]["news_rcp"], "idnewsrcp");
227:         if ($mId !== false) {
228:             $this->loadByPrimaryKey($mId);
229:         }
230:     }
231: 
232:     public function store() {
233:         global $auth;
234: 
235:         $this->set("lastmodified", date('Y-m-d H:i:s'), false);
236:         $this->set("modifiedby", $auth->auth["uid"]);
237:         $success = parent::store();
238: 
239:         // @todo do update below only if code from abve was successfull
240: 
241:         // Update name, email and newsletter type for recipients in pending
242:         // newsletter jobs
243:         $sName = $this->get("name");
244:         $sEmail = $this->get("email");
245:         if ($sName == "") {
246:             $sName = $sEmail;
247:         }
248:         $iNewsType = $this->get("news_type");
249: 
250:         $oLogs = new NewsletterLogCollection();
251:         $oLogs->setWhere("idnewsrcp", $this->get($this->primaryKey));
252:         $oLogs->setWhere("status", "pending");
253:         $oLogs->query();
254: 
255:         while ($oLog = $oLogs->next()) {
256:             $oLog->set("rcpname", $sName);
257:             $oLog->set("rcpemail", $sEmail);
258:             $oLog->set("rcpnewstype", $iNewsType);
259:             $oLog->store();
260:         }
261: 
262:         return $success;
263:     }
264: 
265: }
266: 
267: ?>
CMS CONTENIDO 4.9.3 API documentation generated by ApiGen 2.8.0