fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [17365] more on controller


From: sigurdne
Subject: [Fmsystem-commits] [17365] more on controller
Date: Sat, 25 Nov 2017 14:28:55 -0500 (EST)

Revision: 17365
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=17365
Author:   sigurdne
Date:     2017-11-25 14:28:54 -0500 (Sat, 25 Nov 2017)
Log Message:
-----------
more on controller

Modified Paths:
--------------
    trunk/controller/inc/class.socontrol.inc.php
    trunk/controller/inc/class.uicomponent.inc.php
    trunk/controller/js/controller/component.index.js
    trunk/property/inc/class.soentity.inc.php
    trunk/property/inc/class.solocation.inc.php

Modified: trunk/controller/inc/class.socontrol.inc.php
===================================================================
--- trunk/controller/inc/class.socontrol.inc.php        2017-11-24 20:51:14 UTC 
(rev 17364)
+++ trunk/controller/inc/class.socontrol.inc.php        2017-11-25 19:28:54 UTC 
(rev 17365)
@@ -1131,7 +1131,7 @@
                 * @return array controls assosiated with a component
                 * @throws Exception if missing valid input
                 */
-               function get_controls_at_component2( $data )
+               function get_controls_at_component2( $data , $control_id = 0)
                {
                        if (!isset($data['location_id']) || 
!$data['location_id'])
                        {
@@ -1142,6 +1142,13 @@
                                throw new 
Exception("controller_socontrol::get_controls_at_component - Missing 
component_id in input");
                        }
 
+                       $control_id = (int) $control_id;
+
+                       if($control_id)
+                       {
+                               $filter_control = "AND controller_control.id = 
{$control_id}";
+                       }
+
                        static $users = array(); // cache result
 
                        $location_id = (int)$data['location_id'];
@@ -1158,7 +1165,7 @@
                                . " FROM controller_control_component_list"
                                . " {$this->db->join} controller_control ON 
controller_control.id = controller_control_component_list.control_id"
                                . " {$this->db->left_join} 
controller_control_serie ON (controller_control_component_list.id = 
controller_control_serie.control_relation_id AND 
controller_control_serie.control_relation_type = 'component')"
-                               . " WHERE location_id = {$location_id} AND 
component_id = {$component_id}"
+                               . " WHERE location_id = {$location_id} AND 
component_id = {$component_id} {$filter_control}"
                                . " ORDER BY repeat_type, repeat_interval";
 //                     _debug_array($sql);
                        $this->db->query($sql, __LINE__, __FILE__);
@@ -1644,7 +1651,7 @@
                function add_controll_to_component_from_master( 
$master_component, $targets = array() )
                {
                        $master_component_arr = explode('_', $master_component);
-                       if (count($master_component_arr) != 2)
+                       if (count($master_component_arr) != 3)
                        {
                                throw new 
Exception("controller_socontrol::add_controll_to_component_from_master - 
Missing master component");
                        }
@@ -1651,12 +1658,16 @@
 
                        $location_id = (int)$master_component_arr[0];
                        $component_id = (int)$master_component_arr[1];
+                       $control_id = (int)$master_component_arr[2];
 
                        $sql = "SELECT * FROM controller_control_component_list"
                                . " {$this->db->join} controller_control_serie"
                                . " ON 
controller_control_serie.control_relation_id = 
controller_control_component_list.id"
                                . " AND 
controller_control_serie.control_relation_type = 'component'"
-                               . " WHERE location_id = {$location_id} AND  
component_id = {$component_id} AND controller_control_serie.enabled = 1";
+                               . " WHERE location_id = {$location_id}"
+                               . " AND  component_id = {$component_id}"
+                               . " AND control_id = {$control_id}"
+                               . " AND controller_control_serie.enabled = 1";
 
                        $this->db->query($sql, __LINE__, __FILE__);
 

Modified: trunk/controller/inc/class.uicomponent.inc.php
===================================================================
--- trunk/controller/inc/class.uicomponent.inc.php      2017-11-24 20:51:14 UTC 
(rev 17364)
+++ trunk/controller/inc/class.uicomponent.inc.php      2017-11-25 19:28:54 UTC 
(rev 17365)
@@ -644,6 +644,11 @@
                        $filter_control_id = phpgw::get_var('control_id', 
'int');
                        $location_id = phpgw::get_var('location_id', 'int');
                        $location_code = phpgw::get_var('location_code', 
'string');
+                       $location_name = phpgw::get_var('location_name', 
'string');
+                       if(!$location_name)
+                       {
+                               $location_code = '';
+                       }
                        $control_area = phpgw::get_var('control_area', 'int');
                        $user_id = phpgw::get_var('user_id', 'int');
                        $district_id = phpgw::get_var('district_id', 'int');
@@ -661,6 +666,11 @@
                                $location_id = $filter_component_arr[0];
                                $filter_component = $filter_component_arr[1];
                        }
+                       else
+                       {
+                               $filter_component = array();
+                       }
+
                        if ($org_unit_id = phpgw::get_var('org_unit_id', 'int'))
                        {
                                $_subs = 
execMethod('property.sogeneric.read_tree', array('node_id' => $org_unit_id,
@@ -804,6 +814,7 @@
                                                $_items = 
execMethod('property.solocation.read', array(
                                                        'filter_entity_group' 
=> $entity_group_id,
                                                        'location_id' => 
$_location_id,
+                                                       'control_id' => 
$filter_control_id,
                                                        'district_id' => 
$district_id,
                                                        'location_code' => 
$location_code,
                                                        'control_registered' => 
!$all_items,
@@ -867,7 +878,7 @@
                                {
                                        continue;
                                }
-                               $controls_at_component = 
$so_control->get_controls_at_component2($_item);
+                               $controls_at_component = 
$so_control->get_controls_at_component2($_item, $filter_control_id);
 
                                foreach ($controls_at_component as $component)
                                {
@@ -1023,6 +1034,7 @@
                                        );
                                }
 
+                               $data['control_id'] = $type_array[2];
                                $data['control_type'] = 
$control_names[$type_array[2]];
                                $data['component_url'] = '<a href="' . 
$GLOBALS['phpgw']->link('/index.php', $item_link_data) . "\" 
target='_blank'>{$item_id}{$entry[0]['component']['xml_short_desc']}</a>";
                                $data['component_id'] = $item_id;
@@ -1158,6 +1170,8 @@
                                                $short_description .= ' [' . 
$component['loc1_name'] . ']';
                                        }
 
+
+                                       $data['control_id'] = 0;
                                        $data['control_type'] = '';
                                        $data['component_url'] = '<a href="' . 
$GLOBALS['phpgw']->link('/index.php', $item_link_data) . "\" 
target='_blank'>{$item_id} 
{$location_type_name[$location_id]}</br>{$short_description}</a>";
                                        $data['component_id'] = $item_id;
@@ -1188,7 +1202,7 @@
                                        }
                                        else if ($choose_master)
                                        {
-                                               $row['choose'] = "<input 
id=\"master_component\" type=\"radio\" name=\"master_component\" value = 
\"{$entry['location_id']}_{$entry['component_id']}\" >";
+                                               $row['choose'] = "<input 
id=\"master_component\" type=\"radio\" name=\"master_component\" value = 
\"{$entry['location_id']}_{$entry['component_id']}_{$entry['control_id']}\" >";
                                        }
                                        $row['year'] = $year;
                                        $row['descr'] = 
"Frekvens<br/>Status<br/>Utførende<br/>Tidsbruk";

Modified: trunk/controller/js/controller/component.index.js
===================================================================
--- trunk/controller/js/controller/component.index.js   2017-11-24 20:51:14 UTC 
(rev 17364)
+++ trunk/controller/js/controller/component.index.js   2017-11-25 19:28:54 UTC 
(rev 17365)
@@ -40,6 +40,15 @@
 {
        update_table();
 
+       $("#location_name").focusout(function ()
+       {
+               if($("#location_code").val() && $(this).val() == false)
+               {
+                       $("#location_code").val('');
+                       update_table('');
+               }
+       });
+
        $("#location_name").on("autocompleteselect", function (event, ui)
        {
                var location_code = ui.item.value;

Modified: trunk/property/inc/class.soentity.inc.php
===================================================================
--- trunk/property/inc/class.soentity.inc.php   2017-11-24 20:51:14 UTC (rev 
17364)
+++ trunk/property/inc/class.soentity.inc.php   2017-11-25 19:28:54 UTC (rev 
17365)
@@ -867,6 +867,8 @@
 
                        if ($check_for_control && !$control_registered)
                        {
+                               $filtermethod .= " $where (control_id = 
$control_id OR control_id IS NULL)";
+                               $where = 'AND';
                                $sql .= "{$this->left_join} {$join_control}";
 
                                $sql_custom_field .= ',count(control_id) AS 
has_control';

Modified: trunk/property/inc/class.solocation.inc.php
===================================================================
--- trunk/property/inc/class.solocation.inc.php 2017-11-24 20:51:14 UTC (rev 
17364)
+++ trunk/property/inc/class.solocation.inc.php 2017-11-25 19:28:54 UTC (rev 
17365)
@@ -293,7 +293,7 @@
 
                        $this->db->query($sql, __LINE__, __FILE__);
                        $attribs = array();
-                       
+
                        while ($this->db->next_record())
                        {
                                $id = $this->db->f('id');
@@ -393,7 +393,7 @@
                        $sql = $this->socommon->fm_cache('sql_' . $type_id . 
'_lt' . $lookup_tenant . '_l' . $lookup . '_f' . !!$filter_role_on_contact);
                        if(empty($location_id))
                        {
-                               $location_id = 
$GLOBALS['phpgw']->locations->get_id('property', ".location.{$type_id}");       
                 
+                               $location_id = 
$GLOBALS['phpgw']->locations->get_id('property', ".location.{$type_id}");
                        }
 
 //                     $choice_table = 'phpgw_cust_choice';
@@ -666,40 +666,75 @@
                                $sub_query_street = 
$this->socommon->fm_cache('sub_query_street_' . $type_id . '_' . $lookup_tenant 
. '_' . $lookup);
                        }
 
+                       $items_with_control = array();
                        $filtermethod = '';
                        $where = 'WHERE';
-                       if ($check_for_control && $control_registered && 
$control_id)
+                       /**
+                        * From old scheme: 
controller.uicontrol_register_to_location.index
+                        */
+                       if (!$check_for_control && $control_registered && 
$control_id)
                        {
                                $sql .= "{$this->join} 
controller_control_location_list ON (fm_location{$type_id}.location_code = 
controller_control_location_list.location_code )";
                                $filtermethod .= " $where  
controller_control_location_list.control_id = $control_id";
                                $where = 'AND';
-                       }
-                       else if ($check_for_control && !$control_registered)
+                       }// from new scheme controller.uicomponent.index
+                       else if ($check_for_control)
                        {
-
-                               $sql_without_control = "SELECT DISTINCT 
fm_location2.id as item_id"
-                               . " FROM fm_location2 {$this->left_join} 
controller_control_component_list"
-                               . " ON 
controller_control_component_list.component_id = fm_location2.id"
-                                       . " {$this->left_join} 
controller_control_serie"
+                               $sql_with_control = "SELECT DISTINCT 
fm_location{$type_id}.id as item_id"
+                               . " FROM fm_location{$type_id} {$this->join} 
controller_control_component_list"
+                               . " ON 
controller_control_component_list.component_id = fm_location{$type_id}.id"
+                                       . " {$this->join} 
controller_control_serie"
                                        . " ON 
(controller_control_component_list.id = 
controller_control_serie.control_relation_id"
                                                . " AND 
controller_control_serie.control_relation_type = 'component'"
                                                . " AND 
controller_control_component_list.location_id = {$location_id}"
-                                               . " AND 
controller_control_serie.enabled = 1)"
-                               . " WHERE 
controller_control_component_list.location_id IS NULL";
+                                               . " AND 
controller_control_serie.enabled = 1)";
 
-                               $this->db->query($sql_without_control);
-                               $items = array_merge(array(-1), $filter_item);
+                               if($control_id)
+                               {
+                                       $sql_with_control .= " WHERE control_id 
= {$control_id}";
+                               }
+
+                               $this->db->query($sql_with_control);
+                               $items_with_control = array_merge(array(-1), 
$filter_item);
                                while ($this->db->next_record())
                                {
-                                       $items[] =  
(int)$this->db->f('item_id');
+                                       $items_with_control[] =  
(int)$this->db->f('item_id');
                                }
 
+                               /**
+                                * reset for later use
+                                */
                                $filter_item = array();
 
-                               $filtermethod .= " $where 
fm_location{$type_id}.id IN (". implode(',', $items) . ')';
+                               if($control_registered)
+                               {
+                                       $filtermethod .= " $where 
fm_location{$type_id}.id IN (". implode(',', $items_with_control) . ')';
+
+                               }
+                               else
+                               {
+                                       $sql_without_control = "SELECT DISTINCT 
fm_location{$type_id}.id as item_id"
+                                       . " FROM fm_location{$type_id} 
{$this->left_join} controller_control_component_list"
+                                       . " ON 
controller_control_component_list.component_id = fm_location{$type_id}.id"
+                                               . " {$this->left_join} 
controller_control_serie"
+                                               . " ON 
(controller_control_component_list.id = 
controller_control_serie.control_relation_id"
+                                                       . " AND 
controller_control_serie.control_relation_type = 'component'"
+                                                       . " AND 
controller_control_component_list.location_id = {$location_id}"
+                                                       . " AND 
controller_control_serie.enabled = 1)"
+                                       . " WHERE 
controller_control_component_list.location_id IS NULL";
+
+                                       $this->db->query($sql_without_control);
+                                       $items_without_control = array();
+                                       while ($this->db->next_record())
+                                       {
+                                               $items_without_control[] =  
(int)$this->db->f('item_id');
+                                       }
+
+                                       $filtermethod .= " $where 
fm_location{$type_id}.id IN (". implode(',', 
array_merge($items_without_control, $items_with_control)) . ')';
+                               }
+
                                $where = 'AND';
                        }
-
                        //---------------------start custom user cols
 
                        $user_columns = 
isset($GLOBALS['phpgw_info']['user']['preferences']['property']['location_columns_'
 . $type_id . !!$lookup]) ? 
$GLOBALS['phpgw_info']['user']['preferences']['property']['location_columns_' . 
$type_id . !!$lookup] : array();
@@ -1116,6 +1151,15 @@
                        $this->db->set_fetch_single(false);
 
                        $values = $this->custom->translate_value($dataset, 
$location_id, $location_count);
+
+                       if ($check_for_control)
+                       {
+                               foreach ($values as &$value)
+                               {
+                                       $value['has_control'] = 
!!in_array($value['id'], $items_with_control);
+                               }
+                       }
+
                        return $values;
                }
 
@@ -1313,7 +1357,7 @@
 
                        $location_array = explode('-', $location_code);
                        $type_id = count($location_array);
-                       
+
                        $location_id = !empty($values['location_id']) ? (int) 
$values['location_id'] : null;
 
                        /**




reply via email to

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