<?php
require_once(dirname(__FILE__).'/../../../param/parameters.php');
require_once(dirname(__FILE__).'/../lib/class.MySQL.php');
require_once(dirname(__FILE__).'/class.Log.php');
/**
* ExportException class
*
* @author Olivier G <hide@address.com>
* @version 1.0
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://gemibloo.fr
*/
class ExportException extends Exception {
const DATABASE_FAILED = 2001;
const EMPTY_VARIABLE = 2002;
const CURL_FAILED = 2003;
const UPDATE_REQUEST_FAILED = 2004;
public $response;
function __construct($msg, $code, $response=null) {
parent::__construct($msg, $code);
$this->response = $response;
}//__construct
}//ExportException
/**
* PluginExport class
*
*This abstract class manages only data retrieval from DB. Derived classes implements
*the very export method.
*
* @author Olivier G <hide@address.com>
* @version 1.0
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @link http://gemibloo.fr
*/
abstract class PluginExport{
protected $_id = 0;
protected $_lat = 0.0;
protected $_lng = 0.0;
protected $_location = '';
protected $_content = '';
protected $_timestamp = '';
protected $_image = '';
protected $_ratioHW = '';
/**
* fExport method
*
* This method must be defined in inherited class
*/
abstract protected function fExport();
/**
* __construct method
*
* Extract content form last entry in the DB
*/
protected function _fInitialize(){
$db = new MySQL();
if (FALSE === $db->Open(DB_DATABASE, DB_SERVER, DB_USR, DB_PWD))
throw new ExportException("Connection with database KO.", ExportException::DATABASE_FAILED);
if(FALSE === $db->Query('SELECT * FROM Gemibloo_main_'.GEMIBLOO_VERSION.' WHERE 1 ORDER BY timestamp DESC LIMIT 1;'))
throw new ExportException("Data cannot be inserted in database.", ImportException::DATABASE_FAILED);
$db->MoveFirst();
//Loop through entries
if(! $db->EndOfSeek()){
$row = $db->Row();
$temp = $row->id;
if (empty($temp))
throw new ExportException("Content variable is not set.", ExportException::EMPTY_VARIABLE);
$this->_id = $row->id;
$temp = $row->lat;
if (empty($temp))
throw new ExportException("Latitude variable is not set.", ExportException::EMPTY_VARIABLE);
$this->_lat = $row->lat;
$temp = $row->lng;
if (empty($temp))
throw new ExportException("Longitude variable is not set.", ExportException::EMPTY_VARIABLE);
$this->_lng = $row->lng;
$temp = $row->location;
if (empty($temp))
throw new ExportException("Location variable is not set.", ExportException::EMPTY_VARIABLE);
$this->_location = $row->location;
$temp = $row->content;
if (empty($temp))
throw new ExportException("Content variable is not set.", ExportException::EMPTY_VARIABLE);
$this->_content = $row->content;
$temp = $row->timestamp;
if (empty($temp))
throw new ExportException("Timestamp variable is not set.", ExportException::EMPTY_VARIABLE);
$this->_timestamp = $row->timestamp;
$temp = $row->image;
if (empty($temp))
throw new ExportException("Image variable is not set.", ExportException::EMPTY_VARIABLE);
$this->_image = DATA_URL.$row->image;
$temp = $row->ratioHW;
if (empty($temp))
throw new ExportException("ratioHW variable is not set.", ExportException::EMPTY_VARIABLE);
$this->_ratioHW = $row->ratioHW;//Store full path.
}//if
else
throw new ExportException("Content variable is not set.", ExportException::SQL_REQUEST_FAILED);
}//_fInitialize
}//Export
?>