[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [7429] property: prepare for import
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [7429] property: prepare for import |
Date: |
Fri, 24 Jun 2011 13:57:31 +0000 |
Revision: 7429
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7429
Author: sigurdne
Date: 2011-06-24 13:57:30 +0000 (Fri, 24 Jun 2011)
Log Message:
-----------
property: prepare for import
Modified Paths:
--------------
trunk/property/inc/class.solocation.inc.php
trunk/property/inc/import/default/cvs_import_romdata_bkb
Modified: trunk/property/inc/class.solocation.inc.php
===================================================================
--- trunk/property/inc/class.solocation.inc.php 2011-06-24 08:45:29 UTC (rev
7428)
+++ trunk/property/inc/class.solocation.inc.php 2011-06-24 13:57:30 UTC (rev
7429)
@@ -248,16 +248,15 @@
return $owners;
}
- function check_location($location_code='',$type_id='')
+ function check_location($location_code, $type_id = 0)
{
- $this->db->query("SELECT count(*) AS cnt FROM
fm_location$type_id where location_code='$location_code'");
-
- $this->db->next_record();
-
- if ( $this->db->f('cnt'))
+ if(!$type_id)
{
- return true;
+ $type_id = count(explode('-',$location_code));
}
+ $this->db->query("SELECT count(*) AS cnt FROM
fm_location{$type_id} WHERE location_code='{$location_code}'");
+
+ return $this->db->next_record();
}
function read($data)
Modified: trunk/property/inc/import/default/cvs_import_romdata_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_romdata_bkb 2011-06-24
08:45:29 UTC (rev 7428)
+++ trunk/property/inc/import/default/cvs_import_romdata_bkb 2011-06-24
13:57:30 UTC (rev 7429)
@@ -11,13 +11,15 @@
set_time_limit(10000); //Set the time limit for this
request
$this->account =
(int)$GLOBALS['phpgw_info']['user']['account_id'];
$this->db = & $GLOBALS['phpgw']->db;
+ $this->solocation =
CreateObject('property.solocation');
}
public function add($data)
{
+
$debug = true;
- $error = false;
- $table = 'fm_entity_4_1';
+ $ok = true;
+
$location_code = $this->decode($data[0]);
if(!$location_code)
{
@@ -25,85 +27,93 @@
return false;
}
-//_debug_array($location_code);
- $location_data =
execMethod('property.solocation.read_single', $location_code );
-_debug_array($data);
-//_debug_array($location_data);die();
- if(!$location_data)
+ $location_arr = explode('-',$location_code);
+ $_test_floor =
"{$location_arr[0]}-{$location_arr[1]}-{$location_arr[2]}";
+ $_test_zone =
"{$location_arr[0]}-{$location_arr[1]}-{$location_arr[2]}-{$location_arr[3]}";
+
+ $_ok = false;
+ if(!$this->solocation->check_location($_test_floor))
{
- $this->errors[] = "Error importing location:
{$location_code}";
- $error = true;
- return false;
+ $_ok =
$this->add_location(array('location_code' => $_test_floor, 'name' => "etasje
{{$location_arr[2]}}", 'area' => 0));
+ $ok = $_ok ? $_ok : false;
}
- if($location_data['street_name'])
+ if(!$this->solocation->check_location($_test_zone))
{
- $address[]= $location_data['street_name'];
- $address[]= $location_data['street_number'];
- $address =
$this->db->db_addslashes(implode(" ", $address));
+ $_ok =
$this->add_location(array('location_code' => $_test_zone, 'name' => "sone
{{$location_arr[3]}}", 'area' => 0));
+ $ok = $_ok && $ok ? $_ok : false;
}
- if(!$address)
+ if(!$this->solocation->check_location($location_code))
{
- $address =
$this->db->db_addslashes($location_data['loc1_name']);
+_debug_array($location_code);
+ $_ok =
$this->add_location(array('location_code' => $location_code, 'name' =>
$this->decode($data[6]), 'area' => $this->decode($data[7])));
+ $ok = $_ok && $ok ? $_ok : false;
}
+ return $ok;
+ }
- $id = (int)$data[2];
-
+ protected function add_location($data)
+ {
+ $debug = true;
+ $error = false;
+ $ok = true;
+ $value_set = array();
- $this->messages[] = "Dagens dato er lagt inn som
registreringsdato for {$id} (mangler info)";
- $entry_date = time();
+ $location_arr = explode('-',$data['location_code']);
+ $type_id = count($location_arr);
-//_debug_array($entry_date_info);
-//_debug_array($entry_date);
- $value_set = array();
+ $formatting = array
+ (
+ '%04s',
+ '%02s',
+ '%02s',
+ '%02s',
+ '%03s'
+ );
+
+ $value_set['location_code'] =
$data['location_code'];
+ foreach ($location_arr as $_key => $_loc)
+ {
+ $i = $_key +1;
+ $value_set["loc1{$i}"] =
sprintf($formatting[$_key],$location_arr[$_key]);
+ }
-
- $value_set['num']
= sprintf('%04s',$id);
- $value_set['loc1'] =
$location_data['loc1'];
- $value_set['loc2'] =
$location_data['loc2'];
+ $value_set["loc{$type_id}_name"] =
$this->db->db_addslashes($data['name']);
+ $value_set['category'] = 1;
$value_set['user_id'] =
$this->account;
- $value_set['location_code'] =
$location_code;
- $value_set['address'] =
$address;
- $value_set['entry_date'] =
$entry_date;
- $value_set['museumsnr'] =
$this->db->db_addslashes($data[1]);
- $value_set['betegnelse'] =
$this->db->db_addslashes($data[3]);
- $value_set['beskrivelse'] =
$this->db->db_addslashes($data[4]);
- $value_set['tilstand'] =
$this->db->db_addslashes($data[5]);
+ $value_set['entry_date'] =
time();
+ $value_set['area_net'] =
$data['area'] ? str_replace(',','.',$data['area']) : 0;
+ $value_set['merknader'] =
'Opprettet fra tegning';
- $this->db->query("SELECT id FROM {$table} WHERE id =
{$id}",__LINE__,__FILE__);
- if($this->db->next_record())
- {
- $this->warnings[] = "ID finnes fra før: {$id},
oppdaterer";
- $value_set =
$this->db->validate_update($value_set);
- $sql = "UPDATE {$table} SET {$value_set} WHERE
id = {$id}";
- }
- else
- {
- $value_set['id'] = $id;
- $cols = implode(',', array_keys($value_set));
- $values =
$this->db->validate_insert(array_values($value_set));
+ $cols = implode(',', array_keys($value_set));
+ $values =
$this->db->validate_insert(array_values($value_set));
- $sql = "INSERT INTO {$table} ({$cols}) VALUES
({$values})";
- }
+ $table = "fm_location{$type_id}";
+ $sql = "INSERT INTO {$table} ({$cols}) VALUES
({$values})";
+
+ $sql2 = "INSERT INTO fm_locations (level,
location_code) VALUES ({$type_id}, '{$data['location_code']}')";
+
+
if($debug)
{
_debug_array($sql);
}
else
{
- $request_ok =
$this->db->query($sql,__LINE__,__FILE__);
+ $_ok = $this->db->query($sql,__LINE__,__FILE__);
+ $ok = $_ok ? $_ok : false;
}
if(!$error)
{
- $this->messages[] = "Successfully imported
location: Title ({$this->decode($data[1])})";
+ $this->messages[] = "Successfully imported
location: {$data['location_code']}";
$ok = true;
}
else
{
- $this->errors[] = "Error importing location:
Title ({$this->decode($data[1])})";
+ $this->errors[] = "Error importing location:
{$data['location_code']}";
$ok = false;
}
return $ok;
@@ -124,7 +134,7 @@
}
return stripslashes($converted);
}
-
+
/**
* Test a value for null according to several formats that can
exist in the export.
* Returns true if the value is null according to these rules,
false otherwise.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [7429] property: prepare for import,
Sigurd Nes <=