Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getBikes(array $criteriaList,array $sortFields,$start,$max) {
- $sql ="SELECT ".
- "bike.id as bike_id,".
- "bike.serialnr as bike_serialnr,".
- "bike.active as bike_active,".
- //A
- "bike.shop as shop_id,".
- //B
- "shop.id as shop_id,".
- "shop.shop_name as shop_name,".
- "shop.street as shop_street,".
- "shop.house_nr as shop_house_nr,".
- "shop.postcode as shop_postcode,".
- "shop.city as shop_city,".
- "shop.region as shop_region,".
- "shop.country as shop_country,".
- "shop.email as shop_email,".
- "shop.telephone as shop_telephone,".
- "shop.open_date_info as shop_open_date_info ".
- //---
- "FROM bike ".
- //B
- "INNER JOIN shop ON bike.shop = shop.id";
- $sql.= $this->criteriaToSql($criteriaList).$this->sortToSQL($sortFields);
- $sql.=" LIMIT $start,$max";
- $result = $this->executeAndRetrieve($sql);
- $bikes = array();
- $shopMap = array();
- foreach ($result as $row) {
- $bike = new Bike();
- $bike->id = $row['bike_id'];
- $bike->serialnr =$row['bike_serialnr'];
- $bike->active = $row['bike_active'];
- if(isset($shopMap[$row['shop_id']])) {
- $bike->shop = $bikeMap[$row['shop_id']];
- }
- else {
- //A
- $bike->shop = new ShopDao()->getShop($row['shop_id'])
- //B
- $bike->shop = $shop = new Shop();
- $shop->id =$row['shop_id'];
- $shop->name =$row['shop_name'];
- $shop->street =$row['shop_street'];
- $shop->houseNr =$row['shop_house_nr'];
- $shop->postcode =$row['shop_postcode'];
- $shop->city =$row['shop_city'];
- $shop->region =$row['shop_region'];
- $shop->country =$row['shop_country'];
- $shop->telephone =$row['shop_telephone'];
- $shop->email =$row['shop_email'];
- $shop->openDateInfo =$row['shop_open_date_info'];
- //---
- }
- $bikes[] = $bike;
- }
- return $bikes;
- }
Add Comment
Please, Sign In to add comment