예제 #1
0
 function view_closed_cases()
 {
     $check_list_id = phpgw::get_var('check_list_id');
     $case_location_code = phpgw::get_var('location_code');
     $check_list = $this->so_check_list->get_single($check_list_id);
     // Check list top section info
     $control = $this->so_control->get_single($check_list->get_control_id());
     $location_code = $check_list->get_location_code();
     $component_id = $check_list->get_component_id();
     if ($component_id > 0) {
         $location_id = $check_list->get_location_id();
         $component_id = $check_list->get_component_id();
         $component_arr = execMethod('property.soentity.read_single_eav', array('location_id' => $location_id, 'id' => $component_id));
         $location_name = execMethod('property.bolocation.get_location_name', $component_arr['location_code']);
         $short_desc = $location_name . '::' . execMethod('property.soentity.get_short_description', array('location_id' => $location_id, 'id' => $component_id));
         //				$short_desc = execMethod('property.soentity.get_short_description', array('location_id' => $location_id, 'id' => $component_id));
         $component = new controller_component();
         $component->set_id($component_id);
         $component->set_location_id($location_id);
         $component->set_location_code($component_arr['location_code']);
         $component->set_xml_short_desc($short_desc);
         $component_array = $component->toArray();
         $type = 'component';
         $building_location_code = $this->location_finder->get_building_location_code($component_arr['location_code']);
         $buildings_on_property = array();
     } else {
         $location_code = $check_list->get_location_code();
         $location_array = execMethod('property.bolocation.read_single', array('location_code' => $location_code));
         $type = 'location';
         // Fetches buildings on property
         $buildings_on_property = $this->location_finder->get_buildings_on_property($user_role, $location_code, $level);
     }
     // Check list top section info
     $level = $this->location_finder->get_location_level($location_code);
     $year = date("Y", $check_list->get_deadline());
     $month = date("n", $check_list->get_deadline());
     $user_role = true;
     $closed_check_items_and_cases = $this->so_check_item->get_check_items_with_cases($check_list_id, null, 'closed', null, $case_location_code);
     if ($buildings_on_property) {
         foreach ($buildings_on_property as &$building) {
             $building['selected'] = $building['id'] == $case_location_code ? 1 : 0;
         }
     }
     //---------
     foreach ($closed_check_items_and_cases as $key => $check_item) {
         //		$control_item_with_options = $this->so_control_item->get_single_with_options( $check_item->get_control_item_id() );
         foreach ($check_item->get_cases_array() as $case) {
             $component_location_id = $case->get_component_location_id();
             $component_id = $case->get_component_id();
             if ($component_id) {
                 $short_desc = execMethod('property.soentity.get_short_description', array('location_id' => $component_location_id, 'id' => $component_id));
                 $case->set_component_descr($short_desc);
             }
         }
         //		$check_item->get_control_item()->set_options_array( $control_item_with_options->get_options_array() );
         //		$closed_check_items_and_cases[$key] = $check_item;
     }
     //-------
     $data = array('control' => $control, 'check_list' => $check_list, 'buildings_on_property' => $buildings_on_property, 'location_array' => $location_array, 'component_array' => $component_array, 'type' => $type, 'location_level' => $level, 'current_year' => $year, 'current_month_nr' => $month, 'closed_check_items_and_cases' => $closed_check_items_and_cases, 'check_list' => $check_list, 'cases_view' => 'closed_cases', 'building_location_code' => $building_location_code);
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('controller', 'controller', 'case.js');
     self::add_javascript('controller', 'controller', 'check_list_update_status.js');
     self::render_template_xsl(array('check_list/fragments/check_list_menu', 'case/cases_tab_menu', 'case/view_closed_cases', 'case/case_row', 'check_list/fragments/nav_control_plan', 'check_list/fragments/check_list_top_section', 'check_list/fragments/select_buildings_on_property'), $data);
 }
 function view_control_info()
 {
     $check_list_id = phpgw::get_var('check_list_id');
     $check_list = $this->so->get_single($check_list_id);
     $control = $this->so_control->get_single($check_list->get_control_id());
     $component_id = $check_list->get_component_id();
     if ($component_id > 0) {
         $location_id = $check_list->get_location_id();
         $component_id = $check_list->get_component_id();
         $component_arr = execMethod('property.soentity.read_single_eav', array('location_id' => $location_id, 'id' => $component_id));
         $location_name = execMethod('property.bolocation.get_location_name', $component_arr['location_code']);
         $short_desc = $location_name . '::' . execMethod('property.soentity.get_short_description', array('location_id' => $location_id, 'id' => $component_id));
         $component = new controller_component();
         $component->set_id($component_id);
         $component->set_location_id($location_id);
         $component->set_location_code($component_arr['location_code']);
         $component->set_xml_short_desc($short_desc);
         $component_array = $component->toArray();
         $type = 'component';
         $building_location_code = $this->location_finder->get_building_location_code($component_arr['location_code']);
     } else {
         $location_code = $check_list->get_location_code();
         $location_array = execMethod('property.bolocation.read_single', array('location_code' => $location_code));
         $type = 'location';
         $level = $this->location_finder->get_location_level($location_code);
     }
     $year = date("Y", $check_list->get_deadline());
     $month = date("n", $check_list->get_deadline());
     $level = $this->location_finder->get_location_level($location_code);
     $user_role = true;
     // Fetches buildings on property
     $buildings_on_property = $this->location_finder->get_buildings_on_property($user_role, $location_code, $level);
     $data = array('control' => $control, 'check_list' => $check_list, 'buildings_on_property' => $buildings_on_property, 'location_array' => $location_array, 'component_array' => $component_array, 'type' => $type, 'current_year' => $year, 'current_month_nr' => $month, 'building_location_code' => $building_location_code, 'location_level' => $level);
     phpgwapi_jquery::load_widget('core');
     self::add_javascript('controller', 'controller', 'check_list_update_status.js');
     self::render_template_xsl(array('check_list/fragments/check_list_menu', 'check_list/fragments/check_list_top_section', 'check_list/fragments/nav_control_plan', 'check_list/view_control_info', 'check_list/fragments/select_buildings_on_property'), $data);
 }
 /**
  * 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_controls_by_component($from_date, $to_date, $repeat_type, $return_type = "return_object", $role_id = 0, $filter = null)
 {
     $controls_array = array();
     $sql = "SELECT c.id as control_id, c.*, ";
     $sql .= "bim_item.type as component_type, bim_item.id as component_id, bim_item.location_code, bim_item.address, ";
     $sql .= "cl.location_id, fm_responsibility_role.name AS responsibility_name ";
     $sql .= "FROM controller_control_component_list cl ";
     $sql .= "JOIN fm_bim_item bim_item on cl.component_id = bim_item.id ";
     $sql .= "JOIN fm_bim_type bim_type on cl.location_id = bim_type.location_id ";
     $sql .= "JOIN controller_control c on cl.control_id = c.id ";
     $sql .= "JOIN fm_responsibility_role ON fm_responsibility_role.id = c.responsibility_id ";
     $sql .= "AND bim_item.type = bim_type.id ";
     if ($repeat_type != null) {
         $repeat_type = (int) $repeat_type;
         $sql .= "AND c.repeat_type = {$repeat_type} ";
     }
     if ($role_id) {
         $role_id = (int) $role_id;
         $sql .= "AND c.responsibility_id = {$role_id} ";
     }
     $sql .= "AND ((c.start_date <= {$to_date} AND c.end_date IS NULL) ";
     $sql .= "OR (c.start_date <= {$to_date} AND c.end_date > {$from_date} ))";
     if ($filter != null) {
         $sql .= "AND " . $filter;
     }
     $sql .= "ORDER BY bim_item.id ";
     $this->db->query($sql);
     $component_id = 0;
     $component = null;
     while ($this->db->next_record()) {
         if ($this->db->f('component_id') != $component_id) {
             if ($component_id != 0) {
                 $component->set_controls_array($controls_array);
                 $controls_array = array();
                 if ($return_type == "return_array") {
                     $components_array[] = $component->toArray();
                 } else {
                     $components_array[] = $component;
                 }
             }
             $component = new controller_component();
             $component->set_type($this->unmarshal($this->db->f('component_type'), 'int'));
             $component->set_id($this->unmarshal($this->db->f('component_id'), 'int'));
             $component->set_location_id($this->unmarshal($this->db->f('location_id'), 'int'));
             $component->set_guid($this->unmarshal($this->db->f('guid', true), 'string'));
             $component->set_location_code($this->unmarshal($this->db->f('location_code', true), 'string'));
             $component->set_loc_1($this->unmarshal($this->db->f('loc_1', true), 'string'));
             $component->set_address($this->unmarshal($this->db->f('address', true), 'string'));
         }
         $control = new controller_control($this->unmarshal($this->db->f('control_id'), 'int'));
         $control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
         $control->set_description($this->unmarshal($this->db->f('description', true), 'string'));
         $control->set_start_date($this->unmarshal($this->db->f('start_date'), 'int'));
         $control->set_end_date($this->unmarshal($this->db->f('end_date'), 'int'));
         $control->set_procedure_id($this->unmarshal($this->db->f('procedure_id'), 'int'));
         $control->set_procedure_name($this->unmarshal($this->db->f('procedure_name', true), 'string'));
         $control->set_requirement_id($this->unmarshal($this->db->f('requirement_id'), 'int'));
         $control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id'), 'int'));
         $control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id'), 'int'));
         $control->set_responsibility_name($this->unmarshal($this->db->f('responsibility_name', true), 'string'));
         $control->set_control_area_id($this->unmarshal($this->db->f('control_area_id'), 'int'));
         $control->set_control_area_name($this->unmarshal($this->db->f('control_area_name', true), 'string'));
         $control->set_repeat_type($this->unmarshal($this->db->f('repeat_type'), 'int'));
         $control->set_repeat_type_label($this->unmarshal($this->db->f('repeat_type'), 'int'));
         $control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval'), 'int'));
         if ($return_type == "return_object") {
             $controls_array[] = $control;
         } else {
             $controls_array[] = $control->toArray();
         }
         $component_id = $component->get_id();
     }
     if ($component != null) {
         $component->set_controls_array($controls_array);
         if ($return_type == "return_array") {
             $components_array[] = $component->toArray();
         } else {
             $components_array[] = $component;
         }
         return $components_array;
     } else {
         return null;
     }
 }