| <?php |
|
|
| namespace Kanboard\Model; |
|
|
| use Kanboard\Core\Base; |
|
|
| |
| |
| |
| |
| |
| |
| class CategoryModel extends Base |
| { |
| |
| |
| |
| |
| |
| const TABLE = 'project_has_categories'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function exists($category_id) |
| { |
| return $this->db->table(self::TABLE)->eq('id', $category_id)->exists(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getById($category_id) |
| { |
| return $this->db->table(self::TABLE)->eq('id', $category_id)->findOne(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getNameById($category_id) |
| { |
| return $this->db->table(self::TABLE)->eq('id', $category_id)->findOneColumn('name') ?: ''; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getProjectId($category_id) |
| { |
| return $this->db->table(self::TABLE)->eq('id', $category_id)->findOneColumn('project_id') ?: 0; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function getIdByName($project_id, $category_name) |
| { |
| return (int) $this->db->table(self::TABLE) |
| ->eq('project_id', $project_id) |
| ->eq('name', $category_name) |
| ->findOneColumn('id'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function getList($project_id, $prepend_none = true, $prepend_all = false) |
| { |
| $listing = $this->db->hashtable(self::TABLE) |
| ->eq('project_id', $project_id) |
| ->asc('name') |
| ->getAll('id', 'name'); |
|
|
| $prepend = array(); |
|
|
| if ($prepend_all) { |
| $prepend[-1] = t('All categories'); |
| } |
|
|
| if ($prepend_none) { |
| $prepend[0] = t('No category'); |
| } |
|
|
| return $prepend + $listing; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getAll($project_id) |
| { |
| return $this->db->table(self::TABLE) |
| ->eq('project_id', $project_id) |
| ->asc('name') |
| ->findAll(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function createDefaultCategories($project_id) |
| { |
| $results = array(); |
| $categories = array_unique(explode_csv_field($this->configModel->get('project_categories'))); |
|
|
| foreach ($categories as $category) { |
| $results[] = $this->db->table(self::TABLE)->insert(array( |
| 'project_id' => $project_id, |
| 'name' => $category, |
| )); |
| } |
|
|
| return in_array(false, $results, true); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function create(array $values) |
| { |
| return $this->db->table(self::TABLE)->persist($values); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function update(array $values) |
| { |
| $updates = $values; |
| unset($updates['id']); |
| return $this->db->table(self::TABLE)->eq('id', $values['id'])->save($updates); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function remove($category_id) |
| { |
| $this->db->startTransaction(); |
|
|
| $this->db->table(TaskModel::TABLE)->eq('category_id', $category_id)->update(array('category_id' => 0)); |
|
|
| if (! $this->db->table(self::TABLE)->eq('id', $category_id)->remove()) { |
| $this->db->cancelTransaction(); |
| return false; |
| } |
|
|
| $this->db->closeTransaction(); |
|
|
| return true; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function duplicate($src_project_id, $dst_project_id) |
| { |
| $categories = $this->db |
| ->table(self::TABLE) |
| ->columns('name', 'description', 'color_id') |
| ->eq('project_id', $src_project_id) |
| ->asc('name') |
| ->findAll(); |
|
|
| foreach ($categories as $category) { |
| $category['project_id'] = $dst_project_id; |
|
|
| if (! $this->db->table(self::TABLE)->save($category)) { |
| return false; |
| } |
| } |
|
|
| return true; |
| } |
| } |
|
|