File size: 2,664 Bytes
e4f4821 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
<?php
namespace Kanboard\Model;
use Kanboard\Core\Base;
/**
* Tag Duplication
*
* @package Kanboard\Model
* @author Frederic Guillot
*/
class TagDuplicationModel extends Base
{
/**
* Duplicate project tags to another project
*
* @access public
* @param integer $src_project_id
* @param integer $dst_project_id
* @return bool
*/
public function duplicate($src_project_id, $dst_project_id)
{
$tags = $this->tagModel->getAllByProject($src_project_id);
$results = array();
foreach ($tags as $tag) {
$results[] = $this->tagModel->create($dst_project_id, $tag['name'], $tag['color_id']);
}
return ! in_array(false, $results, true);
}
/**
* Link tags to the new tasks
*
* @access public
* @param integer $src_task_id
* @param integer $dst_task_id
* @param integer $dst_project_id
*/
public function duplicateTaskTagsToAnotherProject($src_task_id, $dst_task_id, $dst_project_id)
{
$tags = $this->taskTagModel->getTagsByTask($src_task_id);
foreach ($tags as $tag) {
$tag_id = $this->tagModel->getIdByName($dst_project_id, $tag['name']);
if (empty($tag_id)) {
$tag_id = $this->tagModel->create($dst_project_id, $tag['name'], $tag['color_id']);
}
$this->taskTagModel->associateTag($dst_task_id, $tag_id);
}
}
/**
* Duplicate tags to the new task
*
* @access public
* @param integer $src_task_id
* @param integer $dst_task_id
*/
public function duplicateTaskTags($src_task_id, $dst_task_id)
{
$tags = $this->taskTagModel->getTagsByTask($src_task_id);
foreach ($tags as $tag) {
$this->taskTagModel->associateTag($dst_task_id, $tag['id']);
}
}
/**
* Sync tags that are not available in destination project
*
* @access public
* @param integer $task_id
* @param integer $dst_project_id
*/
public function syncTaskTagsToAnotherProject($task_id, $dst_project_id)
{
$tags = $this->taskTagModel->getTagsByTaskNotAvailableInProject($task_id, $dst_project_id);
foreach ($tags as $tag) {
$tag_id = $this->tagModel->getIdByName($dst_project_id, $tag['name']);
if (empty($tag_id)) {
$tag_id = $this->tagModel->create($dst_project_id, $tag['name'], $tag['color_id']);
}
$this->taskTagModel->dissociateTag($task_id, $tag['id']);
$this->taskTagModel->associateTag($task_id, $tag_id);
}
}
}
|