Guest User

Untitled

a guest
Apr 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. public function getBikes(array $criteriaList,array $sortFields,$start,$max) {
  2.         $sql ="SELECT ".
  3.                 "bike.id as bike_id,".
  4.                 "bike.serialnr as bike_serialnr,".
  5.                 "bike.active as bike_active,".
  6.                
  7.                 //A
  8.                 "bike.shop as shop_id,".
  9.                
  10.                 //B
  11.                 "shop.id as shop_id,".
  12.                 "shop.shop_name as shop_name,".
  13.                 "shop.street as shop_street,".
  14.                 "shop.house_nr as shop_house_nr,".
  15.                 "shop.postcode as shop_postcode,".
  16.                 "shop.city as shop_city,".
  17.                 "shop.region as shop_region,".
  18.                 "shop.country as shop_country,".
  19.                 "shop.email as shop_email,".
  20.                 "shop.telephone as shop_telephone,".
  21.                 "shop.open_date_info as shop_open_date_info ".
  22.                 //---
  23.                
  24.              "FROM bike ".
  25.  
  26.             //B
  27.             "INNER JOIN shop ON bike.shop = shop.id";
  28.        
  29.         $sql.= $this->criteriaToSql($criteriaList).$this->sortToSQL($sortFields);
  30.        
  31.         $sql.=" LIMIT $start,$max";
  32.         $result = $this->executeAndRetrieve($sql);
  33.         $bikes = array();
  34.         $shopMap = array();
  35.         foreach ($result as $row) {
  36.             $bike = new Bike();
  37.             $bike->id = $row['bike_id'];
  38.             $bike->serialnr =$row['bike_serialnr'];
  39.             $bike->active = $row['bike_active'];
  40.            
  41.             if(isset($shopMap[$row['shop_id']])) {
  42.                 $bike->shop = $bikeMap[$row['shop_id']];
  43.             }
  44.             else {
  45.                 //A
  46.                 $bike->shop = new ShopDao()->getShop($row['shop_id'])
  47.  
  48.                 //B
  49.                 $bike->shop  = $shop = new Shop();
  50.                 $shop->id =$row['shop_id'];
  51.                 $shop->name =$row['shop_name'];
  52.                 $shop->street =$row['shop_street'];
  53.                 $shop->houseNr =$row['shop_house_nr'];
  54.                 $shop->postcode =$row['shop_postcode'];
  55.                 $shop->city =$row['shop_city'];
  56.                 $shop->region =$row['shop_region'];
  57.                 $shop->country =$row['shop_country'];
  58.                 $shop->telephone =$row['shop_telephone'];
  59.                 $shop->email =$row['shop_email'];
  60.                 $shop->openDateInfo =$row['shop_open_date_info'];
  61.                 //---
  62.             }
  63.            
  64.             $bikes[] = $bike;
  65.         }
  66.         return $bikes;
  67.     }
Add Comment
Please, Sign In to add comment