Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.69 KB | None | 0 0
  1. <?php
  2. namespace App\Repositories;
  3.  
  4. use Illuminate\Support\Facades\DB;
  5.  
  6. class FilterRepo
  7. {
  8.     public function dataFilters(){
  9.  
  10.         $mainDistricts = array(
  11.             222 => 'Riverndale', 159 => 'Howard Beach', 200 => 'Rockway',
  12.  
  13.         );
  14.  
  15.         /*$filters_data = DB::table('filters')
  16.             ->leftjoin('filters_data', 'filters.name', '=', 'filters_data.filter_id')
  17.             ->get();*/
  18.  
  19.         $filters_data = DB::select("select filters.*, filters_data.*, if (filters.name in ('sub_districts'), left(filters_data.value, 10), '0') as sort from filters left join filters_data on filters.name = filters_data.filter_id order by filters.id, sort, filters_data.filter_data_id");
  20.  
  21.         $filters = array();
  22.         $id = array();
  23.         $result = array();
  24.         $districts = array();
  25.         $types = array();
  26.  
  27.         $subBoro = array();
  28.         $counts = array();
  29.  
  30.         foreach($filters_data as $key=>$item){
  31.             if ($item->filter_id == 'type'){
  32.                 $types[$item->filter_data_id]= $item;
  33.             }
  34.  
  35.             if ($item->filter_id == 'filters'){
  36.                 $filters[$item->filter_data_id]= $item;
  37.             }
  38.             $subDistrictsCol = array('left' => array(), 'right' => array(), 'center' => array());
  39.             if ($item->filter_id == 'district' && $item->filter_data_id){
  40.                 $item->subdistritcs = array();
  41.                 $item->subdistritcsCol = $subDistrictsCol;
  42.                 $districts[$item->filter_data_id]= $item;
  43.             }
  44.  
  45.             if ($item->filter_id == 'sub_districts'){
  46.                 if ($item->parent_id!=0){
  47.                     if (isset($counts[$item->parent_id])){
  48.                         $counts[$item->parent_id] =  $counts[$item->parent_id]+1;
  49.                     }else {
  50.                         $counts[$item->parent_id] = 1;
  51.                     }
  52.  
  53.                     if ($counts[$item->parent_id]%3==1){
  54.                         $item->rigth = false;
  55.                         $item->left = true;
  56.                         $item->center = false;
  57.                     }elseif ($counts[$item->parent_id]%3==2){
  58.                         $item->rigth = false;
  59.                         $item->left = false;
  60.                         $item->center = true;
  61.                     }else{
  62.                         $item->rigth = true;
  63.                         $item->left = false;
  64.                         $item->center = false;
  65.                     }
  66.                     $item->mainboro = false;
  67.  
  68.                     if (array_key_exists($item->filter_data_id,$mainDistricts)){
  69.                         $item->mainboro = true;
  70.                         $subBoro[$item->district_id] = array();
  71.                     }
  72.  
  73.                     if ($item->district_id && !array_key_exists($item->filter_data_id,$mainDistricts) && $item->parent_id != 1)
  74.                     {
  75.                         $subBoro[$item->district_id][] = $item;
  76.                     }
  77.                     else
  78.                     {
  79.                         if ($item->parent_id == 1){
  80.                             $districts[$item->parent_id]->subdistritcs[$item->district_id][] = $item;
  81.                         }else {
  82.                             $districts[$item->parent_id]->subdistritcs[] = $item;
  83.                         }
  84.                     }
  85.                 }
  86.             }
  87.  
  88.             $data = (array) $item;
  89.  
  90.             if (in_array($data['id'], $id)){
  91.  
  92.                 $result[$data['id']]['sub_filters'][] = [
  93.  
  94.                     'value'=>$data['value'],
  95.                     'parent_id'=>$data['parent_id']
  96.                 ];
  97.             } else {
  98.  
  99.                 $result[$data['id']] = [
  100.                     'id' => $data['id'],
  101.                     'name' => $data['name'],
  102.                     'label' => $data['label'],
  103.                     'general' => $data['general'],
  104.                     'sub_filters' => [[
  105.                         'value'=>$data['value'],
  106.                         'parent_id'=>$data['parent_id']
  107.                     ]]];
  108.                 $id[] = $data['id'];
  109.             }
  110.         }
  111.  
  112.         $subBorougths = $subBoro;
  113.  
  114.         return compact('result','districts', 'types', 'filters','subBorougths');
  115.     }
  116.  
  117.     public function prepareSaveListingFilters($types, $district, $filters){
  118.  
  119. /*print_r($types); echo "<br>";
  120.  
  121. print_r($district);
  122.  
  123. print_r($filters);
  124.  
  125. echo DB::table('filters_data')
  126. ->where('filter_data_id',$types)
  127. ->orWhere('filter_data_id', $district)
  128. ->orWhereIn('filter_data_id', $filters)
  129. ->toSql();
  130. exit;*/
  131.  
  132.         $data = DB::table('filters_data')
  133.             ->where('filter_data_id',$types)
  134.             ->orWhere('filter_data_id', $district)
  135.             ->orWhereIn('filter_data_id', $filters)
  136.             ->get();
  137.  
  138.         $amenities_list = array();
  139.         $features_list = array();
  140.         foreach ($data as $item){
  141.             if($item->filter_id == 'type'){
  142.                 $type = $item->value;
  143.             }
  144.             if($item->filter_id == 'filters' && $item->parent_id == 6){
  145.                 $features_list[] = $item->value;
  146.             }
  147.             if($item->filter_id == 'filters' && $item->parent_id == 0){
  148.                 $amenities_list[] = $item->value;
  149.             }
  150.             if($item->filter_id == 'sub_districts'){
  151.                 $neighborhood = $item->value;
  152.             }
  153.         }
  154.  
  155.         return compact('type', 'features_list', 'amenities_list', 'neighborhood');
  156.     }
  157.  
  158.     public function prepareEditListingData($amenities, $futures)
  159.     {
  160.         return DB::table('filters_data')
  161.             ->select('filter_data_id')
  162.             ->orWhereIn('value', $amenities)
  163.             ->orWhereIn('value', $futures)
  164.             ->get();
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement