Adds new method to validate model on request
Cleans up code formatting
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Models;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@@ -83,9 +84,7 @@ class Model extends \Sudzy\ValidModel {
|
||||
'UPDATE `' . $model::$_table . '`',
|
||||
'SET `deleted_at` = NOW()',
|
||||
'WHERE `id` IN (' . rtrim(str_repeat('?,', count($ids)), ',') . ')'
|
||||
)),
|
||||
$ids
|
||||
);
|
||||
)), $ids);
|
||||
});
|
||||
|
||||
return array('count' => $count);
|
||||
@@ -111,9 +110,7 @@ class Model extends \Sudzy\ValidModel {
|
||||
'UPDATE `' . $model::$_table . '`',
|
||||
'SET `deleted_at` = NULL',
|
||||
'WHERE `id` IN (' . rtrim(str_repeat('?,', count($ids)), ',') . ')'
|
||||
)),
|
||||
$ids
|
||||
);
|
||||
)), $ids);
|
||||
});
|
||||
|
||||
return array('count' => $count);
|
||||
@@ -138,7 +135,8 @@ class Model extends \Sudzy\ValidModel {
|
||||
}
|
||||
|
||||
// get number of affected rows
|
||||
return $orm->get_last_statement()->rowCount();
|
||||
return $orm->get_last_statement()
|
||||
->rowCount();
|
||||
}
|
||||
|
||||
function duplicate($data = array()) {
|
||||
@@ -189,4 +187,13 @@ class Model extends \Sudzy\ValidModel {
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function validate() {
|
||||
$success = true;
|
||||
foreach(array_keys($this->_validations) as $field) {
|
||||
$success = $success && $this->validateField($field, $this->$field);
|
||||
}
|
||||
$this->setError($this->getValidationErrors());
|
||||
return $success;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user