Пример #1
0
 /**
  * Get search terms groups for export
  * @return array search terms groups array with search terms and search terms groups - sites relations
  */
 public function get_search_terms_groups_for_export(&$entites = null)
 {
     $this->load->model('ranking_model');
     !is_null($entites) && ($entites = array('search_terms' => array(), 'search_terms_groups' => array(), 'sites' => array(), 'groups_sites' => array()));
     $search_terms_groups = array();
     $this->ranking_model->table = $this->ranking_model->tables['search_terms_groups'];
     foreach ($this->ranking_model->getRecords() as $search_terms_group) {
         $search_terms_group = (array) $search_terms_group;
         $search_terms_group['search_terms'] = array();
         $search_terms_group['sites'] = array();
         $search_terms_groups[$search_terms_group['id']] = array_diff_key($search_terms_group, array_flip(array('id')));
         $entites && ($entites['search_terms_groups'][] = $search_terms_group);
     }
     $this->ranking_model->table = $this->ranking_model->tables['search_terms'];
     foreach ($this->ranking_model->getRecords() as $search_term) {
         $search_term = (array) $search_term;
         if (isset($search_terms_groups[$search_term['group_id']])) {
             $search_terms_groups[$search_term['group_id']]['search_terms'][] = $search_term['title'];
             $entites && ($entites['search_terms'][] = array_merge($search_term, array('group_name' => $search_terms_groups[$search_term['group_id']]['name'])));
         }
     }
     $this->ranking_model->table = $this->ranking_model->tables['sites'];
     $sites = array();
     foreach ($this->ranking_model->getRecords() as $site) {
         $site = (array) $site;
         $sites[$site['id']] = $site;
     }
     $entites && ($entites['sites'] = $sites);
     $this->ranking_model->table = $this->ranking_model->tables['groups_sites'];
     foreach ($this->ranking_model->getRecords() as $groups_sites) {
         $groups_sites = (array) $groups_sites;
         if (isset($search_terms_groups[$groups_sites['group_id']], $sites[$groups_sites['site_id']])) {
             $search_term_group_site = array_intersect_key($sites[$groups_sites['site_id']], array_flip(array('name', 'url')));
             $search_terms_groups[$groups_sites['group_id']]['sites'][] = $search_term_group_site;
         }
         $entites && ($entites['groups_sites'][] = $groups_sites);
     }
     $results = array();
     foreach ($search_terms_groups as $search_terms_group) {
         $results[$search_terms_group['name']] = array_diff_key($search_terms_group, array_flip(array('name')));
     }
     return $results;
 }