Skip to content

Commit

Permalink
Converted to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
helpfulrobot committed Dec 23, 2015
1 parent 6799fb2 commit 5e8a47e
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 234 deletions.
26 changes: 14 additions & 12 deletions code/controllers/CapturedEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
* @author marcus@silverstripe.com.au
* @license BSD License http://silverstripe.org/bsd-license/
*/
class CapturedEmailController extends Controller {
class CapturedEmailController extends Controller
{

private static $allowed_actions = array('view' => 'CMS_ACCESS_MailCaptureAdmin');
private static $allowed_actions = array('view' => 'CMS_ACCESS_MailCaptureAdmin');

public function view() {
$id = (int) $this->getRequest()->param('ID');
public function view()
{
$id = (int) $this->getRequest()->param('ID');

if ($id) {
$email = DataList::create('CapturedEmail')->byID($id);
if ($email) {
return array('Email' => $email);
return $this->customise()->renderWith('CapturedEmailController_view');
}
}
}
if ($id) {
$email = DataList::create('CapturedEmail')->byID($id);
if ($email) {
return array('Email' => $email);
return $this->customise()->renderWith('CapturedEmailController_view');
}
}
}
}
50 changes: 26 additions & 24 deletions code/controllers/MailCaptureAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@
* @author marcus@silverstripe.com.au
* @license BSD License http://silverstripe.org/bsd-license/
*/
class MailCaptureAdmin extends ModelAdmin {
class MailCaptureAdmin extends ModelAdmin
{

private static $url_segment = 'mailcapture';
private static $menu_title = 'Email Logs';
private static $managed_models = array(
'CapturedEmail',
'MassMailSend',
);
private static $url_segment = 'mailcapture';
private static $menu_title = 'Email Logs';
private static $managed_models = array(
'CapturedEmail',
'MassMailSend',
);

public function init() {
parent::init();
$this->showImportForm = false;
}
public function init()
{
parent::init();
$this->showImportForm = false;
}

public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);

if ($this->modelClass == 'CapturedEmail') {
$grid = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
if ($grid) {
$grid->getConfig()->removeComponentsByType('GridFieldEditButton');
$grid->getConfig()->removeComponentsByType('GridFieldDeleteAction');
$grid->getConfig()->addComponent(new ViewEmailButton());
}
}
return $form;
}
public function getEditForm($id = null, $fields = null)
{
$form = parent::getEditForm($id, $fields);

if ($this->modelClass == 'CapturedEmail') {
$grid = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
if ($grid) {
$grid->getConfig()->removeComponentsByType('GridFieldEditButton');
$grid->getConfig()->removeComponentsByType('GridFieldDeleteAction');
$grid->getConfig()->addComponent(new ViewEmailButton());
}
}
return $form;
}
}
49 changes: 25 additions & 24 deletions code/dataobjects/CapturedEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@
* @author marcus@silverstripe.com.au
* @license BSD License http://silverstripe.org/bsd-license/
*/
class CapturedEmail extends DataObject {
public static $db = array(
'To' => 'Varchar(128)',
'From' => 'Varchar(128)',
'Subject' => 'Varchar(128)',
'Headers' => 'Text',
'Content' => 'Text',
'PlainText' => 'Text',
);
class CapturedEmail extends DataObject
{
public static $db = array(
'To' => 'Varchar(128)',
'From' => 'Varchar(128)',
'Subject' => 'Varchar(128)',
'Headers' => 'Text',
'Content' => 'Text',
'PlainText' => 'Text',
);

public static $has_one = array(
'Send' => 'MassMailSend',
);
public static $has_one = array(
'Send' => 'MassMailSend',
);

public static $summary_fields = array(
'Created',
'Subject',
'To',
'From'
);
public static $searchable_fields = array(
'Subject',
'To',
'From'
);
public static $summary_fields = array(
'Created',
'Subject',
'To',
'From'
);
public static $searchable_fields = array(
'Subject',
'To',
'From'
);

public static $default_sort = 'ID DESC';
public static $default_sort = 'ID DESC';
}
96 changes: 53 additions & 43 deletions code/dataobjects/MassMailSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,65 @@
* @author marcus@silverstripe.com.au
* @license BSD License http://silverstripe.org/bsd-license/
*/
class MassMailSend extends DataObject {
public static $db = array(
'Title' => 'Varchar(128)',
);
class MassMailSend extends DataObject
{
public static $db = array(
'Title' => 'Varchar(128)',
);

public static $has_many = array(
'Emails' => 'CapturedEmail',
);
public static $has_many = array(
'Emails' => 'CapturedEmail',
);

public static $default_sort = 'ID DESC';
public static $default_sort = 'ID DESC';

public function getCMSFields() {
$fields = parent::getCMSFields();
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName('Emails');
$config = GridFieldConfig_Base::create();
$config->addComponent(new ViewEmailButton());
$fields->removeByName('Emails');
$config = GridFieldConfig_Base::create();
$config->addComponent(new ViewEmailButton());

$gf = GridField::create('Emails', 'Sent emails', $this->Emails(), $config);
$gf = GridField::create('Emails', 'Sent emails', $this->Emails(), $config);

$fields->addFieldToTab('Root.Main', $gf);
$fields->addFieldToTab('Root.Main', $gf);

return $fields;
}
return $fields;
}
}

class ViewEmailButton implements GridField_ColumnProvider {
public function augmentColumns($field, &$cols) {
if(!in_array('Actions', $cols)) $cols[] = 'Actions';
}

public function getColumnsHandled($field) {
return array('Actions');
}

public function getColumnContent($field, $record, $col) {
if($record->canView()) {
$data = new ArrayData(array(
'Link' => Controller::join_links('CapturedEmailController', 'view', $record->ID)
));
return $data->renderWith('ViewEmailButton');
}
}

public function getColumnAttributes($field, $record, $col) {
return array('class' => 'col-buttons');
}

public function getColumnMetadata($gridField, $col) {
return array('title' => null);
}
}
class ViewEmailButton implements GridField_ColumnProvider
{
public function augmentColumns($field, &$cols)
{
if (!in_array('Actions', $cols)) {
$cols[] = 'Actions';
}
}

public function getColumnsHandled($field)
{
return array('Actions');
}

public function getColumnContent($field, $record, $col)
{
if ($record->canView()) {
$data = new ArrayData(array(
'Link' => Controller::join_links('CapturedEmailController', 'view', $record->ID)
));
return $data->renderWith('ViewEmailButton');
}
}

public function getColumnAttributes($field, $record, $col)
{
return array('class' => 'col-buttons');
}

public function getColumnMetadata($gridField, $col)
{
return array('title' => null);
}
}
Loading

0 comments on commit 5e8a47e

Please sign in to comment.