Example #1
0
 /**
  * add brand to the group
  * @return json
  * @author Ruslan Ushakov
  */
 function add_brand_to_group()
 {
     $this->load->model('ranking_model');
     $group_id = $this->input->post('group_id');
     $added_brand = $this->input->post('added_brand');
     $new_brand = $this->input->post('new_brand');
     $new_brand_id = 0;
     if (!empty($group_id) && !empty($added_brand)) {
         $this->ranking_model->addBrandToGroup($group_id, $added_brand);
     }
     if (!empty($group_id) && !empty($new_brand)) {
         $new_brand = trim($new_brand);
         $brand = $this->ranking_model->getBrandByName($new_brand);
         if (!empty($brand)) {
             $this->ranking_model->addBrandToGroup($group_id, $brand->id);
             $new_brand_id = $brand->id;
         } else {
             $new_brand_id = $this->ranking_model->selectOrInsertIdBrands($new_brand, '');
             $this->ranking_model->addBrandToGroup($group_id, $new_brand_id);
         }
     }
     $list = $this->ranking_model->getRankingBrandsByGroupId($group_id);
     $this->output->set_content_type('application/json')->set_output(json_encode(array('data' => $list, 'new_brand_id' => $new_brand_id)));
 }