Fix formatting and interfaces in nearly every file
This commit is contained in:
@@ -2,15 +2,21 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Acars;
|
||||
use App\Models\Enums\AcarsType;
|
||||
use App\Models\Enums\PirepState;
|
||||
use App\Models\Pirep;
|
||||
|
||||
class AcarsRepository extends BaseRepository //implements CacheableInterface
|
||||
/**
|
||||
* Class AcarsRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class AcarsRepository extends Repository
|
||||
{
|
||||
//use CacheableRepository;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return Acars::class;
|
||||
@@ -25,10 +31,10 @@ class AcarsRepository extends BaseRepository //implements CacheableInterface
|
||||
{
|
||||
$where = [
|
||||
'pirep_id' => $pirep_id,
|
||||
'type' => $type,
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
switch($type) {
|
||||
switch ($type) {
|
||||
default:
|
||||
case AcarsType::FLIGHT_PATH:
|
||||
case AcarsType::LOG:
|
||||
@@ -50,8 +56,8 @@ class AcarsRepository extends BaseRepository //implements CacheableInterface
|
||||
public function getPositions()
|
||||
{
|
||||
return Pirep::with(['airline', 'position'])
|
||||
->where(['state' => PirepState::IN_PROGRESS])
|
||||
->get();
|
||||
->where(['state' => PirepState::IN_PROGRESS])
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,16 +2,21 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Aircraft;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
class AircraftRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class AircraftRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class AircraftRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
protected $fieldSearchable = [
|
||||
'name' => 'like',
|
||||
'name' => 'like',
|
||||
'registration' => 'like',
|
||||
'active',
|
||||
];
|
||||
@@ -31,7 +36,7 @@ class AircraftRepository extends BaseRepository implements CacheableInterface
|
||||
$items = $this->all();
|
||||
|
||||
foreach ($items as $i) {
|
||||
$retval[$i->id] = $i->subfleet->name . ' - ' . $i->name . ' (' . $i->registration . ')';
|
||||
$retval[$i->id] = $i->subfleet->name.' - '.$i->name.' ('.$i->registration.')';
|
||||
}
|
||||
|
||||
return $retval;
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Airline;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
|
||||
class AirlineRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class AirlineRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class AirlineRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -25,12 +29,12 @@ class AirlineRepository extends BaseRepository implements CacheableInterface
|
||||
* Return the list of airline formatted for a select box
|
||||
* @return array
|
||||
*/
|
||||
public function selectBoxList($add_blank=false): array
|
||||
public function selectBoxList($add_blank = false): array
|
||||
{
|
||||
$retval = [];
|
||||
$items = $this->all();
|
||||
|
||||
if($add_blank) {
|
||||
if ($add_blank) {
|
||||
$retval[''] = '';
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Airport;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
|
||||
class AirportRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class AirportRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class AirportRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -25,12 +29,12 @@ class AirportRepository extends BaseRepository implements CacheableInterface
|
||||
* Return the list of airports formatted for a select box
|
||||
* @return array
|
||||
*/
|
||||
public function selectBoxList($add_blank=false, $only_hubs=false): array
|
||||
public function selectBoxList($add_blank = false, $only_hubs = false): array
|
||||
{
|
||||
$retval = [];
|
||||
$where = [];
|
||||
|
||||
if($only_hubs) {
|
||||
if ($only_hubs) {
|
||||
$where['hub'] = 1;
|
||||
}
|
||||
|
||||
@@ -41,7 +45,7 @@ class AirportRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
foreach ($items as $i) {
|
||||
$retval[$i->icao] = $i->icao . ' - ' . $i->name;
|
||||
$retval[$i->icao] = $i->icao.' - '.$i->name;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Award;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
class AwardRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class AwardRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class AwardRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -19,7 +24,8 @@ class AwardRepository extends BaseRepository implements CacheableInterface
|
||||
return Award::class;
|
||||
}
|
||||
|
||||
public function findByTitle($title) {
|
||||
public function findByTitle($title)
|
||||
{
|
||||
return $this->findByField('title', $title)->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepository {
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param array $columns
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function findWithoutFail($id, $columns = ['*'])
|
||||
{
|
||||
try {
|
||||
return $this->find($id, $columns);
|
||||
} catch (\Exception $e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $values
|
||||
* @return bool
|
||||
*/
|
||||
public function validate($values)
|
||||
{
|
||||
$validator = Validator::make(
|
||||
$values,
|
||||
$this->model()->rules
|
||||
);
|
||||
|
||||
if($validator->fails()) {
|
||||
return $validator->messages();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return N most recent items, sorted by created_at
|
||||
* @param int $count
|
||||
* @param string $sort_by created_at (default) or updated_at
|
||||
* @return mixed
|
||||
*/
|
||||
public function recent($count = null, $sort_by = 'created_at')
|
||||
{
|
||||
return $this->orderBy($sort_by, 'desc')->paginate($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find records with a WHERE clause but also sort them
|
||||
* @param $where
|
||||
* @param $sort_by
|
||||
* @param $order_by
|
||||
* @return $this
|
||||
*/
|
||||
public function whereOrder($where, $sort_by, $order_by='asc')
|
||||
{
|
||||
return $this->scopeQuery(function($query) use ($where, $sort_by, $order_by) {
|
||||
$q = $query->where($where);
|
||||
# See if there are multi-column sorts
|
||||
if(\is_array($sort_by)) {
|
||||
foreach($sort_by as $key => $sort) {
|
||||
$q = $q->orderBy($key, $sort);
|
||||
}
|
||||
} else {
|
||||
$q = $q->orderBy($sort_by, $order_by);
|
||||
}
|
||||
|
||||
return $q;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -24,19 +24,18 @@ class WhereCriteria implements CriteriaInterface
|
||||
$this->where = $where;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply criteria in query repository
|
||||
*
|
||||
* @param Builder|Model $model
|
||||
* @param RepositoryInterface $repository
|
||||
* @param RepositoryInterface $repository
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function apply($model, RepositoryInterface $repository)
|
||||
{
|
||||
if($this->where) {
|
||||
if ($this->where) {
|
||||
$model = $model->where($this->where);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Expense;
|
||||
use Illuminate\Support\Collection;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
@@ -11,7 +12,7 @@ use Prettus\Repository\Traits\CacheableRepository;
|
||||
* Class ExpenseRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class ExpenseRepository extends BaseRepository implements CacheableInterface
|
||||
class ExpenseRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -23,28 +24,27 @@ class ExpenseRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Get all of the expenses for a given type, and also
|
||||
* include expenses for a given airline ID
|
||||
* @param $type
|
||||
* @param $type
|
||||
* @param null $airline_id
|
||||
* @param null $ref_class
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllForType($type, $airline_id=null, $ref_class=null)
|
||||
public function getAllForType($type, $airline_id = null, $ref_class = null)
|
||||
{
|
||||
$where = [
|
||||
'type' => $type,
|
||||
['airline_id', '=', null]
|
||||
];
|
||||
|
||||
if($ref_class) {
|
||||
if ($ref_class) {
|
||||
$where['ref_class'] = $ref_class;
|
||||
}
|
||||
|
||||
$expenses = $this->findWhere($where);
|
||||
|
||||
if($airline_id) {
|
||||
|
||||
if ($airline_id) {
|
||||
$where = [
|
||||
'type' => $type,
|
||||
'type' => $type,
|
||||
'airline_id' => $airline_id
|
||||
];
|
||||
|
||||
|
||||
@@ -2,17 +2,22 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Fare;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
class FareRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class FareRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class FareRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
protected $fieldSearchable = [
|
||||
'code' => 'like',
|
||||
'name' => 'like',
|
||||
'code' => 'like',
|
||||
'name' => 'like',
|
||||
'notes' => 'like',
|
||||
];
|
||||
|
||||
@@ -21,7 +26,8 @@ class FareRepository extends BaseRepository implements CacheableInterface
|
||||
return Fare::class;
|
||||
}
|
||||
|
||||
public function findByCode($code) {
|
||||
public function findByCode($code)
|
||||
{
|
||||
return $this->findByField('code', $code)->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Flight;
|
||||
use App\Repositories\Criteria\WhereCriteria;
|
||||
use Illuminate\Http\Request;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
class FlightRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class FlightRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class FlightRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -16,10 +21,10 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
||||
'arr_airport_id',
|
||||
'dpt_airport_id',
|
||||
'flight_number' => 'like',
|
||||
'flight_code' => 'like',
|
||||
'flight_leg' => 'like',
|
||||
'route' => 'like',
|
||||
'notes' => 'like',
|
||||
'flight_code' => 'like',
|
||||
'flight_leg' => 'like',
|
||||
'route' => 'like',
|
||||
'notes' => 'like',
|
||||
];
|
||||
|
||||
public function model()
|
||||
@@ -29,25 +34,25 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
/**
|
||||
* Find a flight based on the given criterea
|
||||
* @param $airline_id
|
||||
* @param $flight_num
|
||||
* @param $airline_id
|
||||
* @param $flight_num
|
||||
* @param null $route_code
|
||||
* @param null $route_leg
|
||||
* @return mixed
|
||||
*/
|
||||
public function findFlight($airline_id, $flight_num, $route_code=null, $route_leg=null)
|
||||
public function findFlight($airline_id, $flight_num, $route_code = null, $route_leg = null)
|
||||
{
|
||||
$where = [
|
||||
'airline_id' => $airline_id,
|
||||
'airline_id' => $airline_id,
|
||||
'flight_number' => $flight_num,
|
||||
'active' => true,
|
||||
'active' => true,
|
||||
];
|
||||
|
||||
if(filled($route_code)) {
|
||||
if (filled($route_code)) {
|
||||
$where['route_code'] = $route_code;
|
||||
}
|
||||
|
||||
if(filled($route_leg)) {
|
||||
if (filled($route_leg)) {
|
||||
$where['route_leg'] = $route_leg;
|
||||
}
|
||||
|
||||
@@ -57,15 +62,15 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Create the search criteria and return this with the stuff pushed
|
||||
* @param Request $request
|
||||
* @param bool $only_active
|
||||
* @param bool $only_active
|
||||
* @return $this
|
||||
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
||||
*/
|
||||
public function searchCriteria(Request $request, bool $only_active=true)
|
||||
public function searchCriteria(Request $request, bool $only_active = true)
|
||||
{
|
||||
$where = [];
|
||||
|
||||
if($only_active === true) {
|
||||
if ($only_active === true) {
|
||||
$where['active'] = $only_active;
|
||||
}
|
||||
|
||||
@@ -77,7 +82,7 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
||||
$where['airline_id'] = $request->airline_id;
|
||||
}
|
||||
|
||||
if($request->filled('flight_number')) {
|
||||
if ($request->filled('flight_number')) {
|
||||
$where['flight_number'] = $request->flight_number;
|
||||
}
|
||||
|
||||
@@ -94,6 +99,7 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
$this->pushCriteria(new WhereCriteria($request, $where));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Journal;
|
||||
use App\Models\JournalTransaction;
|
||||
use App\Support\Money;
|
||||
@@ -15,7 +16,7 @@ use Prettus\Validator\Exceptions\ValidatorException;
|
||||
* Class JournalRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
class JournalRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -32,9 +33,9 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
* @param Carbon $date
|
||||
* @return string
|
||||
*/
|
||||
public function formatPostDate(Carbon $date=null)
|
||||
public function formatPostDate(Carbon $date = null)
|
||||
{
|
||||
if(!$date) {
|
||||
if (!$date) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -69,13 +70,13 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
* on the transaction itself. A cron will run to reconcile the journal
|
||||
* balance nightly, since they're not atomic operations
|
||||
*
|
||||
* @param Journal $journal
|
||||
* @param Money|null $credit Amount to credit
|
||||
* @param Money|null $debit Amount to debit
|
||||
* @param Model|null $reference The object this is a reference to
|
||||
* @param string|null $memo Memo for this transaction
|
||||
* @param string|null $post_date Date of the posting
|
||||
* @param string|null $transaction_group
|
||||
* @param Journal $journal
|
||||
* @param Money|null $credit Amount to credit
|
||||
* @param Money|null $debit Amount to debit
|
||||
* @param Model|null $reference The object this is a reference to
|
||||
* @param string|null $memo Memo for this transaction
|
||||
* @param string|null $post_date Date of the posting
|
||||
* @param string|null $transaction_group
|
||||
* @param array|string|null $tags
|
||||
* @return mixed
|
||||
* @throws ValidatorException
|
||||
@@ -89,25 +90,26 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
$post_date = null,
|
||||
$transaction_group = null,
|
||||
$tags = null
|
||||
) {
|
||||
)
|
||||
{
|
||||
# tags can be passed in a list
|
||||
if ($tags && \is_array($tags)) {
|
||||
$tags = implode(',', $tags);
|
||||
}
|
||||
|
||||
if(!$post_date) {
|
||||
if (!$post_date) {
|
||||
$post_date = Carbon::now('UTC');
|
||||
}
|
||||
|
||||
$attrs = [
|
||||
'journal_id' => $journal->id,
|
||||
'credit' => $credit ? $credit->getAmount() : null,
|
||||
'debit' => $debit ? $debit->getAmount() : null,
|
||||
'currency' => config('phpvms.currency'),
|
||||
'memo' => $memo,
|
||||
'post_date' => $post_date,
|
||||
'journal_id' => $journal->id,
|
||||
'credit' => $credit ? $credit->getAmount() : null,
|
||||
'debit' => $debit ? $debit->getAmount() : null,
|
||||
'currency' => config('phpvms.currency'),
|
||||
'memo' => $memo,
|
||||
'post_date' => $post_date,
|
||||
'transaction_group' => $transaction_group,
|
||||
'tags' => $tags
|
||||
'tags' => $tags
|
||||
];
|
||||
|
||||
if ($reference !== null) {
|
||||
@@ -127,17 +129,17 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Journal $journal
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $date
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getBalance(Journal $journal=null, Carbon $date=null)
|
||||
public function getBalance(Journal $journal = null, Carbon $date = null)
|
||||
{
|
||||
$journal->refresh();
|
||||
|
||||
if(!$date) {
|
||||
if (!$date) {
|
||||
$date = Carbon::now();
|
||||
}
|
||||
|
||||
@@ -149,19 +151,19 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
/**
|
||||
* Get the credit only balance of the journal based on a given date.
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $start_date
|
||||
* @param null $transaction_group
|
||||
* @param null $transaction_group
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getCreditBalanceBetween(
|
||||
Carbon $date,
|
||||
Journal $journal=null,
|
||||
Carbon $start_date=null,
|
||||
$transaction_group=null
|
||||
Journal $journal = null,
|
||||
Carbon $start_date = null,
|
||||
$transaction_group = null
|
||||
): Money
|
||||
{
|
||||
$where = [];
|
||||
@@ -187,10 +189,10 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $start_date
|
||||
* @param null $transaction_group
|
||||
* @param null $transaction_group
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
@@ -226,8 +228,8 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
/**
|
||||
* Return all transactions for a given object
|
||||
* @param $object
|
||||
* @param null $journal
|
||||
* @param $object
|
||||
* @param null $journal
|
||||
* @param Carbon|null $date
|
||||
* @return array
|
||||
* @throws \UnexpectedValueException
|
||||
@@ -236,7 +238,7 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
public function getAllForObject($object, $journal = null, Carbon $date = null)
|
||||
{
|
||||
$where = [
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class_id' => $object->id,
|
||||
];
|
||||
|
||||
@@ -251,26 +253,26 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
$transactions = $this->whereOrder($where, [
|
||||
'credit' => 'desc',
|
||||
'debit' => 'desc'
|
||||
'debit' => 'desc'
|
||||
])->get();
|
||||
|
||||
return [
|
||||
'credits' => new Money($transactions->sum('credit')),
|
||||
'debits' => new Money($transactions->sum('debit')),
|
||||
'credits' => new Money($transactions->sum('credit')),
|
||||
'debits' => new Money($transactions->sum('debit')),
|
||||
'transactions' => $transactions,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all transactions for a given object
|
||||
* @param $object
|
||||
* @param $object
|
||||
* @param null $journal
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAllForObject($object, $journal = null)
|
||||
{
|
||||
$where = [
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class_id' => $object->id,
|
||||
];
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Navdata;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
class NavdataRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class NavdataRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class NavdataRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\News;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
class NewsRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class NewsRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class NewsRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -20,10 +25,10 @@ class NewsRepository extends BaseRepository implements CacheableInterface
|
||||
* @param int $count
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLatest($count=5)
|
||||
public function getLatest($count = 5)
|
||||
{
|
||||
return $this->orderBy('created_at', 'desc')
|
||||
->with(['user'])
|
||||
->paginate($count);
|
||||
->with(['user'])
|
||||
->paginate($count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,14 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\PirepField;
|
||||
|
||||
class PirepFieldRepository extends BaseRepository
|
||||
/**
|
||||
* Class PirepFieldRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class PirepFieldRepository extends Repository
|
||||
{
|
||||
protected $fieldSearchable = [
|
||||
'name' => 'like',
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Enums\PirepState;
|
||||
use App\Models\Pirep;
|
||||
use App\Models\User;
|
||||
|
||||
class PirepRepository extends BaseRepository
|
||||
/**
|
||||
* Class PirepRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class PirepRepository extends Repository
|
||||
{
|
||||
protected $fieldSearchable = [
|
||||
'user_id',
|
||||
@@ -14,6 +19,9 @@ class PirepRepository extends BaseRepository
|
||||
'state',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return Pirep::class;
|
||||
@@ -25,14 +33,15 @@ class PirepRepository extends BaseRepository
|
||||
* @param User|null $user
|
||||
* @return Pirep
|
||||
*/
|
||||
public function getPending(User $user=null)
|
||||
public function getPending(User $user = null)
|
||||
{
|
||||
$where = [];
|
||||
if($user !== null) {
|
||||
if ($user !== null) {
|
||||
$where['user_id'] = $user->id;
|
||||
}
|
||||
|
||||
$pireps = $this->orderBy('created_at', 'desc')->findWhere($where)->all();
|
||||
|
||||
return $pireps;
|
||||
}
|
||||
|
||||
@@ -52,8 +61,9 @@ class PirepRepository extends BaseRepository
|
||||
}
|
||||
|
||||
$pireps = $this->orderBy('created_at', 'desc')
|
||||
->findWhere($where, ['id'])
|
||||
->count();
|
||||
->findWhere($where, ['id'])
|
||||
->count();
|
||||
|
||||
return $pireps;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,25 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Rank;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
class RankRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class RankRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class RankRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
protected $fieldSearchable = [
|
||||
'name' => 'like',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return Rank::class;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Exceptions\SettingNotFound;
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Log;
|
||||
@@ -10,12 +11,19 @@ use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
use Prettus\Validator\Exceptions\ValidatorException;
|
||||
|
||||
class SettingRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class SettingRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class SettingRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
public $cacheMinutes = 1;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return Setting::class;
|
||||
@@ -32,18 +40,18 @@ class SettingRepository extends BaseRepository implements CacheableInterface
|
||||
$key = Setting::formatKey($key);
|
||||
$setting = $this->findWhere(['id' => $key], ['type', 'value'])->first();
|
||||
|
||||
if(!$setting) {
|
||||
throw new SettingNotFound($key . ' not found');
|
||||
if (!$setting) {
|
||||
throw new SettingNotFound($key.' not found');
|
||||
}
|
||||
|
||||
# cast some types
|
||||
switch($setting->type) {
|
||||
switch ($setting->type) {
|
||||
case 'bool':
|
||||
case 'boolean':
|
||||
$value = $setting->value;
|
||||
if($value === 'true' || $value === '1') {
|
||||
if ($value === 'true' || $value === '1') {
|
||||
$value = true;
|
||||
} elseif($value === 'false' || $value === '0') {
|
||||
} elseif ($value === 'false' || $value === '0') {
|
||||
$value = false;
|
||||
}
|
||||
|
||||
@@ -93,7 +101,7 @@ class SettingRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
try {
|
||||
if(\is_bool($value)) {
|
||||
if (\is_bool($value)) {
|
||||
$value = $value === true ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Subfleet;
|
||||
use Prettus\Repository\Contracts\CacheableInterface;
|
||||
use Prettus\Repository\Traits\CacheableRepository;
|
||||
|
||||
class SubfleetRepository extends BaseRepository implements CacheableInterface
|
||||
/**
|
||||
* Class SubfleetRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class SubfleetRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -15,6 +20,9 @@ class SubfleetRepository extends BaseRepository implements CacheableInterface
|
||||
'type' => 'like',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return Subfleet::class;
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Enums\UserState;
|
||||
use App\Models\User;
|
||||
use App\Repositories\Criteria\WhereCriteria;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserRepository extends BaseRepository
|
||||
/**
|
||||
* Class UserRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class UserRepository extends Repository
|
||||
{
|
||||
protected $fieldSearchable = [
|
||||
'name' => 'like',
|
||||
'name' => 'like',
|
||||
'email' => 'like',
|
||||
'home_airport_id',
|
||||
'curr_airport_id',
|
||||
'state'
|
||||
];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return User::class;
|
||||
@@ -32,8 +41,8 @@ class UserRepository extends BaseRepository
|
||||
];
|
||||
|
||||
$users = $this->orderBy('created_at', 'desc')
|
||||
->findWhere($where, ['id'])
|
||||
->count();
|
||||
->findWhere($where, ['id'])
|
||||
->count();
|
||||
|
||||
return $users;
|
||||
}
|
||||
@@ -41,7 +50,7 @@ class UserRepository extends BaseRepository
|
||||
/**
|
||||
* Create the search criteria and return this with the stuff pushed
|
||||
* @param Request $request
|
||||
* @param bool $only_active
|
||||
* @param bool $only_active
|
||||
* @return $this
|
||||
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
||||
*/
|
||||
@@ -49,7 +58,7 @@ class UserRepository extends BaseRepository
|
||||
{
|
||||
$where = [];
|
||||
|
||||
if($only_active) {
|
||||
if ($only_active) {
|
||||
$where['state'] = UserState::ACTIVE;
|
||||
}
|
||||
|
||||
@@ -66,6 +75,7 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
|
||||
$this->pushCriteria(new WhereCriteria($request, $where));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user