fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [13464] more on controller


From: Sigurd Nes
Subject: [Fmsystem-commits] [13464] more on controller
Date: Fri, 19 Jun 2015 12:37:29 +0000

Revision: 13464
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=13464
Author:   sigurdne
Date:     2015-06-19 12:37:28 +0000 (Fri, 19 Jun 2015)
Log Message:
-----------
more on controller

Modified Paths:
--------------
    trunk/controller/inc/class.socontrol.inc.php
    trunk/controller/inc/class.uicomponent.inc.php
    trunk/controller/templates/base/component.xsl
    trunk/property/inc/class.soentity.inc.php
    trunk/property/setup/phpgw_no.lang

Modified: trunk/controller/inc/class.socontrol.inc.php
===================================================================
--- trunk/controller/inc/class.socontrol.inc.php        2015-06-18 22:39:50 UTC 
(rev 13463)
+++ trunk/controller/inc/class.socontrol.inc.php        2015-06-19 12:37:28 UTC 
(rev 13464)
@@ -38,7 +38,9 @@
   class controller_socontrol extends controller_socommon
   {
                protected static $so;
+               protected $global_lock = false;
 
+
                /**
                 * Get a static reference to the storage object associated with 
this model object
                 *
@@ -905,7 +907,14 @@
 
                        $delete_component = array();
                        $add_component = array();
-                       $this->db->transaction_begin();
+                       if ( $this->db->get_transaction() )
+                       {
+                               $this->global_lock = true;
+                       }
+                       else
+                       {
+                               $this->db->transaction_begin();
+                       }
 
                        if(isset($data['register_component']) && 
is_array($data['register_component']))
                        {
@@ -1017,7 +1026,11 @@
                                $ret += PHPGW_ACL_DELETE; //bit - delete
                        }
  
-                       $this->db->transaction_commit();
+                       if ( !$this->global_lock )
+                       {
+                               $this->db->transaction_commit();
+                       }
+
                        return $ret;
                }
 
@@ -1478,4 +1491,71 @@
                                return PHPGW_ACL_EDIT; // Bit - edit
                        }
                }
+
+               function 
add_controll_to_component_from_master($master_component, $targets = array())
+               {
+                       $master_component_arr = explode('_', $master_component);
+                       if(count($master_component_arr) != 2)
+                       {
+                               throw new 
Exception("controller_socontrol::add_controll_to_component_from_master - 
Missing master component");
+                       }
+
+                       $location_id = (int)$master_component_arr[0];
+                       $component_id = (int)$master_component_arr[1];
+
+                       $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}";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+                       $series = array();
+                       while($this->db->next_record())
+                       {
+                               $start_date             = 
$this->db->f('start_date');
+                               if($start_date < time())
+                               {
+                                       $start_date     = time();
+                               }
+                               $series[] = array(
+                                       'control_id'                    => 
$this->db->f('control_id'),
+                                       'assigned_to'                   => 
$this->db->f('assigned_to'),
+                                       'start_date'                    => 
$start_date,
+                                       'repeat_type'                   => 
$this->db->f('repeat_type'),
+                                       'repeat_interval'               => 
$this->db->f('repeat_interval'),
+                                       'service_time'                  => 
$this->db->f('service_time'),
+                                       'controle_time'                 => 
$this->db->f('controle_time'),
+                                       'duplicate'                             
=> true
+
+                               );
+                       }
+
+                       $this->db->transaction_begin();
+
+                       foreach($targets as $target)
+                       {
+                               $target_component_arr = explode('_', $target);
+
+                               $target_location_id = 
(int)$target_component_arr[0];
+                               $target_component_id = 
(int)$target_component_arr[1];
+                               foreach($series as $serie)
+                               {
+                                       $values = array
+                                       (
+                                               'register_component'    => 
array("{$serie['control_id']}_{$target_location_id}_{$target_component_id}"),
+                                               'assigned_to'                   
=> $serie['assigned_to'],
+                                               'start_date'                    
=> $serie['start_date'],
+                                               'repeat_type'                   
=> $serie['repeat_type'],
+                                               'repeat_interval'               
=> $serie['repeat_interval'],
+                                               'controle_time'                 
=> $serie['controle_time'],
+                                               'service_time'                  
=> $serie['service_time'],
+                                               'duplicate'                     
        => true
+                                       );
+                                       
$this->register_control_to_component($values);
+                               }
+                       }
+                       return $this->db->transaction_commit();
+               }
        }

Modified: trunk/controller/inc/class.uicomponent.inc.php
===================================================================
--- trunk/controller/inc/class.uicomponent.inc.php      2015-06-18 22:39:50 UTC 
(rev 13463)
+++ trunk/controller/inc/class.uicomponent.inc.php      2015-06-19 12:37:28 UTC 
(rev 13464)
@@ -57,9 +57,11 @@
                private $add;
                private $edit;
                private $delete;
+               private $org_units;
                public $public_functions = array
                        (
-                       'index'                                                 
 => true,
+                       'index'                                         => true,
+                       'add_controll_from_master'      => true
                );
 
                public function __construct()
@@ -82,6 +84,35 @@
                        $this->account                  = 
$GLOBALS['phpgw_info']['user']['account_id'];
                }
 
+               public function add_controll_from_master()
+               {
+                       $master_component = phpgw::get_var('master_component', 
'string');
+                       $target = phpgw::get_var('target', 'string');//array of 
strings
+                       $result = array('status' => 'error', 'message' => '');
+
+                       if($this->manage)
+                       {
+                               $so_control     = 
CreateObject('controller.socontrol');
+                               try
+                               {
+                                       $result['status'] = 
$so_control->add_controll_to_component_from_master($master_component, $target);
+                                       $result['message'] = count($target) . ' 
' . lang('added');
+                               }
+                               catch(Exception $e)
+                               {
+                                       if ( $e )
+                                       {
+                                               $result['message'] = 
$e->getMessage();
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               $result['message'] = 'Go away';
+                       }
+                       return $result;
+               }
+
                private function get_location_filter()
                {
                        $entity_group_id = phpgw::get_var('entity_group_id', 
'int');
@@ -218,8 +249,6 @@
                                array('id' => 'not_performed', 'name' => 
lang('status not done')),
                                array('id' => 'done_with_open_deviation', 
'name' => lang('done with open deviation')),
                        );
-                       $location_filter = $this->get_location_filter();
-                       array_unshift($location_filter, array('id' => '', 
'name' => lang('select value')));
 
                        $filter_component = '';
                        if(phpgw::get_var('component_id', 'int'))
@@ -239,13 +268,24 @@
                                                                'list'   => 
execMethod('property.bogeneric.get_list',array('type' => 'entity_group', 
'selected' => phpgw::get_var('entity_group_id'), 'add_empty' => true)),
                                                                'onchange'      
=> 'update_table();'
                                                        ),
+                                                       array('type'     => 
'hidden',
+                                                               'name'   => 
'location_id',
+                                                               'value'  => 
phpgw::get_var('location_id', 'int')
+                                                       ),
                                                        array('type'     => 
'filter',
                                                                'name'   => 
'location_id',
                                                                'text'   => 
lang('component'),
-                                                               'list'   => 
$location_filter,
+                                                               'list'   => 
array(),
                                                                'onchange'      
=> 'update_table();'
-                                                       ),/*
+                                                       ),
                                                        array('type'     => 
'filter',
+                                                               'name'   => 
'org_unit_id',
+                                                               'text'   => 
lang('department'),
+                                                               'list'   => 
execMethod('property.bogeneric.get_list',array('type' => 'org_unit', 'selected' 
=> phpgw::get_var('org_unit_id'), 'add_empty' => true)),
+                                                               'onchange'      
=> 'update_table();'
+                                                       ),
+                                                       /*
+                                                       array('type'     => 
'filter',
                                                                'name'   => 
'control_area',
                                                                'text'   => 
lang('Control_area'),
                                                                'list'   => 
$control_areas_array,
@@ -387,6 +427,21 @@
                        return $fields;
                }
 
+               /**
+               * Get the sublevels of the org tree into one arry
+               */
+               private function _get_children($data = array() )
+               {
+                       foreach ($data as $entry)
+                       {
+                               $this->org_units[]= $entry['id'];
+                               if(isset($entry['children']) && 
$entry['children'])
+                               {
+                                       
$this->_get_children($entry['children']);
+                               }
+                       }
+               }
+
                public function query()
                {
                        $entity_group_id = phpgw::get_var('entity_group_id', 
'int');
@@ -404,6 +459,21 @@
                                $location_id = $filter_component_arr[0];
                                $filter_component = $filter_component_arr[1];
                        }
+                       if($org_unit_id = phpgw::get_var('org_unit_id', 'int'))
+                       {
+                               $_subs = 
execMethod('property.sogeneric.read_tree',array('node_id' => $org_unit_id, 
'type' => 'org_unit'));
+                               $this->org_units[]= $org_unit_id;
+                               foreach($_subs as $entry)
+                               {
+                                       $this->org_units[]= $entry['id'];
+                                       if(isset($entry['children']) && 
$entry['children'])
+                                       {
+                                               
$this->_get_children($entry['children']);
+                                       }
+                               }
+                               unset($entry);
+                               unset($_subs);
+                       }
 
                        $so_control                      = 
CreateObject('controller.socontrol');
                        $this->so                       = 
CreateObject('controller.socheck_list');
@@ -431,6 +501,7 @@
                        if($user_id < 0)
                        {
                                $user_id = $user_id * -1;
+                               $all_items = false;
 
                                $keep_only_assigned_to = $user_id;
                                $assigned_components = 
$so_control->get_assigned_control_components($from_date_ts, $to_date_ts, 
$assigned_to = $user_id);
@@ -478,6 +549,7 @@
                                                'filter_entity_group'           
=> $entity_group_id,
                                                'location_id'                   
        => $_location_id,
                                                'district_id'                   
        => $district_id,
+                                               'org_units'                     
                => $this->org_units,
                                                'allrows'                       
                => true,
                                                'control_registered'            
=> !$all_items,
                                                'check_for_control'             
        => true,
@@ -490,13 +562,14 @@
                                if($lookup_stray_items)
                                {
                                        $_components = 
execMethod('property.soentity.read_entity_group',array(
-                                               'entity_group_id' => 
$entity_group_id,
-                                               'exclude_locations'     => 
$exclude_locations,
-                                               'location_id' => $_location_id,
-                                               'district_id' => $district_id,
-                                               'allrows' => true,
-                                               'control_registered' => 
!$all_items,
-                                               'check_for_control' => true
+                                               'entity_group_id'               
        => $entity_group_id,
+                                               'exclude_locations'             
        => $exclude_locations,
+                                               'location_id'                   
        => $_location_id,
+                                               'district_id'                   
        => $district_id,
+                                               'org_units'                     
                => $this->org_units,
+                                               'allrows'                       
                => true,
+                                               'control_registered'            
=> !$all_items,
+                                               'check_for_control'             
        => true
                                                )
                                        );
                                        $components = array_merge($components, 
$_components);
@@ -751,7 +824,7 @@
                                }
                                else if ($choose_master)
                                {
-                                       $row['choose'] = "<input 
id=\"selected_components\" class=\"mychecks\" type=\"checkbox\" 
name=\"selected_components[]\" value = 
\"{$entry['location_id']}_{$entry['component_id']}\"  
onclick=\"add_from_master({$entry['location_id']},{$entry['component_id']});\">";
+                                       $row['choose'] = "<input 
id=\"selected_components\" class=\"mychecks\" type=\"checkbox\" 
name=\"selected_components[]\" value = 
\"{$entry['location_id']}_{$entry['component_id']}\">";
                                }
 
                                $found_at_least_one = false;

Modified: trunk/controller/templates/base/component.xsl
===================================================================
--- trunk/controller/templates/base/component.xsl       2015-06-18 22:39:50 UTC 
(rev 13463)
+++ trunk/controller/templates/base/component.xsl       2015-06-19 12:37:28 UTC 
(rev 13464)
@@ -20,6 +20,7 @@
        <h2>
                <xsl:value-of select="datatable_name"/>
        </h2>
+       <div id="receipt"></div>
        <xsl:call-template name="icon_color_map" />
        <xsl:apply-templates select="form" />
        <xsl:apply-templates select="paging"/>
@@ -224,6 +225,8 @@
                };
                update_table = function()
                {
+                       $("#receipt").html('');
+
                        var user_id = $("#user_id").val();
                        if(user_id < 0)
                        {
@@ -233,6 +236,8 @@
                                $("[for='location_id']").hide();
                                $("[name='all_items']").hide();
                                $("[for='all_items']").hide();
+                               $( "#org_unit_id" ).hide();
+                               $("[for='org_unit_id']").hide();
                        }
                        else
                        {
@@ -242,6 +247,8 @@
                                $("[for='location_id']").show();
                                $("[name='all_items']").show();
                                $("[for='all_items']").show();
+                               $( "#org_unit_id" ).show();
+                               $("[for='org_unit_id']").show();
                        }
 
                        var requestUrl = $("#queryForm").attr("action");
@@ -334,7 +341,7 @@
                                }
                        });
 
-                       oArgs = {menuaction: 
'controller.uicomponent.add_controll_from _master'};
+                       oArgs = {menuaction: 
'controller.uicomponent.add_controll_from_master'};
                        var requestUrl = phpGWLink('index.php', oArgs, true);
 
                        $.ajax({
@@ -345,7 +352,21 @@
                                success: function(data) {
                                        if( data != null)
                                        {
+console.log(data);
+                                               var message = data.message;
+
+                                               htmlString = "";
+                                               var msg_class = "msg_good";
+                                               if(data.status =='error')
+                                               {
+                                                       msg_class = "error";
+                                               }
+                                               htmlString += "<div class=\"" + 
msg_class + "\">";
+                                               htmlString += message;
+                                               htmlString += '</div>';
                                                update_table();
+                                               $("#receipt").html(htmlString);
+
                                        }
                                }
                        });

Modified: trunk/property/inc/class.soentity.inc.php
===================================================================
--- trunk/property/inc/class.soentity.inc.php   2015-06-18 22:39:50 UTC (rev 
13463)
+++ trunk/property/inc/class.soentity.inc.php   2015-06-19 12:37:28 UTC (rev 
13464)
@@ -509,11 +509,12 @@
                        $filtermethod = "WHERE fm_bim_type.location_id = 
{$location_id}";
                        $where= 'AND';
 
-                       if( $category['org_unit'])
+//                     if( $category['org_unit'])
                        {
                                if($org_units)
                                {
                                        $filtermethod .= " $where ( 
$entity_table.org_unit_id IN(" . implode(',',$org_units) . "))";
+                                       $where= 'AND';
                                }
                        }
 
@@ -1455,7 +1456,7 @@
                        }
 
                        unset($_config);
-                       if( $category['org_unit'])
+//                     if( $category['org_unit'])
                        {
                                if($org_units)
                                {

Modified: trunk/property/setup/phpgw_no.lang
===================================================================
--- trunk/property/setup/phpgw_no.lang  2015-06-18 22:39:50 UTC (rev 13463)
+++ trunk/property/setup/phpgw_no.lang  2015-06-19 12:37:28 UTC (rev 13464)
@@ -537,7 +537,7 @@
 delete workorder       property        no      slett bestilling
 delivered      property        no      Levert
 delivery address       property        no      Leveringsadresse
-department     property        no      Avdeling
+department     common  no      Avdeling
 deposit claim  property        no      Krav mot depositum
 deposition     property        no      Avsetning
 description    property        no      Beskrivelse




reply via email to

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