Advertisement:

Author Topic: Item extend data multilanguage  (Read 53 times)

Web-Media

  • Sr. Member
  • ****
  • Posts: 459
  • Web
Item extend data multilanguage
« on: September 05, 2019, 12:45:35 pm »
This function duplicate the amount of querries required by appending all languages s_title s_description into locale but .. in front end search only 1 is displayed  "curent_user_locale" .
Does any developer use all  $item[locale] front end at once ? Or any usage beside admin ?

Code: [Select]
public function extendData($items) { if( OC_ADMIN ) { $prefLocale = osc_current_admin_locale(); } else { $prefLocale = osc_current_user_locale(); } $results = array(); foreach ($items as $item) { $this->dao->select(); $this->dao->from(DB_TABLE_PREFIX.'t_item_description'); $this->dao->where(DB_TABLE_PREFIX.'t_item_description.fk_i_item_id', $item['pk_i_id']); $result = $this->dao->get(); $descriptions = $result->result(); $item['locale'] = array(); foreach ($descriptions as $desc) { if ($desc['s_title'] != "" || $desc['s_description'] != "") { $item['locale'][$desc['fk_c_locale_code']] = $desc; } } if (isset($item['locale'][$prefLocale])) { $item['s_title'] = $item['locale'][$prefLocale]['s_title']; $item['s_description'] = $item['locale'][$prefLocale]['s_description']; } else { $data = current($item['locale']); $item['s_title'] = $data['s_title']; $item['s_description'] = $data['s_description']; unset($data); } // populate locations and category_name $this->dao->select(DB_TABLE_PREFIX.'t_item_location.*, cd.s_name as s_category_name'); // select sum item_stats $this->dao->select('SUM(`s`.`i_num_views`) as `i_num_views`' ); $this->dao->select('SUM(`s`.`i_num_spam`) as `i_num_spam`' ); $this->dao->select('SUM(`s`.`i_num_bad_classified`) as `i_num_bad_classified`' ); $this->dao->select('SUM(`s`.`i_num_repeated`) as `i_num_repeated`' ); $this->dao->select('SUM(`s`.`i_num_offensive`) as `i_num_offensive`' ); $this->dao->select('SUM(`s`.`i_num_expired`) as `i_num_expired` ' ); $this->dao->select('SUM(`s`.`i_num_premium_views`) as `i_num_premium_views` ' ); $this->dao->from(DB_TABLE_PREFIX.'t_item_location'); $this->dao->from(DB_TABLE_PREFIX.'t_category_description as cd'); $this->dao->from(DB_TABLE_PREFIX.'t_item_stats as s'); $this->dao->where(DB_TABLE_PREFIX.'t_item_location.fk_i_item_id', $item['pk_i_id']);// $this->dao->where(DB_TABLE_PREFIX.'t_item_stats.fk_i_item_id', $item['pk_i_id']); $this->dao->where('s.fk_i_item_id', $item['pk_i_id']); $this->dao->where('cd.fk_i_category_id', $item['fk_i_category_id']); $this->dao->where('cd.fk_c_locale_code', $prefLocale); // group by item_id $this->dao->groupBy('fk_i_item_id'); $result = $this->dao->get(); $extraFields = $result->row(); foreach($extraFields as $key => $value) { $item[$key] = $value; } $results[] = $item; } return $results; }