first commit
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stExporterCsv1250.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
*/
|
||||
|
||||
class stExporterCsv1250 extends stPropelExporter
|
||||
{
|
||||
|
||||
/**
|
||||
* Separator komorek w pliku csv
|
||||
* @var string
|
||||
*/
|
||||
var $delimiter = ";";
|
||||
|
||||
/**
|
||||
* Znak ucieczki w pliku csv
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $enclosure = "\"";
|
||||
|
||||
/**
|
||||
* Unikatowa nazwa exportera
|
||||
* @var string
|
||||
*/
|
||||
var $converter = 'csv';
|
||||
|
||||
/**
|
||||
* Rozszerzenie pliku eksportu
|
||||
* @var string
|
||||
*/
|
||||
var $output_file_extension = 'csv';
|
||||
|
||||
/**
|
||||
* Zapisuje pnaglowek do pliku csv
|
||||
*/
|
||||
protected function writeHeader()
|
||||
{
|
||||
|
||||
// tablica naglowkow
|
||||
$cols = array();
|
||||
|
||||
// dla kazdego elementu obiektu
|
||||
foreach ($this->config['fields'] as $field => $func_name) {
|
||||
// przypisz nazwe
|
||||
$cols[] = iconv('UTF-8', 'windows-1250', $this->getUserName($field));
|
||||
}
|
||||
// otwrzo plik eksportu
|
||||
$this->fh = fopen($this->getFilePath(), "w");
|
||||
|
||||
// zapisz dane naglwoka
|
||||
$this->fputcsv2($this->fh, $cols, $this->delimiter, $this->enclosure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Przeladowanie standardowej funkcji getConvertedData
|
||||
*
|
||||
* @param object $data
|
||||
* @return array
|
||||
*/
|
||||
protected function getConvertedData($data = null)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje dane do pliku csv
|
||||
*
|
||||
* @param object $data
|
||||
*/
|
||||
protected function writeConvertedData($data = null)
|
||||
{
|
||||
$i18n = sfContext::getInstance()->getI18n();
|
||||
// jezeli plik nie zostal otwarty, otwiera go i ustawia wskaznik na koniec pliku
|
||||
if (!$this->fh) {
|
||||
$this->fh = fopen($this->getFilePath(), "a");
|
||||
}
|
||||
|
||||
// jezeli dane wejsciowe sa tablica wykonaj porcedure zapisu
|
||||
if (is_array($data)) {
|
||||
|
||||
//dla kazdego elementu tablicy wykonaj zapis wiersza
|
||||
foreach ($data as $object) {
|
||||
$export = true;
|
||||
|
||||
//tworzy tablice do zapisania
|
||||
$row = array();
|
||||
foreach ($object as $key => $value) {
|
||||
$field = $this->getUserName($key);
|
||||
|
||||
if (strlen((string) $value) > 32000) {
|
||||
$this->logger->add($object[$this->config['primary_key']], $i18n->__(self::FIELD_EXCEEDS_32K_MSG, array('%field%' => $field), 'stImportExportBackend')
|
||||
. ' ' . $i18n->__(self::FIELD_NA_REPLAGE_MSG, array('%field%' => $field), 'stImportExportBackend')
|
||||
);
|
||||
$row[] = '[N/A]';
|
||||
} else {
|
||||
|
||||
$valueTranslit = iconv('UTF-8', 'CP1250//IGNORE', $value);
|
||||
|
||||
if ($value != iconv('CP1250', 'UTF-8', $valueTranslit)) {
|
||||
|
||||
$this->logger->add($object[$this->config['primary_key']], $i18n->__(self::FIELD_INCORRECT_ENCODING, array('%field%' => $field, '%encoding%' => 'Windows-1250'), 'stImportExportBackend')
|
||||
. ' ' .$i18n->__(self::FIELD_NA_REPLAGE_MSG, array('%field%' => $field), 'stImportExportBackend')
|
||||
);
|
||||
$row[] = '[N/A]';
|
||||
} else {
|
||||
$row[] = $valueTranslit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->fputcsv2($this->fh, $row, $this->delimiter, $this->enclosure);
|
||||
}
|
||||
}
|
||||
|
||||
//zamyka plik
|
||||
fclose($this->fh);
|
||||
}
|
||||
|
||||
public function sampleFile($data = array())
|
||||
{
|
||||
if (!$this->fh) {
|
||||
$this->fh = fopen($this->getFilePath(), "a");
|
||||
}
|
||||
$this->writeHeader();
|
||||
$this->writeConvertedData($data);
|
||||
|
||||
return file_get_contents($this->getFilePath());
|
||||
}
|
||||
|
||||
public function fputcsv2($fh, array $fields, $delimiter = ',', $enclosure = '"')
|
||||
{
|
||||
fputcsv($fh, $fields, $delimiter, $enclosure);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stImportExport2csv1250Listener.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
* @author Piotr Halas <piotr.halas@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Klasa słuchacza stImportExport2csv
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stImportExport2csv1250Listener {
|
||||
public static function generate(sfEvent $event)
|
||||
{
|
||||
// możemy wywoływać podaną metodę wielokrotnie co powoduje dołączenie kolejnych plików
|
||||
$event->getSubject()->attachAdminGeneratorFile('stImportExportPlugin', 'stImportExport2csv1250.yml');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stImporterCsv1250.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
*/
|
||||
|
||||
class stImporterCsv1250 extends stPropelImporter
|
||||
{
|
||||
|
||||
var $converter = 'csv';
|
||||
|
||||
/**
|
||||
* Separator komorek w pliku csv
|
||||
* @var string
|
||||
*/
|
||||
var $delimiter = ";";
|
||||
|
||||
/**
|
||||
* Rozszerzenie pliku eksportu
|
||||
* @var string
|
||||
*/
|
||||
var $input_file_extension = 'csv';
|
||||
|
||||
public function getDataCount()
|
||||
{
|
||||
if (is_readable($this->getFilePath()))
|
||||
{
|
||||
return filesize($this->getFilePath());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function loadFile()
|
||||
{
|
||||
|
||||
if (is_readable($this->getFilePath()))
|
||||
{
|
||||
$this->fh = fopen($this->getFilePath(), "r");
|
||||
}
|
||||
}
|
||||
|
||||
public function readHeaderRow()
|
||||
{
|
||||
if ($this->fh)
|
||||
{
|
||||
$this->header_order = $this->removeUserName($this->fgetcsv());
|
||||
}
|
||||
}
|
||||
|
||||
public function skipToData($offset = 0)
|
||||
{
|
||||
if ($offset)
|
||||
{
|
||||
fseek($this->fh, $offset);
|
||||
}
|
||||
}
|
||||
|
||||
protected function readRow()
|
||||
{
|
||||
if ($this->fh)
|
||||
{
|
||||
$row = $this->fgetcsv();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$row = array_slice($row, 0, count($this->header_order), true);
|
||||
|
||||
if (!$this->loadPrimaryKey(array_combine($this->header_order, $row)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$i18n = sfContext::getInstance()->getI18n();
|
||||
$wrongEncoding = false;
|
||||
$data = array();
|
||||
|
||||
foreach ($this->header_order as $key => $name)
|
||||
{
|
||||
if (isset($row[$key]) && trim($row[$key]) != "[N/A]")
|
||||
{
|
||||
if (!$this->hasValidEncoding($row[$key]))
|
||||
{
|
||||
$wrongEncoding = true;
|
||||
$this->logger->add(
|
||||
null,
|
||||
$i18n->__('Niepoprawne kodowanie dla pola %field%', array(
|
||||
'%field%' => $this->getUserName($name)
|
||||
)),
|
||||
stImportExportLog::$FATAL
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data[$name] = iconv('WINDOWS-1250', 'UTF-8', $row[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$wrongEncoding)
|
||||
{
|
||||
$this->processData($data);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function hasValidEncoding($value)
|
||||
{
|
||||
return iconv("WINDOWS-1250", "WINDOWS-1250//IGNORE", $value) == $value && (!preg_match('/[\xA5\xC6\xCA\xA3\xD1\xD3\x8C\x8F\xAF\xB9\xE6\xEA\xB3\xF1\xF3\x9C\x9F\xBF]/', $value) || iconv("UTF-8", "UTF-8//IGNORE", $value) != $value);
|
||||
}
|
||||
|
||||
public function getOffset()
|
||||
{
|
||||
return ftell($this->fh);
|
||||
}
|
||||
|
||||
public function validateFile(array &$errors = null)
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
if (is_readable($this->getFilePath()))
|
||||
{
|
||||
$this->fh = fopen($this->getFilePath(), "r");
|
||||
if ($this->fh)
|
||||
{
|
||||
$header = $this->fgetcsv();
|
||||
|
||||
foreach ($header as $name)
|
||||
{
|
||||
if (!$this->hasValidEncoding($name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->header_order = $this->removeUserName($header);
|
||||
|
||||
$primaryKeys = is_array($this->config['primary_key']) ? $this->config['primary_key'] : array($this->config['primary_key']);
|
||||
$requiredFields = array();
|
||||
|
||||
foreach ($this->requireFields as $name)
|
||||
{
|
||||
$params = $this->config['fields'][$name];
|
||||
|
||||
if (!isset($params['require_with_fields']) || !empty(array_intersect($params['require_with_fields'], $this->header_order)))
|
||||
{
|
||||
$requiredFields[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
$requiredFields = array_merge($primaryKeys, $requiredFields);
|
||||
$missingFields = array_diff($requiredFields, $this->header_order);
|
||||
|
||||
if (empty($missingFields))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$fields = array();
|
||||
|
||||
foreach ($missingFields as $name)
|
||||
{
|
||||
$fields[] = $this->getUserName($name);
|
||||
}
|
||||
|
||||
$errors[] = sfContext::getInstance()->getI18n()->__('Brak wymaganych pól: "%%fields%%"', array(
|
||||
'%%fields%%' => implode('", "', $fields),
|
||||
), 'stImportExportBackend');
|
||||
}
|
||||
|
||||
fclose($this->fh);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function sampleFile($data = array())
|
||||
{
|
||||
|
||||
$exporter = new stExporterCsv($this->model, $this->config, $this->getFilePath());
|
||||
|
||||
return $exporter->sampleFile($data);;
|
||||
}
|
||||
|
||||
public function fgetcsv()
|
||||
{
|
||||
return fgetcsv($this->fh, null, ";", '"', "\0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stExporterCsv.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
*/
|
||||
|
||||
class stExporterCsv extends stPropelExporter
|
||||
{
|
||||
/**
|
||||
* Separator komorek w pliku csv
|
||||
* @var string
|
||||
*/
|
||||
var $delimiter = ";";
|
||||
|
||||
/**
|
||||
* Znak ucieczki w pliku csv
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $enclosure = "\"";
|
||||
|
||||
/**
|
||||
* Unikatowa nazwa exportera
|
||||
* @var string
|
||||
*/
|
||||
var $converter = 'csv';
|
||||
|
||||
/**
|
||||
* Rozszerzenie pliku eksportu
|
||||
* @var string
|
||||
*/
|
||||
var $output_file_extension = 'csv';
|
||||
|
||||
/**
|
||||
* Zapisuje pnaglowek do pliku csv
|
||||
*/
|
||||
protected function writeHeader()
|
||||
{
|
||||
|
||||
// tablica naglowkow
|
||||
$cols = array();
|
||||
|
||||
// dla kazdego elementu obiektu
|
||||
foreach ($this->config['fields'] as $field => $func_name) {
|
||||
// przypisz nazwe
|
||||
$cols[] = $this->getUserName($field);
|
||||
}
|
||||
// otwrzo plik eksportu
|
||||
$this->fh = fopen($this->getFilePath(), "w");
|
||||
|
||||
// zapisz dane naglwoka
|
||||
$this->fputcsv2($this->fh, $cols, $this->delimiter, $this->enclosure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Przeladowanie standardowej funkcji getConvertedData
|
||||
*
|
||||
* @param object $data
|
||||
* @return array
|
||||
*/
|
||||
protected function getConvertedData($data = null)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje dane do pliku csv
|
||||
*
|
||||
* @param object $data
|
||||
*/
|
||||
protected function writeConvertedData($data = null)
|
||||
{
|
||||
|
||||
// jezeli plik nie zostal otwarty, otwiera go i ustawia wskaznik na koniec pliku
|
||||
if (!$this->fh) {
|
||||
$this->fh = fopen($this->getFilePath(), "a");
|
||||
}
|
||||
|
||||
// jezeli dane wejsciowe sa tablica wykonaj porcedure zapisu
|
||||
if (is_array($data)) {
|
||||
|
||||
//dla kazdego elementu tablicy wykonaj zapis wiersza
|
||||
foreach ($data as $object) {
|
||||
$overSize = false;
|
||||
|
||||
//tworzy tablice do zapisania
|
||||
$row = array();
|
||||
foreach ($object as $key => $value) {
|
||||
if (strlen((string) $value) > 32000) {
|
||||
$this->logger->add($object[$this->config['primary_key']], sfContext::getInstance()->getI18n()->__(self::FIELD_EXCEEDS_32K_MSG, array('%field%' => $key), 'stImportExportBackend'));
|
||||
$row[] = '[N/A]';
|
||||
} else {
|
||||
$row[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// zapisuje tablice z danymi do pliku jezeli wielkosc komorek nie zostala przekroczona
|
||||
$this->fputcsv2($this->fh, $row, $this->delimiter, $this->enclosure);
|
||||
}
|
||||
}
|
||||
|
||||
//zamyka plik
|
||||
fclose($this->fh);
|
||||
}
|
||||
|
||||
public function sampleFile($data = array())
|
||||
{
|
||||
if (!$this->fh) {
|
||||
$this->fh = fopen($this->getFilePath(), "a");
|
||||
}
|
||||
$this->writeHeader();
|
||||
$this->writeConvertedData($data);
|
||||
//fclose($this->fh);
|
||||
|
||||
return file_get_contents($this->getFilePath());
|
||||
}
|
||||
|
||||
public function fputcsv2($fh, array $fields, $delimiter = ',', $enclosure = '"')
|
||||
{
|
||||
fputcsv($fh, $fields, $delimiter, $enclosure);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stImportExport2csvListener.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
* @author Piotr Halas <piotr.halas@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Klasa słuchacza stImportExport2csv
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stImportExport2csvListener {
|
||||
public static function generate(sfEvent $event)
|
||||
{
|
||||
// możemy wywoływać podaną metodę wielokrotnie co powoduje dołączenie kolejnych plików
|
||||
$event->getSubject()->attachAdminGeneratorFile('stImportExportPlugin', 'stImportExport2csv.yml');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stImporterCsv.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
*/
|
||||
|
||||
class stImporterCsv extends stPropelImporter
|
||||
{
|
||||
|
||||
var $converter = 'csv';
|
||||
|
||||
/**
|
||||
* Separator komorek w pliku csv
|
||||
* @var string
|
||||
*/
|
||||
var $delimiter = ";";
|
||||
|
||||
/**
|
||||
* Rozszerzenie pliku eksportu
|
||||
* @var string
|
||||
*/
|
||||
var $input_file_extension = 'csv';
|
||||
|
||||
public function getDataCount()
|
||||
{
|
||||
if (is_readable($this->getFilePath()))
|
||||
{
|
||||
return filesize($this->getFilePath());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function loadFile()
|
||||
{
|
||||
if (is_readable($this->getFilePath()))
|
||||
{
|
||||
$this->fh = fopen($this->getFilePath(), "r");
|
||||
}
|
||||
}
|
||||
|
||||
public function readHeaderRow()
|
||||
{
|
||||
if ($this->fh)
|
||||
{
|
||||
$this->header_order = $this->removeUserName($this->fgetcsv());
|
||||
}
|
||||
}
|
||||
|
||||
public function skipToData($offset = 0)
|
||||
{
|
||||
if ($offset)
|
||||
{
|
||||
fseek($this->fh, $offset);
|
||||
}
|
||||
}
|
||||
|
||||
protected function readRow(array &$errors = array())
|
||||
{
|
||||
if ($this->fh)
|
||||
{
|
||||
$row = $this->fgetcsv();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$row = array_slice($row, 0, count($this->header_order), true);
|
||||
|
||||
if (!$this->loadPrimaryKey(array_combine($this->header_order, $row)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$i18n = sfContext::getInstance()->getI18n();
|
||||
$wrongEncoding = false;
|
||||
$data = array();
|
||||
|
||||
foreach ($this->header_order as $key => $name)
|
||||
{
|
||||
if (isset($row[$key]) && trim($row[$key]) != "[N/A]")
|
||||
{
|
||||
if (!$this->hasValidEncoding($row[$key]))
|
||||
{
|
||||
$wrongEncoding = true;
|
||||
$this->logger->add(
|
||||
null,
|
||||
$i18n->__('Niepoprawne kodowanie dla pola %field%', array(
|
||||
'%field%' => $this->getUserName($name)
|
||||
))
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data[$name] = $row[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$wrongEncoding)
|
||||
{
|
||||
$this->processData($data);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function hasValidEncoding($value)
|
||||
{
|
||||
return iconv("UTF-8", "UTF-8//IGNORE", $value) == $value;
|
||||
}
|
||||
|
||||
public function getOffset()
|
||||
{
|
||||
return ftell($this->fh);
|
||||
}
|
||||
|
||||
public function validateFile(array &$errors = null)
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
$i18n = sfContext::getInstance()->getI18n();
|
||||
|
||||
if (is_readable($this->getFilePath()))
|
||||
{
|
||||
$this->fh = fopen($this->getFilePath(), "r");
|
||||
if ($this->fh)
|
||||
{
|
||||
$header = $this->fgetcsv();
|
||||
|
||||
foreach ($header as $name)
|
||||
{
|
||||
if (!$this->hasValidEncoding($name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->header_order = $this->removeUserName($header);
|
||||
|
||||
$primaryKeys = is_array($this->config['primary_key']) ? $this->config['primary_key'] : array($this->config['primary_key']);
|
||||
$requiredFields = array();
|
||||
|
||||
foreach ($this->requireFields as $name)
|
||||
{
|
||||
$params = $this->config['fields'][$name];
|
||||
|
||||
if (!isset($params['require_with_fields']) || !empty(array_intersect($params['require_with_fields'], $this->header_order)))
|
||||
{
|
||||
$requiredFields[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
$requiredFields = array_merge($primaryKeys, $requiredFields);
|
||||
$missingFields = array_diff($requiredFields, $this->header_order);
|
||||
|
||||
if (empty($missingFields))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$fields = array();
|
||||
|
||||
foreach ($missingFields as $name)
|
||||
{
|
||||
$fields[] = $this->getUserName($name);
|
||||
}
|
||||
|
||||
$errors[] = $i18n->__('Brak wymaganych pól: "%%fields%%"', array(
|
||||
'%%fields%%' => implode('", "', $fields),
|
||||
), 'stImportExportBackend');
|
||||
}
|
||||
|
||||
fclose($this->fh);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function sampleFile($data = array())
|
||||
{
|
||||
|
||||
$exporter = new stExporterCsv($this->model, $this->config, $this->getFilePath());
|
||||
|
||||
return $exporter->sampleFile($data);;
|
||||
}
|
||||
|
||||
public function fgetcsv()
|
||||
{
|
||||
return fgetcsv($this->fh, null, ";", '"', "\0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stExporterXml2003.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
* @author Piotr Halas <piotr.halas@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Klasa eksportera do formtu Microsoft Office 2003 xml
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stExporterXml2003 extends stPropelExporter {
|
||||
|
||||
/**
|
||||
* Nagłówek pliku xml
|
||||
* @var string
|
||||
*/
|
||||
var $header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?mso-application progid=\"Excel.Sheet\"?>
|
||||
<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:x2=\"http://schemas.microsoft.com/office/excel/2003/xml\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:html=\"http://www.w3.org/TR/REC-html40\" xmlns:c=\"urn:schemas-microsoft-com:office:component:spreadsheet\">
|
||||
<OfficeDocumentSettings xmlns=\"urn:schemas-microsoft-com:office:office\"></OfficeDocumentSettings>
|
||||
<ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\"></ExcelWorkbook>
|
||||
<Styles></Styles>
|
||||
<ss:Worksheet ss:Name=\"%s\">
|
||||
<Table>";
|
||||
|
||||
/**
|
||||
* Stopka pliku xml
|
||||
* @var string
|
||||
*/
|
||||
var $footer = "</Table><x:WorksheetOptions /></ss:Worksheet></Workbook>";
|
||||
|
||||
/**
|
||||
* Unikatowa nazwa exportera
|
||||
* @var string
|
||||
*/
|
||||
var $converter = 'xml2003';
|
||||
|
||||
/**
|
||||
* Rozszerzenie pliku eksportu
|
||||
* @var string
|
||||
*/
|
||||
var $output_file_extension = 'xml';
|
||||
|
||||
/**
|
||||
* Zwraca nagłowek pliku z nazwą modelu jako nazwa arkusza
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getHeader() {
|
||||
return sprintf($this->header,$this->model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca zawartosc jednego wiersza eksportu do pliku
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getConvertedData($data = array()) {
|
||||
$text = '';
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $object) {
|
||||
$row = "<Row>";
|
||||
$writable = true;
|
||||
|
||||
foreach ($object as $key=>$value) {
|
||||
$tmp = str_replace("\n"," ",htmlspecialchars(html_entity_decode($value,null,'utf-8'),ENT_QUOTES,'utf-8'));
|
||||
if (strlen($tmp)>32000)
|
||||
{
|
||||
$this->logger->add($object[$this->config['primary_key']],sfContext::getInstance()->getI18n()->__('Ciąg znaków w polu %field% jest za długi, pomijam rekord',array('%field%'=>$key)));
|
||||
$writable = false;
|
||||
break;
|
||||
}
|
||||
$row .= "<Cell><Data ss:Type=\"".$this->getFieldType($key)."\">".$tmp."</Data></Cell>";
|
||||
}
|
||||
|
||||
if ($writable) {
|
||||
$text .= $row."</Row>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca zawartosc naglowka tabeli eksportu
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getHeaderRow() {
|
||||
$header = "<Row>";
|
||||
foreach ($this->config['fields'] as $field=>$func_name) {
|
||||
$header .= "<Cell><Data ss:Type=\"String\">".$this->getUserName($field)."</Data></Cell>";
|
||||
}
|
||||
$header .= "</Row>";
|
||||
return $header;
|
||||
}
|
||||
|
||||
public function sampleFile($data = array()) {
|
||||
return $this->getHeader().$this->getHeaderRow().$this->footer;
|
||||
}
|
||||
|
||||
protected function getFieldType($field = '') {
|
||||
if (isset($this->config['fields'][$field]['type'])) {
|
||||
switch($this->config['fields'][$field]['type']) {
|
||||
case "string": return "String"; break;
|
||||
case "integer": return "Number"; break;
|
||||
case "double": return "Number"; break;
|
||||
default: return "String"; break;
|
||||
}
|
||||
}
|
||||
return "String";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stImportExport2xml2003Listener.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
* @author Piotr Halas <piotr.halas@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Klasa sluchacza stImportExport2xml2003
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stImportExport2xml2003Listener {
|
||||
|
||||
/**
|
||||
* Funkcja dodaje do kazdego generowanego modulu informacje o dostepnych imporerach i eksporterach
|
||||
*
|
||||
* @param sfEvent $event
|
||||
*/
|
||||
public static function generate(sfEvent $event)
|
||||
{
|
||||
if (is_file(sfConfig::get('sf_root_dir').'/packages/appImportExportOffice2003Plugin/package.yml'))
|
||||
{
|
||||
$event->getSubject()->attachAdminGeneratorFile('stImportExportPlugin', 'stImportExport2xml2003.yml');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stImporterXml2003.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
* @author Piotr Halas <piotr.halas@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Klasa Importera danych z formatu Microsoft Office 2003 xml
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @property XMLReader $fh
|
||||
*/
|
||||
class stImporterXml2003 extends stPropelImporter
|
||||
{
|
||||
/**
|
||||
* Nagłówek pliku xml
|
||||
* @var string
|
||||
*/
|
||||
var $header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?mso-application progid=\"Excel.Sheet\"?>
|
||||
<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:x2=\"http://schemas.microsoft.com/office/excel/2003/xml\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:html=\"http://www.w3.org/TR/REC-html40\" xmlns:c=\"urn:schemas-microsoft-com:office:component:spreadsheet\">
|
||||
<OfficeDocumentSettings xmlns=\"urn:schemas-microsoft-com:office:office\"></OfficeDocumentSettings>
|
||||
<ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\"></ExcelWorkbook>
|
||||
<Styles></Styles>
|
||||
<ss:Worksheet ss:Name=\"%s\">
|
||||
<Table>";
|
||||
|
||||
/**
|
||||
* Stopka pliku xml
|
||||
* @var string
|
||||
*/
|
||||
var $footer = "</Table><x:WorksheetOptions /></ss:Worksheet></Workbook>";
|
||||
|
||||
/**
|
||||
* Unikatowa nazwa Importera
|
||||
* @var string
|
||||
*/
|
||||
var $converter = 'xml2003';
|
||||
|
||||
/**
|
||||
* Rozszerzenie pliku eksportu
|
||||
* @var string
|
||||
*/
|
||||
var $input_file_extension = 'xml';
|
||||
|
||||
/**
|
||||
* Zwraca liczbę rekordów w pliku
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getDataCount() {
|
||||
// otwiera plik i doczytaj jego naglowek;
|
||||
$this->loadFile();
|
||||
$this->readHeader();
|
||||
|
||||
$count = 0;
|
||||
|
||||
//odczytuje wszystkie rekordy bez czytania danych
|
||||
while ($this->_readRow()) {
|
||||
$count++;
|
||||
}
|
||||
|
||||
//zwraca liczbe rekordow
|
||||
return ($count)?$count-1:0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Główna pętla importu przeładowana na potrzeby importu z xml2003
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function doProcess($offset = 0) {
|
||||
// otwierza plik w wczytuje naglowki
|
||||
$this->loadFile();
|
||||
$this->readHeader();
|
||||
$this->readHeaderRow();
|
||||
|
||||
// pomija wczesniej odczytane dane
|
||||
$this->skipToData($offset);
|
||||
|
||||
// wczytuje dane i dodaje je do bazy danych
|
||||
// zwraca liczbe odczytanych rekordow
|
||||
$readed = $this->readData();
|
||||
|
||||
//zamyka plik
|
||||
$this->closeFile();
|
||||
|
||||
//zwraca nowe polozenie danych
|
||||
return $offset + $readed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wczytuje plik z danymi w przypadku braku pliku wyrzuc wyjactek
|
||||
* @throws IMPORT_NO_FILE
|
||||
*/
|
||||
protected function loadFile() {
|
||||
|
||||
//sprawdza czy plik istnieje i mozna z niego czytac
|
||||
//jezeli nie to wstaw wyjatek braku pliku
|
||||
if (!is_readable($this->getFilePath())) {
|
||||
throw new Exception(IMPORT_NO_FILE);
|
||||
}
|
||||
|
||||
// jezeli plik jest do odczytu to zostanie zalodowany
|
||||
$this->fh = new XMLReader();
|
||||
$this->fh->open($this->getFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca informacje czy plik posiada poprawny naglowek
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function readHeader() {
|
||||
while ($this->fh->read()) {
|
||||
// sprawdza czy w pliku xml jest Worksheet
|
||||
if ($this->fh->depth == 1 && $this->fh->nodeType == XMLReader::ELEMENT && ($this->fh->name == 'ss:Worksheet' || $this->fh->name == 'Worksheet')) {
|
||||
// sprawdza czy w pliku jest akrusz z poprawna nazwa modelu
|
||||
if ($this->fh->getAttribute('ss:Name')==$this->model){
|
||||
while ($this->fh->read() && !($this->fh->nodeType == XMLReader::END_ELEMENT && ($this->fh->name == 'ss:Worksheet' || $this->fh->name == 'Worksheet'))) {
|
||||
// sprawdza czy w pliku jest tabela
|
||||
if ($this->fh->depth == 2 && $this->fh->nodeType == XMLReader::ELEMENT && $this->fh->name == 'Table') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje rekord danych
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function readRow() {
|
||||
|
||||
// tablica z danymi
|
||||
$data = array();
|
||||
|
||||
// index aktualnej komorki
|
||||
$index = 0;
|
||||
|
||||
// szuka kolejnego wiersza w pliku
|
||||
if ($this->fh->depth == 3 && $this->fh->nodeType == XMLReader::ELEMENT && $this->fh->name == 'Row') {
|
||||
|
||||
foreach ($this->header_order as $key=>$name) {
|
||||
$data[$name] = '';
|
||||
}
|
||||
// przeksztalca dane z xmlReader na SimpleXml
|
||||
$cell = $this->ExpandNode($this->fh);
|
||||
|
||||
// dla kazdej komorki w wierszu
|
||||
foreach ($cell->Cell as $name) {
|
||||
|
||||
// pobiera atrybuty komorki
|
||||
$attrs = $name->attributes();
|
||||
|
||||
// sprawdza czy dane sa po kolei, jezeli nie ustawia nowy index danych
|
||||
if (isset($attrs['Index'])) {$index = (integer)$attrs['Index']-1;}
|
||||
|
||||
// jezeli komorka zawiera dane zapamietuje je w zmiennej data
|
||||
if (isset($name->Data)) {
|
||||
if (isset($this->header_order[$index])) {
|
||||
if (strcmp(iconv("UTF-8", "UTF-8//IGNORE", (string)$name->Data),(string)$name->Data)!=0)
|
||||
{
|
||||
$this->logger->add($data[array_search($this->config['primary_key'],$this->header_order)],
|
||||
sfContext::getInstance()->getI18n()->__('Niepoprawne kodowanie dla pola %field%', array('%field%'=>$name)));
|
||||
} else {
|
||||
$data[$this->header_order[$index]] = (string)$name->Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
//zwieksza index o jeden
|
||||
$index++;
|
||||
}
|
||||
// zapisuje pobrane dane do bazy
|
||||
$this->processData($data);
|
||||
// zmienia polozenie na kolejny element w pliku
|
||||
while ($this->fh->read() && !($this->fh->depth == 3 && $this->fh->nodeType == XMLReader::ELEMENT && $this->fh->name == 'Row'));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Odczytuje wiersz naglowka z tabeli
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function readHeaderRow() {
|
||||
|
||||
// index aktualnej komorki
|
||||
$index = 0;
|
||||
|
||||
// odczytaj az do konca wpisu tabeli
|
||||
while ($this->fh->read() && !($this->fh->nodeType == XMLReader::END_ELEMENT && $this->fh->name == 'Table')) {
|
||||
|
||||
// jezeli zostanie znaleziony wiersz zamien go na nagolowek
|
||||
if ($this->fh->depth == 3 && $this->fh->nodeType == XMLReader::ELEMENT && $this->fh->name == 'Row') {
|
||||
|
||||
// przeksztalca dane z xmlReader na SimpleXml
|
||||
$cell = $this->ExpandNode($this->fh);
|
||||
|
||||
// dla kazdej komroki w wierszu
|
||||
foreach ($cell->Cell as $name) {
|
||||
|
||||
// pobiera atrybuty
|
||||
$attrs = $name->attributes();
|
||||
|
||||
// sprawdza czy dane sa po kolei, jezeli nie ustawia nowy index danych
|
||||
if (isset($attrs['Index'])) {$index = (integer)$attrs['Index'];}
|
||||
if (isset($name->Data)) {
|
||||
$this->header_order[$index] = (string)$name->Data;
|
||||
}
|
||||
//zwieksza index o jeden
|
||||
$index++;
|
||||
}
|
||||
// zmienia polozenie na kolejny element w pliku
|
||||
// $this->fh->next();
|
||||
$this->header_order = $this->removeUserName($this->header_order);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Przeskakuje dane ktore zostaly odczytane w poprzednich krokach importu
|
||||
* @var ingeter $offset
|
||||
*/
|
||||
protected function skipToData($offset = 0) {
|
||||
|
||||
// wyzeruj liczbe pominietych elementow
|
||||
$skiped = 0;
|
||||
|
||||
// wykonuje czytanie wiersza az zostanie pominietych offset wierszy lub
|
||||
// w pliu nie bedzie wiecej wierszy
|
||||
while ($skiped<=$offset && $this->_readRow()) {
|
||||
$skiped++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje wiersz bez przetwarzania danych
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _readRow() {
|
||||
// odczytaj az do konca wpisu tabeli
|
||||
while ($this->fh->read() && !($this->fh->nodeType == XMLReader::END_ELEMENT && $this->fh->name == 'Table')) {
|
||||
// jezeli zostanie znaleziony wiersz zamien
|
||||
if ($this->fh->depth == 3 && $this->fh->nodeType == XMLReader::ELEMENT && $this->fh->name == 'Row') {
|
||||
|
||||
// przejdz do nastepnego
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Zamienia dane z XmlReader na SimpleXml
|
||||
*
|
||||
* @param XMLReader $reader
|
||||
* @return object
|
||||
*/
|
||||
function ExpandNode(XMLReader $reader) {
|
||||
$node = $reader->expand();
|
||||
$dom = new DomDocument('1.0','utf-8');
|
||||
$n = $dom->importNode($node,true);
|
||||
$dom->appendChild($n);
|
||||
return simplexml_import_dom($n);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza poprawnosc plik
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function validateFile(array &$errors = null) {
|
||||
return $this->getDataCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca zawartosc naglowka tabeli eksportu
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getHeaderRow() {
|
||||
$header = "<Row>";
|
||||
foreach ($this->config['fields'] as $field=>$func_name) {
|
||||
$header .= "<Cell><Data ss:Type=\"String\">".$field."</Data></Cell>";
|
||||
}
|
||||
$header .= "</Row>";
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca nagłowek pliku z nazwą modelu jako nazwa arkusza
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getHeader() {
|
||||
return sprintf($this->header,$this->model);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generuje plik z przykładowymi danymi
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function sampleFile($data = array()) {
|
||||
return $this->getHeader().$this->getHeaderRow().$this->footer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
104
plugins/stImportExportPlugin/lib/helper/stImportExportHelper.php
Normal file
104
plugins/stImportExportPlugin/lib/helper/stImportExportHelper.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
function _get_propel_object_list_for_import_export($object, $method, $options)
|
||||
{
|
||||
// get the lists of objects
|
||||
$through_class = _get_option($options, 'through_class');
|
||||
|
||||
$c = new Criteria();
|
||||
$c->add(ExportFieldPeer::MODEL, $object->getModel());
|
||||
$c->add(ExportFieldPeer::IS_KEY, 0);
|
||||
|
||||
$objects = sfPropelManyToMany::getAllObjects($object, $through_class, $c);
|
||||
|
||||
if (sfContext::getInstance()->getRequest()->hasErrors())
|
||||
{
|
||||
$ids = sfContext::getInstance()->getRequest()->getParameterHolder()->get('associated_field', 0);
|
||||
$c = new Criteria();
|
||||
$c->add(ExportFieldPeer::ID, $ids, Criteria::IN);
|
||||
$objects_associated = ExportFieldPeer::doSelect($c);
|
||||
}
|
||||
else
|
||||
{
|
||||
$objects_associated = sfPropelManyToMany::getRelatedObjects($object, $through_class, $c);
|
||||
}
|
||||
|
||||
|
||||
$ids = array_map(create_function('$o', 'return $o->getPrimaryKey();'), $objects_associated);
|
||||
|
||||
return array($objects, $objects_associated, $ids);
|
||||
}
|
||||
|
||||
function st_export_type_picker($name, $value, array $options = array())
|
||||
{
|
||||
$content = '';
|
||||
|
||||
foreach ($options['types'] as $type => $label)
|
||||
{
|
||||
$label = __($label, array(), 'stImportExportBackend');
|
||||
$radio = radiobutton_tag($name, $type, $value == $type);
|
||||
$content .= content_tag('li', content_tag('label', $radio . ' ' . $label, array(
|
||||
'style' => 'float: none; width: auto'
|
||||
)));
|
||||
}
|
||||
|
||||
return content_tag('ul', $content);
|
||||
}
|
||||
|
||||
function st_export_profile_picker($name, $value, array $options = array())
|
||||
{
|
||||
$module = $options['module'];
|
||||
$model = $options['model'];
|
||||
$profiles = $options['profiles'];
|
||||
|
||||
$url = 'stImportExportBackend/list?model='.$model.'&for_module='.$module;
|
||||
|
||||
$forwardParameters = stAdminGeneratorHelper::filterAdditionalParameters($options['forward_parameters']);
|
||||
|
||||
foreach ($forwardParameters as $forwardParameterName => $value)
|
||||
{
|
||||
$url .= "&$forwardParameterName=$value";
|
||||
}
|
||||
|
||||
if (!empty($forwardParameters))
|
||||
{
|
||||
$url .= '¶meters=' . implode(',', array_keys($forwardParameters));
|
||||
}
|
||||
|
||||
$select = select_tag($name, options_for_select($profiles, $value));
|
||||
$link = st_get_admin_button('default', __('Zarządzaj profilami', array(), 'stImportExportBackend'), $url, array('size' => 'small', 'class' => 'bs-mt-2', 'icon' => 'stImportExportPlugin'));
|
||||
|
||||
return $select . '<br>' . $link;
|
||||
}
|
||||
|
||||
function st_export_custom_parameter($name, $value, array $options = array())
|
||||
{
|
||||
$parameters = $options['parameters'];
|
||||
$parameterName = $options['parameter_name'];
|
||||
|
||||
$type = isset($parameters['type']) ? $parameters['type'] : 'input_tag';
|
||||
$default = isset($parameters['default']) ? $parameters['default'] : null;
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'checkbox_tag':
|
||||
$content = st_admin_checkbox_tag($name, 1, $default);
|
||||
break;
|
||||
|
||||
case 'select_tag':
|
||||
if (!isset($parameters['choices']))
|
||||
{
|
||||
throw new Exception(sprintf('Missing choices parameter for %s', $parameterName));
|
||||
}
|
||||
$content = select_tag($name, options_for_select($parameters['choices'], $default));
|
||||
break;
|
||||
|
||||
default:
|
||||
$content = $type($name, $default);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
30
plugins/stImportExportPlugin/lib/model/ExportField.php
Normal file
30
plugins/stImportExportPlugin/lib/model/ExportField.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Subclass for representing a row from the 'st_export_field' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model
|
||||
*/
|
||||
class ExportField extends BaseExportField
|
||||
{
|
||||
public function __toString() {
|
||||
return sfContext::getInstance()->getI18N()->__($this->getName(),array(),$this->getI18nFile())."::".$this->getField();
|
||||
}
|
||||
|
||||
public function getI18nFile()
|
||||
{
|
||||
if (!$this->i18n_file)
|
||||
{
|
||||
$this->i18n_file = ExportFieldPeer::getI18nCatalogue($this->getModel());
|
||||
}
|
||||
|
||||
return $this->i18n_file;
|
||||
}
|
||||
|
||||
public function getProfileName()
|
||||
{
|
||||
return sfContext::getInstance()->getI18N()->__($this->getName(), null, $this->getI18nFile());
|
||||
}
|
||||
}
|
||||
37
plugins/stImportExportPlugin/lib/model/ExportFieldPeer.php
Normal file
37
plugins/stImportExportPlugin/lib/model/ExportFieldPeer.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Subclass for performing query and update operations on the 'st_export_field' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model
|
||||
*/
|
||||
class ExportFieldPeer extends BaseExportFieldPeer
|
||||
{
|
||||
public static function doSelectByModel($model)
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->add(self::MODEL, $model);
|
||||
|
||||
$results = array();
|
||||
|
||||
foreach (self::doSelect($c) as $field)
|
||||
{
|
||||
$results[$field->getId()] = $field;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca nazwę katalogu i18n
|
||||
*
|
||||
* @param string $model Nazwa modelu
|
||||
* @return string
|
||||
*/
|
||||
public static function getI18nCatalogue($model)
|
||||
{
|
||||
return 'st'.$model.'ImportExport';
|
||||
}
|
||||
}
|
||||
52
plugins/stImportExportPlugin/lib/model/ExportMd5Hash.php
Normal file
52
plugins/stImportExportPlugin/lib/model/ExportMd5Hash.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Subclass for representing a row from the 'st_export_md5_hash' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model
|
||||
*/
|
||||
class ExportMd5Hash extends BaseExportMd5Hash
|
||||
{
|
||||
protected $backup = array();
|
||||
|
||||
public function setModel($model)
|
||||
{
|
||||
$this->setTypeId(ExportMd5HashPeer::getModelHash($model));
|
||||
}
|
||||
|
||||
public function runDataHashCheck($name, $data, $update = false)
|
||||
{
|
||||
$data = str_replace(array("\r\n"), array("\n"), trim($data));
|
||||
$hash = md5($data);
|
||||
$check = isset($this->md5hash[$name]) && $this->md5hash[$name] == $hash;
|
||||
|
||||
if (!$check && $update)
|
||||
{
|
||||
$this->updateMd5Hash($name, $hash);
|
||||
}
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
public function updateMd5Hash($name, $hash)
|
||||
{
|
||||
$md5hash = $this->getMd5Hash();
|
||||
|
||||
if (!isset($this->backup[$name]) && !$this->isNew())
|
||||
{
|
||||
$this->backup[$name] = isset($md5hash[$name]) ? $md5hash[$name] : null;
|
||||
}
|
||||
|
||||
$md5hash[$name] = $hash;
|
||||
$this->setMd5Hash($md5hash);
|
||||
}
|
||||
|
||||
public function restoreMd5Hash($name)
|
||||
{
|
||||
$md5hash = $this->getMd5Hash();
|
||||
$md5hash[$name] = $this->isNew() ? null : $this->backup[$name];
|
||||
$this->setMd5Hash($md5hash);
|
||||
}
|
||||
}
|
||||
68
plugins/stImportExportPlugin/lib/model/ExportMd5HashPeer.php
Normal file
68
plugins/stImportExportPlugin/lib/model/ExportMd5HashPeer.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Subclass for performing query and update operations on the 'st_export_md5_hash' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model
|
||||
*/
|
||||
class ExportMd5HashPeer extends BaseExportMd5HashPeer
|
||||
{
|
||||
protected static $pool = array();
|
||||
|
||||
protected static $modelHash = array();
|
||||
|
||||
public static function getModelHash($model)
|
||||
{
|
||||
if(!isset(self::$modelHash[$model]))
|
||||
{
|
||||
self::$modelHash[$model] = crc32($model);
|
||||
}
|
||||
|
||||
return self::$modelHash[$model];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $model
|
||||
* @return ExportMd5Hash
|
||||
* @throws PropelException
|
||||
*/
|
||||
public static function retrieveByModelId($id, $model)
|
||||
{
|
||||
$pool = $id.$model;
|
||||
|
||||
if (!isset(self::$pool[$pool]))
|
||||
{
|
||||
$hash = null !== $id ? self::retrieveByPK($id, self::getModelHash($model)) : null;
|
||||
|
||||
if (null === $hash)
|
||||
{
|
||||
$hash = new ExportMd5Hash();
|
||||
$hash->setId($id);
|
||||
$hash->setModel($model);
|
||||
}
|
||||
|
||||
if (null === $id)
|
||||
{
|
||||
return $hash;
|
||||
}
|
||||
|
||||
self::$pool[$pool] = $hash;
|
||||
}
|
||||
|
||||
return self::$pool[$pool];
|
||||
}
|
||||
|
||||
public static function clearHash($id, $model, $name)
|
||||
{
|
||||
$hash = ExportMd5HashPeer::retrieveByModelId($id, 'Product');
|
||||
if (null !== $hash)
|
||||
{
|
||||
$hash->updateMd5Hash($name, null);
|
||||
$hash->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
plugins/stImportExportPlugin/lib/model/ExportProfile.php
Normal file
12
plugins/stImportExportPlugin/lib/model/ExportProfile.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Subclass for representing a row from the 'st_export_profile' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model
|
||||
*/
|
||||
class ExportProfile extends BaseExportProfile
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Subclass for representing a row from the 'st_export_profile_has_export_field' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model
|
||||
*/
|
||||
class ExportProfileHasExportField extends BaseExportProfileHasExportField
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Subclass for performing query and update operations on the 'st_export_profile_has_export_field' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model
|
||||
*/
|
||||
class ExportProfileHasExportFieldPeer extends BaseExportProfileHasExportFieldPeer
|
||||
{
|
||||
}
|
||||
25
plugins/stImportExportPlugin/lib/model/ExportProfilePeer.php
Normal file
25
plugins/stImportExportPlugin/lib/model/ExportProfilePeer.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Subclass for performing query and update operations on the 'st_export_profile' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model
|
||||
*/
|
||||
class ExportProfilePeer extends BaseExportProfilePeer
|
||||
{
|
||||
public static function exist($module, $model, $name, array $exclude = null)
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->add(self::MODEL, stImportExportPropel::getProfileModuleScope($module, $model));
|
||||
$c->add(self::NAME, $name);
|
||||
|
||||
if ($exclude)
|
||||
{
|
||||
$c->add(self::ID, $exclude, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
return self::doCount($c) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* This class adds structure of 'st_export_field' table to 'propel' DatabaseMap object.
|
||||
*
|
||||
*
|
||||
*
|
||||
* These statically-built map classes are used by Propel to do runtime db structure discovery.
|
||||
* For example, the createSelectSql() method checks the type of a given column used in an
|
||||
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
|
||||
* (i.e. if it's a text column type).
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model.map
|
||||
*/
|
||||
class ExportFieldMapBuilder {
|
||||
|
||||
/**
|
||||
* The (dot-path) name of this class
|
||||
*/
|
||||
const CLASS_NAME = 'plugins.stImportExportPlugin.lib.model.map.ExportFieldMapBuilder';
|
||||
|
||||
/**
|
||||
* The database map.
|
||||
*/
|
||||
private $dbMap;
|
||||
|
||||
/**
|
||||
* Tells us if this DatabaseMapBuilder is built so that we
|
||||
* don't have to re-build it every time.
|
||||
*
|
||||
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
|
||||
*/
|
||||
public function isBuilt()
|
||||
{
|
||||
return ($this->dbMap !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databasemap this map builder built.
|
||||
*
|
||||
* @return the databasemap
|
||||
*/
|
||||
public function getDatabaseMap()
|
||||
{
|
||||
return $this->dbMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The doBuild() method builds the DatabaseMap
|
||||
*
|
||||
* @return void
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function doBuild()
|
||||
{
|
||||
$this->dbMap = Propel::getDatabaseMap('propel');
|
||||
|
||||
$tMap = $this->dbMap->addTable('st_export_field');
|
||||
$tMap->setPhpName('ExportField');
|
||||
|
||||
$tMap->setUseIdGenerator(true);
|
||||
|
||||
$tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
|
||||
|
||||
$tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
|
||||
|
||||
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
|
||||
|
||||
$tMap->addColumn('FIELD', 'Field', 'string', CreoleTypes::VARCHAR, false, 255);
|
||||
|
||||
$tMap->addColumn('MODEL', 'Model', 'string', CreoleTypes::VARCHAR, false, 128);
|
||||
|
||||
$tMap->addColumn('IS_KEY', 'IsKey', 'int', CreoleTypes::INTEGER, false, null);
|
||||
|
||||
$tMap->addColumn('NAME', 'Name', 'string', CreoleTypes::VARCHAR, false, 255);
|
||||
|
||||
$tMap->addColumn('I18N_FILE', 'I18nFile', 'string', CreoleTypes::VARCHAR, false, 255);
|
||||
|
||||
$tMap->addColumn('I18N', 'I18n', 'boolean', CreoleTypes::BOOLEAN, false, null);
|
||||
|
||||
} // doBuild()
|
||||
|
||||
} // ExportFieldMapBuilder
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* This class adds structure of 'st_export_md5_hash' table to 'propel' DatabaseMap object.
|
||||
*
|
||||
*
|
||||
*
|
||||
* These statically-built map classes are used by Propel to do runtime db structure discovery.
|
||||
* For example, the createSelectSql() method checks the type of a given column used in an
|
||||
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
|
||||
* (i.e. if it's a text column type).
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model.map
|
||||
*/
|
||||
class ExportMd5HashMapBuilder {
|
||||
|
||||
/**
|
||||
* The (dot-path) name of this class
|
||||
*/
|
||||
const CLASS_NAME = 'plugins.stImportExportPlugin.lib.model.map.ExportMd5HashMapBuilder';
|
||||
|
||||
/**
|
||||
* The database map.
|
||||
*/
|
||||
private $dbMap;
|
||||
|
||||
/**
|
||||
* Tells us if this DatabaseMapBuilder is built so that we
|
||||
* don't have to re-build it every time.
|
||||
*
|
||||
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
|
||||
*/
|
||||
public function isBuilt()
|
||||
{
|
||||
return ($this->dbMap !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databasemap this map builder built.
|
||||
*
|
||||
* @return the databasemap
|
||||
*/
|
||||
public function getDatabaseMap()
|
||||
{
|
||||
return $this->dbMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The doBuild() method builds the DatabaseMap
|
||||
*
|
||||
* @return void
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function doBuild()
|
||||
{
|
||||
$this->dbMap = Propel::getDatabaseMap('propel');
|
||||
|
||||
$tMap = $this->dbMap->addTable('st_export_md5_hash');
|
||||
$tMap->setPhpName('ExportMd5Hash');
|
||||
|
||||
$tMap->setUseIdGenerator(false);
|
||||
|
||||
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
|
||||
|
||||
$tMap->addPrimaryKey('TYPE_ID', 'TypeId', 'int', CreoleTypes::INTEGER, true, null);
|
||||
|
||||
$tMap->addColumn('MD5HASH', 'Md5hash', 'array', CreoleTypes::VARCHAR, false, 8192);
|
||||
|
||||
} // doBuild()
|
||||
|
||||
} // ExportMd5HashMapBuilder
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* This class adds structure of 'st_export_profile_has_export_field' table to 'propel' DatabaseMap object.
|
||||
*
|
||||
*
|
||||
*
|
||||
* These statically-built map classes are used by Propel to do runtime db structure discovery.
|
||||
* For example, the createSelectSql() method checks the type of a given column used in an
|
||||
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
|
||||
* (i.e. if it's a text column type).
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model.map
|
||||
*/
|
||||
class ExportProfileHasExportFieldMapBuilder {
|
||||
|
||||
/**
|
||||
* The (dot-path) name of this class
|
||||
*/
|
||||
const CLASS_NAME = 'plugins.stImportExportPlugin.lib.model.map.ExportProfileHasExportFieldMapBuilder';
|
||||
|
||||
/**
|
||||
* The database map.
|
||||
*/
|
||||
private $dbMap;
|
||||
|
||||
/**
|
||||
* Tells us if this DatabaseMapBuilder is built so that we
|
||||
* don't have to re-build it every time.
|
||||
*
|
||||
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
|
||||
*/
|
||||
public function isBuilt()
|
||||
{
|
||||
return ($this->dbMap !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databasemap this map builder built.
|
||||
*
|
||||
* @return the databasemap
|
||||
*/
|
||||
public function getDatabaseMap()
|
||||
{
|
||||
return $this->dbMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The doBuild() method builds the DatabaseMap
|
||||
*
|
||||
* @return void
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function doBuild()
|
||||
{
|
||||
$this->dbMap = Propel::getDatabaseMap('propel');
|
||||
|
||||
$tMap = $this->dbMap->addTable('st_export_profile_has_export_field');
|
||||
$tMap->setPhpName('ExportProfileHasExportField');
|
||||
|
||||
$tMap->setUseIdGenerator(false);
|
||||
|
||||
$tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
|
||||
|
||||
$tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
|
||||
|
||||
$tMap->addForeignPrimaryKey('EXPORT_PROFILE_ID', 'ExportProfileId', 'int' , CreoleTypes::INTEGER, 'st_export_profile', 'ID', true, null);
|
||||
|
||||
$tMap->addForeignPrimaryKey('EXPORT_FIELD_ID', 'ExportFieldId', 'int' , CreoleTypes::INTEGER, 'st_export_field', 'ID', true, null);
|
||||
|
||||
$tMap->addColumn('POSITION', 'Position', 'int', CreoleTypes::INTEGER, false, null);
|
||||
|
||||
} // doBuild()
|
||||
|
||||
} // ExportProfileHasExportFieldMapBuilder
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* This class adds structure of 'st_export_profile' table to 'propel' DatabaseMap object.
|
||||
*
|
||||
*
|
||||
*
|
||||
* These statically-built map classes are used by Propel to do runtime db structure discovery.
|
||||
* For example, the createSelectSql() method checks the type of a given column used in an
|
||||
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
|
||||
* (i.e. if it's a text column type).
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model.map
|
||||
*/
|
||||
class ExportProfileMapBuilder {
|
||||
|
||||
/**
|
||||
* The (dot-path) name of this class
|
||||
*/
|
||||
const CLASS_NAME = 'plugins.stImportExportPlugin.lib.model.map.ExportProfileMapBuilder';
|
||||
|
||||
/**
|
||||
* The database map.
|
||||
*/
|
||||
private $dbMap;
|
||||
|
||||
/**
|
||||
* Tells us if this DatabaseMapBuilder is built so that we
|
||||
* don't have to re-build it every time.
|
||||
*
|
||||
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
|
||||
*/
|
||||
public function isBuilt()
|
||||
{
|
||||
return ($this->dbMap !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databasemap this map builder built.
|
||||
*
|
||||
* @return the databasemap
|
||||
*/
|
||||
public function getDatabaseMap()
|
||||
{
|
||||
return $this->dbMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The doBuild() method builds the DatabaseMap
|
||||
*
|
||||
* @return void
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function doBuild()
|
||||
{
|
||||
$this->dbMap = Propel::getDatabaseMap('propel');
|
||||
|
||||
$tMap = $this->dbMap->addTable('st_export_profile');
|
||||
$tMap->setPhpName('ExportProfile');
|
||||
|
||||
$tMap->setUseIdGenerator(true);
|
||||
|
||||
$tMap->addColumn('CREATED_AT', 'CreatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
|
||||
|
||||
$tMap->addColumn('UPDATED_AT', 'UpdatedAt', 'int', CreoleTypes::TIMESTAMP, false, null);
|
||||
|
||||
$tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null);
|
||||
|
||||
$tMap->addColumn('NAME', 'Name', 'string', CreoleTypes::VARCHAR, false, 255);
|
||||
|
||||
$tMap->addColumn('MODEL', 'Model', 'string', CreoleTypes::VARCHAR, false, 128);
|
||||
|
||||
} // doBuild()
|
||||
|
||||
} // ExportProfileMapBuilder
|
||||
1250
plugins/stImportExportPlugin/lib/model/om/BaseExportField.php
Normal file
1250
plugins/stImportExportPlugin/lib/model/om/BaseExportField.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,679 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base static class for performing query and update operations on the 'st_export_field' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model.om
|
||||
*/
|
||||
abstract class BaseExportFieldPeer {
|
||||
|
||||
/** the default database name for this class */
|
||||
const DATABASE_NAME = 'propel';
|
||||
|
||||
/** the table name for this class */
|
||||
const TABLE_NAME = 'st_export_field';
|
||||
|
||||
/** A class that can be returned by this peer. */
|
||||
const CLASS_DEFAULT = 'plugins.stImportExportPlugin.lib.model.ExportField';
|
||||
|
||||
/** The total number of columns. */
|
||||
const NUM_COLUMNS = 9;
|
||||
|
||||
/** The number of lazy-loaded columns. */
|
||||
const NUM_LAZY_LOAD_COLUMNS = 0;
|
||||
|
||||
|
||||
/** the column name for the CREATED_AT field */
|
||||
const CREATED_AT = 'st_export_field.CREATED_AT';
|
||||
|
||||
/** the column name for the UPDATED_AT field */
|
||||
const UPDATED_AT = 'st_export_field.UPDATED_AT';
|
||||
|
||||
/** the column name for the ID field */
|
||||
const ID = 'st_export_field.ID';
|
||||
|
||||
/** the column name for the FIELD field */
|
||||
const FIELD = 'st_export_field.FIELD';
|
||||
|
||||
/** the column name for the MODEL field */
|
||||
const MODEL = 'st_export_field.MODEL';
|
||||
|
||||
/** the column name for the IS_KEY field */
|
||||
const IS_KEY = 'st_export_field.IS_KEY';
|
||||
|
||||
/** the column name for the NAME field */
|
||||
const NAME = 'st_export_field.NAME';
|
||||
|
||||
/** the column name for the I18N_FILE field */
|
||||
const I18N_FILE = 'st_export_field.I18N_FILE';
|
||||
|
||||
/** the column name for the I18N field */
|
||||
const I18N = 'st_export_field.I18N';
|
||||
|
||||
/** The PHP to DB Name Mapping */
|
||||
private static $phpNameMap = null;
|
||||
|
||||
|
||||
/**
|
||||
* holds an array of fieldnames
|
||||
*
|
||||
* first dimension keys are the type constants
|
||||
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
|
||||
*/
|
||||
private static $fieldNames = array (
|
||||
BasePeer::TYPE_PHPNAME => array ('CreatedAt', 'UpdatedAt', 'Id', 'Field', 'Model', 'IsKey', 'Name', 'I18nFile', 'I18n', ),
|
||||
BasePeer::TYPE_COLNAME => array (ExportFieldPeer::CREATED_AT, ExportFieldPeer::UPDATED_AT, ExportFieldPeer::ID, ExportFieldPeer::FIELD, ExportFieldPeer::MODEL, ExportFieldPeer::IS_KEY, ExportFieldPeer::NAME, ExportFieldPeer::I18N_FILE, ExportFieldPeer::I18N, ),
|
||||
BasePeer::TYPE_FIELDNAME => array ('created_at', 'updated_at', 'id', 'field', 'model', 'is_key', 'name', 'i18n_file', 'i18n', ),
|
||||
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, )
|
||||
);
|
||||
|
||||
/**
|
||||
* holds an array of keys for quick access to the fieldnames array
|
||||
*
|
||||
* first dimension keys are the type constants
|
||||
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
|
||||
*/
|
||||
private static $fieldKeys = array (
|
||||
BasePeer::TYPE_PHPNAME => array ('CreatedAt' => 0, 'UpdatedAt' => 1, 'Id' => 2, 'Field' => 3, 'Model' => 4, 'IsKey' => 5, 'Name' => 6, 'I18nFile' => 7, 'I18n' => 8, ),
|
||||
BasePeer::TYPE_COLNAME => array (ExportFieldPeer::CREATED_AT => 0, ExportFieldPeer::UPDATED_AT => 1, ExportFieldPeer::ID => 2, ExportFieldPeer::FIELD => 3, ExportFieldPeer::MODEL => 4, ExportFieldPeer::IS_KEY => 5, ExportFieldPeer::NAME => 6, ExportFieldPeer::I18N_FILE => 7, ExportFieldPeer::I18N => 8, ),
|
||||
BasePeer::TYPE_FIELDNAME => array ('created_at' => 0, 'updated_at' => 1, 'id' => 2, 'field' => 3, 'model' => 4, 'is_key' => 5, 'name' => 6, 'i18n_file' => 7, 'i18n' => 8, ),
|
||||
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, )
|
||||
);
|
||||
|
||||
protected static $hydrateMethod = null;
|
||||
|
||||
protected static $postHydrateMethod = null;
|
||||
|
||||
public static function setHydrateMethod($callback)
|
||||
{
|
||||
self::$hydrateMethod = $callback;
|
||||
}
|
||||
|
||||
public static function setPostHydrateMethod($callback)
|
||||
{
|
||||
self::$postHydrateMethod = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MapBuilder the map builder for this peer
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function getMapBuilder()
|
||||
{
|
||||
return BasePeer::getMapBuilder('plugins.stImportExportPlugin.lib.model.map.ExportFieldMapBuilder');
|
||||
}
|
||||
/**
|
||||
* Gets a map (hash) of PHP names to DB column names.
|
||||
*
|
||||
* @return array The PHP to DB name map for this peer
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
|
||||
*/
|
||||
public static function getPhpNameMap()
|
||||
{
|
||||
if (self::$phpNameMap === null) {
|
||||
$map = ExportFieldPeer::getTableMap();
|
||||
$columns = $map->getColumns();
|
||||
$nameMap = array();
|
||||
foreach ($columns as $column) {
|
||||
$nameMap[$column->getPhpName()] = $column->getColumnName();
|
||||
}
|
||||
self::$phpNameMap = $nameMap;
|
||||
}
|
||||
return self::$phpNameMap;
|
||||
}
|
||||
/**
|
||||
* Translates a fieldname to another type
|
||||
*
|
||||
* @param string $name field name
|
||||
* @param string $fromType One of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @param string $toType One of the class type constants
|
||||
* @return string translated name of the field.
|
||||
*/
|
||||
static public function translateFieldName($name, $fromType, $toType)
|
||||
{
|
||||
$toNames = self::getFieldNames($toType);
|
||||
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
|
||||
if ($key === null) {
|
||||
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
|
||||
}
|
||||
return $toNames[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of of field names.
|
||||
*
|
||||
* @param string $type The type of fieldnames to return:
|
||||
* One of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @return array A list of field names
|
||||
*/
|
||||
|
||||
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
|
||||
{
|
||||
if (!array_key_exists($type, self::$fieldNames)) {
|
||||
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
|
||||
}
|
||||
return self::$fieldNames[$type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method which changes table.column to alias.column.
|
||||
*
|
||||
* Using this method you can maintain SQL abstraction while using column aliases.
|
||||
* <code>
|
||||
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
|
||||
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
|
||||
* </code>
|
||||
* @param string $alias The alias for the current table.
|
||||
* @param string $column The column name for current table. (i.e. ExportFieldPeer::COLUMN_NAME).
|
||||
* @return string
|
||||
*/
|
||||
public static function alias($alias, $column)
|
||||
{
|
||||
return str_replace(ExportFieldPeer::TABLE_NAME.'.', $alias.'.', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the columns needed to create a new object.
|
||||
*
|
||||
* Note: any columns that were marked with lazyLoad="true" in the
|
||||
* XML schema will not be added to the select list and only loaded
|
||||
* on demand.
|
||||
*
|
||||
* @param criteria object containing the columns to add.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function addSelectColumns(Criteria $criteria)
|
||||
{
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::CREATED_AT);
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::UPDATED_AT);
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::ID);
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::FIELD);
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::MODEL);
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::IS_KEY);
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::NAME);
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::I18N_FILE);
|
||||
|
||||
$criteria->addSelectColumn(ExportFieldPeer::I18N);
|
||||
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('ExportFieldPeer.postAddSelectColumns')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ExportFieldPeer.postAddSelectColumns'));
|
||||
}
|
||||
}
|
||||
|
||||
const COUNT = 'COUNT(st_export_field.ID)';
|
||||
const COUNT_DISTINCT = 'COUNT(DISTINCT st_export_field.ID)';
|
||||
|
||||
/**
|
||||
* Returns the number of rows matching criteria.
|
||||
*
|
||||
* @param Criteria $criteria
|
||||
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
|
||||
* @param Connection $con
|
||||
* @return int Number of matching rows.
|
||||
*/
|
||||
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
|
||||
{
|
||||
// we're going to modify criteria, so copy it first
|
||||
$criteria = clone $criteria;
|
||||
|
||||
// clear out anything that might confuse the ORDER BY clause
|
||||
$criteria->clearSelectColumns()->clearOrderByColumns();
|
||||
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
|
||||
$criteria->addSelectColumn(ExportFieldPeer::COUNT_DISTINCT);
|
||||
} else {
|
||||
$criteria->addSelectColumn(ExportFieldPeer::COUNT);
|
||||
}
|
||||
|
||||
// just in case we're grouping: add those columns to the select statement
|
||||
foreach($criteria->getGroupByColumns() as $column)
|
||||
{
|
||||
$criteria->addSelectColumn($column);
|
||||
}
|
||||
|
||||
$rs = ExportFieldPeer::doSelectRS($criteria, $con);
|
||||
if ($rs->next()) {
|
||||
return $rs->getInt(1);
|
||||
} else {
|
||||
// no rows returned; we infer that means 0 matches.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Method to select one object from the DB.
|
||||
*
|
||||
* @param Criteria $criteria object used to create the SELECT statement.
|
||||
* @param Connection $con
|
||||
* @return ExportField
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doSelectOne(Criteria $criteria, $con = null)
|
||||
{
|
||||
$critcopy = clone $criteria;
|
||||
$critcopy->setLimit(1);
|
||||
$objects = ExportFieldPeer::doSelect($critcopy, $con);
|
||||
if ($objects) {
|
||||
return $objects[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Method to do selects.
|
||||
*
|
||||
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
|
||||
* @param Connection $con
|
||||
* @return ExportField[]
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doSelect(Criteria $criteria, $con = null)
|
||||
{
|
||||
return ExportFieldPeer::populateObjects(ExportFieldPeer::doSelectRS($criteria, $con));
|
||||
}
|
||||
/**
|
||||
* Prepares the Criteria object and uses the parent doSelect()
|
||||
* method to get a ResultSet.
|
||||
*
|
||||
* Use this method directly if you want to just get the resultset
|
||||
* (instead of an array of objects).
|
||||
*
|
||||
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
|
||||
* @param Connection $con the connection to use
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
* @return ResultSet The resultset object with numerically-indexed fields.
|
||||
* @see BasePeer::doSelect()
|
||||
*/
|
||||
public static function doSelectRS(Criteria $criteria, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if (!$criteria->getSelectColumns()) {
|
||||
$criteria = clone $criteria;
|
||||
ExportFieldPeer::addSelectColumns($criteria);
|
||||
}
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
|
||||
}
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
// BasePeer returns a Creole ResultSet, set to return
|
||||
// rows indexed numerically.
|
||||
$rs = BasePeer::doSelect($criteria, $con);
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
|
||||
}
|
||||
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* The returned array will contain objects of the default type or
|
||||
* objects that inherit from the default.
|
||||
*
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function populateObjects(ResultSet $rs)
|
||||
{
|
||||
|
||||
if (self::$hydrateMethod)
|
||||
{
|
||||
return call_user_func(self::$hydrateMethod, $rs);
|
||||
}
|
||||
$results = array();
|
||||
|
||||
// set the class once to avoid overhead in the loop
|
||||
$cls = ExportFieldPeer::getOMClass();
|
||||
$cls = Propel::import($cls);
|
||||
// populate the object(s)
|
||||
while($rs->next()) {
|
||||
|
||||
$obj = new $cls();
|
||||
$obj->hydrate($rs);
|
||||
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
|
||||
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
/**
|
||||
* Returns the TableMap related to this peer.
|
||||
* This method is not needed for general use but a specific application could have a need.
|
||||
* @return TableMap
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function getTableMap()
|
||||
{
|
||||
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* The class that the Peer will make instances of.
|
||||
*
|
||||
* This uses a dot-path notation which is tranalted into a path
|
||||
* relative to a location on the PHP include_path.
|
||||
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
|
||||
*
|
||||
* @return string path.to.ClassName
|
||||
*/
|
||||
public static function getOMClass()
|
||||
{
|
||||
return ExportFieldPeer::CLASS_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform an INSERT on the database, given a ExportField or Criteria object.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportField object containing data that is used to create the INSERT statement.
|
||||
* @param Connection $con the connection to use
|
||||
* @return mixed The new primary key.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doInsert($values, $con = null)
|
||||
{
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportFieldPeer:doInsert:pre') as $callable)
|
||||
{
|
||||
$ret = call_user_func($callable, 'BaseExportFieldPeer', $values, $con);
|
||||
if (false !== $ret)
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
} else {
|
||||
$criteria = $values->buildCriteria(); // build Criteria from ExportField object
|
||||
}
|
||||
|
||||
$criteria->remove(ExportFieldPeer::ID); // remove pkey col since this table uses auto-increment
|
||||
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table (I guess, conceivably)
|
||||
$con->begin();
|
||||
$pk = BasePeer::doInsert($criteria, $con);
|
||||
$con->commit();
|
||||
} catch(PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportFieldPeer:doInsert:post') as $callable)
|
||||
{
|
||||
call_user_func($callable, 'BaseExportFieldPeer', $values, $con, $pk);
|
||||
}
|
||||
|
||||
return $pk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform an UPDATE on the database, given a ExportField or Criteria object.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportField object containing data that is used to create the UPDATE statement.
|
||||
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
|
||||
* @return int The number of affected rows (if supported by underlying database driver).
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doUpdate($values, $con = null)
|
||||
{
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportFieldPeer:doUpdate:pre') as $callable)
|
||||
{
|
||||
$ret = call_user_func($callable, 'BaseExportFieldPeer', $values, $con);
|
||||
if (false !== $ret)
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
$selectCriteria = new Criteria(self::DATABASE_NAME);
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
|
||||
$comparison = $criteria->getComparison(ExportFieldPeer::ID);
|
||||
$selectCriteria->add(ExportFieldPeer::ID, $criteria->remove(ExportFieldPeer::ID), $comparison);
|
||||
|
||||
} else { // $values is ExportField object
|
||||
$criteria = $values->buildCriteria(); // gets full criteria
|
||||
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
|
||||
}
|
||||
|
||||
// set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
|
||||
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportFieldPeer:doUpdate:post') as $callable)
|
||||
{
|
||||
call_user_func($callable, 'BaseExportFieldPeer', $values, $con, $ret);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to DELETE all rows from the st_export_field table.
|
||||
*
|
||||
* @return int The number of affected rows (if supported by underlying database driver).
|
||||
*/
|
||||
public static function doDeleteAll($con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
$affectedRows = 0; // initialize var to track total num of affected rows
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table or we could emulating ON DELETE CASCADE, etc.
|
||||
$con->begin();
|
||||
$affectedRows += BasePeer::doDeleteAll(ExportFieldPeer::TABLE_NAME, $con);
|
||||
$con->commit();
|
||||
return $affectedRows;
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform a DELETE on the database, given a ExportField or Criteria object OR a primary key value.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportField object or primary key or array of primary keys
|
||||
* which is used to create the DELETE statement
|
||||
* @param Connection $con the connection to use
|
||||
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
|
||||
* if supported by native driver or if emulated using Propel.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doDelete($values, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(ExportFieldPeer::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
} elseif ($values instanceof ExportField) {
|
||||
|
||||
$criteria = $values->buildPkeyCriteria();
|
||||
} else {
|
||||
// it must be the primary key
|
||||
$criteria = new Criteria(self::DATABASE_NAME);
|
||||
$criteria->add(ExportFieldPeer::ID, (array) $values, Criteria::IN);
|
||||
}
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
$affectedRows = 0; // initialize var to track total num of affected rows
|
||||
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table or we could emulating ON DELETE CASCADE, etc.
|
||||
$con->begin();
|
||||
|
||||
$affectedRows += BasePeer::doDelete($criteria, $con);
|
||||
$con->commit();
|
||||
return $affectedRows;
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates all modified columns of given ExportField object.
|
||||
* If parameter $columns is either a single column name or an array of column names
|
||||
* than only those columns are validated.
|
||||
*
|
||||
* NOTICE: This does not apply to primary or foreign keys for now.
|
||||
*
|
||||
* @param ExportField $obj The object to validate.
|
||||
* @param mixed $cols Column name or array of column names.
|
||||
*
|
||||
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
|
||||
*/
|
||||
public static function doValidate(ExportField $obj, $cols = null)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
if ($cols) {
|
||||
$dbMap = Propel::getDatabaseMap(ExportFieldPeer::DATABASE_NAME);
|
||||
$tableMap = $dbMap->getTable(ExportFieldPeer::TABLE_NAME);
|
||||
|
||||
if (! is_array($cols)) {
|
||||
$cols = array($cols);
|
||||
}
|
||||
|
||||
foreach($cols as $colName) {
|
||||
if ($tableMap->containsColumn($colName)) {
|
||||
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
|
||||
$columns[$colName] = $obj->$get();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
$res = BasePeer::doValidate(ExportFieldPeer::DATABASE_NAME, ExportFieldPeer::TABLE_NAME, $columns);
|
||||
if ($res !== true) {
|
||||
$request = sfContext::getInstance()->getRequest();
|
||||
foreach ($res as $failed) {
|
||||
$col = ExportFieldPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
|
||||
$request->setError($col, $failed->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single object by pkey.
|
||||
*
|
||||
* @param mixed $pk the primary key.
|
||||
* @param Connection $con the connection to use
|
||||
* @return ExportField
|
||||
*/
|
||||
public static function retrieveByPK($pk, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
$criteria = new Criteria(ExportFieldPeer::DATABASE_NAME);
|
||||
|
||||
$criteria->add(ExportFieldPeer::ID, $pk);
|
||||
|
||||
|
||||
$v = ExportFieldPeer::doSelect($criteria, $con);
|
||||
|
||||
return !empty($v) > 0 ? $v[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve multiple objects by pkey.
|
||||
*
|
||||
* @param array $pks List of primary keys
|
||||
* @param Connection $con the connection to use
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
* @return ExportField[]
|
||||
*/
|
||||
public static function retrieveByPKs($pks, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
$objs = null;
|
||||
if (empty($pks)) {
|
||||
$objs = array();
|
||||
} else {
|
||||
$criteria = new Criteria();
|
||||
$criteria->add(ExportFieldPeer::ID, $pks, Criteria::IN);
|
||||
$objs = ExportFieldPeer::doSelect($criteria, $con);
|
||||
}
|
||||
return $objs;
|
||||
}
|
||||
|
||||
} // BaseExportFieldPeer
|
||||
|
||||
// static code to register the map builder for this Peer with the main Propel class
|
||||
if (Propel::isInit()) {
|
||||
// the MapBuilder classes register themselves with Propel during initialization
|
||||
// so we need to load them here.
|
||||
try {
|
||||
BaseExportFieldPeer::getMapBuilder();
|
||||
} catch (Exception $e) {
|
||||
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
|
||||
}
|
||||
} else {
|
||||
// even if Propel is not yet initialized, the map builder class can be registered
|
||||
// now and then it will be loaded when Propel initializes.
|
||||
Propel::registerMapBuilder('plugins.stImportExportPlugin.lib.model.map.ExportFieldMapBuilder');
|
||||
}
|
||||
690
plugins/stImportExportPlugin/lib/model/om/BaseExportMd5Hash.php
Normal file
690
plugins/stImportExportPlugin/lib/model/om/BaseExportMd5Hash.php
Normal file
@@ -0,0 +1,690 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base class that represents a row from the 'st_export_md5_hash' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model.om
|
||||
*/
|
||||
abstract class BaseExportMd5Hash extends BaseObject implements Persistent {
|
||||
|
||||
|
||||
protected static $dispatcher = null;
|
||||
|
||||
|
||||
/**
|
||||
* The value for the id field.
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
|
||||
/**
|
||||
* The value for the type_id field.
|
||||
* @var int
|
||||
*/
|
||||
protected $type_id;
|
||||
|
||||
|
||||
/**
|
||||
* The value for the md5hash field.
|
||||
* @var array
|
||||
*/
|
||||
protected $md5hash;
|
||||
|
||||
/**
|
||||
* Flag to prevent endless save loop, if this object is referenced
|
||||
* by another object which falls in this transaction.
|
||||
* @var boolean
|
||||
*/
|
||||
protected $alreadyInSave = false;
|
||||
|
||||
/**
|
||||
* Flag to prevent endless validation loop, if this object is referenced
|
||||
* by another object which falls in this transaction.
|
||||
* @var boolean
|
||||
*/
|
||||
protected $alreadyInValidation = false;
|
||||
|
||||
/**
|
||||
* Get the [id] column value.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [type_id] column value.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTypeId()
|
||||
{
|
||||
|
||||
return $this->type_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [md5hash] column value.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMd5hash()
|
||||
{
|
||||
|
||||
return $this->md5hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of [id] column.
|
||||
*
|
||||
* @param int $v new value
|
||||
* @return void
|
||||
*/
|
||||
public function setId($v)
|
||||
{
|
||||
|
||||
if ($v !== null && !is_int($v) && is_numeric($v)) {
|
||||
$v = (int) $v;
|
||||
}
|
||||
|
||||
if ($this->id !== $v) {
|
||||
$this->id = $v;
|
||||
$this->modifiedColumns[] = ExportMd5HashPeer::ID;
|
||||
}
|
||||
|
||||
} // setId()
|
||||
|
||||
/**
|
||||
* Set the value of [type_id] column.
|
||||
*
|
||||
* @param int $v new value
|
||||
* @return void
|
||||
*/
|
||||
public function setTypeId($v)
|
||||
{
|
||||
|
||||
if ($v !== null && !is_int($v) && is_numeric($v)) {
|
||||
$v = (int) $v;
|
||||
}
|
||||
|
||||
if ($this->type_id !== $v) {
|
||||
$this->type_id = $v;
|
||||
$this->modifiedColumns[] = ExportMd5HashPeer::TYPE_ID;
|
||||
}
|
||||
|
||||
} // setTypeId()
|
||||
|
||||
/**
|
||||
* Set the value of [md5hash] column.
|
||||
*
|
||||
* @param array $v new value
|
||||
* @return void
|
||||
*/
|
||||
public function setMd5hash($v)
|
||||
{
|
||||
|
||||
if ($this->md5hash !== $v) {
|
||||
$this->md5hash = $v;
|
||||
$this->modifiedColumns[] = ExportMd5HashPeer::MD5HASH;
|
||||
}
|
||||
|
||||
} // setMd5hash()
|
||||
|
||||
/**
|
||||
* Hydrates (populates) the object variables with values from the database resultset.
|
||||
*
|
||||
* An offset (1-based "start column") is specified so that objects can be hydrated
|
||||
* with a subset of the columns in the resultset rows. This is needed, for example,
|
||||
* for results of JOIN queries where the resultset row includes columns from two or
|
||||
* more tables.
|
||||
*
|
||||
* @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.
|
||||
* @param int $startcol 1-based offset column which indicates which restultset column to start with.
|
||||
* @return int next starting column
|
||||
* @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
|
||||
*/
|
||||
public function hydrate(ResultSet $rs, $startcol = 1)
|
||||
{
|
||||
try {
|
||||
if ($this->getDispatcher()->getListeners('ExportMd5Hash.preHydrate')) {
|
||||
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ExportMd5Hash.preHydrate', array('resultset' => $rs, 'startcol' => $startcol)));
|
||||
$startcol = $event['startcol'];
|
||||
}
|
||||
|
||||
$this->id = $rs->getInt($startcol + 0);
|
||||
|
||||
$this->type_id = $rs->getInt($startcol + 1);
|
||||
|
||||
$this->md5hash = $rs->getString($startcol + 2) ? unserialize($rs->getString($startcol + 2)) : null;
|
||||
|
||||
$this->resetModified();
|
||||
|
||||
$this->setNew(false);
|
||||
if ($this->getDispatcher()->getListeners('ExportMd5Hash.postHydrate')) {
|
||||
$event = $this->getDispatcher()->notify(new sfEvent($this, 'ExportMd5Hash.postHydrate', array('resultset' => $rs, 'startcol' => $startcol + 3)));
|
||||
return $event['startcol'];
|
||||
}
|
||||
|
||||
// FIXME - using NUM_COLUMNS may be clearer.
|
||||
return $startcol + 3; // 3 = ExportMd5HashPeer::NUM_COLUMNS - ExportMd5HashPeer::NUM_LAZY_LOAD_COLUMNS).
|
||||
|
||||
} catch (Exception $e) {
|
||||
throw new PropelException("Error populating ExportMd5Hash object", $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this object from datastore and sets delete attribute.
|
||||
*
|
||||
* @param Connection $con
|
||||
* @return void
|
||||
* @throws PropelException
|
||||
* @see BaseObject::setDeleted()
|
||||
* @see BaseObject::isDeleted()
|
||||
*/
|
||||
public function delete($con = null)
|
||||
{
|
||||
if ($this->isDeleted()) {
|
||||
throw new PropelException("This object has already been deleted.");
|
||||
}
|
||||
|
||||
if ($this->getDispatcher()->getListeners('ExportMd5Hash.preDelete')) {
|
||||
$this->getDispatcher()->notify(new sfEvent($this, 'ExportMd5Hash.preDelete', array('con' => $con)));
|
||||
}
|
||||
|
||||
if (sfMixer::hasCallables('BaseExportMd5Hash:delete:pre'))
|
||||
{
|
||||
foreach (sfMixer::getCallables('BaseExportMd5Hash:delete:pre') as $callable)
|
||||
{
|
||||
$ret = call_user_func($callable, $this, $con);
|
||||
if ($ret)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(ExportMd5HashPeer::DATABASE_NAME);
|
||||
}
|
||||
|
||||
try {
|
||||
$con->begin();
|
||||
ExportMd5HashPeer::doDelete($this, $con);
|
||||
$this->setDeleted(true);
|
||||
$con->commit();
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($this->getDispatcher()->getListeners('ExportMd5Hash.postDelete')) {
|
||||
$this->getDispatcher()->notify(new sfEvent($this, 'ExportMd5Hash.postDelete', array('con' => $con)));
|
||||
}
|
||||
|
||||
if (sfMixer::hasCallables('BaseExportMd5Hash:delete:post'))
|
||||
{
|
||||
foreach (sfMixer::getCallables('BaseExportMd5Hash:delete:post') as $callable)
|
||||
{
|
||||
call_user_func($callable, $this, $con);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the object in the database. If the object is new,
|
||||
* it inserts it; otherwise an update is performed. This method
|
||||
* wraps the doSave() worker method in a transaction.
|
||||
*
|
||||
* @param Connection $con
|
||||
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
|
||||
* @throws PropelException
|
||||
* @see doSave()
|
||||
*/
|
||||
public function save($con = null)
|
||||
{
|
||||
if ($this->isDeleted()) {
|
||||
throw new PropelException("You cannot save an object that has been deleted.");
|
||||
}
|
||||
|
||||
if (!$this->alreadyInSave) {
|
||||
if ($this->getDispatcher()->getListeners('ExportMd5Hash.preSave')) {
|
||||
$this->getDispatcher()->notify(new sfEvent($this, 'ExportMd5Hash.preSave', array('con' => $con)));
|
||||
}
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportMd5Hash:save:pre') as $callable)
|
||||
{
|
||||
$affectedRows = call_user_func($callable, $this, $con);
|
||||
if (is_int($affectedRows))
|
||||
{
|
||||
return $affectedRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(ExportMd5HashPeer::DATABASE_NAME);
|
||||
}
|
||||
|
||||
try {
|
||||
$con->begin();
|
||||
$affectedRows = $this->doSave($con);
|
||||
$con->commit();
|
||||
|
||||
if (!$this->alreadyInSave) {
|
||||
if ($this->getDispatcher()->getListeners('ExportMd5Hash.postSave')) {
|
||||
$this->getDispatcher()->notify(new sfEvent($this, 'ExportMd5Hash.postSave', array('con' => $con)));
|
||||
}
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportMd5Hash:save:post') as $callable)
|
||||
{
|
||||
call_user_func($callable, $this, $con, $affectedRows);
|
||||
}
|
||||
}
|
||||
|
||||
return $affectedRows;
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the object in the database.
|
||||
*
|
||||
* If the object is new, it inserts it; otherwise an update is performed.
|
||||
* All related objects are also updated in this method.
|
||||
*
|
||||
* @param Connection $con
|
||||
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
|
||||
* @throws PropelException
|
||||
* @see save()
|
||||
*/
|
||||
protected function doSave($con)
|
||||
{
|
||||
$affectedRows = 0; // initialize var to track total num of affected rows
|
||||
if (!$this->alreadyInSave) {
|
||||
$this->alreadyInSave = true;
|
||||
|
||||
|
||||
// If this object has been modified, then save it to the database.
|
||||
if ($this->isModified()) {
|
||||
if ($this->isNew()) {
|
||||
$pk = ExportMd5HashPeer::doInsert($this, $con);
|
||||
$affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
|
||||
// should always be true here (even though technically
|
||||
// BasePeer::doInsert() can insert multiple rows).
|
||||
|
||||
$this->setNew(false);
|
||||
} else {
|
||||
$affectedRows += ExportMd5HashPeer::doUpdate($this, $con);
|
||||
}
|
||||
$this->resetModified(); // [HL] After being saved an object is no longer 'modified'
|
||||
}
|
||||
|
||||
$this->alreadyInSave = false;
|
||||
}
|
||||
return $affectedRows;
|
||||
} // doSave()
|
||||
|
||||
/**
|
||||
* Array of ValidationFailed objects.
|
||||
* @var array ValidationFailed[]
|
||||
*/
|
||||
protected $validationFailures = array();
|
||||
|
||||
/**
|
||||
* Gets any ValidationFailed objects that resulted from last call to validate().
|
||||
*
|
||||
*
|
||||
* @return array ValidationFailed[]
|
||||
* @see validate()
|
||||
*/
|
||||
public function getValidationFailures()
|
||||
{
|
||||
return $this->validationFailures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the objects modified field values and all objects related to this table.
|
||||
*
|
||||
* If $columns is either a column name or an array of column names
|
||||
* only those columns are validated.
|
||||
*
|
||||
* @param mixed $columns Column name or an array of column names.
|
||||
* @return boolean Whether all columns pass validation.
|
||||
* @see doValidate()
|
||||
* @see getValidationFailures()
|
||||
*/
|
||||
public function validate($columns = null)
|
||||
{
|
||||
$res = $this->doValidate($columns);
|
||||
if ($res === true) {
|
||||
$this->validationFailures = array();
|
||||
return true;
|
||||
} else {
|
||||
$this->validationFailures = $res;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function performs the validation work for complex object models.
|
||||
*
|
||||
* In addition to checking the current object, all related objects will
|
||||
* also be validated. If all pass then <code>true</code> is returned; otherwise
|
||||
* an aggreagated array of ValidationFailed objects will be returned.
|
||||
*
|
||||
* @param array $columns Array of column names to validate.
|
||||
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
|
||||
*/
|
||||
protected function doValidate($columns = null)
|
||||
{
|
||||
if (!$this->alreadyInValidation) {
|
||||
$this->alreadyInValidation = true;
|
||||
$retval = null;
|
||||
|
||||
$failureMap = array();
|
||||
|
||||
|
||||
if (($retval = ExportMd5HashPeer::doValidate($this, $columns)) !== true) {
|
||||
$failureMap = array_merge($failureMap, $retval);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->alreadyInValidation = false;
|
||||
}
|
||||
|
||||
return (!empty($failureMap) ? $failureMap : true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a field from the object by name passed in as a string.
|
||||
*
|
||||
* @param string $name name
|
||||
* @param string $type The type of fieldname the $name is of:
|
||||
* one of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @return mixed Value of field.
|
||||
*/
|
||||
public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
|
||||
{
|
||||
$pos = ExportMd5HashPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
|
||||
return $this->getByPosition($pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a field from the object by Position as specified in the xml schema.
|
||||
* Zero-based.
|
||||
*
|
||||
* @param int $pos position in xml schema
|
||||
* @return mixed Value of field at $pos
|
||||
*/
|
||||
public function getByPosition($pos)
|
||||
{
|
||||
switch($pos) {
|
||||
case 0:
|
||||
return $this->getId();
|
||||
break;
|
||||
case 1:
|
||||
return $this->getTypeId();
|
||||
break;
|
||||
case 2:
|
||||
return $this->getMd5hash();
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
break;
|
||||
} // switch()
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the object as an array.
|
||||
*
|
||||
* You can specify the key type of the array by passing one of the class
|
||||
* type constants.
|
||||
*
|
||||
* @param string $keyType One of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @return an associative array containing the field names (as keys) and field values
|
||||
*/
|
||||
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
|
||||
{
|
||||
$keys = ExportMd5HashPeer::getFieldNames($keyType);
|
||||
$result = array(
|
||||
$keys[0] => $this->getId(),
|
||||
$keys[1] => $this->getTypeId(),
|
||||
$keys[2] => $this->getMd5hash(),
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a field from the object by name passed in as a string.
|
||||
*
|
||||
* @param string $name peer name
|
||||
* @param mixed $value field value
|
||||
* @param string $type The type of fieldname the $name is of:
|
||||
* one of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @return void
|
||||
*/
|
||||
public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
|
||||
{
|
||||
$pos = ExportMd5HashPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
|
||||
return $this->setByPosition($pos, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a field from the object by Position as specified in the xml schema.
|
||||
* Zero-based.
|
||||
*
|
||||
* @param int $pos position in xml schema
|
||||
* @param mixed $value field value
|
||||
* @return void
|
||||
*/
|
||||
public function setByPosition($pos, $value)
|
||||
{
|
||||
switch($pos) {
|
||||
case 0:
|
||||
$this->setId($value);
|
||||
break;
|
||||
case 1:
|
||||
$this->setTypeId($value);
|
||||
break;
|
||||
case 2:
|
||||
$this->setMd5hash($value);
|
||||
break;
|
||||
} // switch()
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the object using an array.
|
||||
*
|
||||
* This is particularly useful when populating an object from one of the
|
||||
* request arrays (e.g. $_POST). This method goes through the column
|
||||
* names, checking to see whether a matching key exists in populated
|
||||
* array. If so the setByName() method is called for that column.
|
||||
*
|
||||
* You can specify the key type of the array by additionally passing one
|
||||
* of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
|
||||
* TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
|
||||
*
|
||||
* @param array $arr An array to populate the object from.
|
||||
* @param string $keyType The type of keys the array uses.
|
||||
* @return void
|
||||
*/
|
||||
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
|
||||
{
|
||||
$keys = ExportMd5HashPeer::getFieldNames($keyType);
|
||||
|
||||
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
|
||||
if (array_key_exists($keys[1], $arr)) $this->setTypeId($arr[$keys[1]]);
|
||||
if (array_key_exists($keys[2], $arr)) $this->setMd5hash($arr[$keys[2]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a Criteria object containing the values of all modified columns in this object.
|
||||
*
|
||||
* @return Criteria The Criteria object containing all modified values.
|
||||
*/
|
||||
public function buildCriteria()
|
||||
{
|
||||
$criteria = new Criteria(ExportMd5HashPeer::DATABASE_NAME);
|
||||
|
||||
if ($this->isColumnModified(ExportMd5HashPeer::ID)) $criteria->add(ExportMd5HashPeer::ID, $this->id);
|
||||
if ($this->isColumnModified(ExportMd5HashPeer::TYPE_ID)) $criteria->add(ExportMd5HashPeer::TYPE_ID, $this->type_id);
|
||||
if ($this->isColumnModified(ExportMd5HashPeer::MD5HASH)) $criteria->add(ExportMd5HashPeer::MD5HASH, null !== $this->md5hash && (is_array($this->md5hash) || is_object($this->md5hash)) ? serialize($this->md5hash) : $this->md5hash);
|
||||
|
||||
return $criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a Criteria object containing the primary key for this object.
|
||||
*
|
||||
* Unlike buildCriteria() this method includes the primary key values regardless
|
||||
* of whether or not they have been modified.
|
||||
*
|
||||
* @return Criteria The Criteria object containing value(s) for primary key(s).
|
||||
*/
|
||||
public function buildPkeyCriteria()
|
||||
{
|
||||
$criteria = new Criteria(ExportMd5HashPeer::DATABASE_NAME);
|
||||
|
||||
$criteria->add(ExportMd5HashPeer::ID, $this->id);
|
||||
$criteria->add(ExportMd5HashPeer::TYPE_ID, $this->type_id);
|
||||
|
||||
return $criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the composite primary key for this object.
|
||||
* The array elements will be in same order as specified in XML.
|
||||
* @return array
|
||||
*/
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return array($this->getId(), $this->getTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns [composite] primary key fields
|
||||
*
|
||||
* @param string $keyType
|
||||
* @return array
|
||||
*/
|
||||
public function getPrimaryKeyFields($keyType = BasePeer::TYPE_FIELDNAME)
|
||||
{
|
||||
return array(ExportMd5HashPeer::translateFieldName('id', BasePeer::TYPE_FIELDNAME, $keyType), ExportMd5HashPeer::translateFieldName('type_id', BasePeer::TYPE_FIELDNAME, $keyType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the [composite] primary key.
|
||||
*
|
||||
* @param array $keys The elements of the composite key (order must match the order in XML file).
|
||||
* @return void
|
||||
*/
|
||||
public function setPrimaryKey($keys)
|
||||
{
|
||||
|
||||
$this->setId($keys[0]);
|
||||
|
||||
$this->setTypeId($keys[1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets contents of passed object to values from current object.
|
||||
*
|
||||
* If desired, this method can also make copies of all associated (fkey referrers)
|
||||
* objects.
|
||||
*
|
||||
* @param object $copyObj An object of ExportMd5Hash (or compatible) type.
|
||||
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function copyInto($copyObj, $deepCopy = false)
|
||||
{
|
||||
|
||||
$copyObj->setMd5hash($this->md5hash);
|
||||
|
||||
|
||||
$copyObj->setNew(true);
|
||||
|
||||
$copyObj->setId(NULL); // this is a pkey column, so set to default value
|
||||
|
||||
$copyObj->setTypeId(NULL); // this is a pkey column, so set to default value
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a copy of this object that will be inserted as a new row in table when saved.
|
||||
* It creates a new object filling in the simple attributes, but skipping any primary
|
||||
* keys that are defined for the table.
|
||||
*
|
||||
* If desired, this method can also make copies of all associated (fkey referrers)
|
||||
* objects.
|
||||
*
|
||||
* @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
|
||||
* @return ExportMd5Hash Clone of current object.
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function copy($deepCopy = false)
|
||||
{
|
||||
// we use get_class(), because this might be a subclass
|
||||
$clazz = get_class($this);
|
||||
$copyObj = new $clazz();
|
||||
$this->copyInto($copyObj, $deepCopy);
|
||||
return $copyObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a peer instance associated with this om.
|
||||
*
|
||||
* @return string Peer class name
|
||||
*/
|
||||
public function getPeer()
|
||||
{
|
||||
return 'ExportMd5HashPeer';
|
||||
}
|
||||
|
||||
|
||||
public function getDispatcher()
|
||||
{
|
||||
if (null === self::$dispatcher)
|
||||
{
|
||||
self::$dispatcher = stEventDispatcher::getInstance();
|
||||
}
|
||||
|
||||
return self::$dispatcher;
|
||||
}
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
$event = $this->getDispatcher()->notifyUntil(new sfEvent($this, 'ExportMd5Hash.' . $method, array('arguments' => $arguments, 'method' => $method)));
|
||||
|
||||
if ($event->isProcessed())
|
||||
{
|
||||
return $event->getReturnValue();
|
||||
}
|
||||
|
||||
if (!$callable = sfMixer::getCallable('BaseExportMd5Hash:'.$method))
|
||||
{
|
||||
throw new sfException(sprintf('Call to undefined method BaseExportMd5Hash::%s', $method));
|
||||
}
|
||||
|
||||
array_unshift($arguments, $this);
|
||||
|
||||
return call_user_func_array($callable, $arguments);
|
||||
}
|
||||
|
||||
} // BaseExportMd5Hash
|
||||
@@ -0,0 +1,637 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base static class for performing query and update operations on the 'st_export_md5_hash' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model.om
|
||||
*/
|
||||
abstract class BaseExportMd5HashPeer {
|
||||
|
||||
/** the default database name for this class */
|
||||
const DATABASE_NAME = 'propel';
|
||||
|
||||
/** the table name for this class */
|
||||
const TABLE_NAME = 'st_export_md5_hash';
|
||||
|
||||
/** A class that can be returned by this peer. */
|
||||
const CLASS_DEFAULT = 'plugins.stImportExportPlugin.lib.model.ExportMd5Hash';
|
||||
|
||||
/** The total number of columns. */
|
||||
const NUM_COLUMNS = 3;
|
||||
|
||||
/** The number of lazy-loaded columns. */
|
||||
const NUM_LAZY_LOAD_COLUMNS = 0;
|
||||
|
||||
|
||||
/** the column name for the ID field */
|
||||
const ID = 'st_export_md5_hash.ID';
|
||||
|
||||
/** the column name for the TYPE_ID field */
|
||||
const TYPE_ID = 'st_export_md5_hash.TYPE_ID';
|
||||
|
||||
/** the column name for the MD5HASH field */
|
||||
const MD5HASH = 'st_export_md5_hash.MD5HASH';
|
||||
|
||||
/** The PHP to DB Name Mapping */
|
||||
private static $phpNameMap = null;
|
||||
|
||||
|
||||
/**
|
||||
* holds an array of fieldnames
|
||||
*
|
||||
* first dimension keys are the type constants
|
||||
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
|
||||
*/
|
||||
private static $fieldNames = array (
|
||||
BasePeer::TYPE_PHPNAME => array ('Id', 'TypeId', 'Md5hash', ),
|
||||
BasePeer::TYPE_COLNAME => array (ExportMd5HashPeer::ID, ExportMd5HashPeer::TYPE_ID, ExportMd5HashPeer::MD5HASH, ),
|
||||
BasePeer::TYPE_FIELDNAME => array ('id', 'type_id', 'md5hash', ),
|
||||
BasePeer::TYPE_NUM => array (0, 1, 2, )
|
||||
);
|
||||
|
||||
/**
|
||||
* holds an array of keys for quick access to the fieldnames array
|
||||
*
|
||||
* first dimension keys are the type constants
|
||||
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
|
||||
*/
|
||||
private static $fieldKeys = array (
|
||||
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'TypeId' => 1, 'Md5hash' => 2, ),
|
||||
BasePeer::TYPE_COLNAME => array (ExportMd5HashPeer::ID => 0, ExportMd5HashPeer::TYPE_ID => 1, ExportMd5HashPeer::MD5HASH => 2, ),
|
||||
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'type_id' => 1, 'md5hash' => 2, ),
|
||||
BasePeer::TYPE_NUM => array (0, 1, 2, )
|
||||
);
|
||||
|
||||
protected static $hydrateMethod = null;
|
||||
|
||||
protected static $postHydrateMethod = null;
|
||||
|
||||
public static function setHydrateMethod($callback)
|
||||
{
|
||||
self::$hydrateMethod = $callback;
|
||||
}
|
||||
|
||||
public static function setPostHydrateMethod($callback)
|
||||
{
|
||||
self::$postHydrateMethod = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MapBuilder the map builder for this peer
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function getMapBuilder()
|
||||
{
|
||||
return BasePeer::getMapBuilder('plugins.stImportExportPlugin.lib.model.map.ExportMd5HashMapBuilder');
|
||||
}
|
||||
/**
|
||||
* Gets a map (hash) of PHP names to DB column names.
|
||||
*
|
||||
* @return array The PHP to DB name map for this peer
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
|
||||
*/
|
||||
public static function getPhpNameMap()
|
||||
{
|
||||
if (self::$phpNameMap === null) {
|
||||
$map = ExportMd5HashPeer::getTableMap();
|
||||
$columns = $map->getColumns();
|
||||
$nameMap = array();
|
||||
foreach ($columns as $column) {
|
||||
$nameMap[$column->getPhpName()] = $column->getColumnName();
|
||||
}
|
||||
self::$phpNameMap = $nameMap;
|
||||
}
|
||||
return self::$phpNameMap;
|
||||
}
|
||||
/**
|
||||
* Translates a fieldname to another type
|
||||
*
|
||||
* @param string $name field name
|
||||
* @param string $fromType One of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @param string $toType One of the class type constants
|
||||
* @return string translated name of the field.
|
||||
*/
|
||||
static public function translateFieldName($name, $fromType, $toType)
|
||||
{
|
||||
$toNames = self::getFieldNames($toType);
|
||||
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
|
||||
if ($key === null) {
|
||||
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
|
||||
}
|
||||
return $toNames[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of of field names.
|
||||
*
|
||||
* @param string $type The type of fieldnames to return:
|
||||
* One of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @return array A list of field names
|
||||
*/
|
||||
|
||||
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
|
||||
{
|
||||
if (!array_key_exists($type, self::$fieldNames)) {
|
||||
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
|
||||
}
|
||||
return self::$fieldNames[$type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method which changes table.column to alias.column.
|
||||
*
|
||||
* Using this method you can maintain SQL abstraction while using column aliases.
|
||||
* <code>
|
||||
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
|
||||
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
|
||||
* </code>
|
||||
* @param string $alias The alias for the current table.
|
||||
* @param string $column The column name for current table. (i.e. ExportMd5HashPeer::COLUMN_NAME).
|
||||
* @return string
|
||||
*/
|
||||
public static function alias($alias, $column)
|
||||
{
|
||||
return str_replace(ExportMd5HashPeer::TABLE_NAME.'.', $alias.'.', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the columns needed to create a new object.
|
||||
*
|
||||
* Note: any columns that were marked with lazyLoad="true" in the
|
||||
* XML schema will not be added to the select list and only loaded
|
||||
* on demand.
|
||||
*
|
||||
* @param criteria object containing the columns to add.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function addSelectColumns(Criteria $criteria)
|
||||
{
|
||||
|
||||
$criteria->addSelectColumn(ExportMd5HashPeer::ID);
|
||||
|
||||
$criteria->addSelectColumn(ExportMd5HashPeer::TYPE_ID);
|
||||
|
||||
$criteria->addSelectColumn(ExportMd5HashPeer::MD5HASH);
|
||||
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('ExportMd5HashPeer.postAddSelectColumns')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ExportMd5HashPeer.postAddSelectColumns'));
|
||||
}
|
||||
}
|
||||
|
||||
const COUNT = 'COUNT(st_export_md5_hash.ID)';
|
||||
const COUNT_DISTINCT = 'COUNT(DISTINCT st_export_md5_hash.ID)';
|
||||
|
||||
/**
|
||||
* Returns the number of rows matching criteria.
|
||||
*
|
||||
* @param Criteria $criteria
|
||||
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
|
||||
* @param Connection $con
|
||||
* @return int Number of matching rows.
|
||||
*/
|
||||
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
|
||||
{
|
||||
// we're going to modify criteria, so copy it first
|
||||
$criteria = clone $criteria;
|
||||
|
||||
// clear out anything that might confuse the ORDER BY clause
|
||||
$criteria->clearSelectColumns()->clearOrderByColumns();
|
||||
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
|
||||
$criteria->addSelectColumn(ExportMd5HashPeer::COUNT_DISTINCT);
|
||||
} else {
|
||||
$criteria->addSelectColumn(ExportMd5HashPeer::COUNT);
|
||||
}
|
||||
|
||||
// just in case we're grouping: add those columns to the select statement
|
||||
foreach($criteria->getGroupByColumns() as $column)
|
||||
{
|
||||
$criteria->addSelectColumn($column);
|
||||
}
|
||||
|
||||
$rs = ExportMd5HashPeer::doSelectRS($criteria, $con);
|
||||
if ($rs->next()) {
|
||||
return $rs->getInt(1);
|
||||
} else {
|
||||
// no rows returned; we infer that means 0 matches.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Method to select one object from the DB.
|
||||
*
|
||||
* @param Criteria $criteria object used to create the SELECT statement.
|
||||
* @param Connection $con
|
||||
* @return ExportMd5Hash
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doSelectOne(Criteria $criteria, $con = null)
|
||||
{
|
||||
$critcopy = clone $criteria;
|
||||
$critcopy->setLimit(1);
|
||||
$objects = ExportMd5HashPeer::doSelect($critcopy, $con);
|
||||
if ($objects) {
|
||||
return $objects[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Method to do selects.
|
||||
*
|
||||
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
|
||||
* @param Connection $con
|
||||
* @return ExportMd5Hash[]
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doSelect(Criteria $criteria, $con = null)
|
||||
{
|
||||
return ExportMd5HashPeer::populateObjects(ExportMd5HashPeer::doSelectRS($criteria, $con));
|
||||
}
|
||||
/**
|
||||
* Prepares the Criteria object and uses the parent doSelect()
|
||||
* method to get a ResultSet.
|
||||
*
|
||||
* Use this method directly if you want to just get the resultset
|
||||
* (instead of an array of objects).
|
||||
*
|
||||
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
|
||||
* @param Connection $con the connection to use
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
* @return ResultSet The resultset object with numerically-indexed fields.
|
||||
* @see BasePeer::doSelect()
|
||||
*/
|
||||
public static function doSelectRS(Criteria $criteria, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if (!$criteria->getSelectColumns()) {
|
||||
$criteria = clone $criteria;
|
||||
ExportMd5HashPeer::addSelectColumns($criteria);
|
||||
}
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
|
||||
}
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
// BasePeer returns a Creole ResultSet, set to return
|
||||
// rows indexed numerically.
|
||||
$rs = BasePeer::doSelect($criteria, $con);
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
|
||||
}
|
||||
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* The returned array will contain objects of the default type or
|
||||
* objects that inherit from the default.
|
||||
*
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function populateObjects(ResultSet $rs)
|
||||
{
|
||||
|
||||
if (self::$hydrateMethod)
|
||||
{
|
||||
return call_user_func(self::$hydrateMethod, $rs);
|
||||
}
|
||||
$results = array();
|
||||
|
||||
// set the class once to avoid overhead in the loop
|
||||
$cls = ExportMd5HashPeer::getOMClass();
|
||||
$cls = Propel::import($cls);
|
||||
// populate the object(s)
|
||||
while($rs->next()) {
|
||||
|
||||
$obj = new $cls();
|
||||
$obj->hydrate($rs);
|
||||
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
|
||||
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
/**
|
||||
* Returns the TableMap related to this peer.
|
||||
* This method is not needed for general use but a specific application could have a need.
|
||||
* @return TableMap
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function getTableMap()
|
||||
{
|
||||
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* The class that the Peer will make instances of.
|
||||
*
|
||||
* This uses a dot-path notation which is tranalted into a path
|
||||
* relative to a location on the PHP include_path.
|
||||
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
|
||||
*
|
||||
* @return string path.to.ClassName
|
||||
*/
|
||||
public static function getOMClass()
|
||||
{
|
||||
return ExportMd5HashPeer::CLASS_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform an INSERT on the database, given a ExportMd5Hash or Criteria object.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportMd5Hash object containing data that is used to create the INSERT statement.
|
||||
* @param Connection $con the connection to use
|
||||
* @return mixed The new primary key.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doInsert($values, $con = null)
|
||||
{
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportMd5HashPeer:doInsert:pre') as $callable)
|
||||
{
|
||||
$ret = call_user_func($callable, 'BaseExportMd5HashPeer', $values, $con);
|
||||
if (false !== $ret)
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
} else {
|
||||
$criteria = $values->buildCriteria(); // build Criteria from ExportMd5Hash object
|
||||
}
|
||||
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table (I guess, conceivably)
|
||||
$con->begin();
|
||||
$pk = BasePeer::doInsert($criteria, $con);
|
||||
$con->commit();
|
||||
} catch(PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportMd5HashPeer:doInsert:post') as $callable)
|
||||
{
|
||||
call_user_func($callable, 'BaseExportMd5HashPeer', $values, $con, $pk);
|
||||
}
|
||||
|
||||
return $pk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform an UPDATE on the database, given a ExportMd5Hash or Criteria object.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportMd5Hash object containing data that is used to create the UPDATE statement.
|
||||
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
|
||||
* @return int The number of affected rows (if supported by underlying database driver).
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doUpdate($values, $con = null)
|
||||
{
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportMd5HashPeer:doUpdate:pre') as $callable)
|
||||
{
|
||||
$ret = call_user_func($callable, 'BaseExportMd5HashPeer', $values, $con);
|
||||
if (false !== $ret)
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
$selectCriteria = new Criteria(self::DATABASE_NAME);
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
|
||||
$comparison = $criteria->getComparison(ExportMd5HashPeer::ID);
|
||||
$selectCriteria->add(ExportMd5HashPeer::ID, $criteria->remove(ExportMd5HashPeer::ID), $comparison);
|
||||
|
||||
$comparison = $criteria->getComparison(ExportMd5HashPeer::TYPE_ID);
|
||||
$selectCriteria->add(ExportMd5HashPeer::TYPE_ID, $criteria->remove(ExportMd5HashPeer::TYPE_ID), $comparison);
|
||||
|
||||
} else { // $values is ExportMd5Hash object
|
||||
$criteria = $values->buildCriteria(); // gets full criteria
|
||||
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
|
||||
}
|
||||
|
||||
// set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
|
||||
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportMd5HashPeer:doUpdate:post') as $callable)
|
||||
{
|
||||
call_user_func($callable, 'BaseExportMd5HashPeer', $values, $con, $ret);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to DELETE all rows from the st_export_md5_hash table.
|
||||
*
|
||||
* @return int The number of affected rows (if supported by underlying database driver).
|
||||
*/
|
||||
public static function doDeleteAll($con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
$affectedRows = 0; // initialize var to track total num of affected rows
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table or we could emulating ON DELETE CASCADE, etc.
|
||||
$con->begin();
|
||||
$affectedRows += BasePeer::doDeleteAll(ExportMd5HashPeer::TABLE_NAME, $con);
|
||||
$con->commit();
|
||||
return $affectedRows;
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform a DELETE on the database, given a ExportMd5Hash or Criteria object OR a primary key value.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportMd5Hash object or primary key or array of primary keys
|
||||
* which is used to create the DELETE statement
|
||||
* @param Connection $con the connection to use
|
||||
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
|
||||
* if supported by native driver or if emulated using Propel.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doDelete($values, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(ExportMd5HashPeer::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
} elseif ($values instanceof ExportMd5Hash) {
|
||||
|
||||
$criteria = $values->buildPkeyCriteria();
|
||||
} else {
|
||||
// it must be the primary key
|
||||
$criteria = new Criteria(self::DATABASE_NAME);
|
||||
// primary key is composite; we therefore, expect
|
||||
// the primary key passed to be an array of pkey
|
||||
// values
|
||||
if(count($values) == count($values, COUNT_RECURSIVE))
|
||||
{
|
||||
// array is not multi-dimensional
|
||||
$values = array($values);
|
||||
}
|
||||
$vals = array();
|
||||
foreach($values as $value)
|
||||
{
|
||||
|
||||
$vals[0][] = $value[0];
|
||||
$vals[1][] = $value[1];
|
||||
}
|
||||
|
||||
$criteria->add(ExportMd5HashPeer::ID, $vals[0], Criteria::IN);
|
||||
$criteria->add(ExportMd5HashPeer::TYPE_ID, $vals[1], Criteria::IN);
|
||||
}
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
$affectedRows = 0; // initialize var to track total num of affected rows
|
||||
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table or we could emulating ON DELETE CASCADE, etc.
|
||||
$con->begin();
|
||||
|
||||
$affectedRows += BasePeer::doDelete($criteria, $con);
|
||||
$con->commit();
|
||||
return $affectedRows;
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates all modified columns of given ExportMd5Hash object.
|
||||
* If parameter $columns is either a single column name or an array of column names
|
||||
* than only those columns are validated.
|
||||
*
|
||||
* NOTICE: This does not apply to primary or foreign keys for now.
|
||||
*
|
||||
* @param ExportMd5Hash $obj The object to validate.
|
||||
* @param mixed $cols Column name or array of column names.
|
||||
*
|
||||
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
|
||||
*/
|
||||
public static function doValidate(ExportMd5Hash $obj, $cols = null)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
if ($cols) {
|
||||
$dbMap = Propel::getDatabaseMap(ExportMd5HashPeer::DATABASE_NAME);
|
||||
$tableMap = $dbMap->getTable(ExportMd5HashPeer::TABLE_NAME);
|
||||
|
||||
if (! is_array($cols)) {
|
||||
$cols = array($cols);
|
||||
}
|
||||
|
||||
foreach($cols as $colName) {
|
||||
if ($tableMap->containsColumn($colName)) {
|
||||
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
|
||||
$columns[$colName] = $obj->$get();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
$res = BasePeer::doValidate(ExportMd5HashPeer::DATABASE_NAME, ExportMd5HashPeer::TABLE_NAME, $columns);
|
||||
if ($res !== true) {
|
||||
$request = sfContext::getInstance()->getRequest();
|
||||
foreach ($res as $failed) {
|
||||
$col = ExportMd5HashPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
|
||||
$request->setError($col, $failed->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve object using using composite pkey values.
|
||||
* @param int $id
|
||||
@param int $type_id
|
||||
|
||||
* @param Connection $con
|
||||
* @return ExportMd5Hash
|
||||
*/
|
||||
public static function retrieveByPK( $id, $type_id, $con = null) {
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
$criteria = new Criteria();
|
||||
$criteria->add(ExportMd5HashPeer::ID, $id);
|
||||
$criteria->add(ExportMd5HashPeer::TYPE_ID, $type_id);
|
||||
$v = ExportMd5HashPeer::doSelect($criteria, $con);
|
||||
|
||||
return !empty($v) ? $v[0] : null;
|
||||
}
|
||||
} // BaseExportMd5HashPeer
|
||||
|
||||
// static code to register the map builder for this Peer with the main Propel class
|
||||
if (Propel::isInit()) {
|
||||
// the MapBuilder classes register themselves with Propel during initialization
|
||||
// so we need to load them here.
|
||||
try {
|
||||
BaseExportMd5HashPeer::getMapBuilder();
|
||||
} catch (Exception $e) {
|
||||
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
|
||||
}
|
||||
} else {
|
||||
// even if Propel is not yet initialized, the map builder class can be registered
|
||||
// now and then it will be loaded when Propel initializes.
|
||||
Propel::registerMapBuilder('plugins.stImportExportPlugin.lib.model.map.ExportMd5HashMapBuilder');
|
||||
}
|
||||
1046
plugins/stImportExportPlugin/lib/model/om/BaseExportProfile.php
Normal file
1046
plugins/stImportExportPlugin/lib/model/om/BaseExportProfile.php
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,659 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base static class for performing query and update operations on the 'st_export_profile' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @package plugins.stImportExportPlugin.lib.model.om
|
||||
*/
|
||||
abstract class BaseExportProfilePeer {
|
||||
|
||||
/** the default database name for this class */
|
||||
const DATABASE_NAME = 'propel';
|
||||
|
||||
/** the table name for this class */
|
||||
const TABLE_NAME = 'st_export_profile';
|
||||
|
||||
/** A class that can be returned by this peer. */
|
||||
const CLASS_DEFAULT = 'plugins.stImportExportPlugin.lib.model.ExportProfile';
|
||||
|
||||
/** The total number of columns. */
|
||||
const NUM_COLUMNS = 5;
|
||||
|
||||
/** The number of lazy-loaded columns. */
|
||||
const NUM_LAZY_LOAD_COLUMNS = 0;
|
||||
|
||||
|
||||
/** the column name for the CREATED_AT field */
|
||||
const CREATED_AT = 'st_export_profile.CREATED_AT';
|
||||
|
||||
/** the column name for the UPDATED_AT field */
|
||||
const UPDATED_AT = 'st_export_profile.UPDATED_AT';
|
||||
|
||||
/** the column name for the ID field */
|
||||
const ID = 'st_export_profile.ID';
|
||||
|
||||
/** the column name for the NAME field */
|
||||
const NAME = 'st_export_profile.NAME';
|
||||
|
||||
/** the column name for the MODEL field */
|
||||
const MODEL = 'st_export_profile.MODEL';
|
||||
|
||||
/** The PHP to DB Name Mapping */
|
||||
private static $phpNameMap = null;
|
||||
|
||||
|
||||
/**
|
||||
* holds an array of fieldnames
|
||||
*
|
||||
* first dimension keys are the type constants
|
||||
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
|
||||
*/
|
||||
private static $fieldNames = array (
|
||||
BasePeer::TYPE_PHPNAME => array ('CreatedAt', 'UpdatedAt', 'Id', 'Name', 'Model', ),
|
||||
BasePeer::TYPE_COLNAME => array (ExportProfilePeer::CREATED_AT, ExportProfilePeer::UPDATED_AT, ExportProfilePeer::ID, ExportProfilePeer::NAME, ExportProfilePeer::MODEL, ),
|
||||
BasePeer::TYPE_FIELDNAME => array ('created_at', 'updated_at', 'id', 'name', 'model', ),
|
||||
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
|
||||
);
|
||||
|
||||
/**
|
||||
* holds an array of keys for quick access to the fieldnames array
|
||||
*
|
||||
* first dimension keys are the type constants
|
||||
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
|
||||
*/
|
||||
private static $fieldKeys = array (
|
||||
BasePeer::TYPE_PHPNAME => array ('CreatedAt' => 0, 'UpdatedAt' => 1, 'Id' => 2, 'Name' => 3, 'Model' => 4, ),
|
||||
BasePeer::TYPE_COLNAME => array (ExportProfilePeer::CREATED_AT => 0, ExportProfilePeer::UPDATED_AT => 1, ExportProfilePeer::ID => 2, ExportProfilePeer::NAME => 3, ExportProfilePeer::MODEL => 4, ),
|
||||
BasePeer::TYPE_FIELDNAME => array ('created_at' => 0, 'updated_at' => 1, 'id' => 2, 'name' => 3, 'model' => 4, ),
|
||||
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
|
||||
);
|
||||
|
||||
protected static $hydrateMethod = null;
|
||||
|
||||
protected static $postHydrateMethod = null;
|
||||
|
||||
public static function setHydrateMethod($callback)
|
||||
{
|
||||
self::$hydrateMethod = $callback;
|
||||
}
|
||||
|
||||
public static function setPostHydrateMethod($callback)
|
||||
{
|
||||
self::$postHydrateMethod = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MapBuilder the map builder for this peer
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function getMapBuilder()
|
||||
{
|
||||
return BasePeer::getMapBuilder('plugins.stImportExportPlugin.lib.model.map.ExportProfileMapBuilder');
|
||||
}
|
||||
/**
|
||||
* Gets a map (hash) of PHP names to DB column names.
|
||||
*
|
||||
* @return array The PHP to DB name map for this peer
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
|
||||
*/
|
||||
public static function getPhpNameMap()
|
||||
{
|
||||
if (self::$phpNameMap === null) {
|
||||
$map = ExportProfilePeer::getTableMap();
|
||||
$columns = $map->getColumns();
|
||||
$nameMap = array();
|
||||
foreach ($columns as $column) {
|
||||
$nameMap[$column->getPhpName()] = $column->getColumnName();
|
||||
}
|
||||
self::$phpNameMap = $nameMap;
|
||||
}
|
||||
return self::$phpNameMap;
|
||||
}
|
||||
/**
|
||||
* Translates a fieldname to another type
|
||||
*
|
||||
* @param string $name field name
|
||||
* @param string $fromType One of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @param string $toType One of the class type constants
|
||||
* @return string translated name of the field.
|
||||
*/
|
||||
static public function translateFieldName($name, $fromType, $toType)
|
||||
{
|
||||
$toNames = self::getFieldNames($toType);
|
||||
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
|
||||
if ($key === null) {
|
||||
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
|
||||
}
|
||||
return $toNames[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of of field names.
|
||||
*
|
||||
* @param string $type The type of fieldnames to return:
|
||||
* One of the class type constants TYPE_PHPNAME,
|
||||
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
|
||||
* @return array A list of field names
|
||||
*/
|
||||
|
||||
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
|
||||
{
|
||||
if (!array_key_exists($type, self::$fieldNames)) {
|
||||
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
|
||||
}
|
||||
return self::$fieldNames[$type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method which changes table.column to alias.column.
|
||||
*
|
||||
* Using this method you can maintain SQL abstraction while using column aliases.
|
||||
* <code>
|
||||
* $c->addAlias("alias1", TablePeer::TABLE_NAME);
|
||||
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
|
||||
* </code>
|
||||
* @param string $alias The alias for the current table.
|
||||
* @param string $column The column name for current table. (i.e. ExportProfilePeer::COLUMN_NAME).
|
||||
* @return string
|
||||
*/
|
||||
public static function alias($alias, $column)
|
||||
{
|
||||
return str_replace(ExportProfilePeer::TABLE_NAME.'.', $alias.'.', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the columns needed to create a new object.
|
||||
*
|
||||
* Note: any columns that were marked with lazyLoad="true" in the
|
||||
* XML schema will not be added to the select list and only loaded
|
||||
* on demand.
|
||||
*
|
||||
* @param criteria object containing the columns to add.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function addSelectColumns(Criteria $criteria)
|
||||
{
|
||||
|
||||
$criteria->addSelectColumn(ExportProfilePeer::CREATED_AT);
|
||||
|
||||
$criteria->addSelectColumn(ExportProfilePeer::UPDATED_AT);
|
||||
|
||||
$criteria->addSelectColumn(ExportProfilePeer::ID);
|
||||
|
||||
$criteria->addSelectColumn(ExportProfilePeer::NAME);
|
||||
|
||||
$criteria->addSelectColumn(ExportProfilePeer::MODEL);
|
||||
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('ExportProfilePeer.postAddSelectColumns')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'ExportProfilePeer.postAddSelectColumns'));
|
||||
}
|
||||
}
|
||||
|
||||
const COUNT = 'COUNT(st_export_profile.ID)';
|
||||
const COUNT_DISTINCT = 'COUNT(DISTINCT st_export_profile.ID)';
|
||||
|
||||
/**
|
||||
* Returns the number of rows matching criteria.
|
||||
*
|
||||
* @param Criteria $criteria
|
||||
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
|
||||
* @param Connection $con
|
||||
* @return int Number of matching rows.
|
||||
*/
|
||||
public static function doCount(Criteria $criteria, $distinct = false, $con = null)
|
||||
{
|
||||
// we're going to modify criteria, so copy it first
|
||||
$criteria = clone $criteria;
|
||||
|
||||
// clear out anything that might confuse the ORDER BY clause
|
||||
$criteria->clearSelectColumns()->clearOrderByColumns();
|
||||
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
|
||||
$criteria->addSelectColumn(ExportProfilePeer::COUNT_DISTINCT);
|
||||
} else {
|
||||
$criteria->addSelectColumn(ExportProfilePeer::COUNT);
|
||||
}
|
||||
|
||||
// just in case we're grouping: add those columns to the select statement
|
||||
foreach($criteria->getGroupByColumns() as $column)
|
||||
{
|
||||
$criteria->addSelectColumn($column);
|
||||
}
|
||||
|
||||
$rs = ExportProfilePeer::doSelectRS($criteria, $con);
|
||||
if ($rs->next()) {
|
||||
return $rs->getInt(1);
|
||||
} else {
|
||||
// no rows returned; we infer that means 0 matches.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Method to select one object from the DB.
|
||||
*
|
||||
* @param Criteria $criteria object used to create the SELECT statement.
|
||||
* @param Connection $con
|
||||
* @return ExportProfile
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doSelectOne(Criteria $criteria, $con = null)
|
||||
{
|
||||
$critcopy = clone $criteria;
|
||||
$critcopy->setLimit(1);
|
||||
$objects = ExportProfilePeer::doSelect($critcopy, $con);
|
||||
if ($objects) {
|
||||
return $objects[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Method to do selects.
|
||||
*
|
||||
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
|
||||
* @param Connection $con
|
||||
* @return ExportProfile[]
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doSelect(Criteria $criteria, $con = null)
|
||||
{
|
||||
return ExportProfilePeer::populateObjects(ExportProfilePeer::doSelectRS($criteria, $con));
|
||||
}
|
||||
/**
|
||||
* Prepares the Criteria object and uses the parent doSelect()
|
||||
* method to get a ResultSet.
|
||||
*
|
||||
* Use this method directly if you want to just get the resultset
|
||||
* (instead of an array of objects).
|
||||
*
|
||||
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
|
||||
* @param Connection $con the connection to use
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
* @return ResultSet The resultset object with numerically-indexed fields.
|
||||
* @see BasePeer::doSelect()
|
||||
*/
|
||||
public static function doSelectRS(Criteria $criteria, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if (!$criteria->getSelectColumns()) {
|
||||
$criteria = clone $criteria;
|
||||
ExportProfilePeer::addSelectColumns($criteria);
|
||||
}
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('BasePeer.preDoSelectRs')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($criteria, 'BasePeer.preDoSelectRs'));
|
||||
}
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
// BasePeer returns a Creole ResultSet, set to return
|
||||
// rows indexed numerically.
|
||||
$rs = BasePeer::doSelect($criteria, $con);
|
||||
|
||||
if (stEventDispatcher::getInstance()->getListeners('BasePeer.postDoSelectRs')) {
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($rs, 'BasePeer.postDoSelectRs'));
|
||||
}
|
||||
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* The returned array will contain objects of the default type or
|
||||
* objects that inherit from the default.
|
||||
*
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function populateObjects(ResultSet $rs)
|
||||
{
|
||||
|
||||
if (self::$hydrateMethod)
|
||||
{
|
||||
return call_user_func(self::$hydrateMethod, $rs);
|
||||
}
|
||||
$results = array();
|
||||
|
||||
// set the class once to avoid overhead in the loop
|
||||
$cls = ExportProfilePeer::getOMClass();
|
||||
$cls = Propel::import($cls);
|
||||
// populate the object(s)
|
||||
while($rs->next()) {
|
||||
|
||||
$obj = new $cls();
|
||||
$obj->hydrate($rs);
|
||||
$results[] = self::$postHydrateMethod ? call_user_func(self::$postHydrateMethod, $obj) : $obj;
|
||||
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
/**
|
||||
* Returns the TableMap related to this peer.
|
||||
* This method is not needed for general use but a specific application could have a need.
|
||||
* @return TableMap
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function getTableMap()
|
||||
{
|
||||
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* The class that the Peer will make instances of.
|
||||
*
|
||||
* This uses a dot-path notation which is tranalted into a path
|
||||
* relative to a location on the PHP include_path.
|
||||
* (e.g. path.to.MyClass -> 'path/to/MyClass.php')
|
||||
*
|
||||
* @return string path.to.ClassName
|
||||
*/
|
||||
public static function getOMClass()
|
||||
{
|
||||
return ExportProfilePeer::CLASS_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform an INSERT on the database, given a ExportProfile or Criteria object.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportProfile object containing data that is used to create the INSERT statement.
|
||||
* @param Connection $con the connection to use
|
||||
* @return mixed The new primary key.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doInsert($values, $con = null)
|
||||
{
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportProfilePeer:doInsert:pre') as $callable)
|
||||
{
|
||||
$ret = call_user_func($callable, 'BaseExportProfilePeer', $values, $con);
|
||||
if (false !== $ret)
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
} else {
|
||||
$criteria = $values->buildCriteria(); // build Criteria from ExportProfile object
|
||||
}
|
||||
|
||||
$criteria->remove(ExportProfilePeer::ID); // remove pkey col since this table uses auto-increment
|
||||
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table (I guess, conceivably)
|
||||
$con->begin();
|
||||
$pk = BasePeer::doInsert($criteria, $con);
|
||||
$con->commit();
|
||||
} catch(PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportProfilePeer:doInsert:post') as $callable)
|
||||
{
|
||||
call_user_func($callable, 'BaseExportProfilePeer', $values, $con, $pk);
|
||||
}
|
||||
|
||||
return $pk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform an UPDATE on the database, given a ExportProfile or Criteria object.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportProfile object containing data that is used to create the UPDATE statement.
|
||||
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
|
||||
* @return int The number of affected rows (if supported by underlying database driver).
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doUpdate($values, $con = null)
|
||||
{
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportProfilePeer:doUpdate:pre') as $callable)
|
||||
{
|
||||
$ret = call_user_func($callable, 'BaseExportProfilePeer', $values, $con);
|
||||
if (false !== $ret)
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
$selectCriteria = new Criteria(self::DATABASE_NAME);
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
|
||||
$comparison = $criteria->getComparison(ExportProfilePeer::ID);
|
||||
$selectCriteria->add(ExportProfilePeer::ID, $criteria->remove(ExportProfilePeer::ID), $comparison);
|
||||
|
||||
} else { // $values is ExportProfile object
|
||||
$criteria = $values->buildCriteria(); // gets full criteria
|
||||
$selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
|
||||
}
|
||||
|
||||
// set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
$ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
|
||||
|
||||
|
||||
foreach (sfMixer::getCallables('BaseExportProfilePeer:doUpdate:post') as $callable)
|
||||
{
|
||||
call_user_func($callable, 'BaseExportProfilePeer', $values, $con, $ret);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to DELETE all rows from the st_export_profile table.
|
||||
*
|
||||
* @return int The number of affected rows (if supported by underlying database driver).
|
||||
*/
|
||||
public static function doDeleteAll($con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
$affectedRows = 0; // initialize var to track total num of affected rows
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table or we could emulating ON DELETE CASCADE, etc.
|
||||
$con->begin();
|
||||
$affectedRows += BasePeer::doDeleteAll(ExportProfilePeer::TABLE_NAME, $con);
|
||||
$con->commit();
|
||||
return $affectedRows;
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method perform a DELETE on the database, given a ExportProfile or Criteria object OR a primary key value.
|
||||
*
|
||||
* @param mixed $values Criteria or ExportProfile object or primary key or array of primary keys
|
||||
* which is used to create the DELETE statement
|
||||
* @param Connection $con the connection to use
|
||||
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
|
||||
* if supported by native driver or if emulated using Propel.
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
*/
|
||||
public static function doDelete($values, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(ExportProfilePeer::DATABASE_NAME);
|
||||
}
|
||||
|
||||
if ($values instanceof Criteria) {
|
||||
$criteria = clone $values; // rename for clarity
|
||||
} elseif ($values instanceof ExportProfile) {
|
||||
|
||||
$criteria = $values->buildPkeyCriteria();
|
||||
} else {
|
||||
// it must be the primary key
|
||||
$criteria = new Criteria(self::DATABASE_NAME);
|
||||
$criteria->add(ExportProfilePeer::ID, (array) $values, Criteria::IN);
|
||||
}
|
||||
|
||||
// Set the correct dbName
|
||||
$criteria->setDbName(self::DATABASE_NAME);
|
||||
|
||||
$affectedRows = 0; // initialize var to track total num of affected rows
|
||||
|
||||
try {
|
||||
// use transaction because $criteria could contain info
|
||||
// for more than one table or we could emulating ON DELETE CASCADE, etc.
|
||||
$con->begin();
|
||||
|
||||
$affectedRows += BasePeer::doDelete($criteria, $con);
|
||||
$con->commit();
|
||||
return $affectedRows;
|
||||
} catch (PropelException $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates all modified columns of given ExportProfile object.
|
||||
* If parameter $columns is either a single column name or an array of column names
|
||||
* than only those columns are validated.
|
||||
*
|
||||
* NOTICE: This does not apply to primary or foreign keys for now.
|
||||
*
|
||||
* @param ExportProfile $obj The object to validate.
|
||||
* @param mixed $cols Column name or array of column names.
|
||||
*
|
||||
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
|
||||
*/
|
||||
public static function doValidate(ExportProfile $obj, $cols = null)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
if ($cols) {
|
||||
$dbMap = Propel::getDatabaseMap(ExportProfilePeer::DATABASE_NAME);
|
||||
$tableMap = $dbMap->getTable(ExportProfilePeer::TABLE_NAME);
|
||||
|
||||
if (! is_array($cols)) {
|
||||
$cols = array($cols);
|
||||
}
|
||||
|
||||
foreach($cols as $colName) {
|
||||
if ($tableMap->containsColumn($colName)) {
|
||||
$get = 'get' . $tableMap->getColumn($colName)->getPhpName();
|
||||
$columns[$colName] = $obj->$get();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
$res = BasePeer::doValidate(ExportProfilePeer::DATABASE_NAME, ExportProfilePeer::TABLE_NAME, $columns);
|
||||
if ($res !== true) {
|
||||
$request = sfContext::getInstance()->getRequest();
|
||||
foreach ($res as $failed) {
|
||||
$col = ExportProfilePeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
|
||||
$request->setError($col, $failed->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single object by pkey.
|
||||
*
|
||||
* @param mixed $pk the primary key.
|
||||
* @param Connection $con the connection to use
|
||||
* @return ExportProfile
|
||||
*/
|
||||
public static function retrieveByPK($pk, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
$criteria = new Criteria(ExportProfilePeer::DATABASE_NAME);
|
||||
|
||||
$criteria->add(ExportProfilePeer::ID, $pk);
|
||||
|
||||
|
||||
$v = ExportProfilePeer::doSelect($criteria, $con);
|
||||
|
||||
return !empty($v) > 0 ? $v[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve multiple objects by pkey.
|
||||
*
|
||||
* @param array $pks List of primary keys
|
||||
* @param Connection $con the connection to use
|
||||
* @throws PropelException Any exceptions caught during processing will be
|
||||
* rethrown wrapped into a PropelException.
|
||||
* @return ExportProfile[]
|
||||
*/
|
||||
public static function retrieveByPKs($pks, $con = null)
|
||||
{
|
||||
if ($con === null) {
|
||||
$con = Propel::getConnection(self::DATABASE_NAME);
|
||||
}
|
||||
|
||||
$objs = null;
|
||||
if (empty($pks)) {
|
||||
$objs = array();
|
||||
} else {
|
||||
$criteria = new Criteria();
|
||||
$criteria->add(ExportProfilePeer::ID, $pks, Criteria::IN);
|
||||
$objs = ExportProfilePeer::doSelect($criteria, $con);
|
||||
}
|
||||
return $objs;
|
||||
}
|
||||
|
||||
} // BaseExportProfilePeer
|
||||
|
||||
// static code to register the map builder for this Peer with the main Propel class
|
||||
if (Propel::isInit()) {
|
||||
// the MapBuilder classes register themselves with Propel during initialization
|
||||
// so we need to load them here.
|
||||
try {
|
||||
BaseExportProfilePeer::getMapBuilder();
|
||||
} catch (Exception $e) {
|
||||
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
|
||||
}
|
||||
} else {
|
||||
// even if Propel is not yet initialized, the map builder class can be registered
|
||||
// now and then it will be loaded when Propel initializes.
|
||||
Propel::registerMapBuilder('plugins.stImportExportPlugin.lib.model.map.ExportProfileMapBuilder');
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stImportExportListener.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
*/
|
||||
|
||||
class stImportExportListener {
|
||||
public static function StImportExportGenerate(sfEvent $event) {
|
||||
$event->getSubject()->attachAdminGeneratorFile('stImportExportPlugin', 'importExport.yml');
|
||||
$event->getSubject()->attachAdminGeneratorFile('stImportExportPlugin', 'productCustomData.yml');
|
||||
}
|
||||
}
|
||||
89
plugins/stImportExportPlugin/lib/stImportExportLog.class.php
Normal file
89
plugins/stImportExportPlugin/lib/stImportExportLog.class.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
class stImportExportLog {
|
||||
|
||||
public static $FATAL = 1;
|
||||
public static $WARNING = 2;
|
||||
public static $NOTICE = 3;
|
||||
|
||||
protected $handle = null;
|
||||
|
||||
protected $filename = '';
|
||||
|
||||
protected static $instance = null;
|
||||
|
||||
protected $current_key = '';
|
||||
|
||||
public function __construct($filename) {
|
||||
$this->filename =$filename ;
|
||||
self::$instance = $this;
|
||||
}
|
||||
|
||||
public static function clearLogs($prefix = '*')
|
||||
{
|
||||
$finder = sfFinder::type('file');
|
||||
$importFiles = $finder->name($prefix.'_*.log')->in(sfConfig::get('sf_log_dir')) ;
|
||||
|
||||
foreach ($importFiles as $file)
|
||||
{
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->handle)
|
||||
fclose($this->handle);
|
||||
}
|
||||
|
||||
public function add($key, $msg, $type = 3)
|
||||
{
|
||||
if (empty($key)) $key = $this->getCurrentKey();
|
||||
if ($this->handle == null) {
|
||||
$this->handle = fopen($this->filename, 'a');
|
||||
}
|
||||
if (!empty($msg))
|
||||
{
|
||||
fputcsv($this->handle, array($key, $msg, $type), ';', '"');
|
||||
}
|
||||
}
|
||||
|
||||
public function getLog()
|
||||
{
|
||||
if (file_exists($this->filename)) {
|
||||
|
||||
$handle = fopen($this->filename, 'r');
|
||||
$log = array();
|
||||
while (($log[] = fgetcsv($handle, null, ';', '"')) !== FALSE);
|
||||
return $log;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function hasLog()
|
||||
{
|
||||
if (file_exists($this->filename)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
public static function getActiveLogger()
|
||||
{
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function getCurrentKey()
|
||||
{
|
||||
return $this->current_key;
|
||||
}
|
||||
|
||||
public function setCurrentKey($key)
|
||||
{
|
||||
$this->current_key = $key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
class stImportExportProductCustomData {
|
||||
|
||||
public static function getWholesaleA(Product $object) {
|
||||
return stImportExportProductCustomData::getPriceFor($object->getId(),'A');
|
||||
}
|
||||
|
||||
public static function getWholesaleB(Product $object) {
|
||||
return stImportExportProductCustomData::getPriceFor($object->getId(),'B');
|
||||
}
|
||||
|
||||
public static function getWholesaleC(Product $object) {
|
||||
return stImportExportProductCustomData::getPriceFor($object->getId(),'C');
|
||||
}
|
||||
|
||||
protected static function getPriceFor($product_id, $whole_sale = 'A'){
|
||||
$c = new Criteria();
|
||||
$c->add(ProductHasWholesalePeer::PRODUCT_ID,$product_id);
|
||||
|
||||
$item = ProductHasWholesalePeer::doSelectOne($c);
|
||||
if (is_object($item)) {
|
||||
$func = 'getPrice'.$whole_sale;
|
||||
return $item->$func();
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public static function setWholesaleA(Product $object, $value) {
|
||||
return stImportExportProductCustomData::setPriceFor($object->getId(),'A',$value, $object->getVat());
|
||||
}
|
||||
|
||||
public static function setWholesaleB(Product $object, $value) {
|
||||
return stImportExportProductCustomData::setPriceFor($object->getId(),'B',$value, $object->getVat());
|
||||
}
|
||||
|
||||
public static function setWholesaleC(Product $object, $value) {
|
||||
return stImportExportProductCustomData::setPriceFor($object->getId(),'C',$value, $object->getVat());
|
||||
}
|
||||
|
||||
protected static function setPriceFor($product_id, $whole_sale = 'A', $price = 0.0, $vat){
|
||||
$c = new Criteria();
|
||||
$c->add(ProductHasWholesalePeer::PRODUCT_ID,$product_id);
|
||||
|
||||
$item = ProductHasWholesalePeer::doSelectOne($c);
|
||||
|
||||
if (!is_object($item)) {
|
||||
$item = new ProductHasWholesale();
|
||||
$item->setProductId($product_id);
|
||||
}
|
||||
|
||||
$func = 'setPriceBrutto'.$whole_sale.'ByNetto';
|
||||
$item->$func($price, $vat);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
|
||||
public static function getPositioningTitle(Product $object) {
|
||||
$item = stImportExportProductCustomData::getPositioning($object->getId());
|
||||
|
||||
if (is_object($item)) {
|
||||
return $item->getTitle();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function getPositioningKeywords(Product $object) {
|
||||
$item = stImportExportProductCustomData::getPositioning($object->getId());
|
||||
|
||||
if (is_object($item)) {
|
||||
return $item->getKeywords();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function getPositioningDesc(Product $object) {
|
||||
$item = stImportExportProductCustomData::getPositioning($object->getId());
|
||||
|
||||
if (is_object($item)) {
|
||||
return $item->getDescription();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function setPositioningTitle(Product $object, $value) {
|
||||
$item = stImportExportProductCustomData::getPositioning($object->getId());
|
||||
|
||||
if (!is_object($item)) {
|
||||
$item = new ProductHasPositioning();
|
||||
$item->setProductId($object->getId());
|
||||
}
|
||||
$item->setCulture($object->getCulture());
|
||||
$item->setTitle($value);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
public static function setPositioningKeywords(Product $object, $value) {
|
||||
$item = stImportExportProductCustomData::getPositioning($object->getId());
|
||||
|
||||
if (!is_object($item)) {
|
||||
$item = new ProductHasPositioning();
|
||||
$item->setProductId($object->getId());
|
||||
}
|
||||
$item->setCulture($object->getCulture());
|
||||
$item->setKeywords($value);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
public static function setPositioningDesc(Product $object, $value) {
|
||||
$item = stImportExportProductCustomData::getPositioning($object->getId());
|
||||
|
||||
if (!is_object($item)) {
|
||||
$item = new ProductHasPositioning();
|
||||
$item->setProductId($object->getId());
|
||||
}
|
||||
$item->setCulture($object->getCulture());
|
||||
$item->setDescription($value);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
|
||||
protected static function getPositioning($product_id) {
|
||||
$c = new Criteria();
|
||||
$c->add(ProductHasPositioningPeer::PRODUCT_ID,$product_id);
|
||||
|
||||
return ProductHasPositioningPeer::doSelectOne($c);
|
||||
}
|
||||
|
||||
}
|
||||
512
plugins/stImportExportPlugin/lib/stImportExportPropel.class.php
Normal file
512
plugins/stImportExportPlugin/lib/stImportExportPropel.class.php
Normal file
@@ -0,0 +1,512 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stImportExportPropel.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
* @author Piotr Halas <piotr.halas@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Klasa modulu generator odpowiedzalna za eksport/import danych
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stImportExportPropel
|
||||
{
|
||||
|
||||
public $import;
|
||||
|
||||
public $export;
|
||||
/**
|
||||
* Nazwa metody, przyjmuje wartosci exsport lub import
|
||||
* @protected string
|
||||
*/
|
||||
public $method = '';
|
||||
|
||||
/**
|
||||
* Glowny model importu/eksportu
|
||||
* @protected string
|
||||
*/
|
||||
public $model = '';
|
||||
|
||||
/**
|
||||
* Nazwa klasy eksportera
|
||||
* @protected string
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
public $class_name = '';
|
||||
|
||||
/**
|
||||
* Wskaznik do obiektu eksportera importera
|
||||
* @protected object
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
public $class_handle = null;
|
||||
|
||||
/**
|
||||
* Wskaznik do obiektu kontrolera
|
||||
* @protected object
|
||||
*/
|
||||
public $controller = null;
|
||||
|
||||
/**
|
||||
* Wskaznik do obiektu Context
|
||||
* @protected object
|
||||
*/
|
||||
public $context = null;
|
||||
|
||||
/**
|
||||
* Zmienna zawiera konfiguracje pol do eksportu
|
||||
* @protected string
|
||||
*/
|
||||
public $fields = array();
|
||||
|
||||
/**
|
||||
* Profile id
|
||||
* @protected integer
|
||||
*/
|
||||
public $profile = 0;
|
||||
|
||||
/**
|
||||
* nazwa pliku tymczasowego
|
||||
* @protected string
|
||||
*/
|
||||
public $filepath = null;
|
||||
|
||||
public $export_limit = 20;
|
||||
|
||||
public $import_limit = 5;
|
||||
|
||||
public $auto_detect_line_endings = '';
|
||||
|
||||
/**
|
||||
* Konstruktor klasy, parametr method przyjmuje wartosc 'export' lub 'import'
|
||||
* class zawiera nazwe klasy eksportera
|
||||
* file - nazwe pliku tymczasowego w przypadku importu
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $class
|
||||
* @param string $file
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
public function __construct($method, $class, $filepath, $profile = null)
|
||||
{
|
||||
$this->auto_detect_line_endings = ini_get('auto_detect_line_endings');
|
||||
ini_set('auto_detect_line_endings', true);
|
||||
|
||||
// pobiera instancje clasy contekst oraz cotroller
|
||||
$this->context = sfContext::getInstance();
|
||||
$this->controller = $this->context->getController();
|
||||
|
||||
// zapamietuje podane parametry
|
||||
$this->method = $method;
|
||||
$this->class_name = $class;
|
||||
$this->filepath = $filepath;
|
||||
$this->profile = $profile;
|
||||
|
||||
// odczytuje i ustawia pola wykorzystywane w imporcie eksporcie
|
||||
$this->setFields();
|
||||
|
||||
//tworzy klase importera lub eksportera
|
||||
$this->setImporterExporter();
|
||||
}
|
||||
|
||||
public function setI18nCatalogue($i18nCatalogue)
|
||||
{
|
||||
$this->class_handle->setI18nCatalogue($i18nCatalogue);
|
||||
}
|
||||
|
||||
public function getFilePath()
|
||||
{
|
||||
return $this->filepath;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
ini_set('auto_detect_line_endings',$this->auto_detect_line_endings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera pola do eksportu z konfiguracji
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExportFields()
|
||||
{
|
||||
return $this->export['fields'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera pola do importu z konfiguracji
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImportFields()
|
||||
{
|
||||
return $this->import['fields'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ustawia odpowiednie pola do importu/eksportu
|
||||
*/
|
||||
protected function setFields()
|
||||
{
|
||||
|
||||
// w zaleznosci od metody ustaw odpowiednie pola
|
||||
switch ($this->method)
|
||||
{
|
||||
case "export":
|
||||
$this->fields['primary_key'] = $this->export['primary_key'];
|
||||
$this->fields['fields'] = $this->getExportFields();
|
||||
break;
|
||||
case "import":
|
||||
$this->fields['primary_key'] = $this->import['primary_key'];
|
||||
$this->fields['default_class'] = isset($this->import['default_class']) ? $this->import['default_class'] : null;
|
||||
$this->fields['fields'] = $this->getImportFields();
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->profile != 0)
|
||||
{
|
||||
$profile = ExportProfilePeer::retrieveByPk($this->profile);
|
||||
if (is_object($profile))
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->add(ExportFieldPeer::FIELD, array_keys($this->fields['fields']), Criteria::IN);
|
||||
$c->addJoin(ExportFieldPeer::ID,ExportProfileHasExportFieldPeer::EXPORT_FIELD_ID);
|
||||
$c->add(ExportProfileHasExportFieldPeer::EXPORT_PROFILE_ID, $profile->getId());
|
||||
$c->addAscendingOrderByColumn(ExportProfileHasExportFieldPeer::POSITION);
|
||||
|
||||
$fields = array();
|
||||
$primaryKeys = is_array($this->import['primary_key']) ? $this->import['primary_key'] : array($this->import['primary_key']);
|
||||
|
||||
foreach($primaryKeys as $primaryKey)
|
||||
{
|
||||
$fields[$primaryKey] = $this->fields['fields'][$primaryKey];
|
||||
}
|
||||
|
||||
foreach (ExportFieldPeer::doSelect($c) as $activeFields)
|
||||
{
|
||||
$fields[$activeFields->getField()] = $this->fields['fields'][$activeFields->getField()];
|
||||
}
|
||||
|
||||
//add primary key
|
||||
$this->fields['fields'] = $fields;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy obiekt importera eksportera
|
||||
*/
|
||||
protected function setImporterExporter()
|
||||
{
|
||||
if (!class_exists($this->class_name))
|
||||
{
|
||||
throw new Exception("");
|
||||
}
|
||||
|
||||
$this->fields['class'] = get_class($this);
|
||||
|
||||
if (!isset($this->fields['default_class']))
|
||||
{
|
||||
$this->fields['default_class'] = $this->fields['class'];
|
||||
}
|
||||
|
||||
$this->class_handle = new $this->class_name($this->model, $this->fields, $this->filepath);
|
||||
$this->setLimits();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca klase obsługującą import/export
|
||||
*
|
||||
* @return stPropelImportExportInterface
|
||||
*/
|
||||
public function getImporterExporter()
|
||||
{
|
||||
return $this->class_handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wykonuje methodye doProcess importera/eksportera, jako parametr przyjmyje
|
||||
* numer kroku do wykonan, zwraca numer kolejnego kroku
|
||||
*
|
||||
* @param integer $offset
|
||||
* @return integer
|
||||
*/
|
||||
public function doProcess($offset = 0)
|
||||
{
|
||||
$offset = $this->class_handle->doProcess($offset);
|
||||
return $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca liczbe krokow do wykonania
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getDataCount()
|
||||
{
|
||||
return $this->class_handle->getDataCount();
|
||||
}
|
||||
|
||||
public function setCustomParameters(array $parameters)
|
||||
{
|
||||
$this->class_handle->setCustomParameters($parameters);
|
||||
}
|
||||
|
||||
public function validateFile(array &$errors = null)
|
||||
{
|
||||
return $this->class_handle->validateFile($errors);
|
||||
}
|
||||
|
||||
public function sampleFile()
|
||||
{
|
||||
return $this->class_handle->sampleFile($this->getSampleRow());
|
||||
}
|
||||
|
||||
public function setLimits()
|
||||
{
|
||||
// w zaleznosci od metody ustaw odpowiednie pola
|
||||
|
||||
if ($this->class_handle)
|
||||
{
|
||||
switch ($this->method)
|
||||
{
|
||||
case "export":
|
||||
$this->class_handle->setLimit($this->export_limit);
|
||||
break;
|
||||
case "import":
|
||||
$this->class_handle->setLimit($this->import_limit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getSampleRow()
|
||||
{
|
||||
|
||||
$tmp =array();
|
||||
foreach ($this->fields['fields'] as $key => $field)
|
||||
{
|
||||
if (isset($field['sample']))
|
||||
{
|
||||
$tmp[$key] = $field['sample'];
|
||||
} else
|
||||
{
|
||||
$tmp[$key] = '';
|
||||
}
|
||||
}
|
||||
return array($tmp);
|
||||
}
|
||||
|
||||
public static function fileCleanup()
|
||||
{
|
||||
$current = time();
|
||||
|
||||
$oneHour = 3600;
|
||||
|
||||
foreach (glob(sfConfig::get('sf_data_dir').'/export/*.tmp') as $file)
|
||||
{
|
||||
if ($current - filemtime($file) > $oneHour * 6)
|
||||
{
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (glob(sfConfig::get('sf_data_dir').'/import/*.tmp') as $file)
|
||||
{
|
||||
if ($current - filemtime($file) > $oneHour * 6)
|
||||
{
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getProfiles($module, $model)
|
||||
{
|
||||
$profiles = array(sfContext::getInstance()->getI18n()->__('Profil domyślny', array(), 'stImportExportBackend'));
|
||||
|
||||
$c = new Criteria();
|
||||
$c->add(ExportProfilePeer::MODEL, self::getProfileModuleScope($module, $model));
|
||||
$c->addAscendingOrderByColumn(ExportProfilePeer::NAME);
|
||||
|
||||
foreach (ExportProfilePeer::doSelect($c) as $profile)
|
||||
{
|
||||
$profiles[$profile->getId()] = sfContext::getInstance()->getI18n()->__($profile->getName(), array(), 'stImportExportBackend');
|
||||
}
|
||||
|
||||
return $profiles;
|
||||
}
|
||||
|
||||
public static function getProfileModuleScope($module, $model)
|
||||
{
|
||||
return $module != 'stProduct' ? $module.'::'.$model : $model;
|
||||
}
|
||||
|
||||
public static function updateExportProfiles($model = '', $fields = array(), $primary_key)
|
||||
{
|
||||
$primaryKeys = is_array($primary_key) ? $primary_key : array($primary_key);
|
||||
|
||||
if (is_array($fields) && count($fields))
|
||||
{
|
||||
//inserting new
|
||||
$c = new Criteria();
|
||||
$c->add(ExportFieldPeer::MODEL, $model);
|
||||
|
||||
foreach (ExportFieldPeer::doSelect($c) as $field)
|
||||
{
|
||||
$name = $field->getField();
|
||||
|
||||
if (!isset($fields[$name]))
|
||||
{
|
||||
$field->delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
$field->setName($fields[$name]['name']);
|
||||
|
||||
if (isset($fields[$name]['i18n']))
|
||||
{
|
||||
$field->setI18nFile($fields[$name]['i18n']);
|
||||
}
|
||||
elseif (isset($fields[$name]['i18n_file']))
|
||||
{
|
||||
$field->setI18nFile($fields[$name]['i18n_file']);
|
||||
}
|
||||
|
||||
$field->save();
|
||||
|
||||
unset($fields[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
// throw new Exception("Error Processing Request", 1);
|
||||
|
||||
|
||||
foreach ($fields as $name => $params)
|
||||
{
|
||||
$field = new ExportField();
|
||||
$field->setModel($model);
|
||||
$field->setField($name);
|
||||
$field->setIsKey(in_array($name, $primaryKeys));
|
||||
$field->setName($params['name']);
|
||||
|
||||
if (isset($params['i18n_file']))
|
||||
{
|
||||
$field->setI18nFile($params['i18n_file']);
|
||||
}
|
||||
elseif (isset($params['i18n']))
|
||||
{
|
||||
$field->setI18nFile($params['i18n']);
|
||||
}
|
||||
|
||||
$field->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getFileContents($url, $filename = null)
|
||||
{
|
||||
if (null === $filename)
|
||||
{
|
||||
$filename = basename(rawurldecode($url));
|
||||
$filename = sfConfig::get('sf_upload_dir') . '/assets/' .uniqid() . '-' . sfAssetsLibraryTools::sanitizeName($filename);
|
||||
}
|
||||
|
||||
$fp = fopen($filename, 'w+');
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
fclose($fp);
|
||||
|
||||
if (!$result || $httpCode != 200)
|
||||
{
|
||||
$statuslist = array(
|
||||
'100' => 'Continue',
|
||||
'101' => 'Switching Protocols',
|
||||
'200' => 'OK',
|
||||
'201' => 'Created',
|
||||
'202' => 'Accepted',
|
||||
'203' => 'Non-Authoritative Information',
|
||||
'204' => 'No Content',
|
||||
'205' => 'Reset Content',
|
||||
'206' => 'Partial Content',
|
||||
'300' => 'Multiple Choices',
|
||||
'302' => 'Found',
|
||||
'303' => 'See Other',
|
||||
'304' => 'Not Modified',
|
||||
'305' => 'Use Proxy',
|
||||
'400' => 'Bad Request',
|
||||
'401' => 'Unauthorized',
|
||||
'402' => 'Payment Required',
|
||||
'403' => 'Forbidden',
|
||||
'404' => 'Not Found',
|
||||
'405' => 'Method Not Allowed',
|
||||
'406' => 'Not Acceptable',
|
||||
'407' => 'Proxy Authentication Required',
|
||||
'408' => 'Request Timeout',
|
||||
'409' => 'Conflict',
|
||||
'410' => 'Gone',
|
||||
'411' => 'Length Required',
|
||||
'412' => 'Precondition Failed',
|
||||
'413' => 'Request Entity Too Large',
|
||||
'414' => 'Request-URI Too Long',
|
||||
'415' => 'Unsupported Media Type',
|
||||
'416' => 'Requested Range Not Satisfiable',
|
||||
'417' => 'Expectation Failed',
|
||||
'500' => 'Internal Server Error',
|
||||
'501' => 'Not Implemented',
|
||||
'502' => 'Bad Gateway',
|
||||
'503' => 'Service Unavailable',
|
||||
'504' => 'Gateway Timeout',
|
||||
'505' => 'HTTP Version Not Supported'
|
||||
);
|
||||
|
||||
if ($httpCode != 200)
|
||||
{
|
||||
$error = isset($statuslist[$httpCode]) ? $httpCode . ' ' . $statuslist[$httpCode] : $httpCode;
|
||||
}
|
||||
|
||||
if (is_file($filename))
|
||||
{
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
}
|
||||
516
plugins/stImportExportPlugin/lib/stPropelExporter.class.php
Normal file
516
plugins/stImportExportPlugin/lib/stPropelExporter.class.php
Normal file
@@ -0,0 +1,516 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stPropelExporter.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
* @author Piotr Halas <piotr.halas@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Definicje bledow
|
||||
*/
|
||||
define( "EXPORT_NO_CONFIG", "Plik konfiguracyjny exportu nie istnieje." );
|
||||
|
||||
/**
|
||||
* Klasa obslugi eksportu danych
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stPropelExporter implements stPropelImportExportInterface
|
||||
{
|
||||
|
||||
const FIELD_EXCEEDS_32K_MSG = 'Pole <b>%field%</b> posiada więcej niż 32 000 znaków.';
|
||||
const FIELD_INCORRECT_ENCODING = 'Pole <b>%field%</b> zawiera znaki z poza zakresu kodowania <b>%encoding%</b>.';
|
||||
const FIELD_NA_REPLAGE_MSG = 'Eksport pola zostaje pominięty i jego wartość zostaje zastąpiona w pliku eksportu przez <b>[N/A]</b>. Proszę nie edytować zawartości kolumn z wartością <b>[N/A]</b>, w innym wypadku (przy ponownym imporcie) wartość tego pola zostanie nadpisana.';
|
||||
|
||||
/**
|
||||
* Naglowe pliku
|
||||
* @var string
|
||||
*/
|
||||
var $header = '';
|
||||
|
||||
/**
|
||||
* stopka pliku
|
||||
* @var string
|
||||
*/
|
||||
var $footer = '';
|
||||
|
||||
/**
|
||||
* nazwa modelu
|
||||
* @var string
|
||||
*/
|
||||
var $model = '';
|
||||
|
||||
/**
|
||||
* Unikatowa
|
||||
* @var string
|
||||
*/
|
||||
var $converter = '';
|
||||
|
||||
/**
|
||||
* Konfiguracja modulu
|
||||
* @var array()
|
||||
*/
|
||||
var $config = array();
|
||||
|
||||
/**
|
||||
* nazwa pliku eksprotu
|
||||
* @var string
|
||||
*/
|
||||
var $output_file_extension = '';
|
||||
|
||||
/**
|
||||
* Limit jednoczesnie eksportowanych elementow
|
||||
* @var integer
|
||||
*/
|
||||
var $limit = 20;
|
||||
|
||||
var $hard_limit = null;
|
||||
|
||||
protected $filepath = null;
|
||||
|
||||
/**
|
||||
* Uchwyt pliku
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $fh = null;
|
||||
|
||||
protected $md5hash = array();
|
||||
|
||||
protected $logger = null;
|
||||
|
||||
protected $customParameters = array();
|
||||
|
||||
protected $i18nCatalogue = null;
|
||||
|
||||
/**
|
||||
* konstruktor klasy, nalezy podac nazwe modelu oraz tablice
|
||||
* eksportowanych pol
|
||||
*
|
||||
* @param string $model
|
||||
* @param array $fields
|
||||
*/
|
||||
public function __construct($model = '', $fields = array(), $filepath = null)
|
||||
{
|
||||
$dir = sfConfig::get('sf_data_dir').'/export';
|
||||
|
||||
if (!is_dir($dir))
|
||||
{
|
||||
mkdir($dir, 0755);
|
||||
}
|
||||
|
||||
$this->model = $model;
|
||||
$this->config = $fields;
|
||||
$this->filepath = $filepath;
|
||||
$this->logger = new stImportExportLog(sfConfig::get('sf_log_dir').DIRECTORY_SEPARATOR.'export_'.$model.'.log');
|
||||
|
||||
$this->criteria = $this->getCriteria();
|
||||
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($this->criteria, 'st'.sfContext::getInstance()->getModuleName().'Export.'.$this->model.'Criteria'));
|
||||
}
|
||||
|
||||
public function getFilePath()
|
||||
{
|
||||
return $this->filepath;
|
||||
}
|
||||
|
||||
public function setI18nCatalogue($i18nCatalogue)
|
||||
{
|
||||
$this->i18nCatalogue = $i18nCatalogue;
|
||||
}
|
||||
|
||||
public function setCustomParameters(array $parameters)
|
||||
{
|
||||
$this->customParameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca liczbe rekordow do eksportu
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getDataCount()
|
||||
{
|
||||
return call_user_func($this->model.'Peer::doCount', $this->criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca konfiguracja eksportu
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
public function validateFile(array &$errors = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Glowna petla eksportu, pobiera offset danych do eksportu.
|
||||
* Zwraca offset koljego kroku
|
||||
*
|
||||
* @param integer $offset
|
||||
* @return integer
|
||||
*/
|
||||
public function doProcess($offset=0)
|
||||
{
|
||||
|
||||
// jezeli jest to pierwszy krok zapisuje naglowek i naglowek tabeli
|
||||
if ($offset==0)
|
||||
{
|
||||
$this->writeHeader();
|
||||
$this->writeHeaderRow();
|
||||
$this->clearMd5Hash();
|
||||
}
|
||||
|
||||
// pobiera dane z tabeli
|
||||
$data = $this->getData($offset);
|
||||
|
||||
// oblicza liczbe pobranych danych oraz liczbe calkowita danych w bazie
|
||||
$data_items_count = count($data);
|
||||
$data_all_count = $this->getDataCount();
|
||||
|
||||
// zapisuje dane do pliku
|
||||
$this->writeConvertedData($data);
|
||||
$this->writeMd5Hash();
|
||||
|
||||
// sprawdza czy zakonczono eksport, jezeli tak to zapisuje stopke
|
||||
if ( $data_items_count > 0 && $data_all_count<=( $data_items_count + $offset))
|
||||
{
|
||||
$this->writeFooterRow();
|
||||
$this->writeFooter();
|
||||
$this->moveOutputFile();
|
||||
}
|
||||
|
||||
return $offset+$data_items_count;
|
||||
}
|
||||
|
||||
protected function doSelect(Criteria $c)
|
||||
{
|
||||
return call_user_func($this->model.'Peer::doSelect',$c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera dane z bazy danych poczawszy od offsetu, zwraca pobrane
|
||||
* dane w postaci tablicy
|
||||
*
|
||||
* @param integer $offset
|
||||
* @return array
|
||||
*/
|
||||
protected function getData($offset = 0)
|
||||
{
|
||||
|
||||
//tworzy nowe zapytanie uwzgledniajac offset i limit
|
||||
$c = clone $this->criteria;
|
||||
$c->setOffset($offset);
|
||||
$c->setLimit($this->limit);
|
||||
|
||||
// wykonuje zaputanie do bazy danych
|
||||
$data = $this->doSelect($c);
|
||||
|
||||
$this->md5hash = array();
|
||||
|
||||
$return_data = array();
|
||||
|
||||
// dla kazdego zwrocengo wyniku zapisuje dane do tablicy
|
||||
foreach($data as $row)
|
||||
{
|
||||
$return_row = array();
|
||||
|
||||
// eksport jest wykonywany tylko do pol zapisanych w konfiguracji
|
||||
foreach ($this->config['fields'] as $func_name=>$args)
|
||||
{
|
||||
$type = $args['type'];
|
||||
|
||||
$primaryKey = $row->getPrimaryKey();
|
||||
|
||||
$isCompositePrimaryKey = is_array($primaryKey);
|
||||
|
||||
if ($isCompositePrimaryKey)
|
||||
{
|
||||
$logKey = implode("_", $primaryKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
$logKey = $primaryKey;
|
||||
}
|
||||
|
||||
$this->logger->setCurrentKey($logKey);
|
||||
|
||||
// ustala rzeczywista nazwe funkcji do pobrania danych
|
||||
$real_func_name = 'get'. sfInflector::camelize($func_name);
|
||||
|
||||
if (isset($args['method'])) $real_func_name = $args['method'];
|
||||
|
||||
// pobiera dane z modelu glownego lub zaleznych, jezeli podana funkcja nie wystepuje wstawia watosc null
|
||||
if (!isset($args['class']))
|
||||
{
|
||||
try
|
||||
{
|
||||
$v = $row->$real_func_name($this->logger);
|
||||
|
||||
$return_row[$func_name] = $this->formatValue($v, $type);
|
||||
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->logger->add(null, $e->getMessage(), stImportExportLog::$FATAL);
|
||||
$return_row[$func_name] = null;
|
||||
}
|
||||
}
|
||||
elseif (isset($args['class']) && is_callable($args['class'].'::'.$real_func_name))
|
||||
{
|
||||
try
|
||||
{
|
||||
$v = call_user_func($args['class'].'::'.$real_func_name,$row,$this->logger, $this->customParameters);
|
||||
|
||||
$return_row[$func_name] = $this->formatValue($v, $type);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->logger->add(null, $e->getMessage(), stImportExportLog::$FATAL);
|
||||
$return_row[$func_name] = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$return_row[$func_name] = null;
|
||||
}
|
||||
|
||||
if (isset($args['md5hash']) && $args['md5hash'] && $return_row[$func_name] !== null)
|
||||
{
|
||||
$this->md5hash[$row->getId()][$func_name] = md5($return_row[$func_name]);
|
||||
}
|
||||
}
|
||||
// dodaje dane to glownej tablicy danych
|
||||
$return_data[] = $return_row;
|
||||
}
|
||||
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
public function formatValue($v, $type = null)
|
||||
{
|
||||
switch($type)
|
||||
{
|
||||
case "double":
|
||||
case "float":
|
||||
return stPrice::round($v, 2);
|
||||
case "int":
|
||||
case "integer":
|
||||
case "bool":
|
||||
case "boolean":
|
||||
return intval($v);
|
||||
default:
|
||||
return strval($v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca nowa instancje obiektu Criteria
|
||||
*/
|
||||
protected function getCriteria(Criteria $criteria = null)
|
||||
{
|
||||
if (null === $criteria)
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
}
|
||||
|
||||
return $criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia dane w postaci tablicy na okreslony format,
|
||||
* funkcja ta definiowana jest w eksporterze okreslonego formatu
|
||||
*
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getConvertedData($data = null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje dane do pliku
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
protected function writeConvertedData($data = null)
|
||||
{
|
||||
file_put_contents($this->filepath,$this->getConvertedData($data),FILE_APPEND);
|
||||
}
|
||||
|
||||
protected function writeMd5Hash()
|
||||
{
|
||||
foreach ($this->md5hash as $id => $values)
|
||||
{
|
||||
$md5hash = ExportMd5HashPeer::retrieveByModelId($id, $this->model);
|
||||
|
||||
if (null === $md5hash)
|
||||
{
|
||||
$md5hash = new ExportMd5Hash();
|
||||
$md5hash->setId($id);
|
||||
$md5hash->setModel($this->model);
|
||||
}
|
||||
|
||||
$md5hash->setMd5Hash($values);
|
||||
$md5hash->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected function clearMd5Hash()
|
||||
{
|
||||
$con = Propel::getConnection();
|
||||
$con->executeQuery(sprintf('TRUNCATE %s', ExportMd5HashPeer::TABLE_NAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca tresc naglowka, w funkcji tej moga zostac wykonane dodatkowe opercj na naglowku
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getHeader()
|
||||
{
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje naglowek do pliku
|
||||
*/
|
||||
protected function writeHeader()
|
||||
{
|
||||
file_put_contents($this->filepath,$this->getHeader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca wiersz naglowka, funkcja defioniowana w pliku eksportera
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getHeaderRow()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje wiersz naglowkowy do pliku
|
||||
*/
|
||||
protected function writeHeaderRow()
|
||||
{
|
||||
file_put_contents($this->filepath,$this->getHeaderRow(),FILE_APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca zawartosc stopki
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFooter()
|
||||
{
|
||||
return $this->footer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje zawartosc stopki do pliku
|
||||
*/
|
||||
protected function writeFooter()
|
||||
{
|
||||
file_put_contents($this->filepath,$this->getFooter(),FILE_APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca wiersz stopki
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFooterRow()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapisuje wiersz stopki do pliku
|
||||
*/
|
||||
protected function writeFooterRow()
|
||||
{
|
||||
file_put_contents($this->filepath,$this->getFooterRow(),FILE_APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Umozliwia przeniesienie piku wynikowego po wykonaniu eksportu
|
||||
* Zwraca nazwe pliku.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function moveOutputFile()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function setLimit($limit = 20)
|
||||
{
|
||||
if (is_integer($limit) && $limit>0)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
if ($this->hard_limit && $this->limit > $this->hard_limit)
|
||||
{
|
||||
$this->limit = $this->hard_limit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getUserName($name)
|
||||
{
|
||||
if (is_array($name))
|
||||
{
|
||||
return implode("_", array_map(function($name) {
|
||||
return $this->translateFieldName($name);
|
||||
}, $name));
|
||||
}
|
||||
|
||||
return $this->translateFieldName($name);
|
||||
}
|
||||
|
||||
protected function translateFieldName($name)
|
||||
{
|
||||
if (isset($this->config['fields'][$name]['name']))
|
||||
{
|
||||
$field = $this->config['fields'][$name];
|
||||
$i18nCatalogue = $this->i18nCatalogue;
|
||||
|
||||
if (isset($field['i18n']))
|
||||
{
|
||||
$i18nCatalogue = $field['i18n'];
|
||||
}
|
||||
elseif (isset($field['i18n_file']))
|
||||
{
|
||||
$i18nCatalogue = $field['i18n_file'];
|
||||
}
|
||||
|
||||
return sfContext::getInstance()->getI18N()->__($field['name'], array(), $i18nCatalogue).'::'.$name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
interface stPropelImportExportInterface
|
||||
{
|
||||
public function doProcess($offset=0);
|
||||
public function getUserName($name);
|
||||
public function getConfig();
|
||||
public function validateFile(array &$errors = null);
|
||||
}
|
||||
800
plugins/stImportExportPlugin/lib/stPropelImporter.class.php
Normal file
800
plugins/stImportExportPlugin/lib/stPropelImporter.class.php
Normal file
@@ -0,0 +1,800 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stImportExportPlugin
|
||||
*
|
||||
* Ten plik należy do aplikacji stImportExportPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
||||
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
||||
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
||||
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
||||
* @version $Id: stPropelImporter.class.php 13384 2011-06-02 11:30:57Z piotr $
|
||||
* @author Piotr Halas <piotr.halas@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Definicje bledow importu
|
||||
*/
|
||||
define( "IMPORT_NO_CONFIG", "Plik configuracyjny exportu nie istnieje." );
|
||||
define( "IMPORT_NO_FILE", "Plik z danymi nie istnieje lub nie można go doczytać." );
|
||||
|
||||
/**
|
||||
* Klasa obslugi import danych
|
||||
*
|
||||
* @package stImportExportPlugin
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stPropelImporter implements stPropelImportExportInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* kolejnosc danych w pliku
|
||||
* @var array
|
||||
*/
|
||||
var $header_order = array();
|
||||
|
||||
/**
|
||||
* Sciezka do pliku z danymi
|
||||
* @var string
|
||||
*/
|
||||
var $filepath = null;
|
||||
|
||||
/**
|
||||
* Nazwa modelu podstawowego
|
||||
* @var string
|
||||
*/
|
||||
var $model = '';
|
||||
|
||||
/**
|
||||
* Konfiguracja modulu
|
||||
* @var array
|
||||
*/
|
||||
var $config = array();
|
||||
|
||||
/**
|
||||
* Limit danych ekportowanych/importowanych danych
|
||||
* @var integer
|
||||
*/
|
||||
var $limit = 5;
|
||||
|
||||
var $hard_limit = null;
|
||||
|
||||
/**
|
||||
* uchwyt pliku z danymi
|
||||
* @var mixed
|
||||
*/
|
||||
var $fh = null;
|
||||
|
||||
/**
|
||||
* Unikatowa nazwa konvertera
|
||||
* @var string
|
||||
*/
|
||||
var $converter = '';
|
||||
|
||||
var $culture = null;
|
||||
|
||||
protected static $current_data = array();
|
||||
|
||||
protected static $current_key = '';
|
||||
|
||||
protected $logger = null;
|
||||
|
||||
|
||||
protected $primaryKey = null;
|
||||
|
||||
protected $compositePrimaryKey = false;
|
||||
|
||||
protected $requireOnCreateFields = array();
|
||||
|
||||
protected $requireFields = array();
|
||||
|
||||
protected $i18nCatalogue = null;
|
||||
|
||||
/**
|
||||
* Konstruktor klasy, jako paramtry nalezy podac model bazowy,
|
||||
* liste pol do eksportu/importu, w przypadku importu danych
|
||||
* nalezy podac dodatkowo nazwe pliku
|
||||
*
|
||||
* @param string $model
|
||||
* @param array $fields
|
||||
* @param string file
|
||||
*/
|
||||
public function __construct($model, array $fields, $filepath)
|
||||
{
|
||||
$this->filepath = $filepath;
|
||||
$this->model = $model;
|
||||
$this->config = $fields;
|
||||
$this->culture = stLanguage::getOptLanguage();
|
||||
$this->logger = new stImportExportLog(sfConfig::get('sf_log_dir').DIRECTORY_SEPARATOR.'import_'.$model.'.log');
|
||||
|
||||
foreach ($this->config['fields'] as $name => $params)
|
||||
{
|
||||
if (isset($params['require']) || isset($params['require_with_fields']))
|
||||
{
|
||||
$this->requireFields[] = $name;
|
||||
}
|
||||
|
||||
if (isset($params['require_on_create']))
|
||||
{
|
||||
$this->requireOnCreateFields[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setI18nCatalogue($i18nCatalogue)
|
||||
{
|
||||
$this->i18nCatalogue = $i18nCatalogue;
|
||||
}
|
||||
|
||||
public function getFilePath()
|
||||
{
|
||||
return $this->filepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca konfiguracja importu
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
public function setCulture($culture)
|
||||
{
|
||||
$this->culture = $culture;
|
||||
}
|
||||
|
||||
/**
|
||||
* glowna petla importu, dane przetwarzane sa od offsetu
|
||||
* zwraca kolejny offset
|
||||
*
|
||||
* @param integer $offset
|
||||
* @return integer
|
||||
*/
|
||||
public function doProcess($offset = 0)
|
||||
{
|
||||
// odczytaj plik
|
||||
$this->loadFile();
|
||||
|
||||
// wczytaj plik
|
||||
$this->readHeader();
|
||||
|
||||
//odczytaj wiersz naglowka
|
||||
$this->readHeaderRow();
|
||||
|
||||
//pomin wczesniej odczytane dane
|
||||
$this->skipToData($offset);
|
||||
|
||||
// odczytaj dane
|
||||
$this->readData();
|
||||
|
||||
// zwroc aktualny offset
|
||||
return $this->getOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
* zwraca libcze krokow potrzebnych do odczytania calego pliku
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getDataCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje naglowek pliu, zwraca true w przypadku powowdzeni,
|
||||
* false w przypadku bledu
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function readHeader()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Odczytuje wiersz naglowka , zwraca true w przypadku powowdzeni,
|
||||
* false w przypadku bledu
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function readHeaderRow()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* odczytuje jeden wiersz/blok danych, zwraca true jezeli operacja
|
||||
* zakonczyla sie powodzeniem
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function readRow()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca aktualne polozenie w pliku, potrzebne do wykonania
|
||||
* kolejnego kroku importu
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
protected function getOffset()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera aktualnie dodawany obiekt z wykorzytaniem klucza
|
||||
*
|
||||
* @param mixed $key_value
|
||||
* @return object
|
||||
*/
|
||||
protected function getObject($key_value = null, $culture = null)
|
||||
{
|
||||
if (!$culture) $culter = $this->culture;
|
||||
|
||||
// wyszukaj obiekt spełniający podane kryteria
|
||||
|
||||
if (is_array($key_value))
|
||||
{
|
||||
$object = call_user_func_array($this->model.'Peer::retrieveByPK', $key_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->add(constant("{$this->model}Peer::".strtoupper($this->config['primary_key'])),$key_value);
|
||||
$object = call_user_func($this->model.'Peer::doSelectOne',$c);
|
||||
}
|
||||
|
||||
// jezeli nie znaleziono takiego obiektu to go stwórz
|
||||
if (!$object)
|
||||
{
|
||||
$object = new $this->model;
|
||||
}
|
||||
|
||||
if (method_exists($object,'setCulture'))
|
||||
{
|
||||
$object->setCulture($culture);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
protected function loadPrimaryKey(array $data)
|
||||
{
|
||||
$this->compositePrimaryKey = is_array($this->config['primary_key']);
|
||||
|
||||
if ($this->compositePrimaryKey && (empty($data[$this->config['primary_key'][0]]) || empty($data[$this->config['primary_key'][1]])) || !$this->compositePrimaryKey && empty($data[$this->config['primary_key']]))
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Brak wymaganego pola %s% lub jego wartość jest niepoprawna.', array('%s%' => $this->getUserName($this->config['primary_key'])), 'stImportExportBackend'), stImportExportLog::$WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
// set logger current key;
|
||||
if ($this->compositePrimaryKey)
|
||||
{
|
||||
$this->primaryKey = array(
|
||||
$data[$this->config['primary_key'][0]],
|
||||
$data[$this->config['primary_key'][1]],
|
||||
);
|
||||
|
||||
$this->logger->setCurrentKey(implode("_", $this->primaryKey));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->primaryKey = $data[$this->config['primary_key']];
|
||||
$this->logger->setCurrentKey($this->primaryKey);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wykonuje import danych do bazy
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
protected function processData($data = array())
|
||||
{
|
||||
if (!$this->testRequirements($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!$this->validateData($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$this->logger->add(null, $e->getMessage(), stImportExportLog::$FATAL);
|
||||
return false;
|
||||
}
|
||||
// sprawdza czy podano klucz po ktorym zosanie wyszukany rekord do aktualizacji
|
||||
|
||||
|
||||
// znajduje lub tworzy odpowiedni wpis
|
||||
try
|
||||
{
|
||||
if (method_exists($this->config['class'], 'primaryKeyMapping'))
|
||||
{
|
||||
$primaryKey = call_user_func(array($this->config['class'], 'primaryKeyMapping'), $this->primaryKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
$primaryKey = $this->primaryKey;
|
||||
}
|
||||
|
||||
$object = $this->getObject($primaryKey,$this->culture);
|
||||
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$this->logger->add(null, $e->getMessage(), stImportExportLog::$FATAL);
|
||||
return false;
|
||||
}
|
||||
// jezeli ustawiono status usuniecia nie aktualizuj i usun objekt
|
||||
if (isset($data['import_status']) && mb_strtolower($data['import_status'],'utf-8') == 'd')
|
||||
{
|
||||
if (!$object->isNew())
|
||||
{
|
||||
$object->delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($object->isNew() && !$this->testOnCreateRequirements($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$changed = array();
|
||||
$md5hash = !$this->compositePrimaryKey ? ExportMd5HashPeer::retrieveByModelId($object->getId(), $this->model) : null;
|
||||
// Uzupelnia dane dla obiektu na podstawie modelu
|
||||
foreach ($this->config['fields'] as $func_name => $Peer)
|
||||
{
|
||||
// jezeli dane nie sa ustawione, przypisz domyslne
|
||||
if (!isset($data[$func_name]) && isset($this->config['fields'][$func_name]['default']))
|
||||
{
|
||||
$data[$func_name] = $this->config['fields'][$func_name]['default'];
|
||||
}
|
||||
// jezeli informacja wystepuje w danych zapisuje ja w obiekcie
|
||||
if (isset($data[$func_name]))
|
||||
{
|
||||
$changed[$func_name] = null !== $md5hash && isset($Peer['md5hash']) && $Peer['md5hash'] ? !$md5hash->runDataHashCheck($func_name, $data[$func_name], true) : true;
|
||||
|
||||
if ($changed[$func_name])
|
||||
{
|
||||
// pobiera rzeczywista nazwe funkcji odpowiedzialnej ustawienie danych
|
||||
$real_func_name = 'set'. sfInflector::camelize($func_name);
|
||||
if (isset($Peer['method'])) $real_func_name = $Peer['method'];
|
||||
|
||||
// jezeli metoda istnieje zostanie ona wykonana
|
||||
if (!isset($Peer['class']))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (isset($Peer['custom_method']) && $Peer['custom_method'])
|
||||
{
|
||||
call_user_func($this->config['default_class'].'::'.$real_func_name, $object, $data[$func_name],$this->logger, $data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$object->$real_func_name($data[$func_name], $this->logger);
|
||||
}
|
||||
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$this->logger->add(null, $e->getMessage(), stImportExportLog::$FATAL);
|
||||
if (null !== $md5hash)
|
||||
{
|
||||
$md5hash->restoreMd5Hash($func_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// zapisuje wartosci
|
||||
try
|
||||
{
|
||||
$object->save();
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$this->logger->add(null, $e->getMessage(), stImportExportLog::$FATAL);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Uzupelnia dane z zewnetrznych modeli
|
||||
foreach ($this->config['fields'] as $func_name => $Peer)
|
||||
{
|
||||
|
||||
// jezeli informacja wystepuje w danych wykonuje odpowiednia funkcje
|
||||
if (isset($data[$func_name]) && $changed[$func_name])
|
||||
{
|
||||
|
||||
// pobiera rzeczywista nazwe funkcji odpowiedzialnej ustawienie danych
|
||||
$real_func_name = 'set'. sfInflector::camelize($func_name);
|
||||
if (isset($Peer['method'])) $real_func_name = $Peer['method'];
|
||||
|
||||
|
||||
|
||||
// jezeli metoda istnieje zostanie ona wykonana
|
||||
if (isset($Peer['class']))
|
||||
{
|
||||
$Peer = $Peer['class'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$Peer = $this->config['default_class'];
|
||||
}
|
||||
|
||||
if (is_callable($Peer.'::'.$real_func_name))
|
||||
{
|
||||
try
|
||||
{
|
||||
call_user_func($Peer.'::'.$real_func_name, $object, $data[$func_name],$this->logger, $data);
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$this->logger->add(null, $e->getMessage(), stImportExportLog::$FATAL);
|
||||
|
||||
if (null !== $md5hash)
|
||||
{
|
||||
$md5hash->restoreMd5Hash($func_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
stEventDispatcher::getInstance()->notify(new sfEvent($this, 'stImportExport.Import_'.$this->model, array('modelInstance'=>$object)));
|
||||
|
||||
if (isset($this->config['default_class']) && is_callable($this->config['default_class'].'::preSave'))
|
||||
{
|
||||
call_user_func($this->config['default_class'].'::preSave', $object, $this->logger);
|
||||
}
|
||||
|
||||
$object->save();
|
||||
|
||||
if (null !== $md5hash)
|
||||
{
|
||||
if ($md5hash->isNew())
|
||||
{
|
||||
$md5hash->setId($object->getId());
|
||||
}
|
||||
if ($md5hash->isColumnModified(ExportMd5HashPeer::MD5HASH))
|
||||
{
|
||||
$md5hash->save();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $e)
|
||||
{
|
||||
$this->logger->add(null, $e->getMessage(), stImportExportLog::$FATAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza wymagania dla pól
|
||||
*
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function testRequirements(array $data)
|
||||
{
|
||||
$ret = true;
|
||||
$availableFields = array_keys($data);
|
||||
|
||||
foreach ($this->requireFields as $name)
|
||||
{
|
||||
$params = $this->config['fields'][$name];
|
||||
$required = !isset($params['require_with_fields']) || !empty(array_intersect($params['require_with_fields'], $availableFields));
|
||||
|
||||
if ($required && (!isset($data[$name]) || empty(trim($data[$name]))))
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Brak wymaganego pola: %s%', array('%s%'=>$this->getUserName($name)), 'stImportExportBackend'), stImportExportLog::$WARNING);
|
||||
$ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sprawdza wymagania dla pól podczas tworzenia nowego rekordu
|
||||
* @param array $data Dane
|
||||
* @return bool
|
||||
*/
|
||||
public function testOnCreateRequirements(array $data)
|
||||
{
|
||||
$ret = true;
|
||||
|
||||
foreach ($this->requireOnCreateFields as $name)
|
||||
{
|
||||
if (!isset($data[$name]) || empty(trim($data[$name])))
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Brak wymaganego pola: %s%', array('%s%'=>$this->getUserName($name)), 'stImportExportBackend'), stImportExportLog::$WARNING);
|
||||
$ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waliduje poszczególne pola
|
||||
*
|
||||
* @param array $data Dane
|
||||
* @return bool
|
||||
*/
|
||||
public function validateData(array $data)
|
||||
{
|
||||
|
||||
$isValid = true;
|
||||
|
||||
foreach ($this->config['fields'] as $name => $params)
|
||||
{
|
||||
if (isset($data[$name]))
|
||||
{
|
||||
$type = isset($params['type']) ? $params['type'] : 'string';
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case "string":
|
||||
if (!is_string($data[$name]))
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Niepoprawna wartość pola ', array(), 'stImportExportBackend').$this->getUserName($name).', "'.$data[$name].'" '.sfContext::getInstance()->getI18n()->__('nie jest ciągiem znaków', array(), 'stImportExportBackend'), stImportExportLog::$NOTICE);
|
||||
$isValid = false;
|
||||
}
|
||||
break;
|
||||
case "double":
|
||||
if (((!preg_match('/^-?\d+(\.\d+)?$/', $data[$name])) || substr_count($data[$name], '.') != 1) &&((!preg_match('/^-?\d+(\.\d+)?$/', $data[$name])) || ((float) $data[$name] != (int) $data[$name])))
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Niepoprawna wartość pola ', array(), 'stImportExportBackend').$this->getUserName($name).', "'.$data[$name].'" '.sfContext::getInstance()->getI18n()->__('nie jest liczbą', array(), 'stImportExportBackend'), stImportExportLog::$NOTICE);
|
||||
$isValid = false;
|
||||
}
|
||||
break;
|
||||
case "bool":
|
||||
if (!is_numeric($data[$name]) && !$data[$name] != 0 && !$data[$name] != 1)
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Niepoprawna wartość pola ', array(), 'stImportExportBackend').$this->getUserName($name).', "'.$data[$name].'" '.sfContext::getInstance()->getI18n()->__('nie jest 1 lub 0', array(), 'stImportExportBackend'), stImportExportLog::$NOTICE);
|
||||
$isValid = false;
|
||||
}
|
||||
break;
|
||||
case "boolean":
|
||||
if (!is_numeric($data[$name]) && !$data[$name] != 0 && !$data[$name] != 1)
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Niepoprawna wartość pola ', array(), 'stImportExportBackend').$this->getUserName($name).', "'.$data[$name].'" '.sfContext::getInstance()->getI18n()->__('nie jest 1 lub 0', array(), 'stImportExportBackend'), stImportExportLog::$NOTICE);
|
||||
$isValid = false;
|
||||
}
|
||||
break;
|
||||
case "int":
|
||||
if ((!preg_match('/^-?\d+(\.\d+)?$/', $data[$name])) || ((float) $data[$name] != (int) $data[$name]))
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Niepoprawna wartość pola ', array(), 'stImportExportBackend').$this->getUserName($name).', "'.$data[$name].'" '.sfContext::getInstance()->getI18n()->__('nie jest liczbą całkowitą', array(), 'stImportExportBackend'), stImportExportLog::$NOTICE);
|
||||
$isValid = false;
|
||||
}
|
||||
break;
|
||||
case "integer":
|
||||
if ((!preg_match('/^-?\d+(\.\d+)?$/', $data[$name])) || ((float) $data[$name] != (int) $data[$name]))
|
||||
{
|
||||
$this->logger->add(null, sfContext::getInstance()->getI18n()->__('Niepoprawna wartość pola ', array(), 'stImportExportBackend').$this->getUserName($name).', "'.$data[$name].'" '.sfContext::getInstance()->getI18n()->__('nie jest liczbą całkowitą', array(), 'stImportExportBackend') ,stImportExportLog::$NOTICE);
|
||||
$isValid = false;
|
||||
}
|
||||
break;
|
||||
case "custom":
|
||||
$call = $this->config['default_class'] ? $this->config['default_class'] : $this->model."Peer";
|
||||
|
||||
if (isset($params['class']))
|
||||
{
|
||||
$call = $params['class'];
|
||||
}
|
||||
|
||||
if (is_callable($call."::".sfInflector::camelize("import_validate_".$name)))
|
||||
{
|
||||
if(!call_user_func($call."::".sfInflector::camelize("import_validate_".$name), $data[$name], $this->primaryKey, $data, $this))
|
||||
{
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
if (!is_string($data[$name])) unset($data[$name]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* odczytuje dane z pliku, zwraca liczbe odczytanych danych
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
protected function readData()
|
||||
{
|
||||
$readed = 0;
|
||||
|
||||
// czytaj az do przekroczenia limitu lub gdy plik sie skonczy
|
||||
while ($this->readRow() && $readed<$this->limit)
|
||||
{
|
||||
$readed++;
|
||||
}
|
||||
return $readed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Przeskakuje do odpowiedniego miejsca w czytanym pliku
|
||||
*
|
||||
* @param integer $offset
|
||||
* @return boolean
|
||||
*/
|
||||
protected function skipToData($offset = 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja otwiera plik, kod otwierania musi znalezc sie w eksporterze
|
||||
* do konkretnego formatu, w przypadku powodzenia zwraca true
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function loadFile()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamyka plik, kod zamykania musi znalezc sie w eksporterze
|
||||
* do konkretnego formatu, w przypadku powodzenia zwraca true
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function closeFile()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validateFile(array &$errors = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setLimit($limit = 20)
|
||||
{
|
||||
if (is_integer($limit) && $limit>0)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
if ($this->hard_limit && $this->limit > $this->hard_limit)
|
||||
{
|
||||
$this->limit = $this->hard_limit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function removeUserName($data = array())
|
||||
{
|
||||
|
||||
$tmp = array();
|
||||
foreach ($data as $value)
|
||||
{
|
||||
$new_value_array = explode('::',$value);
|
||||
|
||||
if (isset($new_value_array[1])) $new_value = $new_value_array[1]; else $new_value = $value;
|
||||
$tmp[] = $new_value;
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
public function getUserName($name)
|
||||
{
|
||||
if (is_array($name))
|
||||
{
|
||||
return implode("_", array_map(function($name) {
|
||||
return $this->translateFieldName($name);
|
||||
}, $name));
|
||||
}
|
||||
|
||||
return $this->translateFieldName($name);
|
||||
}
|
||||
|
||||
protected function translateFieldName($name)
|
||||
{
|
||||
if (isset($this->config['fields'][$name]['name']))
|
||||
{
|
||||
$field = $this->config['fields'][$name];
|
||||
$i18nCatalogue = $this->i18nCatalogue;
|
||||
|
||||
if (isset($field['i18n']))
|
||||
{
|
||||
$i18nCatalogue = $field['i18n'];
|
||||
}
|
||||
elseif (isset($field['i18n_file']))
|
||||
{
|
||||
$i18nCatalogue = $field['i18n_file'];
|
||||
}
|
||||
|
||||
return sfContext::getInstance()->getI18N()->__($field['name'], array(), $i18nCatalogue).'::'.$name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public static function getCurrentData()
|
||||
{
|
||||
return stPropelImporter::$current_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca instancje loggera
|
||||
*
|
||||
* @return stImportExportLog
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed function fgetcsv, parameter compatible with fgetcsv
|
||||
*
|
||||
* handle - handle to the file
|
||||
* len - unsued
|
||||
* delimeter - delimeter
|
||||
* enclosure - enclosure
|
||||
*/
|
||||
public static function fixed_fgetcsv($handle, $len = null, $delimeter = ',', $enclosure = '"')
|
||||
{
|
||||
//read lines until even numbers of enclosures or EOF
|
||||
$line = fgets($handle);
|
||||
while (!feof($handle) && substr_count($line,'"')%2) $line .= fgets($handle);
|
||||
|
||||
// return array
|
||||
$ret = array();
|
||||
// cell value
|
||||
$cell = "";
|
||||
|
||||
//split line into cells
|
||||
foreach (explode($delimeter,$line) as $value)
|
||||
{
|
||||
//assign value to cell
|
||||
$cell .= $value;
|
||||
|
||||
// if cell has even numbers of enclosure
|
||||
if (substr_count($cell,$enclosure)%2 == 0)
|
||||
{
|
||||
//remove delimeters from begining and end
|
||||
if (substr($cell,0,1) == $enclosure && substr($cell,0,2) != $enclosure.$enclosure) $cell = ltrim($cell, $enclosure);
|
||||
if (substr($cell,-1) == $enclosure && substr($cell,-2) != $enclosure.$enclosure) $cell = rtrim($cell, $enclosure);
|
||||
//replace escape enclosures
|
||||
$cell = str_replace($enclosure.$enclosure,$enclosure, $cell);
|
||||
$ret[] = $cell;
|
||||
$cell = '';
|
||||
}
|
||||
// cell not endend append deliteter and continue
|
||||
else {$cell .= $delimeter;}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user