Index: trunk/kernel/units/general/cat_dbitem_export.php =================================================================== diff -u -r4243 -r5431 --- trunk/kernel/units/general/cat_dbitem_export.php (.../cat_dbitem_export.php) (revision 4243) +++ trunk/kernel/units/general/cat_dbitem_export.php (.../cat_dbitem_export.php) (revision 5431) @@ -51,6 +51,12 @@ */ var $filePointer = null; + /** + * Custom fields definition of current item + * + * @var Array + */ + var $customFields = Array(); function kCatDBItemExportHelper() { @@ -282,6 +288,7 @@ } else { foreach ($check_fields as $check_field) { + $check_field = preg_replace('/^cust_(.*)/', 'Custom_\\1', $check_field); if (!in_array($check_field, $this->exportOptions['ExportColumns'])) { $object->setError('ExportColumns', 'required'); $ret = false; @@ -354,29 +361,35 @@ fclose($this->filePointer); } + function getCustomSQL() + { + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + + $custom_sql = ''; + foreach ($this->customFields as $custom_id => $custom_name) { + $custom_sql .= 'custom_data.'.$ml_formatter->LangFieldName('cust_'.$custom_id).' AS cust_'.$custom_name.', '; + } + + return preg_replace('/(.*), /', '\\1', $custom_sql); + } + function getExportSQL($count_only = false) { if ($this->exportOptions['export_ids'] === false) { // get links from current category & all it's subcategories $join_clauses = Array(); - $custom_sql = ''; - $custom_table = $this->Application->getUnitOption($this->curItem->Prefix.'-cdata', 'TableName'); - - if ($custom_table) { - $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); - $custom_fields = $this->Application->getUnitOption($this->curItem->Prefix, 'CustomFields'); - - foreach ($custom_fields as $custom_id => $custom_name) { - $custom_sql .= 'custom_data.'.$ml_formatter->LangFieldName('cust_'.$custom_id).' AS cust_'.$custom_name.','; - } + $custom_sql = $this->getCustomSQL(); + if ($custom_sql) { + $custom_table = $this->Application->getUnitOption($this->curItem->Prefix.'-cdata', 'TableName'); $join_clauses[$custom_table.' custom_data'] = 'custom_data.ResourceId = item_table.ResourceId'; } + $join_clauses[TABLE_PREFIX.'CategoryItems ci'] = 'ci.ItemResourceId = item_table.ResourceId'; $join_clauses[TABLE_PREFIX.'Category c'] = 'c.CategoryId = ci.CategoryId'; - $sql = 'SELECT item_table.*, '.$custom_sql.' ci.CategoryId + $sql = 'SELECT item_table.*, ci.CategoryId'.($custom_sql ? ', '.$custom_sql : '').' FROM '.$this->curItem->TableName.' item_table'; foreach ($join_clauses as $table_name => $join_expression) { @@ -425,7 +438,7 @@ $this->exportOptions = $this->loadOptions($event); $this->exportFields = $this->exportOptions['ExportColumns']; $this->curItem =& $event->getObject( Array('skip_autoload' => true) ); - + $this->customFields = $this->Application->getUnitOption($event->Prefix, 'CustomFields'); $this->openFile($event); if ($this->exportOptions['start_from'] == 0) // first export step @@ -636,7 +649,8 @@ break; } $this->curItem->Clear(); - + $this->customFields = $this->Application->getUnitOption($event->Prefix, 'CustomFields'); + if (isset($record_data)) { $this->setImportData($record_data); } @@ -739,7 +753,15 @@ if (count($load_keys)) { $where_clause = ''; foreach ($load_keys as $field_name => $field_value) { - $where_clause .= '(item_table.`'.$field_name.'` = '.$this->Conn->qstr($field_value).') AND '; + if (preg_match('/^cust_(.*)/', $field_name, $regs)) { + $custom_id = array_search($regs[1], $this->customFields); + $field_name = 'l'.$this->Application->GetVar('m_lang').'_cust_'.$custom_id; + $where_clause .= '(custom_data.`'.$field_name.'` = '.$this->Conn->qstr($field_value).') AND '; + } + else { + $where_clause .= '(item_table.`'.$field_name.'` = '.$this->Conn->qstr($field_value).') AND '; + } + } $where_clause = preg_replace('/(.*) AND $/', '\\1', $where_clause); @@ -750,9 +772,11 @@ $parent_path = $this->getParentPath($category_id); $where_clause = '(c.ParentPath LIKE "'.$parent_path.'%") AND '.$where_clause; } - + + $cdata_table = $this->Application->getUnitOption($event->Prefix.'-cdata', 'TableName'); $sql = 'SELECT '.$this->curItem->IDField.' FROM '.$this->curItem->TableName.' item_table + LEFT JOIN '.$cdata_table.' custom_data ON custom_data.ResourceId = item_table.ResourceId LEFT JOIN '.TABLE_PREFIX.'CategoryItems ci ON ci.ItemResourceId = item_table.ResourceId LEFT JOIN '.TABLE_PREFIX.'Category c ON c.CategoryId = ci.CategoryId WHERE '.$where_clause;