2019-02-09 18:06:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-02-10 06:09:56 +00:00
|
|
|
use Google\Cloud\Firestore\FirestoreClient;
|
2019-02-09 18:06:52 +00:00
|
|
|
|
|
|
|
class ParkingLot extends Model
|
|
|
|
{
|
2019-02-10 06:09:56 +00:00
|
|
|
protected $fillable = [ 'firebase_id', 'stall_coordinates', 'reference_image', 'number_of_columns', 'name', 'ref_coords' ];
|
2019-02-09 18:06:52 +00:00
|
|
|
|
|
|
|
public function get_coordinates(){
|
|
|
|
return json_decode( $this->stall_coordinates );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set_coordinates( $coordinates ){
|
|
|
|
$this->stall_coordinates = json_encode( $coordinates );
|
|
|
|
$this->save();
|
|
|
|
}
|
2019-02-10 06:09:56 +00:00
|
|
|
|
|
|
|
public static function getFB(){
|
|
|
|
$db = new FirestoreClient();
|
|
|
|
|
|
|
|
$documents = $db->collection('lots')->documents();
|
|
|
|
$docarr = [];
|
|
|
|
foreach( $documents as $doc ){
|
|
|
|
if ( $doc->exists() ){
|
|
|
|
array_push($docarr, ['id' => $doc->id(), 'data'=>$db->collection('lots')->document($doc->id())->collection('info')->document('lotInfo')->snapshot()->data()]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return $docarr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getFBbyID($id){
|
|
|
|
$db = new FirestoreClient();
|
|
|
|
|
|
|
|
$documents = $db->collection('lots')->documents();
|
|
|
|
foreach( $documents as $doc ){
|
|
|
|
if ( $doc->exists() && $doc->id() === (string) "Lot".$id ){
|
|
|
|
return ['id' => $doc->id(), 'data'=>$db->collection('lots')->document($doc->id())->collection('info')->document('lotInfo')->snapshot()->data()];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-02-09 18:06:52 +00:00
|
|
|
}
|