fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10574] property: more on condition survey


From: Sigurd Nes
Subject: [Fmsystem-commits] [10574] property: more on condition survey
Date: Thu, 06 Dec 2012 09:52:44 +0000

Revision: 10574
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10574
Author:   sigurdne
Date:     2012-12-06 09:52:44 +0000 (Thu, 06 Dec 2012)
Log Message:
-----------
property: more on condition survey

Modified Paths:
--------------
    trunk/property/inc/class.socondition_survey.inc.php

Added Paths:
-----------
    trunk/property/inc/class.socommon_core.inc.php

Added: trunk/property/inc/class.socommon_core.inc.php
===================================================================
--- trunk/property/inc/class.socommon_core.inc.php                              
(rev 0)
+++ trunk/property/inc/class.socommon_core.inc.php      2012-12-06 09:52:44 UTC 
(rev 10574)
@@ -0,0 +1,216 @@
+<?php
+       /**
+       * Common so-functions, database related helpers 
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License v2 or later
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package property
+       * @subpackage core
+       * @version $Id: class.socommon_core.inc.php 10127 2012-10-07 17:06:01Z 
sigurdne $
+       */
+
+       /*
+               This program is free software: you can redistribute it and/or 
modify
+               it under the terms of the GNU Lesser General Public License as 
published by
+               the Free Software Foundation, either version 2 of the License, 
or
+               (at your option) any later version.
+
+               This program is distributed in the hope that it will be useful,
+               but WITHOUT ANY WARRANTY; without even the implied warranty of
+               MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+               GNU Lesser General Public License for more details.
+
+               You should have received a copy of the GNU General Public 
License
+               along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
+        */
+
+
+
+
+       phpgw::import_class('phpgwapi.datetime');
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class property_socommon_core
+       {
+               /**
+               * @var int $_total_records total number of records found
+               */
+               protected $_total_records = 0;
+
+
+               /**
+               * @var int $_receipt feedback on actions
+               */
+               protected $_receipt = array();
+
+
+               /**
+                * @var object $_db reference to the global database object
+                */
+               protected $_db;
+
+               /**
+                * @var string $_join SQL JOIN statement
+                */
+               protected $_join;
+
+               /**
+                * @var string $_like SQL LIKE statement
+                */
+               protected $_like;
+
+
+               public function __construct()
+               {
+                       $this->account          = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
+                       $this->_db                      = & 
$GLOBALS['phpgw']->db;
+                       $this->_join            = & $this->_db->join;
+                       $this->_like            = & $this->_db->like;
+                       $this->custom           = 
createObject('property.custom_fields');
+               }
+
+               /**
+                * Magic get method
+                *
+                * @param string $varname the variable to fetch
+                *
+                * @return mixed the value of the variable sought - null if not 
found
+                */
+               public function __get($varname)
+               {
+                       switch ($varname)
+                       {
+                               case 'total_records':
+                                       return $this->_total_records;
+                                       break;
+                               case 'receipt':
+                                       return $this->_receipt;
+                                       break;
+                               default:
+                                       return null;
+                       }
+               }
+
+               protected function _edit($id, $value_set, $table)
+               {
+                       $id = (int)$id;
+
+                       $value_set      = 
$this->_db->validate_update($value_set);
+
+                       $this->_db->transaction_begin();
+
+                       $sql = "UPDATE {$table} SET $value_set WHERE id= {$id}";
+
+                       try
+                       {
+                               $this->_db->Exception_On_Error = true;
+                               $this->_db->query($sql,__LINE__,__FILE__);
+                               $this->_db->Exception_On_Error = false;
+                       }
+
+                       catch(Exception $e)
+                       {
+                               if ( $e )
+                               {
+                                       throw $e;
+                               }
+                       }
+
+                       $this->_db->transaction_commit();
+                       return $id;
+               }
+
+
+               /**
+                * Get standard valueset for atttibutes and location
+                *
+                * @param array $data the data to organize
+                *
+                * @return array $value_set to either insert or edit
+                */
+
+               protected function _get_value_set($data)
+               {
+                       if(isset($data['location']) && 
is_array($data['location']))
+                       {
+                               foreach ($data['location'] as $input_name => 
$value)
+                               {
+                                       if(isset($value) && $value)
+                                       {
+                                               $value_set[$input_name] = 
$value;
+                                       }
+                               }
+                               $value_set['location_code'] = implode('-', 
$data['location']);
+                       }
+
+                       if(isset($data['extra']) && is_array($data['extra']))
+                       {
+                               foreach ($data['extra'] as $input_name => 
$value)
+                               {
+                                       if(isset($value) && $value)
+                                       {
+                                               $value_set[$input_name] = 
$value;
+                                       }
+                               }
+
+                               if($data['extra']['p_num'] && 
$data['extra']['p_entity_id'] && $data['extra']['p_cat_id'])
+                               {
+                                       $entity = 
CreateObject('property.soadmin_entity');
+                                       $entity_category = 
$entity->read_single_category($data['extra']['p_entity_id'],$data['extra']['p_cat_id']);
+                               }
+                       }
+
+                       if(isset($values['attributes']) && 
is_array($values['attributes']))
+                       {
+                               $data_attribute = 
$this->custom->prepare_for_db($table, $values['attributes']);
+                               if(isset($data_attribute['value_set']))
+                               {
+                                       foreach($data_attribute['value_set'] as 
$input_name => $value)
+                                       {
+                                               if(isset($value) && $value)
+                                               {
+                                                       $value_set[$input_name] 
= $value;
+                                               }
+                                       }
+                               }
+                       }
+
+                       $_address = array();
+                       if(isset($data['street_name']) && $data['street_name'])
+                       {
+                               $_address[] = "{$data['street_name']} 
{$data['street_number']}";
+                       }
+
+                       if(isset($data['location_name']) && 
$data['location_name'])
+                       {
+                               $_address[] = $data['location_name'];
+                       }
+
+                       if(isset($data['additional_info']) && 
$data['additional_info'])
+                       {
+                               foreach($data['additional_info'] as $key => 
$value)
+                               {
+                                       if($value)
+                                       {
+                                               $_address[] = "{$key}|{$value}";
+                                       }
+                               }
+                       }
+
+                       if(isset($entity_category) && $entity_category)
+                       {
+                               $_address[] = 
"{$entity_category['name']}::{$data['extra']['p_num']}";
+                       }
+
+                       $address        = 
$this->_db->db_addslashes(implode('::', $_address));
+
+                       $value_set['address'] = $address;
+
+                       return $value_set;
+               }
+       }

Modified: trunk/property/inc/class.socondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.socondition_survey.inc.php 2012-12-06 09:10:29 UTC 
(rev 10573)
+++ trunk/property/inc/class.socondition_survey.inc.php 2012-12-06 09:52:44 UTC 
(rev 10574)
@@ -28,13 +28,14 @@
        */
 
        phpgw::import_class('phpgwapi.datetime');
+       phpgw::import_class('property.socommon_core');
 
        /**
         * Description
         * @package property
         */
 
-       class property_socondition_survey
+       class property_socondition_survey extends property_socommon_core
        {
                /**
                * @var int $_total_records total number of records found
@@ -66,34 +67,9 @@
 
                public function __construct()
                {
-                       $this->account          = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
-                       $this->_db                      = & 
$GLOBALS['phpgw']->db;
-                       $this->_join            = & $this->_db->join;
-                       $this->_like            = & $this->_db->like;
-                       $this->custom           = 
createObject('property.custom_fields');
+                       parent::__construct();
                }
 
-               /**
-                * Magic get method
-                *
-                * @param string $varname the variable to fetch
-                *
-                * @return mixed the value of the variable sought - null if not 
found
-                */
-               public function __get($varname)
-               {
-                       switch ($varname)
-                       {
-                               case 'total_records':
-                                       return $this->_total_records;
-                                       break;
-                               case 'receipt':
-                                       return $this->_receipt;
-                                       break;
-                               default:
-                                       return null;
-                       }
-               }
 
                function read($data = array())
                {
@@ -207,10 +183,20 @@
 
                        $id = $this->_db->next_id($table);
 
-                       $value_set                                      = 
$this->_get_value_set( $data );
-                       $value_set['id']                        = $id;
-                       $value_set['entry_date']        = time();
+                       $value_set                                              
= $this->_get_value_set( $data );
+                       $value_set['id']                                = $id;
+                       $value_set['entry_date']                = time();
+                       $value_set['title']                             = 
$this->_db->db_addslashes($data['title']);
+                       $value_set['descr']                             = 
$this->_db->db_addslashes($data['descr']);
+                       $value_set['status_id']                 = 
(int)$data['status_id'];
+                       $value_set['category']                  = 
(int)$data['cat_id'];
+                       $value_set['vendor_id']                 = 
(int)$data['vendor_id'];
+                       $value_set['coordinator_id']    = 
(int)$data['coordinator_id'];
+                       $value_set['report_date']               = 
phpgwapi_datetime::date_to_timestamp($data['report_date']);
+                       $value_set['user_id']                   = 
$this->account;
+                       $value_set['modified_date']             = time();
 
+
                        $cols = implode(',', array_keys($value_set));
                        $values = 
$this->_db->validate_insert(array_values($value_set));
                        $sql = "INSERT INTO {$table} ({$cols}) VALUES 
({$values})";
@@ -248,9 +234,19 @@
 
                        $value_set      = $this->_get_value_set( $data );
 
+                       $value_set['title']                             = 
$this->_db->db_addslashes($data['title']);
+                       $value_set['descr']                             = 
$this->_db->db_addslashes($data['descr']);
+                       $value_set['status_id']                 = 
(int)$data['status_id'];
+                       $value_set['category']                  = 
(int)$data['cat_id'];
+                       $value_set['vendor_id']                 = 
(int)$data['vendor_id'];
+                       $value_set['coordinator_id']    = 
(int)$data['coordinator_id'];
+                       $value_set['report_date']               = 
phpgwapi_datetime::date_to_timestamp($data['report_date']);
+                       $value_set['user_id']                   = 
$this->account;
+                       $value_set['modified_date']             = time();
+
                        try
                        {
-                               $this->_edit($id, $value_set);
+                               $this->_edit($id, $value_set, 
'fm_condition_survey');
                        }
 
                        catch(Exception $e)
@@ -275,7 +271,7 @@
 
                        try
                        {
-                               $this->_edit($id, $value_set);
+                               $this->_edit($id, $value_set, 
'fm_condition_survey');
                        }
 
                        catch(Exception $e)
@@ -289,131 +285,6 @@
                        return $id;
                }
 
-               private function _edit($id, $value_set)
-               {
-                       $table = 'fm_condition_survey';
-                       $id = (int)$id;
-
-                       $value_set      = 
$this->_db->validate_update($value_set);
-
-                       $this->_db->transaction_begin();
-
-                       $sql = "UPDATE {$table} SET $value_set WHERE id= {$id}";
-
-                       try
-                       {
-                               $this->_db->Exception_On_Error = true;
-                               $this->_db->query($sql,__LINE__,__FILE__);
-                               $this->_db->Exception_On_Error = false;
-                       }
-
-                       catch(Exception $e)
-                       {
-                               if ( $e )
-                               {
-                                       throw $e;
-                               }
-                       }
-
-                       $this->_db->transaction_commit();
-                       return $id;
-               }
-
-
-               private function _get_value_set($data)
-               {
-                       $value_set = array
-                       (
-                               'title'                         => 
$this->_db->db_addslashes($data['title']),
-                               'descr'                         => 
$this->_db->db_addslashes($data['descr']),
-                               'status_id'                     => 
(int)$data['status_id'],
-                               'category'                      => 
(int)$data['cat_id'],
-                               'vendor_id'                     => 
(int)$data['vendor_id'],
-                               'coordinator_id'        => 
(int)$data['coordinator_id'],
-                               'report_date'           => 
phpgwapi_datetime::date_to_timestamp($data['report_date']),
-                               'user_id'                       => 
$this->account,
-                               'modified_date'         => time(),
-                       );
-
-
-                       if(isset($data['location']) && 
is_array($data['location']))
-                       {
-                               foreach ($data['location'] as $input_name => 
$value)
-                               {
-                                       if(isset($value) && $value)
-                                       {
-                                               $value_set[$input_name] = 
$value;
-                                       }
-                               }
-                               $value_set['location_code'] = implode('-', 
$data['location']);
-                       }
-
-                       if(isset($data['extra']) && is_array($data['extra']))
-                       {
-                               foreach ($data['extra'] as $input_name => 
$value)
-                               {
-                                       if(isset($value) && $value)
-                                       {
-                                               $value_set[$input_name] = 
$value;
-                                       }
-                               }
-
-                               if($data['extra']['p_num'] && 
$data['extra']['p_entity_id'] && $data['extra']['p_cat_id'])
-                               {
-                                       $entity = 
CreateObject('property.soadmin_entity');
-                                       $entity_category = 
$entity->read_single_category($data['extra']['p_entity_id'],$data['extra']['p_cat_id']);
-                               }
-                       }
-
-                       if(isset($values['attributes']) && 
is_array($values['attributes']))
-                       {
-                               $data_attribute = 
$this->custom->prepare_for_db($table, $values['attributes']);
-                               if(isset($data_attribute['value_set']))
-                               {
-                                       foreach($data_attribute['value_set'] as 
$input_name => $value)
-                                       {
-                                               if(isset($value) && $value)
-                                               {
-                                                       $value_set[$input_name] 
= $value;
-                                               }
-                                       }
-                               }
-                       }
-
-                       $_address = array();
-                       if(isset($data['street_name']) && $data['street_name'])
-                       {
-                               $_address[] = "{$data['street_name']} 
{$data['street_number']}";
-                       }
-
-                       if(isset($data['location_name']) && 
$data['location_name'])
-                       {
-                               $_address[] = $data['location_name'];
-                       }
-
-                       if(isset($data['additional_info']) && 
$data['additional_info'])
-                       {
-                               foreach($data['additional_info'] as $key => 
$value)
-                               {
-                                       if($value)
-                                       {
-                                               $_address[] = "{$key}|{$value}";
-                                       }
-                               }
-                       }
-
-                       if(isset($entity_category) && $entity_category)
-                       {
-                               $_address[] = 
"{$entity_category['name']}::{$data['extra']['p_num']}";
-                       }
-
-                       $address        = 
$this->_db->db_addslashes(implode('::', $_address));
-
-                       $value_set['address'] = $address;
-
-                       return $value_set;
-               }
-
                public function import($survey, $import_data = array())
                {
                        if(!isset($survey['id']) || !$survey['id'])




reply via email to

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