phpvms/app/Repositories/AirportRepository.php

59 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Repositories;
use App\Contracts\Repository;
use App\Models\Airport;
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
class AirportRepository extends Repository implements CacheableInterface
{
use CacheableRepository;
protected $fieldSearchable = [
2018-01-04 10:07:34 +08:00
'icao' => 'like',
'name' => 'like',
];
public function model()
{
return Airport::class;
}
/**
* Return the list of airports formatted for a select box
2018-08-27 00:40:04 +08:00
*
* @param bool $add_blank
* @param bool $only_hubs
2018-08-27 00:40:04 +08:00
*
* @return array
*/
public function selectBoxList($add_blank = false, $only_hubs = false): array
{
$retval = [];
$where = [];
if ($only_hubs) {
$where['hub'] = 1;
}
$items = $this->orderBy('icao', 'asc')->findWhere($where);
if ($add_blank) {
$retval[''] = '';
}
foreach ($items as $i) {
$s = $i->icao.' - '.$i->name;
if (!$only_hubs && $i->hub) {
$s .= ' (hub)';
}
$retval[$i->icao] = $s;
}
return $retval;
}
}