public function getListItems() { if (!isset($this->_listItems, $this->_sentCount)) { $allListItems = CampaignMailingBehavior::deliverableItems($this->campaign->list->id); $this->_listItems = array(); $this->_sentCount = 0; foreach ($allListItems as $listItem) { if ($listItem['sent'] == 0) { $this->_listItems[] = $listItem['id']; } else { $this->_sentCount++; } } } return $this->_listItems; }
public function testDeliverableItems() { $listItems = CampaignMailingBehavior::deliverableItems($this->lists('launchedEmailCampaign')->id); $this->assertEquals(array(array('id' => '252', 'sent' => '0', 'uniqueId' => NULL), array('id' => '253', 'sent' => '0', 'uniqueId' => NULL), array('id' => '254', 'sent' => '0', 'uniqueId' => NULL)), $listItems); }
/** * Send mail for any active campaigns, in a batch. * * This method is made public and static to allow it to be called from elsewhere, * without instantiation. * * @param integer $id The ID of the campaign to return status messages for */ public static function sendMail($id = null, $t0 = null) { self::$batchTime = $t0 === null ? time() : $t0; $admin = Yii::app()->settings; $messages = array(); $totalSent = 0; try { // Get all campaigns that could use mailing $campaigns = Campaign::model()->findAllByAttributes(array('complete' => 0, 'active' => 1, 'type' => 'Email'), 'launchdate > 0 AND launchdate < :time', array(':time' => time())); foreach ($campaigns as $campaign) { try { list($sent, $errors) = self::campaignMailing($campaign); } catch (CampaignMailingException $e) { $totalSent += $e->return[0]; $messages = array_merge($messages, $e->return[1]); $messages[] = Yii::t('marketing', 'Successful email sent') . ': ' . $totalSent; $wait = $admin->emailInterval + $admin->emailStartTime - time(); return array('wait' => $wait, 'messages' => $messages); } $messages = array_merge($messages, $errors); $totalSent += $sent; if (time() - self::$batchTime > Yii::app()->settings->batchTimeout) { break; } } if (count($campaigns) == 0) { $messages[] = Yii::t('marketing', 'There is no campaign email to send.'); } } catch (Exception $e) { $messages[] = $e->getMessage(); } $messages[] = $totalSent == 0 ? Yii::t('marketing', 'No email sent.') : Yii::t('marketing', 'Successful email sent') . ': ' . $totalSent; $wait = $admin->emailInterval + $admin->emailStartTime - time(); return array('wait' => $wait, 'messages' => $messages); }