2014-06-06 21:38:34 +10:00
< ? php namespace System\Controllers ;
use Str ;
use Lang ;
use File ;
2014-06-06 22:26:49 +10:00
use Mail ;
2014-06-06 21:38:34 +10:00
use Flash ;
use Backend ;
use Redirect ;
use BackendMenu ;
2014-06-06 22:26:49 +10:00
use BackendAuth ;
2014-06-06 21:38:34 +10:00
use Backend\Classes\Controller ;
2014-07-04 18:47:46 +10:00
use System\Models\MailTemplate ;
2014-06-06 21:38:34 +10:00
use System\Classes\ApplicationException ;
2014-07-27 15:07:22 +11:00
use System\Classes\SettingsManager ;
2014-06-06 21:38:34 +10:00
use Exception ;
/**
2014-07-04 18:47:46 +10:00
* Mail templates controller
2014-06-06 21:38:34 +10:00
*
* @ package october\system
* @ author Alexey Bobkov , Samuel Georges
*
*/
2014-07-04 18:47:46 +10:00
class MailTemplates extends Controller
2014-06-06 21:38:34 +10:00
{
public $implement = [
'Backend.Behaviors.FormController' ,
'Backend.Behaviors.ListController'
];
2014-07-04 18:47:46 +10:00
public $requiredPermissions = [ 'system.manage_mail_templates' ];
2014-06-06 21:38:34 +10:00
public $listConfig = [ 'templates' => 'config_templates_list.yaml' , 'layouts' => 'config_layouts_list.yaml' ];
public $formConfig = 'config_form.yaml' ;
public function __construct ()
{
parent :: __construct ();
BackendMenu :: setContext ( 'October.System' , 'system' , 'settings' );
2014-07-27 15:07:22 +11:00
SettingsManager :: setContext ( 'October.System' , 'mail_templates' );
2014-06-06 21:38:34 +10:00
}
public function index ()
{
2014-07-04 18:47:46 +10:00
/* @todo Remove line if year >= 2015 */ if ( ! \System\Models\MailLayout :: whereCode ( 'default' ) -> count ()) { \Eloquent :: unguard (); with ( new \System\Database\Seeds\SeedSetupMailLayouts ) -> run (); }
2014-06-06 21:38:34 +10:00
2014-07-04 18:47:46 +10:00
MailTemplate :: syncAll ();
2014-08-23 09:41:48 +10:00
$this -> asExtension ( 'ListController' ) -> index ();
2014-07-27 15:07:22 +11:00
$this -> bodyClass = 'compact-container' ;
2014-06-06 21:38:34 +10:00
}
public function formBeforeSave ( $model )
{
$model -> is_custom = true ;
}
2014-06-06 22:26:49 +10:00
public function onTest ( $recordId )
{
try {
$model = $this -> formFindModelObject ( $recordId );
$user = BackendAuth :: getUser ();
2014-07-04 18:14:09 +10:00
$vars = [
'email' => $user -> email ,
'name' => $user -> full_name ,
];
Mail :: send ( $model -> code , [], function ( $message ) use ( $vars ) {
extract ( $vars );
$message -> to ( $email , $name );
2014-06-06 22:26:49 +10:00
});
Flash :: success ( 'The test message has been successfully sent.' );
}
catch ( Exception $ex ) {
Flash :: error ( $ex -> getMessage ());
}
}
2014-06-06 21:38:34 +10:00
}