Пример #1
0
 function save_case_ajax()
 {
     if (!$this->add && !$this->edit) {
         return json_encode(array("status" => "not_saved"));
     }
     $check_list_id = phpgw::get_var('check_list_id');
     $control_item_id = phpgw::get_var('control_item_id');
     $case_descr = phpgw::get_var('case_descr');
     $type = phpgw::get_var('type');
     $status = phpgw::get_var('status');
     $location_code = phpgw::get_var('location_code');
     $component_location_id = phpgw::get_var('component_location_id', 'int');
     $component_id = phpgw::get_var('component_id', 'int');
     $check_list = $this->so_check_list->get_single($check_list_id);
     $control_id = $check_list->get_control_id();
     $location_code = $location_code ? $location_code : $check_list->get_location_code();
     $control = $this->so_control->get_single($control_id);
     $check_item = $this->so_check_item->get_check_item_by_check_list_and_control_item($check_list_id, $control_item_id);
     // Makes a check item if there isn't already made one
     if ($check_item == null) {
         $new_check_item = new controller_check_item();
         $new_check_item->set_check_list_id($check_list_id);
         $new_check_item->set_control_item_id($control_item_id);
         $saved_check_item_id = $this->so_check_item->store($new_check_item);
         $check_item = $this->so_check_item->get_single($saved_check_item_id);
     }
     $todays_date_ts = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
     $user_id = $GLOBALS['phpgw_info']['user']['id'];
     $case = new controller_check_item_case();
     $case->set_check_item_id($check_item->get_id());
     $case->set_descr($case_descr);
     $case->set_user_id($user_id);
     $case->set_entry_date($todays_date_ts);
     $case->set_modified_date($todays_date_ts);
     $case->set_modified_by($user_id);
     $case->set_modified_by($user_id);
     $case->set_status($status);
     $case->set_location_code($location_code);
     $case->set_component_location_id($component_location_id);
     $case->set_component_id($component_id);
     // Saves selected value from  or measurement
     if ($type == 'control_item_type_2') {
         $measurement = phpgw::get_var('measurement');
         $case->set_measurement($measurement);
     } else {
         if ($type == 'control_item_type_3') {
             $option_value = phpgw::get_var('option_value');
             $case->set_measurement($option_value);
         } else {
             if ($type == 'control_item_type_4') {
                 $option_value = phpgw::get_var('option_value');
                 $case->set_measurement($option_value);
             }
         }
     }
     $case_id = $this->so->store($case);
     if ($case_id > 0) {
         return json_encode(array("status" => "saved"));
     } else {
         return json_encode(array("status" => "not_saved"));
     }
 }
 /**
  * Get check item objects from database including related control item and cases
  * 
  * @param	$message_ticket_id get check items and cases for this message
  * @return check item objects 
  */
 public function get_check_items_with_cases_by_message($message_ticket_id)
 {
     $message_ticket_id = (int) $message_ticket_id;
     $sql = "SELECT ci.id as ci_id, control_item_id, cic.component_location_id,";
     $sql .= "check_list_id, cic.id as cic_id, cic.status as cic_status, cic.*, ";
     $sql .= "coi.id as coi_id, coi.* ";
     $sql .= "FROM controller_control_group JOIN controller_control_item ON controller_control_item.control_group_id=controller_control_group.id ";
     $sql .= "JOIN controller_check_item ci ON ci.control_item_id = controller_control_item.id ";
     $sql .= "LEFT JOIN controller_control_item as coi ON ci.control_item_id = coi.id ";
     $sql .= "LEFT JOIN controller_check_item_case as cic ON ci.id = cic.check_item_id ";
     $sql .= "WHERE cic.location_item_id = {$message_ticket_id}";
     $this->db->query($sql);
     $check_item_id = 0;
     $check_item = null;
     while ($this->db->next_record()) {
         if ($this->db->f('ci_id') != $check_item_id) {
             if ($check_item_id) {
                 $check_item->set_cases_array($cases_array);
                 $check_items_array[] = $check_item;
             }
             $check_item = new controller_check_item($this->unmarshal($this->db->f('ci_id'), 'int'));
             $check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id'), 'int'));
             $check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id'), 'int'));
             $control_item = new controller_control_item($this->unmarshal($this->db->f('coi_id'), 'int'));
             $control_item->set_title($this->db->f('title', true), 'string');
             $control_item->set_required($this->db->f('required', true), 'string');
             $control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
             $control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
             $control_item->set_control_group_id($this->db->f('control_group_id'), 'int');
             $control_item->set_component_location_id($this->db->f('component_location_id'), 'int');
             $control_item->set_type($this->db->f('type', true), 'string');
             $check_item->set_control_item($control_item);
             $cases_array = array();
         }
         if ($this->db->f('cic_id')) {
             $case = new controller_check_item_case($this->unmarshal($this->db->f('cic_id'), 'int'));
             $case->set_status($this->unmarshal($this->db->f('cic_status'), 'int'));
             $case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 'int'));
             $case->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
             $case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 'int'));
             $case->set_descr($this->unmarshal($this->db->f('descr', true), 'string'));
             $case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));
             $case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 'int'));
             $case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 'int'));
             $case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
             $cases_array[] = $case;
         }
         $check_item_id = $check_item->get_id();
     }
     if ($check_item != null) {
         $check_item->set_cases_array($cases_array);
         $check_items_array[] = $check_item;
         return $check_items_array;
     } else {
         return null;
     }
 }
Пример #3
0
 /**
  * Get cases for message  
  * 
  * @param	$location_id location id
  * @param	$location_item_id location item id
  * @return array of case object represented as objects or arrays
  */
 public function get_cases_by_message($location_id, $location_item_id)
 {
     $location_id = (int) $location_id;
     $location_item_id = (int) $location_item_id;
     $sql = "SELECT * FROM controller_check_item_case ";
     $sql .= "WHERE location_id = {$location_id} AND location_item_id = {$location_item_id}";
     $this->db->query($sql);
     $cases_array = array();
     while ($this->db->next_record()) {
         $case = new controller_check_item_case($this->unmarshal($this->db->f('id'), 'int'));
         $case->set_check_item_id($this->unmarshal($this->db->f('check_item_id'), 'int'));
         $case->set_status($this->unmarshal($this->db->f('status'), 'int'));
         $case->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
         $case->set_location_item_id($this->unmarshal($this->db->f('location_item_id'), 'int'));
         $case->set_descr($this->unmarshal($this->db->f('descr', true), 'string'));
         $case->set_user_id($this->unmarshal($this->db->f('user_id'), 'int'));
         $case->set_entry_date($this->unmarshal($this->db->f('entry_date'), 'int'));
         $case->set_modified_date($this->unmarshal($this->db->f('modified_date'), 'int'));
         $case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
         $case->set_measurement($this->unmarshal($this->db->f('measurement'), 'string'));
         $case->set_location_code($this->unmarshal($this->db->f('location_code'), 'string'));
         $case->set_component_location_id($this->unmarshal($this->db->f('component_location_id'), 'int'));
         $case->set_component_id($this->unmarshal($this->db->f('component_id'), 'int'));
         $cases_array[] = $case;
     }
     return $cases_array;
 }