2017-06-12 00:36:16 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\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 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
|
|
|
*
|
2020-02-09 02:29:34 +08:00
|
|
|
* @param bool $add_blank
|
|
|
|
* @param bool $only_hubs
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
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-09-09 03:07:31 +08:00
|
|
|
$s = $i->icao.' - '.$i->name;
|
|
|
|
if (!$only_hubs && $i->hub) {
|
|
|
|
$s .= ' (hub)';
|
|
|
|
}
|
|
|
|
|
|
|
|
$retval[$i->icao] = $s;
|
2017-12-02 01:11:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
2017-06-12 00:36:16 +08:00
|
|
|
}
|