fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [11468] generic import


From: Sigurd Nes
Subject: [Fmsystem-commits] [11468] generic import
Date: Sat, 16 Nov 2013 18:18:26 +0000

Revision: 11468
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11468
Author:   sigurdne
Date:     2013-11-16 18:18:26 +0000 (Sat, 16 Nov 2013)
Log Message:
-----------
generic import

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

Modified: trunk/property/inc/class.uiimport.inc.php
===================================================================
--- trunk/property/inc/class.uiimport.inc.php   2013-11-16 10:39:53 UTC (rev 
11467)
+++ trunk/property/inc/class.uiimport.inc.php   2013-11-16 18:18:26 UTC (rev 
11468)
@@ -29,6 +29,7 @@
 
                // Label on the import button. Changes as we step through the 
import process.
                protected $import_button_label;
+               protected $download_template_button_label;
 
                protected $defalt_values;
 
@@ -58,7 +59,39 @@
                {
                        // Set the submit button label to its initial state
                        $this->import_button_label = "Start import";
+                       $this->download_template_button_label = 'Download 
template';
 
+                       $check_method = 0;
+                       if($this->conv_type = phpgw::get_var('conv_type'))
+                       {
+                               $check_method ++;
+                       }
+                       if ($location_id = phpgw::get_var('location_id', 'int'))
+                       {
+                               $check_method ++;
+                       }
+                               
+                       if($table = phpgw::get_var('table'))
+                       {
+                               $check_method ++;
+                       }
+
+                       if($check_method > 1)
+                       {
+                               phpgwapi_cache::session_set('property', 
'import_message', 'choose only one target!');
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction'=>'property.uiimport.index'));
+                       }
+
+
+                       phpgwapi_cache::session_set('property', 
'import_settings', $_POST);                     
+
+                       $download_template = 
phpgw::get_var('download_template');
+                       
+                       if($download_template)
+                       {
+                               $this->get_template($location_id);
+                       }
+                       
                        // If the parameter 'importsubmit' exist (submit button 
in import form), set path
                        if (phpgw::get_var("importsubmit")) 
                        {
@@ -68,29 +101,7 @@
                                        
$GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction'=>'property.uiimport.index'));
                                }
 
-                               phpgwapi_cache::session_set('property', 
'import_settings', $_POST);
 
-                               $check_method = 0;
-                               if($this->conv_type = 
phpgw::get_var('conv_type'))
-                               {
-                                       $check_method ++;
-                               }
-                               if ($location_id = 
phpgw::get_var('location_id', 'int'))
-                               {
-                                       $check_method ++;
-                               }
-                               
-                               if($table = phpgw::get_var('table'))
-                               {
-                                       $check_method ++;
-                               }
-
-                               if($check_method > 1)
-                               {
-                                       phpgwapi_cache::session_set('property', 
'import_message', 'choose only one target!');
-                                       
$GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction'=>'property.uiimport.index'));
-                               }
-
                                $start_time = time(); // Start time of import
                                $start = date("G:i:s",$start_time);
                                echo "<h3>Import started at: {$start}</h3>";
@@ -310,6 +321,9 @@
                                                        <input type="checkbox" 
name="debug" id="debug" {$debug_checked} value ='1' />
                                                </p>
                                                <p>
+                                                       <input type="submit" 
name="download_template" value="{$this->download_template_button_label}"  />
+                                               </p>
+                                               <p>
                                                        <input type="submit" 
name="importsubmit" value="{$this->import_button_label}"  />
                                                </p>
                                        </fieldset>
@@ -347,6 +361,76 @@
                        return $this->steps;
                }
 
+               protected function get_template($location_id = 0)
+               {
+                       $_fields = array();
+                       if(!$location_id && $this->table)
+                       {
+                               $metadata = $this->db->metadata($this->table);
+
+                               foreach ($metadata as $field => $info)
+                               {
+                                       $_fields[$field] = true;
+                               }
+
+                       }
+                       else if($location_id && !$category = 
execMethod('property.soadmin_entity.get_single_category', $location_id ))
+                       {
+                               throw new Exception("Not a valid location for 
{$location_id}");
+                       }
+                       else if($location_id)
+                       {
+                               $entity_id = $category['entity_id'];
+                               $cat_id = $category['id'];
+
+                               if ($category['is_eav'])
+                               {
+                                       $this->table = 'fm_bim_item';
+
+                                       $metadata = 
$this->db->metadata($this->table);
+                               
+                                       foreach ($metadata as $field  => $info)
+                                       {
+                                               if ($field == 
'xml_representation' || $field == 'guid')
+                                               {
+                                                       continue;
+                                               }
+                                               $_fields[$field] = true;
+                                       }
+
+                                       $custom                 = 
createObject('property.custom_fields');
+                                       $attributes     = 
$custom->find2($location_id, 0, '', 'ASC', 'attrib_sort', true, true);
+
+                                       foreach($attributes as $attribute)
+                                       {
+                                               
$_fields[$attribute['column_name']] = true;
+                                       }
+                               }
+                               else
+                               {
+                                       $this->table = 
"fm_entity_{$category['entity_id']}_{$category['id']}";
+                                       $metadata = 
$this->db->metadata($this->table);
+                                       foreach ($metadata as $field  => $info)
+                                       {
+                                               $_fields[$field] = true;
+                                       }
+                               }
+                       }
+
+                       $fields = array_keys($_fields);
+
+                       if(phpgw::get_var('debug', 'bool'))
+                       {
+                               _debug_array($fields);
+                       }
+                       else
+                       {
+                               $bocommon = CreateObject('property.bocommon');
+                               $bocommon->download(array(),$fields,$fields);
+                               $GLOBALS['phpgw']->common->phpgw_exit();
+                       }
+               }
+
                protected function import_data()
                {
                        $metadata = array();
@@ -479,13 +563,13 @@
 
                        $rows = count($data)+1;
 
-                       for ($i=$start; $i<$rows; $i++ )
+                       for ($row=$start; $row<$rows; $row++ )
                        {
                                $_result = array();
                                $j=0;
-                               foreach($data[$i] as $key => $value)
+                               foreach($data[$row] as $key => $value)
                                {
-                                       $_result[$j] = trim($value);
+                                       $_result[] = 
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j,$row)->getCalculatedValue();
                                        $j++;
                                }
                                $result[] = $_result;




reply via email to

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