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 log 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:  * Newsletter log class.
 18:  *
 19:  * @package Plugin
 20:  * @subpackage Newsletter
 21:  * @method NewsletterLog createNewItem
 22:  * @method NewsletterLog next
 23:  */
 24: class NewsletterLogCollection extends ItemCollection {
 25:     /**
 26:      * Constructor Function
 27:      *
 28:      * @throws cInvalidArgumentException
 29:      */
 30:     public function __construct() {
 31:         global $cfg;
 32:         parent::__construct($cfg["tab"]["news_log"], "idnewslog");
 33:         $this->_setItemClass("NewsletterLog");
 34:     }
 35: 
 36:     /**
 37:      * Creates a single new log item
 38:      *
 39:      * @param $idnewsjob integer ID of corresponding newsletter send job
 40:      * @param $idnewsrcp integer ID of recipient
 41:      *
 42:      * @return bool|Item
 43:      * @throws cDbException
 44:      * @throws cException
 45:      * @throws cInvalidArgumentException
 46:      */
 47:     public function create($idnewsjob, $idnewsrcp) {
 48: 
 49:         $this->resetQuery();
 50:         $this->setWhere("idnewsjob", $idnewsjob);
 51:         $this->setWhere("idnewsrcp", $idnewsrcp);
 52:         $this->query();
 53: 
 54:         if ($oItem = $this->next()) {
 55:             return $oItem;
 56:         }
 57: 
 58:         $oRecipient = new NewsletterRecipient();
 59:         if ($oRecipient->loadByPrimaryKey($idnewsrcp)) {
 60:             $oItem = $this->createNewItem();
 61: 
 62:             $oItem->set("idnewsjob", $idnewsjob);
 63:             $oItem->set("idnewsrcp", $idnewsrcp);
 64: 
 65:             $sEMail = $oRecipient->get("email");
 66:             $sName = $oRecipient->get("name");
 67: 
 68:             if ($sName == "") {
 69:                 $oItem->set("rcpname", $sEMail);
 70:             } else {
 71:                 $oItem->set("rcpname", $sName);
 72:             }
 73: 
 74:             $oItem->set("rcpemail", $sEMail);
 75:             $oItem->set("rcphash", $oRecipient->get("hash"));
 76:             $oItem->set("rcpnewstype", $oRecipient->get("news_type"));
 77:             $oItem->set("status", "pending");
 78:             $oItem->set("created", date('Y-m-d H:i:s'), false);
 79:             $oItem->store();
 80: 
 81:             return $oItem;
 82:         } else {
 83:             return false;
 84:         }
 85:     }
 86: 
 87:     /**
 88:      * Gets all active recipients as specified for the newsletter and adds for
 89:      * every recipient a log item
 90:      *
 91:      * @param  int $idnewsjob ID of corresponding newsletter dispatch job
 92:      * @param  int $idnews    ID of newsletter
 93:      *
 94:      * @return  int  Recipient count
 95:      * @throws cDbException
 96:      * @throws cException
 97:      * @throws cInvalidArgumentException
 98:      */
 99:     public function initializeJob($idnewsjob, $idnews) {
100:         global $cfg;
101: 
102:         $idnewsjob = cSecurity::toInteger($idnewsjob);
103:         $idnews = cSecurity::toInteger($idnews);
104: 
105:         $oNewsletter = new Newsletter();
106:         if ($oNewsletter->loadByPrimaryKey($idnews)) {
107:             $sDestination = $oNewsletter->get("send_to");
108:             $iIDClient = $oNewsletter->get("idclient");
109:             $iIDLang = $oNewsletter->get("idlang");
110:             $nrc = new NewsletterRecipientCollection();
111:             $nrcClassName = cString::toLowerCase(get_class($nrc));
112:             
113:             switch ($sDestination) {
114:                 case "all":
115:                     $sDistinct = "";
116:                     $sFrom = "";
117:                     $sSQL = "deactivated='0' AND confirmed='1' AND idclient='" . $iIDClient . "' AND idlang='" . $iIDLang . "'";
118:                     break;
119:                 case "default":
120:                     $sDistinct = "distinct";
121:                     $sFrom = $cfg["tab"]["news_groups"] . " AS groups, " . $cfg["tab"]["news_groupmembers"] . " AS groupmembers ";
122:                     $sSQL = $nrcClassName . ".idclient = '" . $iIDClient . "' AND " . $nrcClassName . ".idlang = '" . $iIDLang . "' AND " . $nrcClassName . ".deactivated = '0' AND " . $nrcClassName . ".confirmed = '1' AND " . $nrcClassName . ".idnewsrcp = groupmembers.idnewsrcp AND " . "groupmembers.idnewsgroup = groups.idnewsgroup AND " . "groups.defaultgroup = '1' AND groups.idclient = '" . $iIDClient . "' AND " . "groups.idlang = '" . $iIDLang . "'";
123:                     break;
124:                 case "selection":
125:                     $aGroups = unserialize($oNewsletter->get("send_ids"));
126: 
127:                     if (is_array($aGroups) && count($aGroups) > 0) {
128:                         $sGroups = "'" . implode("','", $aGroups) . "'";
129: 
130:                         $sDistinct = "distinct";
131:                         $sFrom = $cfg["tab"]["news_groupmembers"] . " AS groupmembers ";
132:                         $sSQL = "newsletterrecipientcollection.idclient = '" . $iIDClient . "' AND newsletterrecipientcollection.idlang = '" . $iIDLang . "' AND newsletterrecipientcollection.deactivated = '0' AND newsletterrecipientcollection.confirmed = '1' AND newsletterrecipientcollection.idnewsrcp = groupmembers.idnewsrcp AND " . "groupmembers.idnewsgroup IN (" . $sGroups . ")";
133:                     } else {
134:                         $sDestination = "unknown";
135:                     }
136:                     break;
137:                 case "single":
138:                     $iID = $oNewsletter->get("send_ids");
139:                     if (is_numeric($iID)) {
140:                         $sDistinct = "";
141:                         $sFrom = "";
142:                         $sSQL = "idnewsrcp = '" . $iID . "'";
143:                     } else {
144:                         $sDestination = "unknown";
145:                     }
146:                     break;
147:                 default:
148:                     $sDestination = "unknown";
149:             }
150:             unset($oNewsletter);
151: 
152:             if ($sDestination == "unknown") {
153:                 return 0;
154:             } else {
155:                 $oRecipients = new NewsletterRecipientCollection();
156:                 $oRecipients->flexSelect($sDistinct, $sFrom, $sSQL, "", "", "");
157: 
158:                 $iRecipients = $oRecipients->count();
159: 
160:                 while ($oRecipient = $oRecipients->next()) {
161:                     $this->create($idnewsjob, $oRecipient->get($oRecipient->getPrimaryKeyName()));
162:                 }
163: 
164:                 return $iRecipients;
165:             }
166:         } else {
167:             return 0;
168:         }
169:     }
170: 
171:     /**
172:      * Overriden delete function to update recipient count if removing recipient
173:      * from the list
174:      *
175:      * @param int $idnewslog ID
176:      */
177:     public function delete($idnewslog) {
178:         $idnewslog = cSecurity::toInteger($idnewslog);
179: 
180:         $oLog = new NewsletterLog($idnewslog);
181:         $iIDNewsJob = $oLog->get("idnewsjob");
182:         unset($oLog);
183: 
184:         $oJob = new NewsletterJob($iIDNewsJob);
185:         $oJob->set("rcpcount", $oJob->get("rcpcount") - 1);
186:         $oJob->store();
187:         unset($oJob);
188: 
189:         parent::delete($idnewslog);
190:     }
191: 
192:     /**
193:      * @param $idnewsjob
194:      *
195:      * @return bool
196:      * @throws cException
197:      */
198:     public function deleteJob($idnewsjob) {
199:         $idnewsjob = cSecurity::toInteger($idnewsjob);
200:         $this->setWhere("idnewsjob", $idnewsjob);
201:         $this->query();
202: 
203:         while ($oItem = $this->next()) {
204:             $this->delete($oItem->get($oItem->getPrimaryKeyName()));
205:         }
206: 
207:         return true;
208:     }
209: 
210: }
211: 
212: /**
213:  * Single NewsletterLog Item
214:  */
215: class NewsletterLog extends Item {
216:     /**
217:      * Constructor Function
218:      *
219:      * @param mixed $mId Specifies the ID of item to load
220:      *
221:      * @throws cDbException
222:      * @throws cException
223:      */
224:     public function __construct($mId = false) {
225:         global $cfg;
226:         parent::__construct($cfg["tab"]["news_log"], "idnewslog");
227:         if ($mId !== false) {
228:             $this->loadByPrimaryKey($mId);
229:         }
230:     }
231: 
232:     /**
233:      * Userdefined setter for newsletter logs fields.
234:      *
235:      * @param string $name
236:      * @param mixed  $value
237:      * @param bool   $bSafe Flag to run defined inFilter on passed value
238:      *
239:      * @return bool
240:      */
241:     public function setField($name, $value, $bSafe = true) {
242:         switch ($name) {
243:             case 'idnewsjob':
244:                 $value = (int) $value;
245:                 break;
246:             case 'idnewsrcp':
247:                 $value = (int) $value;
248:                 break;
249:         }
250: 
251:         return parent::setField($name, $value, $bSafe);
252:     }
253: 
254: }
255: 
256: ?>
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0