| <?php |
|
|
| namespace Kanboard\Model; |
|
|
| use Kanboard\Core\Base; |
|
|
| |
| |
| |
| |
| |
| |
| class GroupModel extends Base |
| { |
| |
| |
| |
| |
| |
| const TABLE = 'groups'; |
|
|
| |
| |
| |
| |
| |
| |
| public function getQuery() |
| { |
| return $this->db->table(self::TABLE) |
| ->columns('id', 'name', 'external_id') |
| ->subquery('SELECT COUNT(*) FROM '.GroupMemberModel::TABLE.' WHERE group_id='.self::TABLE.'.id', 'nb_users'); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getById($group_id) |
| { |
| return $this->db->table(self::TABLE)->eq('id', $group_id)->findOne(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getByExternalId($external_id) |
| { |
| return $this->db->table(self::TABLE)->eq('external_id', $external_id)->findOne(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getByExternalIds(array $external_ids) |
| { |
| if (empty($external_ids)) { |
| return []; |
| } |
|
|
| return $this->db->table(self::TABLE)->in('external_id', $external_ids)->findAll(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getAll() |
| { |
| return $this->getQuery()->asc('name')->findAll(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function search($input) |
| { |
| return $this->db->table(self::TABLE)->ilike('name', '%'.$input.'%')->asc('name')->findAll(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function remove($group_id) |
| { |
| return $this->db->table(self::TABLE)->eq('id', $group_id)->remove(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function create($name, $external_id = '') |
| { |
| return $this->db->table(self::TABLE)->persist(array( |
| 'name' => $name, |
| 'external_id' => $external_id, |
| )); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function update(array $values) |
| { |
| $updates = $values; |
| unset($updates['id']); |
| return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($updates); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function getOrCreateExternalGroupId($name, $external_id) |
| { |
| $group_id = $this->db->table(self::TABLE)->eq('external_id', $external_id)->findOneColumn('id'); |
|
|
| if (empty($group_id)) { |
| $group_id = $this->create($name, $external_id); |
| } |
|
|
| return $group_id; |
| } |
| } |
|
|