public function add() { $this->load->helper('form'); $this->load->library('form_validation'); $this->load->library('session'); if ($this->form_validation->run('goal/add') === FALSE) { $this->load->view("templates/errorForm.php", array("fields" => array('startDate', 'endDate', 'task', 'hour'))); } else { $startDate = $this->input->post("startDate"); $endDate = $this->input->post("endDate"); $taskId = $this->input->post("task"); $val = $this->input->post("hour") * 3600; $description = $this->input->post("description"); $goal = new Goal(); try { $this->load->library("jdf"); if (!checkDateString($startDate) || !checkDateString($endDate)) { show_error("data wrong", 400); return; } $startDate = makeTime($startDate); $endDate = makeTime($endDate); $goal->create($val, $startDate, $endDate, $description)->save(new Task($taskId), new User($this->session->getStudentId())); $this->load->view("goal/goal_created"); } catch (Goal_Start_Greater_Than_End $e) { $this->load->view("goal/goal_error.php"); Goal_Error::Goal_Start_Greater_Than_End(); } catch (UserNotFound $e) { $this->load->view("user/user_error.php"); User_Error::UserNotFound(); } catch (Goal_Overlap $e) { $this->load->view("goal/goal_error.php"); Goal_Error::Goal_Overlap(); } catch (Goal_Value_Invalid $e) { $this->load->view("goal/goal_error.php"); Goal_Error::Goal_Value_Invalid(); } } }