Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/cat_dbitem_export_helper.php
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | |||||
* | * | ||||
* @param kEvent|bool $event | * @param kEvent|bool $event | ||||
* @param kCatDBItem|bool $object | * @param kCatDBItem|bool $object | ||||
* @param bool $set_status | * @param bool $set_status | ||||
*/ | */ | ||||
function fillRequiredFields($event, &$object, $set_status = false) | function fillRequiredFields($event, &$object, $set_status = false) | ||||
{ | { | ||||
if ( $object == $this->false ) { | if ( $object == $this->false ) { | ||||
/** @var kCatDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kCatDBItem */ | |||||
} | } | ||||
$has_empty = false; | $has_empty = false; | ||||
$fields = $object->getFields(); | $fields = $object->getFields(); | ||||
if ( $object->isField('CreatedById') ) { | if ( $object->isField('CreatedById') ) { | ||||
// CSV file was created without required CreatedById column | // CSV file was created without required CreatedById column | ||||
if ( $object->isRequired('CreatedById') ) { | if ( $object->isRequired('CreatedById') ) { | ||||
Show All 13 Lines | |||||
if ( $object->GetDBField($field_name) ) { | if ( $object->GetDBField($field_name) ) { | ||||
continue; | continue; | ||||
} | } | ||||
$formatter_class = getArrayValue($field_options, 'formatter'); | $formatter_class = getArrayValue($field_options, 'formatter'); | ||||
if ( $formatter_class ) { | if ( $formatter_class ) { | ||||
// not tested | // not tested | ||||
/** @var kFormatter $formatter */ | |||||
$formatter = $this->Application->recallObject($formatter_class); | $formatter = $this->Application->recallObject($formatter_class); | ||||
/* @var $formatter kFormatter */ | |||||
$sample_value = $formatter->GetSample($field_name, $field_options, $object); | $sample_value = $formatter->GetSample($field_name, $field_options, $object); | ||||
} | } | ||||
$has_empty = true; | $has_empty = true; | ||||
$object->SetField($field_name, isset($sample_value) && $sample_value ? $sample_value : 'no value'); | $object->SetField($field_name, isset($sample_value) && $sample_value ? $sample_value : 'no value'); | ||||
} | } | ||||
$object->UpdateFormattersSubFields(); | $object->UpdateFormattersSubFields(); | ||||
Show All 15 Lines | |||||
if ($this->Application->RecallVar($event->getPrefixSpecial().'_ForceNotValid')) | if ($this->Application->RecallVar($event->getPrefixSpecial().'_ForceNotValid')) | ||||
{ | { | ||||
$this->Application->StoreVar($event->getPrefixSpecial().'_ForceNotValid', 0); | $this->Application->StoreVar($event->getPrefixSpecial().'_ForceNotValid', 0); | ||||
return false; | return false; | ||||
} | } | ||||
$this->fillRequiredFields($event, $this->false); | $this->fillRequiredFields($event, $this->false); | ||||
/** @var kCatDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kCatDBItem */ | |||||
$cross_unique_fields = Array('FieldsSeparatedBy', 'FieldsEnclosedBy'); | $cross_unique_fields = Array('FieldsSeparatedBy', 'FieldsEnclosedBy'); | ||||
if (($object->GetDBField('CategoryFormat') == 1) || ($event->Special == 'import')) // in one field | if (($object->GetDBField('CategoryFormat') == 1) || ($event->Special == 'import')) // in one field | ||||
{ | { | ||||
$object->setRequired('CategorySeparator'); | $object->setRequired('CategorySeparator'); | ||||
$cross_unique_fields[] = 'CategorySeparator'; | $cross_unique_fields[] = 'CategorySeparator'; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Opens file required for export/import operations | * Opens file required for export/import operations | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function openFile($event) | function openFile($event) | ||||
{ | { | ||||
/** @var FileHelper $file_helper */ | |||||
$file_helper = $this->Application->recallObject('FileHelper'); | $file_helper = $this->Application->recallObject('FileHelper'); | ||||
/* @var $file_helper FileHelper */ | |||||
$file_helper->CheckFolder(EXPORT_PATH); | $file_helper->CheckFolder(EXPORT_PATH); | ||||
if ( $event->Special == 'export' ) { | if ( $event->Special == 'export' ) { | ||||
$first_step = $this->exportOptions['start_from'] == 0; | $first_step = $this->exportOptions['start_from'] == 0; | ||||
$this->filePointer = fopen($this->getExportFilename(), $first_step ? 'w' : 'r+'); | $this->filePointer = fopen($this->getExportFilename(), $first_step ? 'w' : 'r+'); | ||||
if ( !$first_step ) { | if ( !$first_step ) { | ||||
Show All 17 Lines | |||||
*/ | */ | ||||
function closeFile() | function closeFile() | ||||
{ | { | ||||
fclose($this->filePointer); | fclose($this->filePointer); | ||||
} | } | ||||
function getCustomSQL() | function getCustomSQL() | ||||
{ | { | ||||
/** @var kMultiLanguage $ml_formatter */ | |||||
$ml_formatter = $this->Application->recallObject('kMultiLanguage'); | $ml_formatter = $this->Application->recallObject('kMultiLanguage'); | ||||
/* @var $ml_formatter kMultiLanguage */ | |||||
$custom_sql = ''; | $custom_sql = ''; | ||||
foreach ($this->customFields as $custom_id => $custom_name) { | foreach ($this->customFields as $custom_id => $custom_name) { | ||||
$custom_sql .= 'custom_data.' . $ml_formatter->LangFieldName('cust_' . $custom_id) . ' AS cust_' . $custom_name . ', '; | $custom_sql .= 'custom_data.' . $ml_formatter->LangFieldName('cust_' . $custom_id) . ' AS cust_' . $custom_name . ', '; | ||||
} | } | ||||
return substr($custom_sql, 0, -2); | return substr($custom_sql, 0, -2); | ||||
▲ Show 20 Lines • Show All 660 Lines • ▼ Show 20 Line(s) | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
function getCategoryPath() | function getCategoryPath() | ||||
{ | { | ||||
$category_id = $this->curItem->GetDBField('CategoryId'); | $category_id = $this->curItem->GetDBField('CategoryId'); | ||||
$category_path = $this->getFromCache('category_path', $category_id); | $category_path = $this->getFromCache('category_path', $category_id); | ||||
if ( !$category_path ) { | if ( !$category_path ) { | ||||
/** @var kMultiLanguage $ml_formatter */ | |||||
$ml_formatter = $this->Application->recallObject('kMultiLanguage'); | $ml_formatter = $this->Application->recallObject('kMultiLanguage'); | ||||
/* @var $ml_formatter kMultiLanguage */ | |||||
$sql = 'SELECT ' . $ml_formatter->LangFieldName('CachedNavbar') . ' | $sql = 'SELECT ' . $ml_formatter->LangFieldName('CachedNavbar') . ' | ||||
FROM ' . TABLE_PREFIX . 'Categories | FROM ' . TABLE_PREFIX . 'Categories | ||||
WHERE CategoryId = ' . $category_id; | WHERE CategoryId = ' . $category_id; | ||||
$category_path = $this->Conn->GetOne($sql); | $category_path = $this->Conn->GetOne($sql); | ||||
$category_path = $category_path ? explode('&|&', $category_path) : Array (); | $category_path = $category_path ? explode('&|&', $category_path) : Array (); | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Sets correct available & export fields | * Sets correct available & export fields | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function prepareExportColumns($event) | function prepareExportColumns($event) | ||||
{ | { | ||||
/** @var kCatDBItem $object */ | |||||
$object = $event->getObject( Array('skip_autoload' => true) ); | $object = $event->getObject( Array('skip_autoload' => true) ); | ||||
/* @var $object kCatDBItem */ | |||||
if ( !$object->isField('ExportColumns') ) { | if ( !$object->isField('ExportColumns') ) { | ||||
// import/export prefix was used (see kDBEventHandler::prepareObject) but object don't plan to be imported/exported | // import/export prefix was used (see kDBEventHandler::prepareObject) but object don't plan to be imported/exported | ||||
return ; | return ; | ||||
} | } | ||||
$available_columns = Array(); | $available_columns = Array(); | ||||
Show All 16 Lines | |||||
$fields = $object->getFields(); | $fields = $object->getFields(); | ||||
foreach ($fields as $field_name => $field_options) { | foreach ($fields as $field_name => $field_options) { | ||||
if ( !$object->skipField($field_name) ) { | if ( !$object->skipField($field_name) ) { | ||||
$available_columns[$field_name] = $field_name.( $object->isRequired($field_name) ? '*' : ''); | $available_columns[$field_name] = $field_name.( $object->isRequired($field_name) ? '*' : ''); | ||||
} | } | ||||
} | } | ||||
/** @var kDBEventHandler $handler */ | |||||
$handler = $this->Application->recallObject($event->Prefix.'_EventHandler'); | $handler = $this->Application->recallObject($event->Prefix.'_EventHandler'); | ||||
/* @var $handler kDBEventHandler */ | |||||
$available_columns = array_merge($available_columns, $handler->getCustomExportColumns($event)); | $available_columns = array_merge($available_columns, $handler->getCustomExportColumns($event)); | ||||
// custom fields | // custom fields | ||||
$custom_fields = $object->getCustomFields(); | $custom_fields = $object->getCustomFields(); | ||||
foreach ($custom_fields as $custom_id => $custom_name) | foreach ($custom_fields as $custom_id => $custom_name) | ||||
{ | { | ||||
Show All 35 Lines | |||||
/** | /** | ||||
* Prepares export presets | * Prepares export presets | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
function PrepareExportPresets($event) | function PrepareExportPresets($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(Array ('skip_autoload' => true)); | $object = $event->getObject(Array ('skip_autoload' => true)); | ||||
/* @var $object kDBItem */ | |||||
$options = $object->GetFieldOptions('ExportPresets'); | $options = $object->GetFieldOptions('ExportPresets'); | ||||
$export_settings = $this->Application->RecallPersistentVar('export_settings'); | $export_settings = $this->Application->RecallPersistentVar('export_settings'); | ||||
if ( !$export_settings ) { | if ( !$export_settings ) { | ||||
return; | return; | ||||
} | } | ||||
Show All 35 Lines | |||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function updateImportFiles($event) | protected function updateImportFiles($event) | ||||
{ | { | ||||
if ( $event->Special != 'import' ) { | if ( $event->Special != 'import' ) { | ||||
return ; | return ; | ||||
} | } | ||||
/** @var FileHelper $file_helper */ | |||||
$file_helper = $this->Application->recallObject('FileHelper'); | $file_helper = $this->Application->recallObject('FileHelper'); | ||||
/* @var $file_helper FileHelper */ | |||||
$import_filenames = Array (); | $import_filenames = Array (); | ||||
$file_helper->CheckFolder(EXPORT_PATH); | $file_helper->CheckFolder(EXPORT_PATH); | ||||
$iterator = new DirectoryIterator(EXPORT_PATH); | $iterator = new DirectoryIterator(EXPORT_PATH); | ||||
/* @var $file_info DirectoryIterator */ | /** @var DirectoryIterator $file_info */ | ||||
foreach ($iterator as $file_info) { | foreach ($iterator as $file_info) { | ||||
$file = $file_info->getFilename(); | $file = $file_info->getFilename(); | ||||
if ( $file_info->isDir() || $file == 'dummy' || $file_info->getSize() == 0 ) { | if ( $file_info->isDir() || $file == 'dummy' || $file_info->getSize() == 0 ) { | ||||
continue; | continue; | ||||
} | } | ||||
$import_filenames[$file] = $file . ' (' . kUtil::formatSize( $file_info->getSize() ) . ')'; | $import_filenames[$file] = $file . ' (' . kUtil::formatSize( $file_info->getSize() ) . ')'; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$object->SetFieldOption('ImportLocalFilename', 'options', $import_filenames); | $object->SetFieldOption('ImportLocalFilename', 'options', $import_filenames); | ||||
} | } | ||||
/** | /** | ||||
* Returns module folder | * Returns module folder | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
Show All 18 Lines | |||||
if ( !$items_info ) { | if ( !$items_info ) { | ||||
$items_info = unserialize($this->Application->RecallVar($event->getPrefixSpecial() . '_ItemsInfo')); | $items_info = unserialize($this->Application->RecallVar($event->getPrefixSpecial() . '_ItemsInfo')); | ||||
$this->Application->SetVar($event->getPrefixSpecial(true), $items_info); | $this->Application->SetVar($event->getPrefixSpecial(true), $items_info); | ||||
} | } | ||||
list($item_id, $field_values) = each($items_info); | list($item_id, $field_values) = each($items_info); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(Array ('skip_autoload' => true)); | $object = $event->getObject(Array ('skip_autoload' => true)); | ||||
/* @var $object kDBItem */ | |||||
$object->SetFieldsFromHash($field_values); | $object->SetFieldsFromHash($field_values); | ||||
$field_values['ImportFilename'] = $object->GetDBField('ImportFilename'); //if upload formatter has renamed the file during moving !!! | $field_values['ImportFilename'] = $object->GetDBField('ImportFilename'); //if upload formatter has renamed the file during moving !!! | ||||
$object->setID($item_id); | $object->setID($item_id); | ||||
$this->setRequiredFields($event); | $this->setRequiredFields($event); | ||||
// save export/import options | // save export/import options | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | |||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function setRequiredFields($event) | function setRequiredFields($event) | ||||
{ | { | ||||
$required_fields['common'] = Array('FieldsSeparatedBy', 'LineEndings', 'CategoryFormat'); | $required_fields['common'] = Array('FieldsSeparatedBy', 'LineEndings', 'CategoryFormat'); | ||||
$required_fields['export'] = Array('ExportFormat', 'ExportFilename','ExportColumns'); | $required_fields['export'] = Array('ExportFormat', 'ExportFilename','ExportColumns'); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ($this->_getExportSavePreset($object)) { | if ($this->_getExportSavePreset($object)) { | ||||
$required_fields['export'][] = 'ExportPresetName'; | $required_fields['export'][] = 'ExportPresetName'; | ||||
} | } | ||||
$required_fields['import'] = Array('FieldTitles', 'ImportSource', 'CheckDuplicatesMethod'); // ImportFilename, ImportLocalFilename | $required_fields['import'] = Array('FieldTitles', 'ImportSource', 'CheckDuplicatesMethod'); // ImportFilename, ImportLocalFilename | ||||
if ($event->Special == 'import') | if ($event->Special == 'import') | ||||
Show All 15 Lines |