/** * Get array with check lists for a control on a component within time period and for a specified repeat type * * @param $control_id control id * @param $location_code location code * @param $from_date_ts start time period * @param $to_date_ts end time period * @param $repeat_type_expr repeat type expression * @return array with check list objects */ function get_check_lists_for_control_and_component($control_id, $location_id, $component_id, $from_date_ts, $to_date_ts, $repeat_type = null, $user_id = 0) { $control_id = (int) $control_id; $location_id = (int) $location_id; $component_id = (int) $component_id; $user_id = (int) $user_id; $sql = "SELECT cl.id as cl_id, cl.status as cl_status, cl.comment as cl_comment, deadline, planned_date, completed_date, cl.assigned_to, "; $sql .= "cl.component_id as cl_component_id, cl.location_id as cl_location_id," . " cl.location_code as cl_location_code, num_open_cases, num_pending_cases ,cl.serie_id, cl.billable_hours, cs.repeat_type "; $sql .= "FROM controller_check_list cl "; $sql .= "LEFT JOIN controller_control c on cl.control_id = c.id "; $sql .= "LEFT JOIN controller_control_serie cs on cl.serie_id = cs.id "; $sql .= "WHERE cl.control_id = {$control_id} "; $sql .= "AND cl.component_id = {$component_id} "; $sql .= "AND cl.location_id = {$location_id} "; if ($repeat_type != null) { $sql .= "AND c.repeat_type = {$repeat_type} "; } // if($user_id) // { // $sql .= " AND assigned_to = {$user_id} "; // } $sql .= "AND deadline BETWEEN {$from_date_ts} AND {$to_date_ts} "; // _debug_array($sql); $this->db->query($sql); $check_lists_array = array(); while ($this->db->next_record()) { $check_list = new controller_check_list($this->unmarshal($this->db->f('cl_id'), 'int')); $check_list->set_status($this->unmarshal($this->db->f('cl_status'), 'int')); $check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 'string')); $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int')); $check_list->set_planned_date($this->unmarshal($this->db->f('planned_date'), 'int')); $check_list->set_completed_date($this->unmarshal($this->db->f('completed_date'), 'int')); $check_list->set_component_id($this->unmarshal($this->db->f('cl_component_id'), 'int')); $check_list->set_location_id($this->unmarshal($this->db->f('cl_location_id'), 'int')); $check_list->set_location_code($this->unmarshal($this->db->f('cl_location_code', true), 'string')); $check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases'), 'int')); $check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases'), 'int')); $check_list->set_assigned_to($this->unmarshal($this->db->f('assigned_to'), 'int')); $check_list->set_serie_id($this->db->f('serie_id')); $check_list->set_repeat_type($this->db->f('repeat_type')); $check_list->set_billable_hours((double) $this->db->f('billable_hours')); $check_lists_array[] = $check_list; } return array("location_code" => $location_code, "check_lists_array" => $check_lists_array); }