2015-07-30 16:37:42 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manage IOformat of LSldapObject import/export
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
class LSioFormat {
|
|
|
|
|
|
|
|
var $config=False;
|
|
|
|
var $driver=False;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param[in] string $LSobject The LSobject type name
|
|
|
|
* @param[in] string $ioFormat The ioFormat name
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function __construct($LSobject, $ioFormat) {
|
2015-07-30 16:37:42 +02:00
|
|
|
$conf=LSconfig::get('LSobjects.'.$LSobject.".ioFormat.".$ioFormat);
|
|
|
|
if(is_array($conf)) {
|
|
|
|
$this -> config=$conf;
|
|
|
|
if (isset($this -> config['driver']) && LSsession :: loadLSclass('LSioFormat'.$this -> config['driver'])) {
|
|
|
|
$driverClass='LSioFormat'.$this -> config['driver'];
|
|
|
|
$driverOptions=array();
|
|
|
|
if (isset($this -> config['driver_options'])) $driverOptions = $this -> config['driver_options'];
|
|
|
|
$this -> driver = new $driverClass($driverOptions);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSioFormat_01',$this -> config['driver']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if ioFormat driver is ready
|
|
|
|
*
|
|
|
|
* @retval boolean True if ioFormat driver is ready, false otherwise
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function ready() {
|
2015-07-30 16:37:42 +02:00
|
|
|
return (is_array($this -> config) && $this -> driver !== False);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load and valid file
|
|
|
|
*
|
|
|
|
* @param[in] string $file The file path to load
|
|
|
|
*
|
|
|
|
* @retval boolean True if file is loaded and valid, false otherwise
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function loadFile($file) {
|
2015-07-30 16:37:42 +02:00
|
|
|
if ($this -> driver -> loadFile($file)) {
|
|
|
|
return $this -> driver -> isValid();
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retreive all objects contained by the loaded file
|
|
|
|
*
|
|
|
|
* @retval array The objects contained by the loaded file
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getAll() {
|
2015-07-30 16:37:42 +02:00
|
|
|
return $this -> driver -> getAllFormated($this -> config['fields'],$this -> config['generated_fields']);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LSerror :: defineError('LSioFormat_01',
|
|
|
|
_("LSioFormat : IOformat driver %{driver} invalid or unavailable.")
|
|
|
|
);
|
2019-03-11 22:42:20 +01:00
|
|
|
|