function organizeExportColumn($data,$table,&$elements,&$action,&$types){
switch($data){
case 'product':
switch($table){
case 'product':
$ids = array();
$database = JFactory::getDBO();
foreach($elements as $element){
if(isset($element->product_parent_id->id)){
$ids[] = $element->product_parent_id->id;
}else if($element->product_parent_id){
$ids[] = $element->product_parent_id;
}
}
if(!empty($ids)){
$tIds = array();
foreach($ids as $id){
if(isset($id->id))
$tIds[$id->id] = $id->id;
elseif($id != 0)
$tIds[$id] = $id;
}
$query = 'SELECT product_id, product_code';
$query .= ' FROM '.hikashop_table('product');
$query .= ' WHERE product_id IN ('.implode(',',$tIds).')';
$database->setQuery($query);
$rows = $database->loadObjectList();
foreach($elements as $element){
$id = $element->product_parent_id;
$element->product_parent_id = '';
$types['product_parent_id']->type = 'text';
foreach($rows as $row){
if($id->id != $row->product_id){continue;}
$element->product_parent_id = $row->product_code;
}
}
}
break;
case 'related':
$ids = array();
$database = JFactory::getDBO();
foreach($elements as $element){
$ids[] = $element->product_id;
}
$query = 'SELECT pr.product_id, p.product_code';
$query .= ' FROM '.hikashop_table('product').' AS p';
$query .= ' INNER JOIN '.hikashop_table('product_related').' AS pr ON pr.product_related_id = p.product_id';
$query .= ' WHERE pr.product_id IN ('.implode(',',$ids).')';
$database->setQuery($query);
$rows = $database->loadObjectList();
$types['related']->type = 'text';
foreach($elements as $element){
foreach($element as $key=>$related){
if($key == 'related'){
foreach($related as $product){
$product->related = '';
foreach($rows as $row){
if($element->product_id != $row->product_id){continue;}
$product->related = $row->product_code;
}
}
}
}
}
break;
case 'category':
unset($action['category']);
$database = JFactory::getDBO();
$ids = array();
foreach($elements as $element){
foreach($element as $key=>$data){
if($key == 'category'){
foreach($data as $category){
if(isset($category->category_id)){
$ids[] = (int)$category->category_id;
}
}
}
}
}
if(!empty($ids)){
$query = 'SELECT DISTINCT category_name, category_id';
$query .= ' FROM '.hikashop_table('category');
$query .= ' WHERE category_id IN ('.implode(',',$ids).')';
$database->setQuery($query);
$rows = $database->loadObjectList();
foreach($elements as $element){
foreach($element as $key=>$data){
if($key == 'category'){
foreach($data as $category){
if(isset($category->category_id)){
$array = array();
foreach($rows as $row){
if($row->category_id == $category->category_id){
$array[] = $row->category_name;
}
}
$category->categories = $this->separator($array,$data,$table);
$types['categories'] = new stdClass();
$types['categories']->type = 'text';
$action['category']['categories'] = 'categories';
}
}
}
}
}
}
break;
}
break;
case 'user':
switch($table){
case 'address':
foreach($elements as $element){
if(!isset($element->address)){continue;}
foreach($element->address as $k=>$address){
if($address->address_default != 1){
unset($element->address[$k]);
}
}
}
break;
}
break;
case 'category':
unset($action['category']);
$database = JFactory::getDBO();
$ids = array();
foreach($elements as $category){
if(isset($category->category_id)){
$ids[] = (int)$category->category_id;
}
if(isset($category->category_parent_id)){
$ids[] = (int)$category->category_parent_id->id;
}
}
if(!empty($ids)){
$query = 'SELECT DISTINCT category_name, category_id';
$query .= ' FROM '.hikashop_table('category');
$query .= ' WHERE category_id IN ('.implode(',',$ids).')';
$database->setQuery($query);
$rows = $database->loadObjectList();
foreach($elements as $category){
if(isset($category->category_parent_id->id)){
$array = array();
foreach($rows as $row){
if($row->category_id == $category->category_parent_id->id){
$array[] = $row->category_name;
}
}
$category->parent_category = $this->separator($array,$data,$table);
$types['parent_category']->type = 'text';
$action['category']['parent_category'] = 'parent_category';
}
if(isset($category->category_id)){
$array = array();
foreach($rows as $row){
if($row->category_id == $category->category_id){
$array[] = $row->category_name;
}
}
$category->categories = $this->separator($array,$data,$table);
$types['categories']->type = 'text';
$action['category']['categories'] = 'categories';
}
}
}
break;
case 'order':
switch($table){
case 'address':
if(isset($action['address'])){
foreach($elements as $element){
$element->shipping_address = array();
$element->billing_address = array();
if(!isset($element->address)){continue;}
foreach($element->address as $address){
if($address->address_id === $element->order_shipping_address_id && $address->address_id === $element->order_billing_address_id){
$object = new stdClass();
foreach($address as $column=>$value){
if(isset($action['address'][$column])){continue;}
$shipping_column = 'shipping_'.$column;
$billing_column = 'billing_'.$column;
$action['shipping_address']->$shipping_column = $shipping_column;
$action['billing_address']->$billing_column = $billing_column;
$object->$shipping_column=$value;
$object->$billing_column=$value;
$types[$billing_column]->type = $types[$column]->type;
$types[$shipping_column]->type = $types[$column]->type;
}
$element->shipping_address[] = $object;
$element->billing_address[] = $object;
}else if($address->address_id === $element->order_shipping_address_id){
$object = new stdClass();
foreach($address as $column=>$value){
if(isset($action['address'][$column])){continue;}
$shipping_column = 'shipping_'.$column;
$action['shipping_address']->$shipping_column = $shipping_column;
$object->$shipping_column=$value;
$types[$shipping_column]->type = $types[$column]->type;
}
$element->shipping_address[] = $object;
}else if($address->address_id === $element->order_billing_address_id){
$object = new stdClass();
foreach($address as $column=>$value){
if(!isset($action['address'][$column])){continue;}
$billing_column = 'billing_'.$column;
$action['billing_address']->$billing_column = $billing_column;
$object->$billing_column=$value;
$types[$billing_column]->type = $types[$column]->type;
}
$element->billing_address[] = $object;
}
}
}
unset($action['address']);
}
break;
case 'order_product':
if(isset($action['order_product'])){
foreach($elements as $element){
$cpt = 1;
if(!isset($element->order_product)){continue;}
if(!isset($element->order_full_tax)){
$element->order_full_tax = new stdClass();
$element->order_full_tax->value = 0;
// $action['order']['order_full_tax'] = 'order_full_tax';
$types['order_full_tax'] = new stdClass();
$types['order_full_tax']->type = 'price';
}
if(!isset($element->order_shipping_tax->value)){
$tmpValue = (int)$element->order_shipping_tax;
$element->order_shipping_tax = new stdClass();
$element->order_shipping_tax->value = $tmpValue;
}
if(!isset($element->order_discount_tax->value)){
$tmpValue = (int)$element->order_discount_tax;
$element->order_discount_tax = new stdClass();
$element->order_discount_tax->value = $tmpValue;
}
$element->order_full_tax->value += (int)$element->order_shipping_tax->value - (int)$element->order_discount_tax->value;
$element->order_full_tax->currency = $element->order_currency_id;
foreach($element->order_product as $product){
if(isset($product->order_product_quantity) && isset($product->order_product_tax)){
$element->order_full_tax->value+=round($product->order_product_quantity*$product->order_product_tax,2);
}
$tablename = 'product'.$cpt;
$object = new stdClass();
foreach($product as $column=>$value){
if(!isset($action['order_product'][$column])){continue;}
$product_column = 'item'.$cpt.'_'.$column;
if(!isset($action[$tablename]))
$action[$tablename] = new stdClass();
$action[$tablename]->$product_column = $product_column;
$object->$product_column = $value;
$types[$product_column] = new stdClass();
if(isset($types[$column]->type)){
$types[$product_column]->type = $types[$column]->type;
}else{
$types[$product_column]->type = '';
}
}
$element->$tablename = array($object);
$cpt++;
}
}
unset($action['order_product']);
}
break;
case 'joomla_users':
if(isset($action['joomla_users'])){
foreach($elements as $element){
foreach($element->joomla_users as $joomla_users){
foreach($joomla_users as $column=>$value){
$types[$column] = new stdClass();
if(!isset($types[$column]->type)){
$types[$column]->type = '';
}
}
}
}
}
break;
}
break;
}
}