|
| 1 | +<?php |
| 2 | +defined('BASEPATH') or exit('Sem Permissão'); |
| 3 | + |
| 4 | +require_once(APPPATH.'controllers/Team.php'); |
| 5 | + |
| 6 | +class TeamTask extends CI_Controller{ |
| 7 | + public function insert($team_id){ |
| 8 | + $user = authorize(1); |
| 9 | + |
| 10 | + $team = Team::iManageThisTeam($team_id, $user->id_user); |
| 11 | + |
| 12 | + $this->load->model('TeamTaskModel'); |
| 13 | + |
| 14 | + $newTask = new stdClass(); |
| 15 | + $newTask->team_id = $team_id; |
| 16 | + $newTask->teamtask_id = $this->input->post('tag', true); |
| 17 | + $newTask->created_by = $user->id_user; |
| 18 | + $newTask->title = $this->input->post('title', true); |
| 19 | + $newTask->priority = $this->input->post('priority', true); |
| 20 | + $newTask->description = $this->input->post('description', true); |
| 21 | + $newTask->created_in = datetime_current(); |
| 22 | + |
| 23 | + $this->TeamTaskModel->insert($newTask); |
| 24 | + |
| 25 | + $this->session->set_flashdata('success', 'Nova Tarefa Criada'); |
| 26 | + redirect('time/'.$team_id); |
| 27 | + } |
| 28 | + |
| 29 | + public function delete($team_id, $task_id){ |
| 30 | + $user = authorize(1); |
| 31 | + |
| 32 | + $team = Team::iManageThisTeam($team_id, $user->id_user); |
| 33 | + |
| 34 | + $teamTask = $this->thisTaskBelongsToTheTeam($task_id, $team_id); |
| 35 | + |
| 36 | + $this->TeamTaskModel->deleteById($task_id); |
| 37 | + |
| 38 | + $this->session->set_flashdata('success', 'Tarefa Excluída'); |
| 39 | + |
| 40 | + redirect('time/'.$team_id); |
| 41 | + } |
| 42 | + |
| 43 | + public function edit($team_id, $task_id){ |
| 44 | + $user = authorize(1); |
| 45 | + |
| 46 | + $team = Team::iManageThisTeam($team_id, $user->id_user); |
| 47 | + |
| 48 | + $teamTask = $this->thisTaskBelongsToTheTeam($task_id, $team_id); |
| 49 | + |
| 50 | + $page = [ |
| 51 | + 'page_title' => 'Editar Etiqueta', |
| 52 | + 'page_content' => 'teamtask/edit', |
| 53 | + 'user' => $user, |
| 54 | + 'task' => $teamTask, |
| 55 | + 'team_id' => $team_id, |
| 56 | + ]; |
| 57 | + |
| 58 | + $this->load->view('public/base', $page); |
| 59 | + } |
| 60 | + |
| 61 | + public function update($team_id, $task_id){ |
| 62 | + $user = authorize(1); |
| 63 | + |
| 64 | + $team = Team::iManageThisTeam($team_id, $user->id_user); |
| 65 | + |
| 66 | + $teamTask = $this->thisTaskBelongsToTheTeam($task_id, $team_id); |
| 67 | + |
| 68 | + $newTeamTask = new stdClass(); |
| 69 | + $newTeamTask->title = $this->input->post('title', true); |
| 70 | + $newTeamTask->description = $this->input->post('description', true); |
| 71 | + $newTeamTask->priority = $this->input->post('priority', true); |
| 72 | + $newTeamTask->teamtag_id = $this->input->post('tag', true); |
| 73 | + $newTeamTask->created_by = $user->id_user; |
| 74 | + |
| 75 | + $this->TeamTaskModel->updateById($newTeamTask, $task_id); |
| 76 | + |
| 77 | + $this->session->set_flashdata('success', 'Tarefa Atualizada'); |
| 78 | + redirect('time/'.$team_id); |
| 79 | + } |
| 80 | + |
| 81 | + public function complete($team_id, $task_id){ |
| 82 | + $user = authorize(1); |
| 83 | + |
| 84 | + $teamTask = $this->thisTaskBelongsToTheTeam($task_id, $team_id); |
| 85 | + |
| 86 | + $newTask = new stdClass(); |
| 87 | + $newTask->status = 1; |
| 88 | + $newTask->completed_in = datetime_current(); |
| 89 | + |
| 90 | + $this->TeamTaskModel->updateById($newTask, $task_id); |
| 91 | + |
| 92 | + $this->session->set_flashdata('success', 'Tarefa Concluída'); |
| 93 | + |
| 94 | + redirect('time/'.$team_id); |
| 95 | + } |
| 96 | + |
| 97 | + public function reopen($team_id, $task_id){ |
| 98 | + $user = authorize(1); |
| 99 | + |
| 100 | + $teamTask = $this->thisTaskBelongsToTheTeam($task_id, $team_id); |
| 101 | + |
| 102 | + $newTask = new stdClass(); |
| 103 | + $newTask->status = 0; |
| 104 | + $newTask->completed_in = ''; |
| 105 | + |
| 106 | + $this->TeamTaskModel->updateById($newTask, $task_id); |
| 107 | + |
| 108 | + $this->session->set_flashdata('success', 'Tarefa Reaberta'); |
| 109 | + |
| 110 | + redirect('time/'.$team_id); |
| 111 | + } |
| 112 | + |
| 113 | + public function thisTaskBelongsToTheTeam($id_task, $team_id){ |
| 114 | + $this->load->model('TeamTaskModel'); |
| 115 | + |
| 116 | + $task = $this->TeamTaskModel->searchByIdAndTeam($id_task, $team_id); |
| 117 | + |
| 118 | + if(!$task){ |
| 119 | + $this->session->set_flashdata('error', 'Essa tarefa não pertence ao time'); |
| 120 | + redirect('time/'.$team_id); |
| 121 | + } |
| 122 | + |
| 123 | + return $task; |
| 124 | + } |
| 125 | +} |
0 commit comments