Major update of unit tests / updated routers + models + react
This commit is contained in:
@ -19,20 +19,24 @@ class CustomField extends Model {
|
||||
function asArray() {
|
||||
$model = parent::asArray();
|
||||
|
||||
$model['params'] = (
|
||||
is_serialized($this->params)
|
||||
? unserialize($this->params)
|
||||
: $this->params
|
||||
);
|
||||
|
||||
if(isset($model['params'])) {
|
||||
$model['params'] = (
|
||||
is_array($this->params)
|
||||
? $this->params
|
||||
: unserialize($this->params)
|
||||
);
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
||||
function save() {
|
||||
if(is_null($this->params)) {
|
||||
$this->params = array();
|
||||
}
|
||||
$this->set('params', (
|
||||
is_serialized($this->params)
|
||||
? $this->params
|
||||
: serialize($this->params)
|
||||
is_array($this->params)
|
||||
? serialize($this->params)
|
||||
: $this->params
|
||||
));
|
||||
return parent::save();
|
||||
}
|
||||
@ -66,12 +70,6 @@ class CustomField extends Model {
|
||||
$custom_field->set($data);
|
||||
}
|
||||
|
||||
try {
|
||||
$custom_field->save();
|
||||
return $custom_field;
|
||||
} catch(Exception $e) {
|
||||
return $custom_field->getValidationErrors();
|
||||
}
|
||||
return false;
|
||||
return $custom_field->save();
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
Reference in New Issue
Block a user