2017-06-12 00:36:16 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Repository;
|
2017-06-12 00:36:16 +08:00
|
|
|
use App\Models\Airport;
|
2017-12-01 10:28:45 +08:00
|
|
|
use Prettus\Repository\Contracts\CacheableInterface;
|
2018-02-21 12:33:09 +08:00
|
|
|
use Prettus\Repository\Traits\CacheableRepository;
|
2017-08-25 02:03:10 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class AirportRepository
|
|
|
|
*/
|
|
|
|
class AirportRepository extends Repository implements CacheableInterface
|
2017-06-12 00:36:16 +08:00
|
|
|
{
|
2017-12-01 10:28:45 +08:00
|
|
|
use CacheableRepository;
|
|
|
|
|
2017-06-12 00:36:16 +08:00
|
|
|
protected $fieldSearchable = [
|
2018-01-04 10:07:34 +08:00
|
|
|
'icao' => 'like',
|
2017-12-02 00:53:33 +08:00
|
|
|
'name' => 'like',
|
2017-06-12 00:36:16 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Airport::class;
|
|
|
|
}
|
2017-12-02 01:11:03 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the list of airports formatted for a select box
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @param mixed $add_blank
|
|
|
|
* @param mixed $only_hubs
|
|
|
|
*
|
2017-12-02 01:11:03 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function selectBoxList($add_blank = false, $only_hubs = false): array
|
2017-12-02 01:11:03 +08:00
|
|
|
{
|
|
|
|
$retval = [];
|
2017-12-31 23:42:31 +08:00
|
|
|
$where = [];
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($only_hubs) {
|
2017-12-31 23:42:31 +08:00
|
|
|
$where['hub'] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = $this->orderBy('icao', 'asc')->findWhere($where);
|
2017-12-05 02:05:31 +08:00
|
|
|
|
|
|
|
if ($add_blank) {
|
|
|
|
$retval[''] = '';
|
|
|
|
}
|
|
|
|
|
2017-12-02 01:11:03 +08:00
|
|
|
foreach ($items as $i) {
|
2018-03-20 09:50:40 +08:00
|
|
|
$retval[$i->icao] = $i->icao.' - '.$i->name;
|
2017-12-02 01:11:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|