phpvms/app/Repositories/AirportRepository.php

62 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Repositories;
use App\Interfaces\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
*/
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 mixed $add_blank
* @param mixed $only_hubs
*
* @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;
}
}