From cf08f809315e8afbdea5cf2c1d11ae215efe554d Mon Sep 17 00:00:00 2001
From: dogmatic69
', '
', '
'), "\n\r", implode("\n", array( + $mail['NewsletterTemplate']['header'], + $mail['Newsletter']['text'], + $mail['NewsletterTemplate']['footer'] + )))), + 'viewVars' => $email['var'] + )); + + if (!$sent) { + return false; + } + + return true; + } } \ No newline at end of file diff --git a/Core/Newsletter/Model/Newsletter.php b/Core/Newsletter/Model/Newsletter.php index ded1c3fde..a9f6ae6a6 100755 --- a/Core/Newsletter/Model/Newsletter.php +++ b/Core/Newsletter/Model/Newsletter.php @@ -48,7 +48,8 @@ class Newsletter extends NewsletterAppModel { 'toSend' => true, 'paginated' => true, 'preview' => true, - 'deleteable' => true + 'deleteable' => true, + 'email' => true ); /** @@ -81,7 +82,7 @@ public function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); $this->order = array( - $this->alias . '.' . $this->displayField => 'asc' + $this->alias . '.slug' => 'asc' ); $this->validate = array( @@ -103,7 +104,7 @@ public function __construct($id = false, $table = null, $ds = null) { 'message' => __d('newsletter', 'Please enter the from address') ), 'email' => array( - 'rule' => array( 'email', true ), + 'rule' => array('email', true), 'message' => __d('newsletter', 'Please enter a valid email addres') ) ), @@ -138,10 +139,20 @@ public function __construct($id = false, $table = null, $ds = null) { ); } +/** + * General find + * + * @param string $state + * @param array $query + * @param array $results + * + * @return array + */ protected function _findPaginated($state, array $query, array $results = array()) { if ($state == 'before') { $query['fields'] = array_merge((array)$query['fields'], array( $this->alias . '.' . $this->primaryKey, + $this->alias . '.slug', $this->alias . '.newsletter_campaign_id', $this->alias . '.from', $this->alias . '.reply_to', @@ -149,21 +160,28 @@ protected function _findPaginated($state, array $query, array $results = array() $this->alias . '.active', $this->alias . '.sent', $this->alias . '.created', - )); - $query['contain'] = array_merge((array)$query['fields'], array( - 'NewsletterCampaign' => array( - 'fields' => array( - 'NewsletterCampaign.name' - ) - ) + $this->NewsletterCampaign->alias . '.' . $this->NewsletterCampaign->displayField )); + + $query['joins'] = (array)$query['joins']; + $query['joins'][] = $this->autoJoinModel($this->NewsletterCampaign); + return $query; } return $results; } +/** + * Find only active newsletters + * + * @param string $state + * @param array $query + * @param array $results + * + * @return array + */ protected function _findActive($state, array $query, array $results = array()) { if ($state == 'before') { $query['fields'] = array_merge((array)$query['fields'], array( @@ -196,11 +214,23 @@ protected function _findActive($state, array $query, array $results = array()) { return $results; } +/** + * Find preview data + * + * @param string $state + * @param array $query + * @param array $results + * + * @return array + * + * @throws InvalidArgumentException + */ protected function _findPreview($state, array $query, array $results = array()) { if ($state == 'before') { if (empty($query[0])) { throw new InvalidArgumentException(__d('newsletter', 'Invalid newsletter selected')); } + $query['fields'] = array_merge((array)$query['fields'], array( $this->alias . '.' . $this->primaryKey, $this->alias . '.html', @@ -218,6 +248,7 @@ protected function _findPreview($state, array $query, array $results = array()) $query['limit'] = 1; return $query; } + if (empty($results[0])) { return array(); } @@ -228,6 +259,8 @@ protected function _findPreview($state, array $query, array $results = array()) /** * Get newsletters that can be deleted safely * + * This method takes list of `ids` and returns a list of ids that can be safely removed. + * * @param string $state * @param array $query * @param array $results @@ -236,7 +269,7 @@ protected function _findPreview($state, array $query, array $results = array()) * * @throws InvalidArgumentException */ - protected function _findDeletable($state, array $query, array $results = array()) { + protected function _findDeleteable($state, array $query, array $results = array()) { if ($state == 'before') { if (empty($query['ids'])) { throw new InvalidArgumentException(__d('newsletter', 'No newsletters selected')); @@ -262,6 +295,41 @@ protected function _findDeletable($state, array $query, array $results = array() return $results; } + protected function _findEmail($state, array $query, array $results = array()) { + if ($state == 'before') { + if (empty($query[0])) { + throw new CakeException(__d('newsletter', 'No email selected')); + } + + $query['fields'] = array_merge((array)$query['fields'], array( + $this->alias . '.' . $this->primaryKey, + $this->alias . '.from', + $this->alias . '.reply_to', + $this->alias . '.subject', + $this->alias . '.html', + $this->alias . '.text', + + $this->NewsletterTemplate->alias . '.header', + $this->NewsletterTemplate->alias . '.footer', + )); + + $query['conditions'] = array_merge((array)$query['conditions'], array( + $this->alias . '.slug' => $query[0] + )); + + $query['joins'] = (array)$query['joins']; + $query['joins'][] = $this->autoJoinModel($this->NewsletterTemplate); + + $query['limit'] = 1; + return $query; + } + if (empty($results[0])) { + throw new CakeException(__d('newsletter', 'No email found')); + } + + return $results[0]; + } + /** * toggle the send status * diff --git a/Core/Newsletter/View/Newsletters/admin_form.ctp b/Core/Newsletter/View/Newsletters/admin_form.ctp index f0e46328f..dfc42d743 100755 --- a/Core/Newsletter/View/Newsletters/admin_form.ctp +++ b/Core/Newsletter/View/Newsletters/admin_form.ctp @@ -32,6 +32,7 @@ echo $this->Form->create('Newsletter'); 'class' => 'span9' )), $this->Html->tag('div', implode('', array( + $this->Form->input('slug'), $this->Form->input('campaign_id', array( 'empty' => Configure::read('Website.empty_select') )), diff --git a/Core/Newsletter/View/Newsletters/admin_index.ctp b/Core/Newsletter/View/Newsletters/admin_index.ctp index 0ae749746..2bba90d4f 100755 --- a/Core/Newsletter/View/Newsletters/admin_index.ctp +++ b/Core/Newsletter/View/Newsletters/admin_index.ctp @@ -35,6 +35,7 @@ $this->Form->checkbox('all') => array( 'class' => 'first' ), + $this->Paginator->sort('slug', __d('newsletter', 'Alias')), $this->Paginator->sort('subject'), $this->Paginator->sort('NewsletterCampaign.name', __d('newsletter', 'Campaign')) => array( 'class' => 'larger' @@ -54,6 +55,14 @@ ?>