Some refactoring for PHP 5.3
This commit is contained in:
parent
77e10d2582
commit
c49d46718a
|
|
@ -61,7 +61,7 @@ class CommentCreation extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
return $this->comment->create(array(
|
||||
return (bool) $this->comment->create(array(
|
||||
'reference' => $data['reference'],
|
||||
'comment' => $data['comment'],
|
||||
'task_id' => $data['task_id'],
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class TaskCreation extends Base
|
|||
*/
|
||||
public function doAction(array $data)
|
||||
{
|
||||
return $this->taskCreation->create(array(
|
||||
return (bool) $this->taskCreation->create(array(
|
||||
'project_id' => $data['project_id'],
|
||||
'title' => $data['title'],
|
||||
'reference' => $data['reference'],
|
||||
|
|
|
|||
|
|
@ -90,6 +90,26 @@ abstract class Base
|
|||
return Tool::loadModel($this->container, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a record in the database
|
||||
*
|
||||
* @access public
|
||||
* @param string $table Table name
|
||||
* @param array $values Form values
|
||||
* @return boolean|integer
|
||||
*/
|
||||
public function persist($table, array $values)
|
||||
{
|
||||
return $this->db->transaction(function($db) use ($table, $values) {
|
||||
|
||||
if (! $db->table($table)->save($values)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (int) $db->getConnection()->getLastId();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove keys from an array
|
||||
*
|
||||
|
|
|
|||
|
|
@ -98,14 +98,7 @@ class Category extends Base
|
|||
*/
|
||||
public function create(array $values)
|
||||
{
|
||||
return $this->db->transaction(function($db) use ($values) {
|
||||
|
||||
if (! $db->table(Category::TABLE)->save($values)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (int) $db->getConnection()->getLastId();
|
||||
});
|
||||
return $this->persist(self::TABLE, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class Comment extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Save a comment in the database
|
||||
* Create a new comment
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
|
|
@ -104,20 +104,13 @@ class Comment extends Base
|
|||
public function create(array $values)
|
||||
{
|
||||
$values['date'] = time();
|
||||
$comment_id = $this->persist(self::TABLE, $values);
|
||||
|
||||
return $this->db->transaction(function($db) use ($values) {
|
||||
if ($comment_id) {
|
||||
$this->event->trigger(self::EVENT_CREATE, array('id' => $comment_id) + $values);
|
||||
}
|
||||
|
||||
if (! $db->table(Comment::TABLE)->save($values)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$comment_id = (int) $db->getConnection()->getLastId();
|
||||
$values['id'] = $comment_id;
|
||||
|
||||
$this->event->trigger(self::EVENT_CREATE, $values);
|
||||
|
||||
return $comment_id;
|
||||
});
|
||||
return $comment_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ class SubTask extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
* Create a new subtask
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
|
|
@ -143,20 +143,13 @@ class SubTask extends Base
|
|||
public function create(array $values)
|
||||
{
|
||||
$this->prepare($values);
|
||||
$subtask_id = $this->persist(self::TABLE, $values);
|
||||
|
||||
return $this->db->transaction(function($db) use ($values) {
|
||||
if ($subtask_id) {
|
||||
$this->event->trigger(self::EVENT_CREATE, array('id' => $subtask_id) + $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 $subtask_id;
|
||||
});
|
||||
return $subtask_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class TaskCreation extends Base
|
|||
public function create(array $values)
|
||||
{
|
||||
$this->prepare($values);
|
||||
$task_id = $this->persist($values);
|
||||
$task_id = $this->persist(Task::TABLE, $values);
|
||||
$this->fireEvents($task_id, $values);
|
||||
|
||||
return (int) $task_id;
|
||||
|
|
@ -51,25 +51,6 @@ class TaskCreation extends Base
|
|||
$values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the task to the database
|
||||
*
|
||||
* @access private
|
||||
* @param array $values Form values
|
||||
* @return boolean|integer
|
||||
*/
|
||||
private function persist(array $values)
|
||||
{
|
||||
return $this->db->transaction(function($db) use ($values) {
|
||||
|
||||
if (! $db->table(Task::TABLE)->save($values)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $db->getConnection()->getLastId();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire events
|
||||
*
|
||||
|
|
|
|||
|
|
@ -260,15 +260,7 @@ class User extends Base
|
|||
public function create(array $values)
|
||||
{
|
||||
$this->prepare($values);
|
||||
|
||||
return $this->db->transaction(function($db) use ($values) {
|
||||
|
||||
if (! $db->table(User::TABLE)->save($values)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (int) $db->getConnection()->getLastId();
|
||||
});
|
||||
return $this->persist(self::TABLE, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
require __DIR__.'/../app/common.php';
|
||||
|
||||
use Model\Task;
|
||||
use Model\TaskCreation;
|
||||
use Model\SubTask;
|
||||
use Model\Project;
|
||||
use Model\ProjectPermission;
|
||||
|
|
@ -14,7 +14,7 @@ $task_per_column = 50;
|
|||
$userModel = new User($container);
|
||||
$projectModel = new Project($container);
|
||||
$permissionModel = new ProjectPermission($container);
|
||||
$taskModel = new Task($container);
|
||||
$taskModel = new TaskCreation($container);
|
||||
$subtaskModel = new SubTask($container);
|
||||
|
||||
for ($i = 0; $i <= 100; $i++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue