Esempio n. 1
0
 /**
  *
  */
 public function __construct(Client $client, array $vehicle)
 {
     $this->client = $client;
     $this->id = $vehicle['id'];
     $this->url = $vehicle['url'];
     $this->name = $vehicle['name'];
     $this->image = $vehicle['image'];
     if (isset($vehicle['trend'])) {
         $input = $client->createTrendInputConversion();
         foreach ($vehicle['trend'] as $fuelup) {
             $this->trend[] = FuelUp::createFromTrend($this, $fuelup, $input);
         }
         // Sort by date DESC
         usort($this->trend, array(FuelUp::class, 'dateCmp'));
     }
 }
Esempio n. 2
0
 /**
  *
  */
 public function getFuelUpsWithIds(Vehicle $vehicle, $limit = 15)
 {
     $query = http_build_query(array('iDisplayStart' => 0, 'iDisplayLength' => $limit, 'sSortDir_0' => 'desc', 'usercar_id' => $vehicle->id));
     $response = $this->_get('ajax/fuelup-log?' . $query);
     if ($response->code == 200) {
         if ($response->response) {
             $fuelups = array();
             foreach ($response->response['aaData'] as $fuelup) {
                 if (preg_match('#fuelups/(\\d+)/edit#', $fuelup[0], $match)) {
                     $fuelup = array('id' => $match[1], 'usercar_id' => $vehicle->id, 'fuelup_date' => $fuelup[2][0], 'miles_last_fuelup' => $fuelup[3][0], 'amount' => $fuelup[4][0]);
                     $fuelups[$fuelup['id']] = FuelUp::createFromDetail($vehicle, $fuelup);
                 }
             }
             // Sort by date DESC
             uasort($fuelups, array(FuelUp::class, 'dateCmp'));
             return $fuelups;
         }
     }
     return array();
 }