Skip to content

Commit

Permalink
Merge branch 'newsletter-update' of git://github.com/BigHeadCreations…
Browse files Browse the repository at this point in the history
…/infinitas into dev
  • Loading branch information
dogmatic69 committed Oct 1, 2012
2 parents a3a7ef4 + b46842d commit 3b67418
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 17 deletions.
1 change: 1 addition & 0 deletions Config/bootstrap.php
Expand Up @@ -38,6 +38,7 @@
App::uses('ModelBehavior', 'Model');
App::uses('AppController', 'Controller');
App::uses('AppHelper', 'View/Helper');
App::uses('InfinitasEmail', 'Core/Emails/Network/Email');

App::uses('ClearCache', 'Data.Lib');
App::uses('EventCore', 'Events.Lib');
Expand Down
53 changes: 53 additions & 0 deletions Config/email.php
@@ -0,0 +1,53 @@
<?php
/**
* This is email configuration file.
*
* Use it to configure email transports of Cake.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.Config
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* In this file you set up your send email details.
*
* @package cake.config
*/
/**
* Email configuration class.
* You can specify multiple configurations for production, development and testing.
*
* transport => The name of a supported transport; valid options are as follows:
* Mail - Send using PHP mail function
* Smtp - Send using SMTP
* Debug - Do not send the email, just return the result
*
* You can add custom transports (or override existing transports) by adding the
* appropriate file to app/Network/Email. Transports should be named 'YourTransport.php',
* where 'Your' is the name of the transport.
*
* from =>
* The origin email. See CakeEmail::from() about the valid values
*
*/
class EmailConfig {

public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'infinitastest@gmail.com',
'password' => 'testtesttest',
'transport' => 'Smtp'
);

}
5 changes: 5 additions & 0 deletions Core/Emails/Network/Email/InfinitasEmail.php
@@ -0,0 +1,5 @@
<?php

class InfinitasEmail extends CakeEmail {

}
Expand Up @@ -163,6 +163,7 @@ public function actionAdminEdit($id = null, $query = array()) {
$query['conditions'][$this->Controller->{$this->Controller->modelClass}->alias . '.' . $this->Controller->{$this->Controller->modelClass}->primaryKey] = $id;

$this->Controller->request->data = $this->Controller->{$this->Controller->modelClass}->find('first', $query);

if(empty($this->Controller->request->data)) {
$this->Controller->notice('invalid');
}
Expand Down
20 changes: 16 additions & 4 deletions Core/Libs/Controller/Component/MassActionComponent.php
Expand Up @@ -256,8 +256,9 @@ public function __handleDeletes($ids) {
* they will be inactive and inactive records will be active.
*
* @param array $ids array of ids.
* @param string $message optional string you want the notice to display
*/
public function toggle($ids) {
public function toggle($ids, $message = null) {
if(!$this->Controller->{$this->Controller->modelClass}->hasField('active')) {
throw new Exception(sprintf('The model "%s" does not have an active field', $this->Controller->modelClass));
}
Expand Down Expand Up @@ -286,6 +287,16 @@ public function toggle($ids) {
if ($this->Controller->{$this->Controller->modelClass}->updateAll($newValues, $conditions)) {
$this->Controller->{$this->Controller->modelClass}->afterSave(false);


if (!empty($message)) {
$this->Controller->notice(
$message,
array(
'redirect' => true
)
);
}

$this->Controller->notice(
sprintf(__('The %s were toggled'), $this->Controller->prettyModelName),
array(
Expand Down Expand Up @@ -547,7 +558,8 @@ public function generic($action = 'add', $ids = null) {
if (!empty($ids)) {
$url = array_merge($url, $ids);
}

$this->Controller->redirect(array_merge($url, $this->Controller->request->params['named'], (array)$this->request->params['pass']));
$this->Controller->redirect(array_merge($url, $this->Controller->request->params['named'], (array)$this->Controller->request->params['pass']));
}
}

}
79 changes: 67 additions & 12 deletions Core/Newsletter/Controller/NewslettersController.php
Expand Up @@ -244,6 +244,22 @@ public function admin_index() {
}

public function admin_add() {
if ($this->request->isPost()) {
$campaignId = $this->request->data['Newsletter']['campaign_id'];

$campaign = $this->Newsletter->Campaign->find('first', array(
'fields' => array(
'template_id'
),
'conditions' => array(
'Campaign.id' => $campaignId
)
)
);

$this->request->data['Newsletter']['template_id'] = $campaign['Campaign']['template_id'];
}

parent::admin_add();

$campaigns = $this->Newsletter->Campaign->find('list');
Expand All @@ -268,6 +284,8 @@ public function admin_view($id = null) {
}

$newsletter = $this->Newsletter->read(null, $id);
$templateId = $newsletter['Newsletter']['template_id'];
$template = $this->Newsletter->Template->read(null, $templateId);

if (!empty($this->request->data)) {
$id = $this->request->data['Newsletter']['id'];
Expand All @@ -282,24 +300,20 @@ public function admin_view($id = null) {
)
);
}

$sent = 0;
foreach($addresses as $address) {
$this->Email->from = 'Infinitas Test Mail <' . $newsletter['Newsletter']['from'] . '>';
$this->Email->to = 'Test <' . $address . '>';
$email = new InfinitasEmail('gmail');
$email->from(array($newsletter['Newsletter']['from'] => 'Infinitas'));
$email->to($address);

$this->Email->subject = strip_tags($newsletter['Newsletter']['subject']);
$this->set('email', $newsletter['Template']['header'] . $newsletter['Newsletter']['html'] . $newsletter['Template']['footer']);
$email->subject(strip_tags($newsletter['Newsletter']['subject']));

if ($this->Email->send()) {
if ($email->send($template['Template']['header'] . $newsletter['Newsletter']['html'] . $template['Template']['footer'])) {
$sent++;
}

pr($this->Email->smtpError);

$this->Email->reset();
}

}

$this->notice(sprintf(__('%s mails were sent'), $sent));
}

Expand All @@ -310,6 +324,12 @@ public function admin_view($id = null) {
$this->set('newsletter', $this->Newsletter->read(null, $id));
}

public function admin_edit($id = null) {
parent::admin_edit();

$this->set('campaigns', $this->Newsletter->Campaign->find('list'));
}

public function admin_preview($id = null) {
$this->layout = 'ajax';

Expand Down Expand Up @@ -338,6 +358,7 @@ public function admin_preview($id = null) {
);

$this->set('data', $newsletter['Template']['header'] . $newsletter['Newsletter']['html'] . $newsletter['Template']['footer']);
Configure::write('debug', 0);
}
}

Expand Down Expand Up @@ -451,4 +472,38 @@ public function admin_stopAll() {
)
);
}

public function admin_mass() {
if ($this->MassAction->getAction() == 'send') {
$ids = $this->{$this->modelClass}->find(
'list',
array(
'conditions' => array(
$this->{$this->modelClass}->alias . '.active' => 0,
$this->{$this->modelClass}->alias . '.' . $this->{$this->modelClass}->primaryKey => $this->MassAction->getIds($this->MassAction->getAction(), $this->request->data[$this->modelClass])
)
)
);

if(empty($ids)) {
$this->notice(
__d('newsletter', 'Nothing to send'),
array(
'level' => 'warning',
'redirect' => ''
)
);
}

if (count($ids) == 1) {
$message = 'Newsletter is now sending';
} else {
$message = 'The Newsletters are now sending';
}

$this->MassAction->toggle(array_keys($ids), $message);
}

parent::admin_mass();
}
}
2 changes: 1 addition & 1 deletion Core/Newsletter/View/Newsletters/admin_view.ctp
Expand Up @@ -27,7 +27,7 @@
<h3><?php echo __('Test in a mail client'); ?></h3>
<?php
echo $this->Form->create('Newsletter', array('action' => 'view'));
echo '<p>', __('Enter the email addresses you would like to send to seperated by a , {comma}.'), '</p>';
echo '<p>', __('Enter the email addresses you would like to send to seperated by a , {comma} (but with no spaces)'), '</p>';
echo $this->Form->input('id', array('value' => $this->data['Newsletter']['id']));
echo $this->Form->input('email_addresses', array('type' => 'textarea', 'class' => 'title'));
echo $this->Form->end('Send the test');
Expand Down

0 comments on commit 3b67418

Please sign in to comment.