Create new class SubtaskPositionModel
This commit is contained in:
@@ -168,7 +168,7 @@ class SubtaskController extends BaseController
|
||||
$values = $this->request->getJson();
|
||||
|
||||
if (! empty($values) && $this->helper->user->hasProjectAccess('SubtaskController', 'movePosition', $project_id)) {
|
||||
$result = $this->subtaskModel->changePosition($task_id, $values['subtask_id'], $values['position']);
|
||||
$result = $this->subtaskPositionModel->changePosition($task_id, $values['subtask_id'], $values['position']);
|
||||
$this->response->json(array('result' => $result));
|
||||
} else {
|
||||
throw new AccessForbiddenException();
|
||||
|
||||
@@ -90,6 +90,7 @@ use Pimple\Container;
|
||||
* @property \Kanboard\Model\ProjectTaskPriorityModel $projectTaskPriorityModel
|
||||
* @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel
|
||||
* @property \Kanboard\Model\SubtaskModel $subtaskModel
|
||||
* @property \Kanboard\Model\SubtaskPositionModel $subtaskPositionModel
|
||||
* @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel
|
||||
* @property \Kanboard\Model\SwimlaneModel $swimlaneModel
|
||||
* @property \Kanboard\Model\TagDuplicationModel $tagDuplicationModel
|
||||
|
||||
@@ -272,39 +272,6 @@ class SubtaskModel extends Base
|
||||
return $this->db->table(self::TABLE)->eq('task_id', $task_id)->update(array('status' => self::STATUS_DONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save subtask position
|
||||
*
|
||||
* @access public
|
||||
* @param integer $task_id
|
||||
* @param integer $subtask_id
|
||||
* @param integer $position
|
||||
* @return boolean
|
||||
*/
|
||||
public function changePosition($task_id, $subtask_id, $position)
|
||||
{
|
||||
if ($position < 1 || $position > $this->db->table(self::TABLE)->eq('task_id', $task_id)->count()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$subtask_ids = $this->db->table(self::TABLE)->eq('task_id', $task_id)->neq('id', $subtask_id)->asc('position')->findAllByColumn('id');
|
||||
$offset = 1;
|
||||
$results = array();
|
||||
|
||||
foreach ($subtask_ids as $current_subtask_id) {
|
||||
if ($offset == $position) {
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$results[] = $this->db->table(self::TABLE)->eq('id', $current_subtask_id)->update(array('position' => $offset));
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$results[] = $this->db->table(self::TABLE)->eq('id', $subtask_id)->update(array('position' => $position));
|
||||
|
||||
return !in_array(false, $results, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the status of subtask
|
||||
*
|
||||
|
||||
47
app/Model/SubtaskPositionModel.php
Normal file
47
app/Model/SubtaskPositionModel.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use Kanboard\Core\Base;
|
||||
|
||||
/**
|
||||
* Class SubtaskPositionModel
|
||||
*
|
||||
* @package Kanboard\Model
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class SubtaskPositionModel extends Base
|
||||
{
|
||||
/**
|
||||
* Change subtask position
|
||||
*
|
||||
* @access public
|
||||
* @param integer $task_id
|
||||
* @param integer $subtask_id
|
||||
* @param integer $position
|
||||
* @return boolean
|
||||
*/
|
||||
public function changePosition($task_id, $subtask_id, $position)
|
||||
{
|
||||
if ($position < 1 || $position > $this->db->table(SubtaskModel::TABLE)->eq('task_id', $task_id)->count()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$subtask_ids = $this->db->table(SubtaskModel::TABLE)->eq('task_id', $task_id)->neq('id', $subtask_id)->asc('position')->findAllByColumn('id');
|
||||
$offset = 1;
|
||||
$results = array();
|
||||
|
||||
foreach ($subtask_ids as $current_subtask_id) {
|
||||
if ($offset == $position) {
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$results[] = $this->db->table(SubtaskModel::TABLE)->eq('id', $current_subtask_id)->update(array('position' => $offset));
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$results[] = $this->db->table(SubtaskModel::TABLE)->eq('id', $subtask_id)->update(array('position' => $position));
|
||||
|
||||
return !in_array(false, $results, true);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@ class ClassProvider implements ServiceProviderInterface
|
||||
'ProjectUserRoleModel',
|
||||
'RememberMeSessionModel',
|
||||
'SubtaskModel',
|
||||
'SubtaskPositionModel',
|
||||
'SubtaskTimeTrackingModel',
|
||||
'SwimlaneModel',
|
||||
'TagDuplicationModel',
|
||||
|
||||
Reference in New Issue
Block a user