public function __construct($aRequestPath)
 {
     parent::__construct($aRequestPath);
     $sBase = Manager::usePath();
     $iId = Manager::usePath();
     // Base path "newsletter" > display newsletter
     if ($sBase === 'newsletter') {
         $iId = is_numeric($sBase) ? $sBase : $iId;
         $this->oNewsletter = NewsletterQuery::create()->findPk($iId);
         if ($this->oNewsletter === null) {
             throw new Exception('No such newsletter exists');
         }
     } else {
         if ($sBase === 'mailing') {
             $this->oMailing = NewsletterMailingQuery::create()->findPk($iId);
             if ($this->oMailing === null) {
                 throw new Exception('No such mailing exists');
             }
             $this->oNewsletter = $this->oMailing->getNewsletter();
         } elseif (is_numeric($sBase)) {
             $this->oNewsletter = NewsletterQuery::create()->findPk($sBase);
         }
     }
     // Throw exception if no newsletter is found
     if ($this->oNewsletter === null) {
         throw new Exception('Error in DisplayNewsletterFileModule::__construct(): No such newsletter exists');
     }
     // Optional handling of authentication
     FilterModule::getFilters()->handleNewsletterDisplayRequested($this->oNewsletter);
 }
 private function getNewsletterMailings()
 {
     $aResult = array();
     $aSubscriberGroups = SubscriberGroupQuery::create()->distinct()->joinNewsletterMailing(null, Criteria::INNER_JOIN)->orderByName()->find();
     foreach ($aSubscriberGroups as $oSubscriberGroup) {
         $aNewsletterMailing = NewsletterMailingQuery::create()->filterByNewsletterId($this->iNewsletterId)->orderByCreatedAt(Criteria::DESC)->filterBySubscriberGroup($oSubscriberGroup)->find();
         $iCountMailings = count($aNewsletterMailing);
         $bHasMailing = $iCountMailings > 0;
         if ($bHasMailing) {
             $aSubscriberGroup = array('UserInitials' => array(), 'DateSent' => array(), 'RecipientCount' => array());
             foreach ($aNewsletterMailing as $i => $oNewsletterMailing) {
                 $sAdditionalMailingCount = '';
                 // Fill Groupname only once
                 if ($i === 0) {
                     if ($oNewsletterMailing->getSubscriberGroupName()) {
                         $aSubscriberGroup['MailGroupName'] = $oNewsletterMailing->getSubscriberGroupName();
                         $aSubscriberGroup['MailGroupType'] = TranslationPeer::getString('wns.mail_group.subscribers');
                     } else {
                         $aSubscriberGroup['MailGroupName'] = $oNewsletterMailing->getMailGroupId();
                         $aSubscriberGroup['MailGroupType'] = TranslationPeer::getString('wns.mail_group.external');
                     }
                     if ($iCountMailings - 1 > 0) {
                         $sAdditionalMailingCount = ' (+' . ($iCountMailings - 1) . ')';
                     }
                 } else {
                     continue;
                 }
                 // Fill all mailing infos
                 $aSubscriberGroup['UserInitials'][] = $oNewsletterMailing->getUserRelatedByCreatedBy() ? $oNewsletterMailing->getUserRelatedByCreatedBy()->getInitials() : '';
                 $aSubscriberGroup['DateSent'][] = $oNewsletterMailing->getDateSentFormatted('H:i') . $sAdditionalMailingCount;
                 $aSubscriberGroup['RecipientCount'][] = $oNewsletterMailing->getRecipientCount();
                 $aSubscriberGroup['CountAdditionalMailings'] = null;
             }
             $aResult[] = $aSubscriberGroup;
         }
     }
     return $aResult;
 }
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Newsletter is new, it will return
  * an empty collection; or if this Newsletter has previously
  * been saved, it will retrieve related NewsletterMailings from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in Newsletter.
  *
  * @param Criteria $criteria optional Criteria object to narrow the query
  * @param PropelPDO $con optional connection object
  * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return PropelObjectCollection|NewsletterMailing[] List of NewsletterMailing objects
  */
 public function getNewsletterMailingsJoinUserRelatedByUpdatedBy($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = NewsletterMailingQuery::create(null, $criteria);
     $query->joinWith('UserRelatedByUpdatedBy', $join_behavior);
     return $this->getNewsletterMailings($query, $con);
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(NewsletterMailingPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = NewsletterMailingQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // denyable behavior
         if (!(NewsletterMailingPeer::isIgnoringRights() || $this->mayOperate("delete"))) {
             throw new PropelException(new NotPermittedException("delete.by_role", array("role_key" => "newsletter_mailings")));
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Example #5
0
 public function getLastMailing()
 {
     return NewsletterMailingQuery::create()->filterByNewsletter($this)->orderByCreatedAt(Criteria::DESC)->findOne();
 }
 public function getSubscriberGroupHasNewsletterMailings($iSubscriberGroupId)
 {
     return NewsletterMailingQuery::create()->filterBySubscriberGroupId($iSubscriberGroupId)->count() > 0;
 }
 /**
  * Returns a new NewsletterMailingQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   NewsletterMailingQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return NewsletterMailingQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof NewsletterMailingQuery) {
         return $criteria;
     }
     $query = new NewsletterMailingQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }