Exemplo n.º 1
0
 public function sendNewsletterAction()
 {
     $releaseID = $this->_getParam('newsletterID');
     $this->view->assign('releaseID', $releaseID);
     if ($this->_request->isPost()) {
         $this->_redirect("/newsletter/index/edit/newsletterID/{$releaseID}");
     } elseif (empty($releaseID)) {
         /*
          * The following part of code is to send data with CRON task.
          * Code not finished. To be implemented in further version.
          */
         $this->disableView();
         //            $releaseId  = $this->_getParam('newsletterID');
         $oNewsRelease = new NewsletterReleases();
         $primary = $oNewsRelease->info('primary');
         $select = $oNewsRelease->select()->from($oNewsRelease->info('name'));
         $nrData = $oNewsRelease->fetchAll($select)->toArray();
         $listSent = array();
         $listDest = array();
         $listIds = array();
         foreach ($nrData as $release) {
             $scheduled = $release['NR_MailingDateTimeScheduled'];
             $oDate = new Zend_Date($scheduled, 'fr');
             $now = Zend_Date::now('fr')->getTimestamp();
             $timeToSend = $oDate->compareTimestamp($now);
             if ($timeToSend < 1 && (int) $release['NR_Status'] != 1 && $oDate->get() > 0) {
                 $massMailingResults = $this->sendMassMailingAction($release['NR_ID']);
                 array_push($listSent, $release['NR_Title']);
                 array_push($listIds, $release['NR_ID']);
                 array_push($listDest, $release['NR_AdminEmail']);
             }
         }
         if (!empty($listDest) || !empty($listSent) || !empty($listIds)) {
             $data = array('list' => $listSent, 'dest' => $listDest, 'ids' => $listIds);
             $this->_adminNotification($data);
             $this->_logSending($data);
         }
     }
 }