Major update of unit tests / updated routers + models + react

This commit is contained in:
Jonathan Labreuille
2016-02-04 19:04:52 +01:00
parent 233020ca20
commit 55f851208b
25 changed files with 523 additions and 441 deletions

View File

@ -8,6 +8,10 @@ class Newsletter extends Model {
function __construct() {
parent::__construct();
$this->addValidations('type', array(
'required' => __('You need to specify a type.')
));
}
function save() {
@ -15,9 +19,23 @@ class Newsletter extends Model {
$this->set_expr('deleted_at', 'NULL');
}
$this->set('body',
is_array($this->body)
? json_encode($this->body)
: $this->body
);
return parent::save();
}
function asArray() {
$model = parent::asArray();
if(isset($model['body'])) {
$model['body'] = json_decode($model['body'], true);
}
return $model;
}
function delete() {
// delete all relations to segments
NewsletterSegment::where('newsletter_id', $this->id)->deleteMany();