/**
  * Get components and populates array of controls that should be carried out on the components on a location within period
  *
  * @param $location_code the locaction code for the location the control should be carried out for   
  * @param $from_date start date for period
  * @param $to_date end date for period
  * @param $repeat_type Dag, Uke, Måned, År 
  * @param $return_type return data as objects or as arrays
  * @param $role_id responsible role for carrying out the control  
  * @return array of components as objects or arrays
  */
 public function get_assigned_check_list_by_component($from_date, $to_date, $repeat_type, $user_id, $completed = null, $return_type = "return_object")
 {
     $repeat_type = $repeat_type;
     $user_id = (int) $user_id;
     $sql = "SELECT DISTINCT controller_check_list.location_code, controller_check_list.control_id, controller_check_list.id AS check_list_id," . " controller_control.description, controller_control.start_date, end_date, deadline,planned_date, completed_date," . " control_area_id,controller_check_list.location_id,title,controller_check_list.component_id" . " FROM controller_check_list" . " {$this->join} controller_control ON controller_check_list.control_id = controller_control.id" . " {$this->join} controller_control_component_list " . " ON (controller_control_component_list.control_id = controller_check_list.control_id" . " AND controller_control_component_list.location_id = controller_check_list.location_id" . " AND controller_control_component_list.component_id = controller_check_list.component_id)" . " WHERE controller_check_list.assigned_to = {$user_id} AND status = 0";
     if ($repeat_type) {
         //				$sql .= "AND controller_control.repeat_type = $repeat_type ";
     }
     //FIXME
     if ($completed) {
         $sql .= " AND ( planned_date < {$to_date} AND controller_check_list.completed_date IS NULL) ";
         //				$sql .= " AND ((deadline <= $to_date AND controller_control.end_date IS NULL) ";
         //				$sql .= " OR (deadline <= $to_date AND deadline > $from_date ))";
         //				$sql .= " AND controller_check_list.completed_date IS NULL ";
     } else {
         $sql .= " AND (planned_date > {$from_date} AND planned_date <= {$to_date} AND controller_control.end_date IS NULL) ";
     }
     $this->db->query($sql);
     $check_list_array = array();
     while ($this->db->next_record()) {
         $check_list = new controller_check_list($this->unmarshal($this->db->f('check_list_id'), 'int'));
         $check_list->set_control_id($this->unmarshal($this->db->f('control_id'), 'int'));
         $check_list->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
         $check_list->set_component_id($this->unmarshal($this->db->f('component_id'), 'int'));
         $check_list->set_title($this->unmarshal($this->db->f('title', true), 'string'));
         $check_list->set_description($this->unmarshal($this->db->f('description', true), 'string'));
         $check_list->set_start_date($this->unmarshal($this->db->f('start_date'), 'int'));
         $check_list->set_end_date($this->unmarshal($this->db->f('end_date'), 'int'));
         $check_list->set_deadline($this->unmarshal($this->db->f('deadline'), 'int'));
         $check_list->set_control_area_id($this->unmarshal($this->db->f('control_area_id'), 'int'));
         $check_list->set_assigned_to($this->unmarshal($user_id, '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_location_code($this->unmarshal($this->db->f('location_code', true), 'string'));
         if ($return_type == "return_object") {
             $check_list_array[] = $check_list;
         } else {
             $check_list_array[] = $check_list->toArray();
         }
     }
     return $check_list_array;
 }