function decorate_comments($objects) { $updated = array(); foreach ($objects as $object) { $updated[] = decorate_comment($object); } return $updated; }
/** * Creates a new comment on the screen * @param $screen */ private function add_comment($screen) { $this->load->library('form_validation'); $this->form_validation->set_rules('content', 'Content', 'trim|required|xss_clean'); $this->form_validation->set_rules('time', 'Time', 'trim|xss_clean'); $this->form_validation->set_rules('begin_x', 'Begin X', 'trim|xss_clean'); $this->form_validation->set_rules('begin_y', 'Begin Y', 'trim|xss_clean'); $this->form_validation->set_rules('end_x', 'End X', 'trim|xss_clean'); $this->form_validation->set_rules('end_y', 'End Y', 'trim|xss_clean'); $this->form_validation->set_rules('left_x', 'Left X', 'trim|xss_clean'); $this->form_validation->set_rules('is_task', 'Is Task', 'trim|integer|xss_clean'); $this->form_validation->set_rules('marker', 'Marker', 'trim|integer|xss_clean'); $this->form_validation->set_rules('assignee_uuid', 'Assignee', 'trim|xss_clean'); if ($this->form_validation->run() == FALSE) { json_error('There was a problem with your submission: ' . validation_errors(' ', ' ')); } else { $data = array('screen_id' => $screen->id, 'project_id' => $screen->project_id, 'is_task' => intval($this->post('is_task', TRUE)), 'marker' => intval($this->post('marker', TRUE)), 'ordering' => $this->Comment->get_max_ordering_for_screen($screen->id) + 1, 'creator_id' => get_user_id(), 'time' => $this->post('time', TRUE), 'begin_x' => $this->post('begin_x', TRUE), 'begin_y' => $this->post('begin_y', TRUE), 'end_x' => $this->post('end_x', TRUE), 'end_y' => $this->post('end_y', TRUE), 'left_x' => $this->post('left_x', TRUE), 'content' => $this->post('content', TRUE)); $assignee_uuid = $this->post('assignee_uuid', TRUE); if ($assignee_uuid) { $assignee_id = $this->User->get_id($assignee_uuid); if (!$assignee_id) { json_error('There is no user with that id to assign this task to'); return; } if (!$this->User->is_on_project($screen->project_id, $assignee_id)) { json_error('You cannot assign a task to a user who is not assigned to this project'); return; } $data['assignee_id'] = $assignee_id; $data['is_task'] = 1; } $comment_id = $this->Comment->add($data); activity_add_comment_screen($comment_id); $this->Project_Statistic->comment_project($screen->project_id); $comment = decorate_comment($this->Comment->load($comment_id)); $this->response($comment); } }