Improve API to return id instead of a boolean

This commit is contained in:
Frédéric Guillot
2014-11-22 18:22:10 -05:00
parent 15038cdb10
commit 77e10d2582
13 changed files with 270 additions and 310 deletions

View File

@@ -138,19 +138,25 @@ class SubTask extends Base
*
* @access public
* @param array $values Form values
* @return bool
* @return bool|integer
*/
public function create(array $values)
{
$this->prepare($values);
$result = $this->db->table(self::TABLE)->save($values);
if ($result) {
$values['id'] = $this->db->getConnection()->getLastId();
return $this->db->transaction(function($db) use ($values) {
if (! $db->table(SubTask::TABLE)->save($values)) {
return false;
}
$subtask_id = (int) $db->getConnection()->getLastId();
$values['id'] = $subtask_id;
$this->event->trigger(self::EVENT_CREATE, $values);
}
return $result;
return $subtask_id;
});
}
/**