fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [9576] Fix for duplicate controls on home-page


From: Erik Holm-Larsen
Subject: [Fmsystem-commits] [9576] Fix for duplicate controls on home-page
Date: Wed, 13 Jun 2012 12:07:34 +0000

Revision: 9576
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=9576
Author:   erikhl
Date:     2012-06-13 12:07:31 +0000 (Wed, 13 Jun 2012)
Log Message:
-----------
Fix for duplicate controls on home-page

Modified Paths:
--------------
    trunk/controller/inc/class.socheck_list.inc.php
    trunk/controller/inc/class.socontrol.inc.php
    trunk/controller/inc/hook_home.inc.php

Modified: trunk/controller/inc/class.socheck_list.inc.php
===================================================================
--- trunk/controller/inc/class.socheck_list.inc.php     2012-06-13 12:05:13 UTC 
(rev 9575)
+++ trunk/controller/inc/class.socheck_list.inc.php     2012-06-13 12:07:31 UTC 
(rev 9576)
@@ -224,7 +224,54 @@
                $sql .= "FROM controller_check_list cl ";
                $sql .= "WHERE cl.control_id = $control_id ";
                $sql .= "AND cl.location_code = '{$location_code}' "; 
+               $sql .= "AND NOT cl.planned_date IS NULL ";
+               $sql .= "AND cl.completed_date IS NULL ";
                $sql .= "ORDER BY cl.id;";
+               //var_dump($sql);
+               $this->db->query($sql);
+               
+               $check_list_id = 0;
+               $check_list = null;
+               while ($this->db->next_record()) {
+               
+                       if( $this->db->f('cl_id', true) != $check_list_id ){
+                               
+                               if($check_list_id != 0){
+                                       $check_list_array[] = $check_list;
+                               }
+                               
+                               $check_list = new 
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+                               
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true), 
'int'));
+                               
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true), 
'string'));
+                               
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true), 
'int'));
+                               
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date', 
true), 'int'));
+                               
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date', 
true), 'int')); 
+                               
$check_list->set_component_id($this->unmarshal($this->db->f('component_id', 
true), 'int'));
+                               
$check_list->set_location_code($this->unmarshal($this->db->f('location_code', 
true), 'string'));
+                               
$check_list->set_num_open_cases($this->unmarshal($this->db->f('num_open_cases', 
true), 'int')); 
+                               
$check_list->set_num_pending_cases($this->unmarshal($this->db->f('num_pending_cases',
 true), 'int'));
+                       }
+                       $check_list_id =  $check_list->get_id();
+               }
+               
+               if($check_list != null){
+                       $check_list_array[] = $check_list;
+               
+                       return $check_list_array;
+               }else {
+                       return null;
+               }
+       }
+       
+       function get_unplanned_check_lists_for_control($control_id, 
$location_code){
+               $sql = "SELECT cl.id as cl_id, cl.status as cl_status, 
cl.comment as cl_comment, deadline, planned_date, "; 
+               $sql .= "completed_date, component_id, location_code, 
num_open_cases, num_pending_cases ";
+               $sql .= "FROM controller_check_list cl ";
+               $sql .= "WHERE cl.control_id = $control_id ";
+               $sql .= "AND cl.location_code = '{$location_code}' "; 
+               $sql .= "AND cl.planned_date IS NULL ";
+               $sql .= "AND cl.completed_date IS NULL ";
+               $sql .= "ORDER BY cl.id;";
 
                $this->db->query($sql);
                

Modified: trunk/controller/inc/class.socontrol.inc.php
===================================================================
--- trunk/controller/inc/class.socontrol.inc.php        2012-06-13 12:05:13 UTC 
(rev 9575)
+++ trunk/controller/inc/class.socontrol.inc.php        2012-06-13 12:07:31 UTC 
(rev 9576)
@@ -113,6 +113,24 @@
                        //return isset($result);
                }
 
+               function get_controls_for_location($location_code, $from_date, 
$to_date, $repeat_type)
+               {
+                   $controls = array();
+                   $controls_loc = 
$this->get_controls_by_location($location_code, $from_date, $to_date, 
$repeat_type );
+                   $controls_comp = 
$this->get_controls_for_components_by_location($location_code, $from_date, 
$to_date, $repeat_type );
+                   
+                   foreach($controls_loc as $cl)
+                   {
+                       $controls[] = $cl;
+                   }
+                   foreach($controls_comp as $cc)
+                   {
+                       $controls[] = $cc;
+                   }
+                   
+                   return $controls;
+               }
+               
                public function get_controls_by_location($location_code, 
$from_date, $to_date, $repeat_type, $return_type = "return_object")
                {
                        $controls_array = array();
@@ -128,7 +146,7 @@
                        
                        $sql .= "AND (c.start_date <= $from_date AND c.end_date 
IS NULL ";
                        $sql .= "OR c.start_date > $from_date AND c.start_date 
< $to_date)";
-                       
+                       //var_dump($sql."<br/>");
                        $this->db->query($sql);
 
                        while($this->db->next_record()) {
@@ -161,7 +179,57 @@
                                return null;
                        }
                }
+               
+           public function 
get_controls_for_components_by_location($location_code, $from_date, $to_date, 
$repeat_type, $return_type = "return_object")
+               {
+                       $controls_array = array();
+                       $joins .= " {$this->left_join} fm_responsibility_role 
ON (c.responsibility_id = fm_responsibility_role.id)";
+                       
+                       $sql  = "SELECT distinct c.*, 
fm_responsibility_role.name AS responsibility_name FROM 
controller_control_component_list ccl "; 
+                       $sql .= "LEFT JOIN controller_control c on 
ccl.control_id=c.id ";
+                       $sql .= "LEFT JOIN fm_responsibility_role ON 
fm_responsibility_role.id = c.responsibility_id ";
+                       $sql .= "LEFT JOIN fm_bim_item ON fm_bim_item.id = 
ccl.component_id ";
+                       $sql .= "WHERE fm_bim_item.loc1 = '$location_code' ";
+                       
+                       if( is_numeric($repeat_type) )
+                               $sql .= "AND c.repeat_type = $repeat_type ";
+                       
+                       $sql .= "AND (c.start_date <= $from_date AND c.end_date 
IS NULL ";
+                       $sql .= "OR c.end_date > $from_date AND c.start_date < 
$to_date)";
+                       //var_dump($sql."<br/>");
+                       $this->db->query($sql);
+                       
+                       while($this->db->next_record()) {
+                               $control = new 
controller_control($this->unmarshal($this->db->f('id', true), 'int'));
+                               
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+                               
$control->set_description($this->unmarshal($this->db->f('description', true), 
'boolean'));
+                               
$control->set_start_date($this->unmarshal($this->db->f('start_date', true), 
'int'));
+                               
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
+                               
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true), 
'int'));
+                               
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id', 
true), 'int'));
+                               
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
 true), 'int'));
+                               
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
 true), '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', 
true), 'int'));
+                               
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true), 
'int'));
+                               
$control->set_repeat_type_label($this->unmarshal($this->db->f('repeat_type', 
true), 'int'));
+                               
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval', 
true), 'int'));
+                               
+                               if($return_type == "return_object")
+                                       $controls_array[] = $control;
+                               else
+                                       $controls_array[] = $control->toArray();
+                       }
 
+                       if( count( $controls_array ) > 0 ){
+                               return $controls_array; 
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+
                function get_controls_by_control_area($control_area_id)
                {
                        $control_area_id = (int) $control_area_id;
@@ -212,7 +280,7 @@
                        while($this->db->next_record()) {
                                $control_id = 
$this->unmarshal($this->db->f('id', true), 'int');
                                $title = $this->unmarshal($this->db->f('title', 
true), 'string');
-                               $location_code = 
$this->unmarshal($this->db->f('location_code', true), 'strign');
+                               $location_code = 
$this->unmarshal($this->db->f('location_code', true), 'string');
 
                                $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$location_code));
 
@@ -227,7 +295,45 @@
                                return null;
                        }
                }
+               
+           function get_components_for_control($control_id)
+               {
+                       $controls_array = array();
 
+                       $sql =  "SELECT c.id, c.title, ccl.component_id, 
bim_type.description, bim.location_code ";
+            $sql .= "FROM controller_control c, 
controller_control_component_list ccl, fm_bim_item bim, fm_bim_type bim_type "; 
+                       $sql .= "WHERE ccl.control_id = $control_id ";
+            $sql .= "AND ccl.control_id = c.id ";
+                       $sql .= "AND bim.id = ccl.component_id ";
+                       $sql .= "AND bim_type.id = bim.type";
+
+                       $this->db->query($sql);
+
+                       while($this->db->next_record()) {
+                               $control_id = 
$this->unmarshal($this->db->f('id', true), 'int');
+                               $title = $this->unmarshal($this->db->f('title', 
true), 'string');
+                               $component_id = 
$this->unmarshal($this->db->f('component_id', true), 'int');
+                               $component_type = 
$this->unmarshal($this->db->f('description', true), 'string');
+                               $component_location_code = 
$this->unmarshal($this->db->f('location_code', true), 'string');
+                               //$component_guid = 
$this->unmarshal($this->db->f('guid', true), 'string');
+                               //$component_description = 
$this->getBimItemAttributeValue($component_guid, "beskrivelse");
+                               //$component_name = 
$this->getBimItemAttributeValue($component_guid, "betegnelse");
+                               //$component_author = 
$this->getBimItemAttributeValue($component_guid, "juridisk_person");
+                               
+                               $location_array = 
execMethod('property.bolocation.read_single', array('location_code' => 
$component_location_code));
+                               
+                               $controls_array[] = array("id" => $control_id, 
"title" => $title, "component_id" => $component_id, "component_description" => 
$component_type, "component_location" => $location_array["loc1_name"]);
+                       }
+
+                       if( count( $controls_array ) > 0 ){
+                               return $controls_array; 
+                       }
+                       else
+                       {
+                               return null;
+                       }
+               }
+
                function get_control_location($control_id, $location_code)
                {
                        $control_id = (int)$control_id;
@@ -636,6 +742,7 @@
                {
                        $columnAlias = "attribute_values";
                        $sql = "select 
array_to_string(xpath('descendant-or-self::*[{$attribute}]/{$attribute}/text()',
 (select xml_representation from fm_bim_item where guid='{$bimItemGuid}')), 
',') as $columnAlias";
+                       //var_dump($sql);
                        $this->db->query($sql,__LINE__,__FILE__);
                        if($this->db->num_rows() > 0)
                        {

Modified: trunk/controller/inc/hook_home.inc.php
===================================================================
--- trunk/controller/inc/hook_home.inc.php      2012-06-13 12:05:13 UTC (rev 
9575)
+++ trunk/controller/inc/hook_home.inc.php      2012-06-13 12:07:31 UTC (rev 
9576)
@@ -67,14 +67,22 @@
 
        $location_finder = new location_finder();
        $my_locations = $location_finder->get_responsibilities( $criteria );
-       
+       $unique_locations = array();
+       foreach($my_locations as $loc)
+       {
+           if(!in_array($loc["location_code"],$unique_locations))
+           {
+               $unique_locations[] = $loc["location_code"];
+           }
+       }
+
        $repeat_type = null;
        $controls_for_location_array = array();
-       foreach($my_locations as $location)
+       foreach($unique_locations as $location)
        {
-               $controls_for_location_array[] = 
array($location["location_code"], 
$so_control->get_controls_by_location($location["location_code"], 
$from_date_ts, $to_date_ts, $repeat_type ));
+           $controls_for_location_array[] = array($location, 
$so_control->get_controls_for_location($location, $from_date_ts, $to_date_ts, 
$repeat_type ));
        }
-       
+
        $controls_array = array();
        $control_dates = array();
        foreach($controls_for_location_array as $control_arr){
@@ -86,7 +94,7 @@
                        $controls_array[] = array($current_location, $control, 
$date_generator->get_dates());
                }
        }
-       
+
        $portalbox1 = CreateObject('phpgwapi.listbox', array
        (
                'title'         => "Mine planlagte kontroller",
@@ -130,7 +138,6 @@
                $curr_location = $control_instance[0];
                $current_control = $control_instance[1];
                $check_lists = 
$so->get_planned_check_lists_for_control($current_control->get_id(), 
$curr_location);
-               //_debug_array($check_lists);
                $location_array = execMethod('property.bolocation.read_single', 
array('location_code' => $curr_location));
                $location_name = $location_array["loc1_name"];
                foreach($control_areas['cat_list'] as $area)
@@ -203,7 +210,8 @@
        {
                $curr_location = $control_instance[0];
                $current_control = $control_instance[1];
-               $check_lists = 
$so->get_planned_check_lists_for_control($current_control->get_id(), 
$curr_location);
+               unset($check_lists);
+               $check_lists = 
$so->get_unplanned_check_lists_for_control($current_control->get_id(), 
$curr_location);
                //$control_location = 
$so_control->getLocationCodeFromControl($current_control->get_id());
                $location_array = execMethod('property.bolocation.read_single', 
array('location_code' => $curr_location));
                $location_name = $location_array["loc1_name"];
@@ -214,11 +222,7 @@
                                $control_area_name = $area['name'];
                        }
                }
-               $planned_lists = array();
-               foreach($check_lists as $check_list)
-               {
-                       $planned_lists = $check_list->get_deadline();
-               }
+
                $current_dates = $control_instance[2];
                
                foreach($current_dates as $current_date)
@@ -227,7 +231,7 @@
                        {
                                foreach($check_lists as $check_list)
                                {
-                                       if($current_date != 
$check_list->get_deadline())
+                                       if(intval($current_date) > 
intval($check_list->get_deadline()) && intval($current_date) != 
intval($check_list->get_deadline()))
                                        {
                                                $next_date = "Fristdato: " . 
date('d/m/Y', $current_date);
                                                $portalbox2_data[] = array
@@ -237,6 +241,16 @@
                                                        'link' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list.add_check_list', 'date' => $current_date, 'control_id' 
=> $current_control->get_id(), 'location_code' => $curr_location))
                                                ));
                                        }
+                                       else
+                                       {
+                                               $next_date = "Fristdato: " . 
date('d/m/Y', $check_list->get_deadline());
+                                               $portalbox2_data[] = array
+                                               ($current_date, array
+                                               (
+                                                       'text' => 
"{$location_name} - {$control_area_name} - {$current_control->get_title()} :: 
{$next_date}",
+                                                       'link' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'controller.uicheck_list.edit_check_list', 'check_list_id' => 
$check_list->get_id()))
+                                               ));                             
            
+                                       }
                                }
                        }
                        else
@@ -254,6 +268,7 @@
        //sort data by due date for check list
        sort($portalbox2_data);
        //$limit = 20;
+       //$limit_no_of_assigned = 50;
        $tmp = 0;
        foreach($portalbox2_data as $check_list_dates)
        {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]