Exemple #1
0
 /**
  * Return array of available brands by site id
  * @return json
  * @author Ruslan Ushakov
  */
 public function getAvailableBrandsForSite()
 {
     $this->load->model('ranking_model');
     $page = (int) $this->input->post('page');
     $select2_search_term = $this->input->post('select2_search_term');
     $site_id = $this->input->post('site_id');
     $limit = $this->input->post('limit');
     $offset = $this->input->post('offset');
     $term = $this->input->post('term');
     $compare_site_id = (int) $this->input->post('compare_site_id');
     $selected_ids = $this->input->post('selected_brands');
     $scroll = $this->input->post('scroll');
     $selected_groups_ids = array();
     $selected_brands = array();
     if (!empty($selected_ids)) {
         foreach ($selected_ids as $id) {
             if (strpos($id, 'g') !== false) {
                 $selected_groups_ids[] = (int) substr($id, 1);
             } else {
                 if (!in_array($id, $selected_brands)) {
                     $selected_brands[] = $id;
                 }
             }
         }
     }
     if (!empty($compare_site_id)) {
         $site_id = array($site_id, $compare_site_id);
     }
     if (!$scroll || $scroll == 'false') {
         if (!empty($selected_groups_ids)) {
             $selected_groups = $this->ranking_model->getAvailableRankingBrandGroups($site_id, $selected_groups_ids);
         } else {
             $selected_groups = array();
         }
         $brands_groups = $this->ranking_model->getAvailableRankingBrandGroups($site_id, 0, $selected_groups_ids);
         $brands_groups = array_merge($selected_groups, $brands_groups);
     } else {
         $brands_groups = array();
     }
     if (!empty($selected_brands) && (!$scroll || $scroll == 'false')) {
         $selected = $this->ranking_model->getAvailableBrandsForSite($site_id, 1000, 0, '', array(), $selected_brands);
     } else {
         $selected = array();
     }
     if ($page) {
         $data = $this->ranking_model->getAvailableBrandsForSiteSearchBox($site_id, $page, $select2_search_term);
     } else {
         $data = $this->ranking_model->getAvailableBrandsForSite($site_id, $limit, $offset, $term, $selected_brands);
         $data = array_merge($selected, $data);
     }
     if (!$page) {
         $data = array_merge($brands_groups, $data);
     }
     //remove slashes from brand name like "That\'s My Ticket"
     if (!empty($data)) {
         foreach ($data as &$brand) {
             $brand->name = ucwords(strtolower(strip_slashes($brand->name)));
             if (isset($brand->image_url)) {
                 unset($brand->image_url);
             }
         }
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($data));
 }