|
| 1 | +<?php |
| 2 | +defined('BASEPATH') or exit('Sem Permissão'); |
| 3 | + |
| 4 | +require_once(APPPATH.'controllers/Team.php'); |
| 5 | + |
| 6 | +class TeamTag extends CI_Controller{ |
| 7 | + public function index(){ |
| 8 | + |
| 9 | + } |
| 10 | + |
| 11 | + public function insert($team_id){ |
| 12 | + $user = authorize(1); |
| 13 | + |
| 14 | + $team = Team::iManageThisTeam($team_id, $user->id_user); |
| 15 | + |
| 16 | + $new_tag = new stdClass(); |
| 17 | + $new_tag->team_id = $team_id; |
| 18 | + $new_tag->created_by = $user->id_user; |
| 19 | + $new_tag->name = $this->input->post('name', true); |
| 20 | + $new_tag->color = $this->input->post('color', true); |
| 21 | + $new_tag->description = $this->input->post('description', true); |
| 22 | + $new_tag->created_in = datetime_current(); |
| 23 | + |
| 24 | + $this->load->model('TeamTagModel'); |
| 25 | + $this->TeamTagModel->insert($new_tag); |
| 26 | + |
| 27 | + $this->session->set_flashdata('success', 'Etiqueta Criada'); |
| 28 | + redirect('time/'.$team_id.'#tags'); |
| 29 | + } |
| 30 | + |
| 31 | + public function delete($team_id, $tag_id){ |
| 32 | + $user = authorize(1); |
| 33 | + |
| 34 | + $team = Team::iManageThisTeam($team_id, $user->id_user); |
| 35 | + |
| 36 | + $teamTag = $this->thisTagBelongsToTheTeam($tag_id, $team_id); |
| 37 | + |
| 38 | + $this->TeamTagModel->deleteById($tag_id); |
| 39 | + |
| 40 | + $this->session->set_flashdata('success', 'Etiqueta Excluída'); |
| 41 | + |
| 42 | + redirect('time/'.$team_id.'#tags'); |
| 43 | + } |
| 44 | + |
| 45 | + public function edit($team_id, $tag_id){ |
| 46 | + $user = authorize(1); |
| 47 | + |
| 48 | + $team = Team::iManageThisTeam($team_id, $user->id_user); |
| 49 | + |
| 50 | + $teamTag = $this->thisTagBelongsToTheTeam($tag_id, $team_id); |
| 51 | + |
| 52 | + $page = [ |
| 53 | + 'page_title' => 'Editar Etiqueta', |
| 54 | + 'page_content' => 'teamtag/edit', |
| 55 | + 'user' => $user, |
| 56 | + 'tag' => $teamTag, |
| 57 | + 'team_id' => $team_id, |
| 58 | + ]; |
| 59 | + |
| 60 | + $this->load->view('public/base', $page); |
| 61 | + } |
| 62 | + |
| 63 | + public function update($team_id, $tag_id){ |
| 64 | + $user = authorize(1); |
| 65 | + |
| 66 | + $team = Team::iManageThisTeam($team_id, $user->id_user); |
| 67 | + |
| 68 | + $teamTag = $this->thisTagBelongsToTheTeam($tag_id, $team_id); |
| 69 | + |
| 70 | + $teamTag->name = $this->input->post('name', true); |
| 71 | + $teamTag->description = $this->input->post('description', true); |
| 72 | + $teamTag->color = $this->input->post('color', true); |
| 73 | + |
| 74 | + $this->TeamTagModel->updateById($teamTag, $tag_id); |
| 75 | + |
| 76 | + $this->session->set_flashdata('success', 'Etiqueta Atualizada'); |
| 77 | + redirect('time/'.$team_id.'#tags'); |
| 78 | + } |
| 79 | + |
| 80 | + public function thisTagBelongsToTheTeam($id_tag, $team_id){ |
| 81 | + $this->load->model('TeamTagModel'); |
| 82 | + |
| 83 | + $tag = $this->TeamTagModel->searchByIdAndTeam($id_tag, $team_id); |
| 84 | + |
| 85 | + if(!$tag){ |
| 86 | + $this->session->set_flashdata('error', 'Essa etiqueta não pertence ao time'); |
| 87 | + redirect('time/'.$team_id.'#tags'); |
| 88 | + } |
| 89 | + |
| 90 | + return $tag; |
| 91 | + } |
| 92 | +} |
0 commit comments