Exemplo n.º 1
0
 public function getData()
 {
     $data = parent::getData();
     $types_by_id = $data->getValues('type', 'id');
     unset($types_by_id['']);
     if (count($types_by_id) == 0) {
         return $data;
     }
     $base_component = fx::component($this->component_id);
     $base_type = $base_component['keyword'];
     $base_table = $base_component->getContentTable();
     $types = array();
     foreach ($types_by_id as $id => $type) {
         if ($type != $base_type) {
             if (!isset($types[$type])) {
                 $types[$type] = array();
             }
             $types[$type][] = $id;
         }
     }
     foreach ($types as $type => $ids) {
         if (!$type) {
             continue;
         }
         $type_tables = array_reverse(fx::data($type)->getTables());
         $missed_tables = array();
         foreach ($type_tables as $table) {
             if ($table == $base_table) {
                 break;
             }
             $missed_tables[] = $table;
         }
         $base_missed_table = array_shift($missed_tables);
         if (!$base_missed_table) {
             fx::log('empty base table');
             continue;
         }
         $q = "SELECT * FROM `{{" . $base_missed_table . "}}` \n";
         foreach ($missed_tables as $mt) {
             $q .= " INNER JOIN `{{" . $mt . '}}` ON `{{' . $mt . '}}`.id = `{{' . $base_missed_table . "}}`.id\n";
         }
         $q .= "WHERE `{{" . $base_missed_table . "}}`.id IN (" . join(", ", $ids) . ")";
         $extensions = fx::db()->getIndexedResults($q);
         foreach ($data as $data_index => $data_item) {
             if (isset($extensions[$data_item['id']])) {
                 $data[$data_index] = array_merge($data_item, $extensions[$data_item['id']]);
             }
         }
     }
     return $data;
 }