2014-06-06 11:38:34 +00:00
|
|
|
<?php namespace System\Models;
|
|
|
|
|
|
|
|
|
|
use Model;
|
2015-01-28 07:03:35 +00:00
|
|
|
use ApplicationException;
|
2014-06-06 11:38:34 +00:00
|
|
|
|
2014-10-03 08:00:21 +00:00
|
|
|
/**
|
|
|
|
|
* Mail layout
|
|
|
|
|
*
|
|
|
|
|
* @package october\system
|
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
|
*/
|
2014-07-04 08:47:46 +00:00
|
|
|
class MailLayout extends Model
|
2014-06-06 11:38:34 +00:00
|
|
|
{
|
2014-07-11 11:15:21 +00:00
|
|
|
use \October\Rain\Database\Traits\Validation;
|
|
|
|
|
|
2014-06-06 11:38:34 +00:00
|
|
|
/**
|
|
|
|
|
* @var string The database table used by the model.
|
|
|
|
|
*/
|
2014-07-04 08:47:46 +00:00
|
|
|
protected $table = 'system_mail_layouts';
|
2014-06-06 11:38:34 +00:00
|
|
|
|
|
|
|
|
public $rules = [
|
2014-07-04 08:47:46 +00:00
|
|
|
'code' => 'required|unique:system_mail_layouts',
|
2014-06-06 11:38:34 +00:00
|
|
|
'name' => 'required',
|
|
|
|
|
'content_html' => 'required',
|
|
|
|
|
];
|
|
|
|
|
|
2016-03-29 07:17:25 +00:00
|
|
|
public static $codeCache;
|
|
|
|
|
|
2014-06-06 11:38:34 +00:00
|
|
|
public function beforeDelete()
|
|
|
|
|
{
|
2014-10-18 09:58:50 +00:00
|
|
|
if ($this->is_locked) {
|
2014-06-06 11:38:34 +00:00
|
|
|
throw new ApplicationException('Cannot delete this template because it is locked');
|
2014-10-18 09:58:50 +00:00
|
|
|
}
|
2014-06-06 11:38:34 +00:00
|
|
|
}
|
2016-03-29 07:17:25 +00:00
|
|
|
|
|
|
|
|
public static function listCodes()
|
|
|
|
|
{
|
|
|
|
|
if (self::$codeCache !== null) {
|
|
|
|
|
return self::$codeCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self::$codeCache = self::lists('id', 'code');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getIdFromCode($code)
|
|
|
|
|
{
|
|
|
|
|
return array_get(self::listCodes(), $code);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-18 09:58:50 +00:00
|
|
|
}
|