You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
web-panel/app/ParkingLot.php

48 lines
1.4 KiB

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Google\Cloud\Firestore\FirestoreClient;
class ParkingLot extends Model
{
protected $fillable = [ 'firebase_id', 'stall_coordinates', 'reference_image', 'number_of_columns', 'name', 'ref_coords' ];
public function get_coordinates(){
return json_decode( $this->stall_coordinates );
}
public function set_coordinates( $coordinates ){
$this->stall_coordinates = json_encode( $coordinates );
$this->save();
}
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;
}
}