Compare commits
72
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18206f4601 | ||
|
|
845514da2c | ||
|
|
531489bfde | ||
|
|
601a17e1e6 | ||
|
|
3be8b1c4b9 | ||
|
|
b4e33bb37e | ||
|
|
a8e6f1191b | ||
|
|
3a0140c2d0 | ||
|
|
547b159570 | ||
|
|
cab5c03c0b | ||
|
|
777a696b35 | ||
|
|
90344fb6e6 | ||
|
|
7481dab012 | ||
|
|
dead1cfd0f | ||
|
|
544462f420 | ||
|
|
a31201dfd3 | ||
|
|
9d336c1140 | ||
|
|
96d33c11c8 | ||
|
|
48cada2053 | ||
|
|
2a05013f66 | ||
|
|
4267648da5 | ||
|
|
5ada327236 | ||
|
|
82825ef77b | ||
|
|
db532e0f16 | ||
|
|
9b2e466b7e | ||
|
|
17447c6903 | ||
|
|
ad86e996d7 | ||
|
|
5a5fd02dac | ||
|
|
97f095e4e9 | ||
|
|
a2f91b6754 | ||
|
|
a9e5554dea | ||
|
|
5b10dca868 | ||
|
|
11cebb3e6e | ||
|
|
96c17d33bc | ||
|
|
9abc892698 | ||
|
|
67a51da220 | ||
|
|
7e586a273a | ||
|
|
8a591c11a5 | ||
|
|
728b033675 | ||
|
|
68a6ed24cb | ||
|
|
7d8a34645e | ||
|
|
4985da991b | ||
|
|
c94358350a | ||
|
|
d3ec0f4de3 | ||
|
|
ede5b74383 | ||
|
|
e7bbd6cccb | ||
|
|
edcea258ce | ||
|
|
5adc0b4072 | ||
|
|
fe7120e21a | ||
|
|
30be7c245c | ||
|
|
7cb9ae4ec3 | ||
|
|
6f1a5f1dc2 | ||
|
|
e3c3c81d19 | ||
|
|
352f1ee9f8 | ||
|
|
dff4273c72 | ||
|
|
77a4acb569 | ||
|
|
ff6827b368 | ||
|
|
594d0eb222 | ||
|
|
ee61de62fa | ||
|
|
f2be14402f | ||
|
|
a186bfae2a | ||
|
|
6e6ba85080 | ||
|
|
d2272e32a6 | ||
|
|
b6c0946795 | ||
|
|
fca04e6b0c | ||
|
|
5094fce4b0 | ||
|
|
fe0ef60b6c | ||
|
|
5094375e13 | ||
|
|
ec6cb42bfd | ||
|
|
14d0e99a37 | ||
|
|
f8c7bc31f5 | ||
|
|
2545328233 |
@@ -30,6 +30,7 @@ declare -a remove_files=(
|
|||||||
intellij_style.xml
|
intellij_style.xml
|
||||||
config.php
|
config.php
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
|
docker-compose.local.yml
|
||||||
Makefile
|
Makefile
|
||||||
phpcs.xml
|
phpcs.xml
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
@@ -73,8 +74,12 @@ ls -al $BASE_DIR/../
|
|||||||
|
|
||||||
tar -czf $TAR_NAME -C $BASE_DIR .
|
tar -czf $TAR_NAME -C $BASE_DIR .
|
||||||
sha256sum $TAR_NAME >"$TAR_NAME.sha256"
|
sha256sum $TAR_NAME >"$TAR_NAME.sha256"
|
||||||
tar2zip $TAR_NAME
|
|
||||||
|
cd $BASE_DIR;
|
||||||
|
zip -r $ZIP_NAME *
|
||||||
sha256sum $ZIP_NAME >"$ZIP_NAME.sha256"
|
sha256sum $ZIP_NAME >"$ZIP_NAME.sha256"
|
||||||
|
mv $ZIP_NAME /tmp
|
||||||
|
mv "$ZIP_NAME.sha256" /tmp
|
||||||
|
|
||||||
ls -al /tmp
|
ls -al /tmp
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
php-versions: ['7.3', '7.4']
|
php-versions: ['7.3', '7.4', '8.0']
|
||||||
name: PHP ${{ matrix.php-versions }}
|
name: PHP ${{ matrix.php-versions }}
|
||||||
env:
|
env:
|
||||||
extensions: intl, pcov, mbstring
|
extensions: intl, pcov, mbstring
|
||||||
@@ -41,7 +41,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
path: ${{ steps.composer-cache.outputs.dir }}
|
path: ${{ steps.composer-cache.outputs.dir }}
|
||||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||||
restore-keys: ${{ runner.os }}-composer-
|
|
||||||
|
|
||||||
# Configure PHP
|
# Configure PHP
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
|
|||||||
+4
-1
@@ -2,7 +2,7 @@ FROM php:7.4-fpm-alpine
|
|||||||
|
|
||||||
WORKDIR /var/www/
|
WORKDIR /var/www/
|
||||||
|
|
||||||
RUN apk add gmp-dev icu-dev
|
RUN apk add gmp-dev icu-dev zlib-dev libpng-dev
|
||||||
RUN curl --silent --show-error https://getcomposer.org/installer | php
|
RUN curl --silent --show-error https://getcomposer.org/installer | php
|
||||||
|
|
||||||
# Copy any config files in
|
# Copy any config files in
|
||||||
@@ -14,6 +14,7 @@ RUN docker-php-ext-install \
|
|||||||
calendar \
|
calendar \
|
||||||
intl \
|
intl \
|
||||||
pdo_mysql \
|
pdo_mysql \
|
||||||
|
gd \
|
||||||
gmp \
|
gmp \
|
||||||
opcache && \
|
opcache && \
|
||||||
docker-php-ext-enable pdo_mysql opcache
|
docker-php-ext-enable pdo_mysql opcache
|
||||||
@@ -26,4 +27,6 @@ RUN php composer.phar install \
|
|||||||
--no-scripts \
|
--no-scripts \
|
||||||
--prefer-dist
|
--prefer-dist
|
||||||
|
|
||||||
|
RUN chown -R www-data:www-data /var/www
|
||||||
|
|
||||||
EXPOSE 9000
|
EXPOSE 9000
|
||||||
|
|||||||
@@ -109,17 +109,9 @@ reset-installer:
|
|||||||
@php artisan database:create --reset
|
@php artisan database:create --reset
|
||||||
@php artisan migrate:refresh --seed
|
@php artisan migrate:refresh --seed
|
||||||
|
|
||||||
.PHONY: docker
|
.PHONY: docker-test
|
||||||
docker:
|
docker-test:
|
||||||
@mkdir -p $(CURR_PATH)/tmp/mysql
|
@docker-compose -f docker-compose.yml -f docker-compose.local.yml up
|
||||||
|
|
||||||
-docker rm -f phpvms
|
|
||||||
docker build -t phpvms .
|
|
||||||
docker run --name=phpvms \
|
|
||||||
-v $(CURR_PATH):/var/www/ \
|
|
||||||
-v $(CURR_PATH)/tmp/mysql:/var/lib/mysql \
|
|
||||||
-p 8080:80 \
|
|
||||||
phpvms
|
|
||||||
|
|
||||||
.PHONY: docker-clean
|
.PHONY: docker-clean
|
||||||
docker-clean:
|
docker-clean:
|
||||||
|
|||||||
@@ -30,15 +30,16 @@ A full distribution, with all of the composer dependencies, is available at this
|
|||||||
|
|
||||||
[View installation details](https://docs.phpvms.net/installation/installation)
|
[View installation details](https://docs.phpvms.net/installation/installation)
|
||||||
|
|
||||||
## Development Environment
|
## Development Environment with Docker
|
||||||
|
|
||||||
A full development environment can be brought up using Docker:
|
A full development environment can be brought up using Docker, without having to install composer/npm locally
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer install
|
make docker-test
|
||||||
npm install
|
|
||||||
docker-compose build
|
# **OR** with docker-compose directly
|
||||||
docker-compose up
|
|
||||||
|
docker-compose -f docker-compose.yml -f docker-compose.local.yml up
|
||||||
```
|
```
|
||||||
|
|
||||||
Then go to `http://localhost`. If you're using dnsmasq, the `app` container is listening on `phpvms.test`, or you can add to your `/etc/hosts` file:
|
Then go to `http://localhost`. If you're using dnsmasq, the `app` container is listening on `phpvms.test`, or you can add to your `/etc/hosts` file:
|
||||||
@@ -47,6 +48,8 @@ Then go to `http://localhost`. If you're using dnsmasq, the `app` container is l
|
|||||||
127.0.0.1 phpvms.test
|
127.0.0.1 phpvms.test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `docker-compose.local.yml` overrides the `app` section in `docker-compose.yml`. The standard `docker-compose.yml` can be used if you want to deploy from the image, or as a template for your own Dockerized deployments.
|
||||||
|
|
||||||
### Building JS/CSS assets
|
### Building JS/CSS assets
|
||||||
|
|
||||||
Yarn is required, run:
|
Yarn is required, run:
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App;
|
||||||
|
use App\Contracts\Command;
|
||||||
|
|
||||||
|
class EmailTest extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'phpvms:email-test';
|
||||||
|
protected $description = 'Send a test notification to admins';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run dev related commands
|
||||||
|
*
|
||||||
|
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
/** @var App\Notifications\NotificationEventsHandler $eventHandler */
|
||||||
|
$eventHandler = app(App\Notifications\NotificationEventsHandler::class);
|
||||||
|
|
||||||
|
$news = new App\Models\News();
|
||||||
|
$news->user_id = 1;
|
||||||
|
$news->subject = 'Test News';
|
||||||
|
$news->body = 'Test Body';
|
||||||
|
$news->save();
|
||||||
|
|
||||||
|
$newsEvent = new App\Events\NewsAdded($news);
|
||||||
|
$eventHandler->onNewsAdded($newsEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App;
|
||||||
|
use App\Contracts\Command;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class ProcessQueue extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'queue:cron';
|
||||||
|
protected $description = 'Process the queue from a cron job';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the queue tasks
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
Artisan::call('queue:work', [
|
||||||
|
'--sansdaemon' => null,
|
||||||
|
'--stop-when-empty' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Log::info(Artisan::output());
|
||||||
|
///** @var App\Support\WorkCommand $queueWorker */
|
||||||
|
//$queueWorker = new App\Support\WorkCommand(app('queue.worker'), app('cache.store'));
|
||||||
|
|
||||||
|
//$queueWorker->setInput($queueWorker->createInputFromArguments([]));
|
||||||
|
//$queueWorker->handle();
|
||||||
|
|
||||||
|
/*$output = $this->call('queue:work', [
|
||||||
|
'--stop-when-empty' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Log::info($output);*/
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Cron;
|
||||||
|
|
||||||
|
use App\Contracts\Command;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This just calls the CronHourly event, so all of the
|
||||||
|
* listeners, etc can just be called to run those tasks
|
||||||
|
*/
|
||||||
|
class JobQueue extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'cron:queue';
|
||||||
|
protected $description = 'Run the cron queue tasks';
|
||||||
|
protected $schedule;
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$this->redirectLoggingToFile('cron');
|
||||||
|
Artisan::call('queue:cron');
|
||||||
|
|
||||||
|
$this->info(Artisan::output());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
use App\Console\Cron\Hourly;
|
use App\Console\Cron\Hourly;
|
||||||
|
use App\Console\Cron\JobQueue;
|
||||||
use App\Console\Cron\Monthly;
|
use App\Console\Cron\Monthly;
|
||||||
use App\Console\Cron\Nightly;
|
use App\Console\Cron\Nightly;
|
||||||
use App\Console\Cron\Weekly;
|
use App\Console\Cron\Weekly;
|
||||||
@@ -25,6 +26,13 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule): void
|
protected function schedule(Schedule $schedule): void
|
||||||
{
|
{
|
||||||
|
// If not using the queue worker then run those via cron
|
||||||
|
if (!config('queue.worker', false)) {
|
||||||
|
$schedule->command(JobQueue::class)
|
||||||
|
->everyMinute()
|
||||||
|
->withoutOverlapping();
|
||||||
|
}
|
||||||
|
|
||||||
$schedule->command(Nightly::class)->dailyAt('01:00');
|
$schedule->command(Nightly::class)->dailyAt('01:00');
|
||||||
$schedule->command(Weekly::class)->weeklyOn(0);
|
$schedule->command(Weekly::class)->weeklyOn(0);
|
||||||
$schedule->command(Monthly::class)->monthlyOn(1);
|
$schedule->command(Monthly::class)->monthlyOn(1);
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ abstract class Command extends \Illuminate\Console\Command
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
// Running in the console but not in the tests
|
// Running in the console but not in the tests
|
||||||
if (app()->runningInConsole() && env('APP_ENV') !== 'testing') {
|
/*if (app()->runningInConsole() && env('APP_ENV') !== 'testing') {
|
||||||
$this->redirectLoggingToFile('stdout');
|
$this->redirectLoggingToFile('stdout');
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Contracts;
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
use App\Notifications\Channels\Discord\DiscordMessage;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class Notification extends \Illuminate\Notifications\Notification implements ShouldQueue
|
class Notification extends \Illuminate\Notifications\Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
@@ -17,14 +17,14 @@ class Notification extends \Illuminate\Notifications\Notification implements Sho
|
|||||||
{
|
{
|
||||||
// Look in the notifications.channels config and see where this particular
|
// Look in the notifications.channels config and see where this particular
|
||||||
// notification can go. Map it to $channels
|
// notification can go. Map it to $channels
|
||||||
$klass = static::class;
|
/*$klass = static::class;
|
||||||
$notif_config = config('notifications.channels', []);
|
$notif_config = config('notifications.channels', []);
|
||||||
if (!array_key_exists($klass, $notif_config)) {
|
if (!array_key_exists($klass, $notif_config)) {
|
||||||
Log::error('Notification type '.$klass.' missing from notifications config, defaulting to mail');
|
Log::error('Notification type '.$klass.' missing from notifications config, defaulting to mail');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->channels = $notif_config[$klass];
|
$this->channels = $notif_config[$klass];*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,8 +34,16 @@ class Notification extends \Illuminate\Notifications\Notification implements Sho
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function via($notifiable)
|
/*public function via($notifiable)
|
||||||
{
|
{
|
||||||
return $this->channels;
|
return $this->channels;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return DiscordMessage|null
|
||||||
|
*/
|
||||||
|
public function toDiscordChannel($notifiable): ?DiscordMessage
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Contracts;
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
use function is_array;
|
||||||
use Prettus\Repository\Eloquent\BaseRepository;
|
use Prettus\Repository\Eloquent\BaseRepository;
|
||||||
|
use Prettus\Repository\Exceptions\RepositoryException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin \Prettus\Repository\Eloquent\BaseRepository
|
* @mixin BaseRepository
|
||||||
*/
|
*/
|
||||||
abstract class Repository extends BaseRepository
|
abstract class Repository extends BaseRepository
|
||||||
{
|
{
|
||||||
@@ -20,8 +23,8 @@ abstract class Repository extends BaseRepository
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->find($id, $columns);
|
return $this->find($id, $columns);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,11 +35,7 @@ abstract class Repository extends BaseRepository
|
|||||||
*/
|
*/
|
||||||
public function validate($values)
|
public function validate($values)
|
||||||
{
|
{
|
||||||
$validator = Validator::make(
|
$validator = Validator::make($values, $this->model()->rules);
|
||||||
$values,
|
|
||||||
$this->model()->rules
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
return $validator->messages();
|
return $validator->messages();
|
||||||
}
|
}
|
||||||
@@ -50,6 +49,8 @@ abstract class Repository extends BaseRepository
|
|||||||
* @param int $count
|
* @param int $count
|
||||||
* @param string $sort_by created_at (default) or updated_at
|
* @param string $sort_by created_at (default) or updated_at
|
||||||
*
|
*
|
||||||
|
* @throws RepositoryException
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function recent($count = null, $sort_by = 'created_at')
|
public function recent($count = null, $sort_by = 'created_at')
|
||||||
@@ -71,7 +72,7 @@ abstract class Repository extends BaseRepository
|
|||||||
return $this->scopeQuery(function ($query) use ($where, $sort_by, $order_by) {
|
return $this->scopeQuery(function ($query) use ($where, $sort_by, $order_by) {
|
||||||
$q = $query->where($where);
|
$q = $query->where($where);
|
||||||
// See if there are multi-column sorts
|
// See if there are multi-column sorts
|
||||||
if (\is_array($sort_by)) {
|
if (is_array($sort_by)) {
|
||||||
foreach ($sort_by as $key => $sort) {
|
foreach ($sort_by as $key => $sort) {
|
||||||
$q = $q->orderBy($key, $sort);
|
$q = $q->orderBy($key, $sort);
|
||||||
}
|
}
|
||||||
@@ -98,7 +99,7 @@ abstract class Repository extends BaseRepository
|
|||||||
return $this->scopeQuery(function ($query) use ($col, $values, $sort_by, $order_by) {
|
return $this->scopeQuery(function ($query) use ($col, $values, $sort_by, $order_by) {
|
||||||
$q = $query->whereNotIn($col, $values);
|
$q = $query->whereNotIn($col, $values);
|
||||||
// See if there are multi-column sorts
|
// See if there are multi-column sorts
|
||||||
if (\is_array($sort_by)) {
|
if (is_array($sort_by)) {
|
||||||
foreach ($sort_by as $key => $sort) {
|
foreach ($sort_by as $key => $sort) {
|
||||||
$q = $q->orderBy($key, $sort);
|
$q = $q->orderBy($key, $sort);
|
||||||
}
|
}
|
||||||
@@ -118,7 +119,7 @@ abstract class Repository extends BaseRepository
|
|||||||
* @param array $columns
|
* @param array $columns
|
||||||
* @param string $method
|
* @param string $method
|
||||||
*
|
*
|
||||||
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
* @throws RepositoryException
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Contracts;
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
use App\Support\Resources\CustomAnonymousResourceCollection;
|
||||||
|
use App\Support\Resources\CustomPaginatedResourceResponse;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use Illuminate\Pagination\AbstractPaginator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for a resource/response
|
* Base class for a resource/response
|
||||||
@@ -26,4 +29,28 @@ class Resource extends JsonResource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customize the response to exclude all the extra data that isn't used. Based on:
|
||||||
|
* https://gist.github.com/derekphilipau/4be52164a69ce487dcd0673656d280da
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function toResponse($request)
|
||||||
|
{
|
||||||
|
return $this->resource instanceof AbstractPaginator
|
||||||
|
? (new CustomPaginatedResourceResponse($this))->toResponse($request)
|
||||||
|
: parent::toResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function collection($resource)
|
||||||
|
{
|
||||||
|
return tap(new CustomAnonymousResourceCollection($resource, static::class), function ($collection) {
|
||||||
|
if (property_exists(static::class, 'preserveKeys')) {
|
||||||
|
$collection->preserveKeys = (new static([]))->preserveKeys === true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Cron\Nightly;
|
namespace App\Cron\Hourly;
|
||||||
|
|
||||||
use App\Contracts\Listener;
|
use App\Contracts\Listener;
|
||||||
use App\Events\CronNightly;
|
use App\Events\CronHourly;
|
||||||
use App\Services\SimBriefService;
|
use App\Services\SimBriefService;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@@ -22,9 +22,9 @@ class ClearExpiredSimbrief extends Listener
|
|||||||
/**
|
/**
|
||||||
* @param \App\Events\CronNightly $event
|
* @param \App\Events\CronNightly $event
|
||||||
*/
|
*/
|
||||||
public function handle(CronNightly $event): void
|
public function handle(CronHourly $event): void
|
||||||
{
|
{
|
||||||
Log::info('Nightly: Removing expired Simbrief entries');
|
Log::info('Hourly: Removing expired Simbrief entries');
|
||||||
$this->simbriefSvc->removeExpiredEntries();
|
$this->simbriefSvc->removeExpiredEntries();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,11 @@ namespace App\Cron\Hourly;
|
|||||||
|
|
||||||
use App\Contracts\Listener;
|
use App\Contracts\Listener;
|
||||||
use App\Events\CronHourly;
|
use App\Events\CronHourly;
|
||||||
|
use App\Events\PirepCancelled;
|
||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove expired live flights
|
* Remove expired live flights
|
||||||
@@ -27,8 +29,13 @@ class RemoveExpiredLiveFlights extends Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$date = Carbon::now('UTC')->subHours(setting('acars.live_time'));
|
$date = Carbon::now('UTC')->subHours(setting('acars.live_time'));
|
||||||
Pirep::where('updated_at', '<', $date)
|
$pireps = Pirep::where('updated_at', '<', $date)
|
||||||
->where('state', PirepState::IN_PROGRESS)
|
->where('state', PirepState::IN_PROGRESS)
|
||||||
->delete();
|
->get();
|
||||||
|
foreach ($pireps as $pirep) {
|
||||||
|
event(new PirepCancelled($pirep));
|
||||||
|
Log::info('Cron: Deleting Expired Live PIREP id='.$pirep->id.', state='.PirepState::label($pirep->state));
|
||||||
|
$pirep->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ use App\Events\CronNightly;
|
|||||||
use App\Services\VersionService;
|
use App\Services\VersionService;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if any pilots should be set to ON LEAVE status
|
|
||||||
*/
|
|
||||||
class NewVersionCheck extends Listener
|
class NewVersionCheck extends Listener
|
||||||
{
|
{
|
||||||
private $versionSvc;
|
private $versionSvc;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ if (!function_exists('createFactoryICAO')) {
|
|||||||
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||||
$max = strlen($characters) - 1;
|
$max = strlen($characters) - 1;
|
||||||
$string = '';
|
$string = '';
|
||||||
for ($i = 0; $i < 4; $i++) {
|
for ($i = 0; $i < 5; $i++) {
|
||||||
try {
|
try {
|
||||||
$string .= $characters[random_int(0, $max)];
|
$string .= $characters[random_int(0, $max)];
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Contracts\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase Airport ICAO size to 5 chars
|
||||||
|
* https://github.com/nabeelio/phpvms/issues/1052
|
||||||
|
*/
|
||||||
|
class IncreaseIcaoSizes extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('airports', function (Blueprint $table) {
|
||||||
|
$table->string('iata', 5)->change();
|
||||||
|
$table->string('icao', 5)->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('pireps', function (Blueprint $table) {
|
||||||
|
$table->string('dpt_airport_id', 5)->change();
|
||||||
|
$table->string('arr_airport_id', 5)->change();
|
||||||
|
$table->string('alt_airport_id', 5)->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class RemoveSettingSimbriefExpireDays extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
DB::table('settings')
|
||||||
|
->where(['key' => 'simbrief.expire_days'])
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Contracts\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class DiscordFields extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
// Delete the old Discord fields and then a webhook will get added
|
||||||
|
DB::table('settings')
|
||||||
|
->where(['key' => 'notifications.discord_api_key'])
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
DB::table('settings')
|
||||||
|
->where(['key' => 'notifications.discord_public_channel_id'])
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
DB::table('settings')
|
||||||
|
->where(['key' => 'notifications.discord_public_channel_id'])
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
// Add a field to the user to enter their own Discord ID
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('discord_id')
|
||||||
|
->default('')
|
||||||
|
->after('rank_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Contracts\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class DiscordPrivateChannelId extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
// Add a field to the user to enter their own Discord ID
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('discord_private_channel_id')
|
||||||
|
->default('')
|
||||||
|
->after('discord_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,519 +1,5 @@
|
|||||||
acars:
|
acars:
|
||||||
- id: aM8QpMPEB15e
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.934117958358'
|
|
||||||
lon: '-76.77856721815'
|
|
||||||
heading: '124'
|
|
||||||
altitude: '8.1663703232199'
|
|
||||||
vs: '0'
|
|
||||||
gs: '0.0064996252497234'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: eZ6VJ3xj8vge
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.934117498661'
|
|
||||||
lon: '-76.778566516289'
|
|
||||||
heading: '124'
|
|
||||||
altitude: '8.1664622222087'
|
|
||||||
vs: '0'
|
|
||||||
gs: '0'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: bo2QqDLl2lLa
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.933884143334'
|
|
||||||
lon: '-76.778210172233'
|
|
||||||
heading: '124'
|
|
||||||
altitude: '8.1707802663933'
|
|
||||||
vs: '0'
|
|
||||||
gs: '14.419195209695'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: aM8QpM4qV2Be
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.933705349611'
|
|
||||||
lon: '-76.777936938059'
|
|
||||||
heading: '124'
|
|
||||||
altitude: '8.170089899507'
|
|
||||||
vs: '0'
|
|
||||||
gs: '15.392330039049'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: dR6oxR9qjoOd
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.933130691906'
|
|
||||||
lon: '-76.777152737985'
|
|
||||||
heading: '158'
|
|
||||||
altitude: '8.1683570286331'
|
|
||||||
vs: '0'
|
|
||||||
gs: '10.450467475023'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: erkRwJODRvEa
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.932580370289'
|
|
||||||
lon: '-76.777450200122'
|
|
||||||
heading: '221'
|
|
||||||
altitude: '8.1695896791822'
|
|
||||||
vs: '0'
|
|
||||||
gs: '12.932334300694'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: b2kv53VMy7Ad
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.932012550651'
|
|
||||||
lon: '-76.778009113329'
|
|
||||||
heading: '296'
|
|
||||||
altitude: '8.1683852467213'
|
|
||||||
vs: '0'
|
|
||||||
gs: '10.502719192825'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: eXDoE14JxAve
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.932052237309'
|
|
||||||
lon: '-76.778111495187'
|
|
||||||
heading: '290'
|
|
||||||
altitude: '8.1719753739837'
|
|
||||||
vs: '0'
|
|
||||||
gs: '12.643743277153'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: b68R5gZ5YyOe
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.932664026837'
|
|
||||||
lon: '-76.779705339967'
|
|
||||||
heading: '293'
|
|
||||||
altitude: '8.2203963962548'
|
|
||||||
vs: '0'
|
|
||||||
gs: '64.870244840054'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: bqxYvGNN5N0a
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.934300220408'
|
|
||||||
lon: '-76.783954914814'
|
|
||||||
heading: '293'
|
|
||||||
altitude: '8.3302468103811'
|
|
||||||
vs: '0'
|
|
||||||
gs: '122.78529244208'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: en5rpBKw514d
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.935736496556'
|
|
||||||
lon: '-76.78765616448'
|
|
||||||
heading: '293'
|
|
||||||
altitude: '49.554739665916'
|
|
||||||
vs: '21'
|
|
||||||
gs: '146.79677958636'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: erkRwJA29l2a
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '17.976972983585'
|
|
||||||
lon: '-76.896548114872'
|
|
||||||
heading: '297'
|
|
||||||
altitude: '6228.684012199'
|
|
||||||
vs: '62'
|
|
||||||
gs: '281.03976876098'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: dR6oxR3r5nwd
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.061360208405'
|
|
||||||
lon: '-77.056156629983'
|
|
||||||
heading: '301'
|
|
||||||
altitude: '12522.331716891'
|
|
||||||
vs: '25'
|
|
||||||
gs: '371.70833265547'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: e1wr82J877Zb
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.17373613295'
|
|
||||||
lon: '-77.260347185993'
|
|
||||||
heading: '301'
|
|
||||||
altitude: '16802.15636323'
|
|
||||||
vs: '43'
|
|
||||||
gs: '421.37353688139'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: bqxYvGyExN2a
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.193907285814'
|
|
||||||
lon: '-77.29810465405'
|
|
||||||
heading: '297'
|
|
||||||
altitude: '17395.953175647'
|
|
||||||
vs: '40'
|
|
||||||
gs: '425.98105291451'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: aQW0wQDQk5Md
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.648921231143'
|
|
||||||
lon: '-78.014696613517'
|
|
||||||
heading: '323'
|
|
||||||
altitude: '37108.124381987'
|
|
||||||
vs: '22'
|
|
||||||
gs: '438.52028383384'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: e9rQ5lk3p63a
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.796585259338'
|
|
||||||
lon: '-78.194734005052'
|
|
||||||
heading: '260'
|
|
||||||
altitude: '39718.178225504'
|
|
||||||
vs: '19'
|
|
||||||
gs: '432.41969107334'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: aQW0wQP8vZqd
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.660552760063'
|
|
||||||
lon: '-78.407597067994'
|
|
||||||
heading: '242'
|
|
||||||
altitude: '40998.775690971'
|
|
||||||
vs: '-25'
|
|
||||||
gs: '449.51695639627'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: bqxYvGKgp32a
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.592775999582'
|
|
||||||
lon: '-78.638711340118'
|
|
||||||
heading: '298'
|
|
||||||
altitude: '41060.297106821'
|
|
||||||
vs: '0'
|
|
||||||
gs: '427.14806185954'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: bqxYvGg2r02a
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.718367591656'
|
|
||||||
lon: '-78.840980459275'
|
|
||||||
heading: '284'
|
|
||||||
altitude: '41065.55293844'
|
|
||||||
vs: '1'
|
|
||||||
gs: '424.89060056552'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: e0RV61wPj53b
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.77448809677'
|
|
||||||
lon: '-79.082727467209'
|
|
||||||
heading: '283'
|
|
||||||
altitude: '41069.809333539'
|
|
||||||
vs: '0'
|
|
||||||
gs: '425.02780492483'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: dwpmBOo3wWwe
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.813031600863'
|
|
||||||
lon: '-79.249543355636'
|
|
||||||
heading: '283'
|
|
||||||
altitude: '41072.545805172'
|
|
||||||
vs: '0'
|
|
||||||
gs: '425.04687332464'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: ejRqlxXoZPle
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.840653974635'
|
|
||||||
lon: '-79.370042672541'
|
|
||||||
heading: '283'
|
|
||||||
altitude: '40396.200981621'
|
|
||||||
vs: '-16'
|
|
||||||
gs: '428.08364925851'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: eVOPBYw4q9Xa
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.868358744495'
|
|
||||||
lon: '-79.491434926253'
|
|
||||||
heading: '283'
|
|
||||||
altitude: '39399.093383161'
|
|
||||||
vs: '-16'
|
|
||||||
gs: '427.57826037174'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: aOYyrOmVPzEd
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.896191929474'
|
|
||||||
lon: '-79.613169477385'
|
|
||||||
heading: '284'
|
|
||||||
altitude: '36491.730092364'
|
|
||||||
vs: '-55'
|
|
||||||
gs: '429.74732238829'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: dL98oLQgyzje
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.9242378342'
|
|
||||||
lon: '-79.736368411294'
|
|
||||||
heading: '284'
|
|
||||||
altitude: '32998.644142986'
|
|
||||||
vs: '-61'
|
|
||||||
gs: '434.90864533098'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: e9rQ5lqD2o8a
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
|
||||||
nav_type: null
|
|
||||||
order: '0'
|
|
||||||
name: null
|
|
||||||
log: null
|
|
||||||
lat: '18.952608029755'
|
|
||||||
lon: '-79.861339775352'
|
|
||||||
heading: '284'
|
|
||||||
altitude: '29069.168636089'
|
|
||||||
vs: '-68'
|
|
||||||
gs: '441.90475491564'
|
|
||||||
transponder: null
|
|
||||||
autopilot: null
|
|
||||||
fuel_flow: null
|
|
||||||
sim_time: now
|
|
||||||
created_at: 'now'
|
|
||||||
updated_at: 'now'
|
|
||||||
- id: av2oANWY1vma
|
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -550,8 +36,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: e1wr82gp8zGb
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -569,8 +54,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: dG65jDL2gK0b
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -588,8 +72,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: epYQ0ENmyvXa
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -607,8 +90,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: erkRwJPrVoEa
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -626,8 +108,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: e1wr82gZXqZb
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -645,8 +126,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: eER95AJ4XLga
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -664,8 +144,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: dPNZvP0O0Gza
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -683,8 +162,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: aQW0wQYVm2Yd
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
@@ -702,8 +180,7 @@ acars:
|
|||||||
sim_time: now
|
sim_time: now
|
||||||
created_at: 'now'
|
created_at: 'now'
|
||||||
updated_at: 'now'
|
updated_at: 'now'
|
||||||
- id: eXDoE11x32We
|
- pirep_id: b68R5gwVzpVe
|
||||||
pirep_id: b68R5gwVzpVe
|
|
||||||
type: '0'
|
type: '0'
|
||||||
nav_type: null
|
nav_type: null
|
||||||
order: '0'
|
order: '0'
|
||||||
|
|||||||
@@ -54,6 +54,13 @@
|
|||||||
options: ''
|
options: ''
|
||||||
type: text
|
type: text
|
||||||
description: 'Enter your Google Analytics Tracking ID'
|
description: 'Enter your Google Analytics Tracking ID'
|
||||||
|
- key: general.record_user_ip
|
||||||
|
name: 'Record user IP address'
|
||||||
|
group: general
|
||||||
|
value: true
|
||||||
|
options: ''
|
||||||
|
type: boolean
|
||||||
|
description: Record the user's IP address on register/login
|
||||||
- key: units.currency
|
- key: units.currency
|
||||||
name: 'Currency'
|
name: 'Currency'
|
||||||
group: units
|
group: units
|
||||||
@@ -144,6 +151,20 @@
|
|||||||
options:
|
options:
|
||||||
type: text
|
type: text
|
||||||
description: If an airport's Jet A Fuel Cost isn't added, set this value by default
|
description: If an airport's Jet A Fuel Cost isn't added, set this value by default
|
||||||
|
- key: airports.default_100ll_fuel_cost
|
||||||
|
name: 'Default 100LL Fuel Cost'
|
||||||
|
group: airports
|
||||||
|
value: 0.9
|
||||||
|
options:
|
||||||
|
type: text
|
||||||
|
description: If an airport's 100LL Fuel Cost isn't added, set this value by default
|
||||||
|
- key: airports.default_mogas_fuel_cost
|
||||||
|
name: 'Default MOGAS Fuel Cost'
|
||||||
|
group: airports
|
||||||
|
value: 0.8
|
||||||
|
options:
|
||||||
|
type: text
|
||||||
|
description: If an airport's MOGAS Fuel Cost isn't added, set this value by default
|
||||||
- key: bids.disable_flight_on_bid
|
- key: bids.disable_flight_on_bid
|
||||||
name: 'Disable flight on bid'
|
name: 'Disable flight on bid'
|
||||||
group: bids
|
group: bids
|
||||||
@@ -193,13 +214,13 @@
|
|||||||
options: ''
|
options: ''
|
||||||
type: boolean
|
type: boolean
|
||||||
description: 'Only allow briefs to be created for bidded flights'
|
description: 'Only allow briefs to be created for bidded flights'
|
||||||
- key: simbrief.expire_days
|
- key: simbrief.expire_hours
|
||||||
name: 'Simbrief Expire Time'
|
name: 'Simbrief Expire Time'
|
||||||
group: simbrief
|
group: simbrief
|
||||||
value: 5
|
value: 6
|
||||||
options: ''
|
options: ''
|
||||||
type: number
|
type: number
|
||||||
description: 'Days after how long to remove unused briefs'
|
description: 'Hours after how long to remove unused briefs'
|
||||||
- key: simbrief.noncharter_pax_weight
|
- key: simbrief.noncharter_pax_weight
|
||||||
name: 'Non-Charter Passenger Weight'
|
name: 'Non-Charter Passenger Weight'
|
||||||
group: simbrief
|
group: simbrief
|
||||||
@@ -242,6 +263,13 @@
|
|||||||
options: ''
|
options: ''
|
||||||
type: boolean
|
type: boolean
|
||||||
description: 'Use privatized user name as SimBrief OFP captain name'
|
description: 'Use privatized user name as SimBrief OFP captain name'
|
||||||
|
- key: simbrief.block_aircraft
|
||||||
|
name: 'Restrict Aircraft'
|
||||||
|
group: simbrief
|
||||||
|
value: false
|
||||||
|
options: ''
|
||||||
|
type: boolean
|
||||||
|
description: 'When enabled, an aircraft can only be used for one active SimBrief OFP and Flight/Pirep'
|
||||||
- key: pireps.duplicate_check_time
|
- key: pireps.duplicate_check_time
|
||||||
name: 'PIREP duplicate time check'
|
name: 'PIREP duplicate time check'
|
||||||
group: pireps
|
group: pireps
|
||||||
@@ -347,20 +375,20 @@
|
|||||||
options: ''
|
options: ''
|
||||||
type: boolean
|
type: boolean
|
||||||
description: 'Count transfer hours in calculations, like ranks and the total hours'
|
description: 'Count transfer hours in calculations, like ranks and the total hours'
|
||||||
- key: notifications.discord_api_key
|
- key: notifications.discord_public_webhook_url
|
||||||
name: Discord API token
|
name: Discord Public Webhook URL
|
||||||
group: notifications
|
group: notifications
|
||||||
value: ''
|
value: ''
|
||||||
options: ''
|
options: ''
|
||||||
type: text
|
type: text
|
||||||
description: Discord API token for notifications
|
description: The Discord Webhook URL for public notifications
|
||||||
- key: 'notifications.discord_public_channel_id'
|
- key: notifications.discord_private_webhook_url
|
||||||
name: 'Discord Public Channel ID'
|
name: Discord Private Webhook URL
|
||||||
group: 'notifications'
|
group: notifications
|
||||||
value: ''
|
value: ''
|
||||||
options: ''
|
options: ''
|
||||||
type: 'text'
|
type: text
|
||||||
description: 'Discord public channel ID for broadcasat notifications'
|
description: The Discord Webhook URL for private notifications
|
||||||
- key: 'cron.random_id'
|
- key: 'cron.random_id'
|
||||||
name: 'Cron Randomized ID'
|
name: 'Cron Randomized ID'
|
||||||
group: 'cron'
|
group: 'cron'
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Contracts\Event;
|
||||||
|
use App\Models\Pirep;
|
||||||
|
|
||||||
|
class PirepStateChange extends Event
|
||||||
|
{
|
||||||
|
public $pirep;
|
||||||
|
|
||||||
|
public function __construct(Pirep $pirep)
|
||||||
|
{
|
||||||
|
$this->pirep = $pirep;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Contracts\Event;
|
||||||
|
use App\Models\Pirep;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status change like Boarding, Taxi, etc
|
||||||
|
*/
|
||||||
|
class PirepStatusChange extends Event
|
||||||
|
{
|
||||||
|
public $pirep;
|
||||||
|
|
||||||
|
public function __construct(Pirep $pirep)
|
||||||
|
{
|
||||||
|
$this->pirep = $pirep;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use App\Models\Aircraft;
|
||||||
|
|
||||||
|
class AircraftNotAvailable extends AbstractHttpException
|
||||||
|
{
|
||||||
|
public const MESSAGE = 'The aircraft is not available for flight';
|
||||||
|
|
||||||
|
private $aircraft;
|
||||||
|
|
||||||
|
public function __construct(Aircraft $aircraft)
|
||||||
|
{
|
||||||
|
$this->aircraft = $aircraft;
|
||||||
|
parent::__construct(
|
||||||
|
400,
|
||||||
|
static::MESSAGE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getErrorType(): string
|
||||||
|
{
|
||||||
|
return 'aircraft-not-available';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getErrorDetails(): string
|
||||||
|
{
|
||||||
|
return $this->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getErrorMetadata(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'aircraft_id' => $this->aircraft->id,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use App\Models\Pirep;
|
||||||
|
|
||||||
|
class PirepError extends AbstractHttpException
|
||||||
|
{
|
||||||
|
private $pirep;
|
||||||
|
private $error;
|
||||||
|
|
||||||
|
public function __construct(Pirep $pirep, string $error)
|
||||||
|
{
|
||||||
|
$this->error = $error;
|
||||||
|
$this->pirep = $pirep;
|
||||||
|
parent::__construct(400, $error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the RFC 7807 error type (without the URL root)
|
||||||
|
*/
|
||||||
|
public function getErrorType(): string
|
||||||
|
{
|
||||||
|
return 'pirep-error';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the detailed error string
|
||||||
|
*/
|
||||||
|
public function getErrorDetails(): string
|
||||||
|
{
|
||||||
|
return $this->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array with the error details, merged with the RFC7807 response
|
||||||
|
*/
|
||||||
|
public function getErrorMetadata(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'pirep_id' => $this->pirep->id,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
class UserNotFound extends AbstractHttpException
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
404,
|
||||||
|
'User not found'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the RFC 7807 error type (without the URL root)
|
||||||
|
*/
|
||||||
|
public function getErrorType(): string
|
||||||
|
{
|
||||||
|
return 'user-not-found';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the detailed error string
|
||||||
|
*/
|
||||||
|
public function getErrorDetails(): string
|
||||||
|
{
|
||||||
|
return $this->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array with the error details, merged with the RFC7807 response
|
||||||
|
*/
|
||||||
|
public function getErrorMetadata(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -152,7 +152,7 @@ class FlightController extends Controller
|
|||||||
{
|
{
|
||||||
return view('admin.flights.create', [
|
return view('admin.flights.create', [
|
||||||
'flight' => null,
|
'flight' => null,
|
||||||
'days' => [],
|
'days' => 0,
|
||||||
'flight_fields' => $this->flightFieldRepo->all(),
|
'flight_fields' => $this->flightFieldRepo->all(),
|
||||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||||
'airports' => $this->airportRepo->selectBoxList(true, false),
|
'airports' => $this->airportRepo->selectBoxList(true, false),
|
||||||
|
|||||||
@@ -7,29 +7,24 @@ use App\Repositories\KvpRepository;
|
|||||||
use App\Services\CronService;
|
use App\Services\CronService;
|
||||||
use App\Services\VersionService;
|
use App\Services\VersionService;
|
||||||
use App\Support\Utils;
|
use App\Support\Utils;
|
||||||
use Codedge\Updater\UpdaterManager;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Laracasts\Flash\Flash;
|
use Laracasts\Flash\Flash;
|
||||||
use Nwidart\Modules\Facades\Module;
|
|
||||||
|
|
||||||
class MaintenanceController extends Controller
|
class MaintenanceController extends Controller
|
||||||
{
|
{
|
||||||
private $cronSvc;
|
private $cronSvc;
|
||||||
private $kvpRepo;
|
private $kvpRepo;
|
||||||
private $updateManager;
|
|
||||||
private $versionSvc;
|
private $versionSvc;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
CronService $cronSvc,
|
CronService $cronSvc,
|
||||||
KvpRepository $kvpRepo,
|
KvpRepository $kvpRepo,
|
||||||
UpdaterManager $updateManager,
|
|
||||||
VersionService $versionSvc
|
VersionService $versionSvc
|
||||||
) {
|
) {
|
||||||
$this->cronSvc = $cronSvc;
|
$this->cronSvc = $cronSvc;
|
||||||
$this->kvpRepo = $kvpRepo;
|
$this->kvpRepo = $kvpRepo;
|
||||||
$this->updateManager = $updateManager;
|
|
||||||
$this->versionSvc = $versionSvc;
|
$this->versionSvc = $versionSvc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,24 +101,6 @@ class MaintenanceController extends Controller
|
|||||||
return redirect(route('admin.maintenance.index'));
|
return redirect(route('admin.maintenance.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the phpVMS install
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function update(Request $request)
|
|
||||||
{
|
|
||||||
$new_version_tag = $this->kvpRepo->get('latest_version_tag');
|
|
||||||
Log::info('Attempting to update to '.$new_version_tag);
|
|
||||||
|
|
||||||
$module = Module::find('updater');
|
|
||||||
$module->enable();
|
|
||||||
|
|
||||||
return redirect('/update/downloader');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable the cron, or if it's enabled, change the ID that is used
|
* Enable the cron, or if it's enabled, change the ID that is used
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class PirepController extends Controller
|
|||||||
$tmp[$ac->id] = $ac['name'].' - '.$ac['registration'];
|
$tmp[$ac->id] = $ac['name'].' - '.$ac['registration'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$aircraft[$subfleet->name] = $tmp;
|
$aircraft[$subfleet->type] = $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $aircraft;
|
return $aircraft;
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ use App\Contracts\Controller;
|
|||||||
use App\Http\Requests\CreateUserRequest;
|
use App\Http\Requests\CreateUserRequest;
|
||||||
use App\Http\Requests\UpdateUserRequest;
|
use App\Http\Requests\UpdateUserRequest;
|
||||||
use App\Models\Rank;
|
use App\Models\Rank;
|
||||||
use App\Models\Role;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserAward;
|
use App\Models\UserAward;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
|
use App\Repositories\RoleRepository;
|
||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use App\Support\Timezonelist;
|
use App\Support\Timezonelist;
|
||||||
@@ -29,6 +29,7 @@ class UserController extends Controller
|
|||||||
private $airlineRepo;
|
private $airlineRepo;
|
||||||
private $airportRepo;
|
private $airportRepo;
|
||||||
private $pirepRepo;
|
private $pirepRepo;
|
||||||
|
private $roleRepo;
|
||||||
private $userRepo;
|
private $userRepo;
|
||||||
private $userSvc;
|
private $userSvc;
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ class UserController extends Controller
|
|||||||
* @param AirlineRepository $airlineRepo
|
* @param AirlineRepository $airlineRepo
|
||||||
* @param AirportRepository $airportRepo
|
* @param AirportRepository $airportRepo
|
||||||
* @param PirepRepository $pirepRepo
|
* @param PirepRepository $pirepRepo
|
||||||
|
* @param RoleRepository $roleRepo
|
||||||
* @param UserRepository $userRepo
|
* @param UserRepository $userRepo
|
||||||
* @param UserService $userSvc
|
* @param UserService $userSvc
|
||||||
*/
|
*/
|
||||||
@@ -45,12 +47,14 @@ class UserController extends Controller
|
|||||||
AirlineRepository $airlineRepo,
|
AirlineRepository $airlineRepo,
|
||||||
AirportRepository $airportRepo,
|
AirportRepository $airportRepo,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
|
RoleRepository $roleRepo,
|
||||||
UserRepository $userRepo,
|
UserRepository $userRepo,
|
||||||
UserService $userSvc
|
UserService $userSvc
|
||||||
) {
|
) {
|
||||||
$this->airlineRepo = $airlineRepo;
|
$this->airlineRepo = $airlineRepo;
|
||||||
$this->airportRepo = $airportRepo;
|
$this->airportRepo = $airportRepo;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
|
$this->roleRepo = $roleRepo;
|
||||||
$this->userSvc = $userSvc;
|
$this->userSvc = $userSvc;
|
||||||
$this->userRepo = $userRepo;
|
$this->userRepo = $userRepo;
|
||||||
}
|
}
|
||||||
@@ -88,6 +92,7 @@ class UserController extends Controller
|
|||||||
->mapWithKeys(function ($item, $key) {
|
->mapWithKeys(function ($item, $key) {
|
||||||
return [strtolower($item['alpha2']) => $item['name']];
|
return [strtolower($item['alpha2']) => $item['name']];
|
||||||
});
|
});
|
||||||
|
$roles = $this->roleRepo->selectBoxList(false, true);
|
||||||
|
|
||||||
return view('admin.users.create', [
|
return view('admin.users.create', [
|
||||||
'user' => null,
|
'user' => null,
|
||||||
@@ -98,7 +103,7 @@ class UserController extends Controller
|
|||||||
'countries' => $countries,
|
'countries' => $countries,
|
||||||
'airports' => $airports,
|
'airports' => $airports,
|
||||||
'ranks' => Rank::all()->pluck('name', 'id'),
|
'ranks' => Rank::all()->pluck('name', 'id'),
|
||||||
'roles' => Role::all()->pluck('name', 'id'),
|
'roles' => $roles,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +168,7 @@ class UserController extends Controller
|
|||||||
|
|
||||||
$airlines = $this->airlineRepo->selectBoxList();
|
$airlines = $this->airlineRepo->selectBoxList();
|
||||||
$airports = $this->airportRepo->selectBoxList(false);
|
$airports = $this->airportRepo->selectBoxList(false);
|
||||||
|
$roles = $this->roleRepo->selectBoxList(false, true);
|
||||||
|
|
||||||
return view('admin.users.edit', [
|
return view('admin.users.edit', [
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
@@ -173,7 +179,7 @@ class UserController extends Controller
|
|||||||
'airports' => $airports,
|
'airports' => $airports,
|
||||||
'airlines' => $airlines,
|
'airlines' => $airlines,
|
||||||
'ranks' => Rank::all()->pluck('name', 'id'),
|
'ranks' => Rank::all()->pluck('name', 'id'),
|
||||||
'roles' => Role::all()->pluck('name', 'id'),
|
'roles' => $roles,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,15 +258,12 @@ class UserController extends Controller
|
|||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
$user = $this->userRepo->findWithoutFail($id);
|
$user = $this->userRepo->findWithoutFail($id);
|
||||||
|
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
Flash::error('User not found');
|
Flash::error('User not found');
|
||||||
|
|
||||||
return redirect(route('admin.users.index'));
|
return redirect(route('admin.users.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->userRepo->delete($id);
|
$this->userSvc->removeUser($user);
|
||||||
|
|
||||||
Flash::success('User deleted successfully.');
|
Flash::success('User deleted successfully.');
|
||||||
|
|
||||||
return redirect(route('admin.users.index'));
|
return redirect(route('admin.users.index'));
|
||||||
|
|||||||
@@ -16,9 +16,8 @@ class AirlineController extends Controller
|
|||||||
*
|
*
|
||||||
* @param AirlineRepository $airlineRepo
|
* @param AirlineRepository $airlineRepo
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(AirlineRepository $airlineRepo)
|
||||||
AirlineRepository $airlineRepo
|
{
|
||||||
) {
|
|
||||||
$this->airlineRepo = $airlineRepo;
|
$this->airlineRepo = $airlineRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,9 +30,7 @@ class AirlineController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$airports = $this->airlineRepo
|
$airports = $this->airlineRepo->whereOrder(['active' => true], 'name')->get();
|
||||||
->whereOrder(['active' => true], 'name', 'asc')
|
|
||||||
->paginate();
|
|
||||||
|
|
||||||
return AirlineResource::collection($airports);
|
return AirlineResource::collection($airports);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ use App\Models\Enums\PirepFieldSource;
|
|||||||
use App\Models\Enums\PirepSource;
|
use App\Models\Enums\PirepSource;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Models\PirepComment;
|
use App\Models\PirepComment;
|
||||||
use App\Repositories\AcarsRepository;
|
use App\Models\PirepFare;
|
||||||
|
use App\Models\PirepFieldValue;
|
||||||
use App\Repositories\JournalRepository;
|
use App\Repositories\JournalRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
use App\Services\FareService;
|
|
||||||
use App\Services\Finance\PirepFinanceService;
|
use App\Services\Finance\PirepFinanceService;
|
||||||
use App\Services\PirepService;
|
use App\Services\PirepService;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
@@ -37,8 +37,6 @@ use Illuminate\Support\Facades\Log;
|
|||||||
|
|
||||||
class PirepController extends Controller
|
class PirepController extends Controller
|
||||||
{
|
{
|
||||||
private $acarsRepo;
|
|
||||||
private $fareSvc;
|
|
||||||
private $financeSvc;
|
private $financeSvc;
|
||||||
private $journalRepo;
|
private $journalRepo;
|
||||||
private $pirepRepo;
|
private $pirepRepo;
|
||||||
@@ -46,8 +44,6 @@ class PirepController extends Controller
|
|||||||
private $userSvc;
|
private $userSvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param AcarsRepository $acarsRepo
|
|
||||||
* @param FareService $fareSvc
|
|
||||||
* @param PirepFinanceService $financeSvc
|
* @param PirepFinanceService $financeSvc
|
||||||
* @param JournalRepository $journalRepo
|
* @param JournalRepository $journalRepo
|
||||||
* @param PirepRepository $pirepRepo
|
* @param PirepRepository $pirepRepo
|
||||||
@@ -55,16 +51,12 @@ class PirepController extends Controller
|
|||||||
* @param UserService $userSvc
|
* @param UserService $userSvc
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AcarsRepository $acarsRepo,
|
|
||||||
FareService $fareSvc,
|
|
||||||
PirepFinanceService $financeSvc,
|
PirepFinanceService $financeSvc,
|
||||||
JournalRepository $journalRepo,
|
JournalRepository $journalRepo,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
PirepService $pirepSvc,
|
PirepService $pirepSvc,
|
||||||
UserService $userSvc
|
UserService $userSvc
|
||||||
) {
|
) {
|
||||||
$this->acarsRepo = $acarsRepo;
|
|
||||||
$this->fareSvc = $fareSvc;
|
|
||||||
$this->financeSvc = $financeSvc;
|
$this->financeSvc = $financeSvc;
|
||||||
$this->journalRepo = $journalRepo;
|
$this->journalRepo = $journalRepo;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
@@ -101,7 +93,7 @@ class PirepController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Check if a PIREP is cancelled
|
* Check if a PIREP is cancelled
|
||||||
*
|
*
|
||||||
* @param $pirep
|
* @param Pirep $pirep
|
||||||
*
|
*
|
||||||
* @throws \App\Exceptions\PirepCancelled
|
* @throws \App\Exceptions\PirepCancelled
|
||||||
*/
|
*/
|
||||||
@@ -113,50 +105,52 @@ class PirepController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $pirep
|
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return PirepFieldValue[]
|
||||||
*/
|
*/
|
||||||
protected function updateFields($pirep, Request $request)
|
protected function getFields(Request $request): ?array
|
||||||
{
|
{
|
||||||
if (!$request->filled('fields')) {
|
if (!$request->filled('fields')) {
|
||||||
return;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$pirep_fields = [];
|
$pirep_fields = [];
|
||||||
foreach ($request->input('fields') as $field_name => $field_value) {
|
foreach ($request->input('fields') as $field_name => $field_value) {
|
||||||
$pirep_fields[] = [
|
$pirep_fields[] = new PirepFieldValue([
|
||||||
'name' => $field_name,
|
'name' => $field_name,
|
||||||
'value' => $field_value,
|
'value' => $field_value,
|
||||||
'source' => PirepFieldSource::ACARS,
|
'source' => PirepFieldSource::ACARS,
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pirepSvc->updateCustomFields($pirep->id, $pirep_fields);
|
return $pirep_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the fares
|
* Save the fares
|
||||||
*
|
*
|
||||||
* @param $pirep
|
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* @return PirepFare[]
|
||||||
*/
|
*/
|
||||||
protected function updateFares($pirep, Request $request)
|
protected function getFares(Request $request): ?array
|
||||||
{
|
{
|
||||||
if (!$request->filled('fares')) {
|
if (!$request->filled('fares')) {
|
||||||
return;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$fares = [];
|
$fares = [];
|
||||||
foreach ($request->post('fares') as $fare) {
|
foreach ($request->post('fares') as $fare) {
|
||||||
$fares[] = [
|
$fares[] = new PirepFare([
|
||||||
'fare_id' => $fare['id'],
|
'fare_id' => $fare['id'],
|
||||||
'count' => $fare['count'],
|
'count' => $fare['count'],
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fareSvc->saveForPirep($pirep, $fares);
|
return $fares;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,6 +167,7 @@ class PirepController extends Controller
|
|||||||
'comments',
|
'comments',
|
||||||
'flight',
|
'flight',
|
||||||
'simbrief',
|
'simbrief',
|
||||||
|
'position',
|
||||||
'user',
|
'user',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -210,14 +205,13 @@ class PirepController extends Controller
|
|||||||
$attrs = $this->parsePirep($request);
|
$attrs = $this->parsePirep($request);
|
||||||
$attrs['source'] = PirepSource::ACARS;
|
$attrs['source'] = PirepSource::ACARS;
|
||||||
|
|
||||||
$pirep = $this->pirepSvc->prefile($user, $attrs);
|
$fields = $this->getFields($request);
|
||||||
|
$fares = $this->getFares($request);
|
||||||
|
$pirep = $this->pirepSvc->prefile($user, $attrs, $fields, $fares);
|
||||||
|
|
||||||
Log::info('PIREP PREFILED');
|
Log::info('PIREP PREFILED');
|
||||||
Log::info($pirep->id);
|
Log::info($pirep->id);
|
||||||
|
|
||||||
$this->updateFields($pirep, $request);
|
|
||||||
$this->updateFares($pirep, $request);
|
|
||||||
|
|
||||||
return $this->get($pirep->id);
|
return $this->get($pirep->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,9 +252,9 @@ class PirepController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$pirep = $this->pirepRepo->update($attrs, $pirep_id);
|
$fields = $this->getFields($request);
|
||||||
$this->updateFields($pirep, $request);
|
$fares = $this->getFares($request);
|
||||||
$this->updateFares($pirep, $request);
|
$pirep = $this->pirepSvc->update($pirep_id, $attrs, $fields, $fares);
|
||||||
|
|
||||||
event(new PirepUpdated($pirep));
|
event(new PirepUpdated($pirep));
|
||||||
|
|
||||||
@@ -303,11 +297,13 @@ class PirepController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$pirep = $this->pirepSvc->file($pirep, $attrs);
|
$fields = $this->getFields($request);
|
||||||
$this->updateFields($pirep, $request);
|
$fares = $this->getFares($request);
|
||||||
$this->updateFares($pirep, $request);
|
$pirep = $this->pirepSvc->file($pirep, $attrs, $fields, $fares);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error($e);
|
Log::error($e);
|
||||||
|
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if there there is any route data posted
|
// See if there there is any route data posted
|
||||||
@@ -409,7 +405,8 @@ class PirepController extends Controller
|
|||||||
$pirep = Pirep::find($pirep_id);
|
$pirep = Pirep::find($pirep_id);
|
||||||
$this->checkCancelled($pirep);
|
$this->checkCancelled($pirep);
|
||||||
|
|
||||||
$this->updateFields($pirep, $request);
|
$fields = $this->getFields($request);
|
||||||
|
$this->pirepSvc->updateCustomFields($pirep_id, $fields);
|
||||||
|
|
||||||
return new PirepFieldCollection($pirep->fields);
|
return new PirepFieldCollection($pirep->fields);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
|
use App\Exceptions\UserNotFound;
|
||||||
use App\Http\Resources\Bid as BidResource;
|
use App\Http\Resources\Bid as BidResource;
|
||||||
use App\Http\Resources\Pirep as PirepResource;
|
use App\Http\Resources\Pirep as PirepResource;
|
||||||
use App\Http\Resources\Subfleet as SubfleetResource;
|
use App\Http\Resources\Subfleet as SubfleetResource;
|
||||||
@@ -91,6 +92,10 @@ class UserController extends Controller
|
|||||||
public function get($id)
|
public function get($id)
|
||||||
{
|
{
|
||||||
$user = $this->userSvc->getUser($id);
|
$user = $this->userSvc->getUser($id);
|
||||||
|
if ($user === null) {
|
||||||
|
throw new UserNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
return new UserResource($user);
|
return new UserResource($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +113,9 @@ class UserController extends Controller
|
|||||||
{
|
{
|
||||||
$user_id = $this->getUserId($request);
|
$user_id = $this->getUserId($request);
|
||||||
$user = $this->userSvc->getUser($user_id);
|
$user = $this->userSvc->getUser($user_id);
|
||||||
|
if ($user === null) {
|
||||||
|
throw new UserNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
// Add a bid
|
// Add a bid
|
||||||
if ($request->isMethod('PUT') || $request->isMethod('POST')) {
|
if ($request->isMethod('PUT') || $request->isMethod('POST')) {
|
||||||
@@ -146,6 +154,10 @@ class UserController extends Controller
|
|||||||
public function fleet(Request $request)
|
public function fleet(Request $request)
|
||||||
{
|
{
|
||||||
$user = $this->userRepo->find($this->getUserId($request));
|
$user = $this->userRepo->find($this->getUserId($request));
|
||||||
|
if ($user === null) {
|
||||||
|
throw new UserNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
$subfleets = $this->userSvc->getAllowableSubfleets($user);
|
$subfleets = $this->userSvc->getAllowableSubfleets($user);
|
||||||
|
|
||||||
return SubfleetResource::collection($subfleets);
|
return SubfleetResource::collection($subfleets);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Auth;
|
|||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Exceptions\PilotIdNotFound;
|
use App\Exceptions\PilotIdNotFound;
|
||||||
use App\Models\Enums\UserState;
|
use App\Models\Enums\UserState;
|
||||||
|
use App\Models\User;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -104,14 +105,16 @@ class LoginController extends Controller
|
|||||||
*/
|
*/
|
||||||
protected function sendLoginResponse(Request $request)
|
protected function sendLoginResponse(Request $request)
|
||||||
{
|
{
|
||||||
|
/** @var User $user */
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
$user->last_ip = $request->ip();
|
if (setting('general.record_user_ip', true)) {
|
||||||
$user->save();
|
$user->last_ip = $request->ip();
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
|
||||||
if ($user->state !== UserState::ACTIVE && $user->state !== UserState::ON_LEAVE) {
|
if ($user->state !== UserState::ACTIVE && $user->state !== UserState::ON_LEAVE) {
|
||||||
Log::info('Trying to login '.$user->ident.', state '
|
Log::info('Trying to login '.$user->ident.', state '.UserState::label($user->state));
|
||||||
.UserState::label($user->state));
|
|
||||||
|
|
||||||
// Log them out
|
// Log them out
|
||||||
$this->guard()->logout();
|
$this->guard()->logout();
|
||||||
|
|||||||
@@ -119,11 +119,16 @@ class RegisterController extends Controller
|
|||||||
*
|
*
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
protected function create(array $opts)
|
protected function create(Request $request): User
|
||||||
{
|
{
|
||||||
// Default options
|
// Default options
|
||||||
|
$opts = $request->all();
|
||||||
$opts['password'] = Hash::make($opts['password']);
|
$opts['password'] = Hash::make($opts['password']);
|
||||||
|
|
||||||
|
if (setting('general.record_user_ip', true)) {
|
||||||
|
$opts['last_ip'] = $request->ip();
|
||||||
|
}
|
||||||
|
|
||||||
// Convert transfer hours into minutes
|
// Convert transfer hours into minutes
|
||||||
if (isset($opts['transfer_time'])) {
|
if (isset($opts['transfer_time'])) {
|
||||||
$opts['transfer_time'] *= 60;
|
$opts['transfer_time'] *= 60;
|
||||||
@@ -158,7 +163,7 @@ class RegisterController extends Controller
|
|||||||
{
|
{
|
||||||
$this->validator($request->all())->validate();
|
$this->validator($request->all())->validate();
|
||||||
|
|
||||||
$user = $this->create($request->all());
|
$user = $this->create($request);
|
||||||
if ($user->state === UserState::PENDING) {
|
if ($user->state === UserState::PENDING) {
|
||||||
return view('auth.pending');
|
return view('auth.pending');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ class AirportController extends Controller
|
|||||||
{
|
{
|
||||||
$id = strtoupper($id);
|
$id = strtoupper($id);
|
||||||
|
|
||||||
$airport = $this->airportRepo->find($id);
|
$airport = $this->airportRepo->where('id', $id)->first();
|
||||||
if (empty($airport)) {
|
if (!$airport) {
|
||||||
Flash::error('Airport not found!');
|
Flash::error('Airport not found!');
|
||||||
return redirect(route('frontend.dashboard.index'));
|
return redirect(route('frontend.dashboard.index'));
|
||||||
}
|
}
|
||||||
@@ -46,12 +46,14 @@ class AirportController extends Controller
|
|||||||
->with(['dpt_airport', 'arr_airport', 'airline'])
|
->with(['dpt_airport', 'arr_airport', 'airline'])
|
||||||
->findWhere([
|
->findWhere([
|
||||||
'arr_airport_id' => $id,
|
'arr_airport_id' => $id,
|
||||||
|
'active' => 1,
|
||||||
])->all();
|
])->all();
|
||||||
|
|
||||||
$outbound_flights = $this->flightRepo
|
$outbound_flights = $this->flightRepo
|
||||||
->with(['dpt_airport', 'arr_airport', 'airline'])
|
->with(['dpt_airport', 'arr_airport', 'airline'])
|
||||||
->findWhere([
|
->findWhere([
|
||||||
'dpt_airport_id' => $id,
|
'dpt_airport_id' => $id,
|
||||||
|
'active' => 1,
|
||||||
])->all();
|
])->all();
|
||||||
|
|
||||||
return view('airports.show', [
|
return view('airports.show', [
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Frontend;
|
|||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Models\Bid;
|
use App\Models\Bid;
|
||||||
use App\Models\Enums\FlightType;
|
use App\Models\Enums\FlightType;
|
||||||
|
use App\Models\Flight;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\Criteria\WhereCriteria;
|
use App\Repositories\Criteria\WhereCriteria;
|
||||||
@@ -105,6 +106,15 @@ class FlightController extends Controller
|
|||||||
Log::emergency($e);
|
Log::emergency($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get only used Flight Types for the search form
|
||||||
|
// And filter according to settings
|
||||||
|
$usedtypes = Flight::select('flight_type')->where($where)->groupby('flight_type')->orderby('flight_type', 'asc')->get();
|
||||||
|
// Build collection with type codes and labels
|
||||||
|
$flight_types = collect('', '');
|
||||||
|
foreach ($usedtypes as $ftype) {
|
||||||
|
$flight_types->put($ftype->flight_type, FlightType::label($ftype->flight_type));
|
||||||
|
}
|
||||||
|
|
||||||
$flights = $this->flightRepo->searchCriteria($request)
|
$flights = $this->flightRepo->searchCriteria($request)
|
||||||
->with([
|
->with([
|
||||||
'dpt_airport',
|
'dpt_airport',
|
||||||
@@ -128,7 +138,7 @@ class FlightController extends Controller
|
|||||||
'saved' => $saved_flights,
|
'saved' => $saved_flights,
|
||||||
'subfleets' => $this->subfleetRepo->selectBoxList(true),
|
'subfleets' => $this->subfleetRepo->selectBoxList(true),
|
||||||
'flight_number' => $request->input('flight_number'),
|
'flight_number' => $request->input('flight_number'),
|
||||||
'flight_types' => FlightType::select(true),
|
'flight_types' => $flight_types,
|
||||||
'flight_type' => $request->input('flight_type'),
|
'flight_type' => $request->input('flight_type'),
|
||||||
'arr_icao' => $request->input('arr_icao'),
|
'arr_icao' => $request->input('arr_icao'),
|
||||||
'dep_icao' => $request->input('dep_icao'),
|
'dep_icao' => $request->input('dep_icao'),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Frontend;
|
namespace App\Http\Controllers\Frontend;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
|
use App\Models\Enums\UserState;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@@ -15,7 +16,7 @@ class HomeController extends Controller
|
|||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$users = User::orderBy('created_at', 'desc')->take(4)->get();
|
$users = User::where('state', '!=', UserState::DELETED)->orderBy('created_at', 'desc')->take(4)->get();
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
Log::emergency($e);
|
Log::emergency($e);
|
||||||
return view('system/errors/database_error', [
|
return view('system/errors/database_error', [
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use App\Models\Enums\PirepSource;
|
|||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
use App\Models\Fare;
|
use App\Models\Fare;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
|
use App\Models\PirepFare;
|
||||||
use App\Models\SimBrief;
|
use App\Models\SimBrief;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\AircraftRepository;
|
use App\Repositories\AircraftRepository;
|
||||||
@@ -103,7 +104,7 @@ class PirepController extends Controller
|
|||||||
$tmp[$ac->id] = $ac['name'].' - '.$ac['registration'];
|
$tmp[$ac->id] = $ac['name'].' - '.$ac['registration'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$aircraft[$subfleet->name] = $tmp;
|
$aircraft[$subfleet->type] = $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $aircraft;
|
return $aircraft;
|
||||||
@@ -112,19 +113,18 @@ class PirepController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Save any custom fields found
|
* Save any custom fields found
|
||||||
*
|
*
|
||||||
* @param Pirep $pirep
|
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*/
|
*/
|
||||||
protected function saveCustomFields(Pirep $pirep, Request $request)
|
protected function saveCustomFields(Request $request): array
|
||||||
{
|
{
|
||||||
$custom_fields = [];
|
$fields = [];
|
||||||
$pirep_fields = $this->pirepFieldRepo->all();
|
$pirep_fields = $this->pirepFieldRepo->all();
|
||||||
foreach ($pirep_fields as $field) {
|
foreach ($pirep_fields as $field) {
|
||||||
if (!$request->filled($field->slug)) {
|
if (!$request->filled($field->slug)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$custom_fields[] = [
|
$fields[] = [
|
||||||
'name' => $field->name,
|
'name' => $field->name,
|
||||||
'slug' => $field->slug,
|
'slug' => $field->slug,
|
||||||
'value' => $request->input($field->slug),
|
'value' => $request->input($field->slug),
|
||||||
@@ -132,8 +132,9 @@ class PirepController extends Controller
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info('PIREP Custom Fields', $custom_fields);
|
Log::info('PIREP Custom Fields', $fields);
|
||||||
$this->pirepSvc->updateCustomFields($pirep->id, $custom_fields);
|
|
||||||
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,10 +160,10 @@ class PirepController extends Controller
|
|||||||
$count = $request->input($field_name);
|
$count = $request->input($field_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fares[] = [
|
$fares[] = new PirepFare([
|
||||||
'fare_id' => $fare->id,
|
'fare_id' => $fare->id,
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fareSvc->saveForPirep($pirep, $fares);
|
$this->fareSvc->saveForPirep($pirep, $fares);
|
||||||
@@ -389,8 +390,8 @@ class PirepController extends Controller
|
|||||||
$attrs['submitted_at'] = Carbon::now('UTC');
|
$attrs['submitted_at'] = Carbon::now('UTC');
|
||||||
$pirep->submitted_at = Carbon::now('UTC');
|
$pirep->submitted_at = Carbon::now('UTC');
|
||||||
|
|
||||||
$pirep = $this->pirepSvc->create($pirep);
|
$fields = $this->saveCustomFields($request);
|
||||||
$this->saveCustomFields($pirep, $request);
|
$pirep = $this->pirepSvc->create($pirep, $fields);
|
||||||
$this->saveFares($pirep, $request);
|
$this->saveFares($pirep, $request);
|
||||||
$this->pirepSvc->saveRoute($pirep);
|
$this->pirepSvc->saveRoute($pirep);
|
||||||
|
|
||||||
@@ -399,7 +400,13 @@ class PirepController extends Controller
|
|||||||
if ($brief !== null) {
|
if ($brief !== null) {
|
||||||
/** @var SimBriefService $sbSvc */
|
/** @var SimBriefService $sbSvc */
|
||||||
$sbSvc = app(SimBriefService::class);
|
$sbSvc = app(SimBriefService::class);
|
||||||
$sbSvc->attachSimbriefToPirep($pirep, $brief);
|
// Keep the flight_id with SimBrief depending on the button selected
|
||||||
|
// Save = Keep the flight_id , Submit = Remove the flight_id
|
||||||
|
if ($attrs['submit'] === 'save') {
|
||||||
|
$sbSvc->attachSimbriefToPirep($pirep, $brief, true);
|
||||||
|
} elseif ($attrs['submit'] === 'submit') {
|
||||||
|
$sbSvc->attachSimbriefToPirep($pirep, $brief);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,7 +532,8 @@ class PirepController extends Controller
|
|||||||
$this->pirepSvc->saveRoute($pirep);
|
$this->pirepSvc->saveRoute($pirep);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->saveCustomFields($pirep, $request);
|
$fields = $this->saveCustomFields($request);
|
||||||
|
$this->pirepSvc->updateCustomFields($pirep->id, $fields);
|
||||||
$this->saveFares($pirep, $request);
|
$this->saveFares($pirep, $request);
|
||||||
|
|
||||||
if ($attrs['submit'] === 'save') {
|
if ($attrs['submit'] === 'save') {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use App\Repositories\AirlineRepository;
|
|||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
use App\Support\Countries;
|
use App\Support\Countries;
|
||||||
|
use App\Support\Discord;
|
||||||
use App\Support\Timezonelist;
|
use App\Support\Timezonelist;
|
||||||
use App\Support\Utils;
|
use App\Support\Utils;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -181,6 +182,16 @@ class ProfileController extends Controller
|
|||||||
Storage::delete($user->avatar);
|
Storage::delete($user->avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find out the user's private channel id
|
||||||
|
/*
|
||||||
|
// TODO: Uncomment when Discord API functionality is enabled
|
||||||
|
if ($request->filled('discord_id')) {
|
||||||
|
$discord_id = $request->post('discord_id');
|
||||||
|
if ($discord_id !== $user->discord_id) {
|
||||||
|
$req_data['discord_private_channel_id'] = Discord::getPrivateChannelId($discord_id);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
if ($request->hasFile('avatar')) {
|
if ($request->hasFile('avatar')) {
|
||||||
$avatar = $request->file('avatar');
|
$avatar = $request->file('avatar');
|
||||||
$file_name = $user->ident.'.'.$avatar->getClientOriginalExtension();
|
$file_name = $user->ident.'.'.$avatar->getClientOriginalExtension();
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ class SimBriefController
|
|||||||
return redirect(route('frontend.flights.index'));
|
return redirect(route('frontend.flights.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate SimBrief Static ID
|
||||||
|
$static_id = $user->ident.'_'.$flight->id;
|
||||||
|
|
||||||
// No aircraft selected, show selection form
|
// No aircraft selected, show selection form
|
||||||
if (!$aircraft_id) {
|
if (!$aircraft_id) {
|
||||||
// If no subfleets defined for flight get them from user
|
// If no subfleets defined for flight get them from user
|
||||||
@@ -100,6 +103,13 @@ class SimBriefController
|
|||||||
$aircrafts = $aircrafts->where('airport_id', $flight->dpt_airport_id);
|
$aircrafts = $aircrafts->where('airport_id', $flight->dpt_airport_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setting('simbrief.block_aircraft')) {
|
||||||
|
// Build a list of aircraft_id's being used for active sb packs
|
||||||
|
$sb_aircraft = SimBrief::whereNotNull('flight_id')->pluck('aircraft_id');
|
||||||
|
// Filter aircraft list to non used/blocked ones
|
||||||
|
$aircrafts = $aircrafts->whereNotIn('id', $sb_aircraft);
|
||||||
|
}
|
||||||
|
|
||||||
return view('flights.simbrief_aircraft', [
|
return view('flights.simbrief_aircraft', [
|
||||||
'flight' => $flight,
|
'flight' => $flight,
|
||||||
'aircrafts' => $aircrafts,
|
'aircrafts' => $aircrafts,
|
||||||
@@ -230,6 +240,7 @@ class SimBriefController
|
|||||||
'tpayload' => $tpayload,
|
'tpayload' => $tpayload,
|
||||||
'tcargoload' => $tcargoload,
|
'tcargoload' => $tcargoload,
|
||||||
'loaddist' => implode(' ', $loaddist),
|
'loaddist' => implode(' ', $loaddist),
|
||||||
|
'static_id' => $static_id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,6 +371,31 @@ class SimBriefController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest generated OFP. Pass in two additional items, the Simbrief userid and static_id
|
||||||
|
* This will get the latest edited/regenerated of from Simbrief and update our records
|
||||||
|
* We do not need to send the fares again, so used an empty array
|
||||||
|
*/
|
||||||
|
public function update_ofp(Request $request)
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = Auth::user();
|
||||||
|
$ofp_id = $request->input('ofp_id');
|
||||||
|
$flight_id = $request->input('flight_id');
|
||||||
|
$aircraft_id = $request->input('aircraft_id');
|
||||||
|
$sb_userid = $request->input('sb_userid');
|
||||||
|
$sb_static_id = $request->input('sb_static_id');
|
||||||
|
$fares = [];
|
||||||
|
|
||||||
|
$simbrief = $this->simBriefSvc->downloadOfp($user->id, $ofp_id, $flight_id, $aircraft_id, $fares, $sb_userid, $sb_static_id);
|
||||||
|
if ($simbrief === null) {
|
||||||
|
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
|
||||||
|
return $error->getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect(route('frontend.simbrief.briefing', [$ofp_id]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the API code
|
* Generate the API code
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ use Illuminate\Support\Facades\Log;
|
|||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
use Laracasts\Flash\Flash;
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
class InstallerController extends Controller
|
class InstallerController extends Controller
|
||||||
@@ -210,7 +209,7 @@ class InstallerController extends Controller
|
|||||||
// Now write out the env file
|
// Now write out the env file
|
||||||
$attrs = [
|
$attrs = [
|
||||||
'SITE_NAME' => $request->post('site_name'),
|
'SITE_NAME' => $request->post('site_name'),
|
||||||
'SITE_URL' => $request->post('site_url'),
|
'APP_URL' => $request->post('app_url'),
|
||||||
'DB_CONNECTION' => $request->post('db_conn'),
|
'DB_CONNECTION' => $request->post('db_conn'),
|
||||||
'DB_HOST' => $request->post('db_host'),
|
'DB_HOST' => $request->post('db_host'),
|
||||||
'DB_PORT' => $request->post('db_port'),
|
'DB_PORT' => $request->post('db_port'),
|
||||||
|
|||||||
@@ -3,49 +3,32 @@
|
|||||||
namespace App\Http\Controllers\System;
|
namespace App\Http\Controllers\System;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Repositories\KvpRepository;
|
|
||||||
use App\Services\AnalyticsService;
|
|
||||||
use App\Services\Installer\InstallerService;
|
use App\Services\Installer\InstallerService;
|
||||||
use App\Services\Installer\MigrationService;
|
use App\Services\Installer\MigrationService;
|
||||||
use App\Services\Installer\SeederService;
|
use App\Services\Installer\SeederService;
|
||||||
use Codedge\Updater\UpdaterManager;
|
|
||||||
use function count;
|
use function count;
|
||||||
use Illuminate\Contracts\View\Factory;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\View\View;
|
|
||||||
|
|
||||||
class UpdateController extends Controller
|
class UpdateController extends Controller
|
||||||
{
|
{
|
||||||
private $analyticsSvc;
|
|
||||||
private $installerSvc;
|
private $installerSvc;
|
||||||
private $kvpRepo;
|
|
||||||
private $migrationSvc;
|
private $migrationSvc;
|
||||||
private $seederSvc;
|
private $seederSvc;
|
||||||
private $updateManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param AnalyticsService $analyticsSvc
|
|
||||||
* @param InstallerService $installerSvc
|
* @param InstallerService $installerSvc
|
||||||
* @param KvpRepository $kvpRepo
|
|
||||||
* @param MigrationService $migrationSvc
|
* @param MigrationService $migrationSvc
|
||||||
* @param SeederService $seederSvc
|
* @param SeederService $seederSvc
|
||||||
* @param UpdaterManager $updateManager
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AnalyticsService $analyticsSvc,
|
|
||||||
InstallerService $installerSvc,
|
InstallerService $installerSvc,
|
||||||
KvpRepository $kvpRepo,
|
|
||||||
MigrationService $migrationSvc,
|
MigrationService $migrationSvc,
|
||||||
SeederService $seederSvc,
|
SeederService $seederSvc
|
||||||
UpdaterManager $updateManager
|
|
||||||
) {
|
) {
|
||||||
$this->analyticsSvc = $analyticsSvc;
|
|
||||||
$this->migrationSvc = $migrationSvc;
|
$this->migrationSvc = $migrationSvc;
|
||||||
$this->seederSvc = $seederSvc;
|
$this->seederSvc = $seederSvc;
|
||||||
$this->installerSvc = $installerSvc;
|
$this->installerSvc = $installerSvc;
|
||||||
$this->kvpRepo = $kvpRepo;
|
|
||||||
$this->updateManager = $updateManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,38 +90,4 @@ class UpdateController extends Controller
|
|||||||
{
|
{
|
||||||
return redirect('/admin');
|
return redirect('/admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the update page with the latest version
|
|
||||||
*
|
|
||||||
* @return Factory|View
|
|
||||||
*/
|
|
||||||
public function updater()
|
|
||||||
{
|
|
||||||
$version = $this->kvpRepo->get('latest_version_tag');
|
|
||||||
|
|
||||||
return view('system.updater.downloader/downloader', [
|
|
||||||
'version' => $version,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Download the actual update and then forward the user to the updater page
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function update_download()
|
|
||||||
{
|
|
||||||
$version = $this->kvpRepo->get('latest_version_tag');
|
|
||||||
if (empty($version)) {
|
|
||||||
return view('system.updater.steps.step1-no-update');
|
|
||||||
}
|
|
||||||
|
|
||||||
$release = $this->updateManager->source('github')->fetch($version);
|
|
||||||
$this->updateManager->source('github')->update($release);
|
|
||||||
$this->analyticsSvc->sendUpdate();
|
|
||||||
|
|
||||||
Log::info('Update completed to '.$version.', redirecting');
|
|
||||||
return redirect('/update');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ class ApiAuth implements Middleware
|
|||||||
return $user;
|
return $user;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Force english locale for API
|
||||||
|
app()->setLocale('en');
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class JsonResponse implements Middleware
|
|||||||
{
|
{
|
||||||
$response = $next($request);
|
$response = $next($request);
|
||||||
$response->headers->set('Content-Type', 'application/json');
|
$response->headers->set('Content-Type', 'application/json');
|
||||||
|
$response->headers->set('charset', 'utf-8');
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class FileRequest extends FormRequest
|
|||||||
return [
|
return [
|
||||||
'distance' => 'required|numeric',
|
'distance' => 'required|numeric',
|
||||||
'flight_time' => 'required|integer',
|
'flight_time' => 'required|integer',
|
||||||
'fuel_used' => 'required|numeric',
|
'fuel_used' => 'sometimes|numeric',
|
||||||
'block_time' => 'sometimes|integer',
|
'block_time' => 'sometimes|integer',
|
||||||
'airline_id' => 'sometimes|exists:airlines,id',
|
'airline_id' => 'sometimes|exists:airlines,id',
|
||||||
'aircraft_id' => 'sometimes|exists:aircraft,id',
|
'aircraft_id' => 'sometimes|exists:aircraft,id',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class News extends Resource
|
|||||||
$res = parent::toArray($request);
|
$res = parent::toArray($request);
|
||||||
$res['user'] = [
|
$res['user'] = [
|
||||||
'id' => $this->user->id,
|
'id' => $this->user->id,
|
||||||
'name' => $this->user->name,
|
'name' => $this->user->name_private,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Log\Events\MessageLogged;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show logs in the console
|
||||||
|
*
|
||||||
|
* https://stackoverflow.com/questions/48264479/log-laravel-with-artisan-output
|
||||||
|
*/
|
||||||
|
class MessageLoggedListener
|
||||||
|
{
|
||||||
|
public function handle(MessageLogged $event)
|
||||||
|
{
|
||||||
|
if (app()->runningInConsole() && app()->environment() !== 'testing') {
|
||||||
|
$output = new ConsoleOutput();
|
||||||
|
$output->writeln("<$event->level>$event->message</$event->level>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,10 +6,7 @@ use App\Contracts\Listener;
|
|||||||
use App\Events\PirepPrefiled;
|
use App\Events\PirepPrefiled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for and run any of the award classes. Don't modify this.
|
* Handler for PIREP events
|
||||||
* See the documentation on creating awards:
|
|
||||||
*
|
|
||||||
* @url http://docs.phpvms.net/customizing/awards
|
|
||||||
*/
|
*/
|
||||||
class PirepEventsHandler extends Listener
|
class PirepEventsHandler extends Listener
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use Carbon\Carbon;
|
|||||||
* @property int id
|
* @property int id
|
||||||
* @property mixed subfleet_id
|
* @property mixed subfleet_id
|
||||||
* @property string airport_id The apt where the aircraft is
|
* @property string airport_id The apt where the aircraft is
|
||||||
|
* @property string ident
|
||||||
* @property string name
|
* @property string name
|
||||||
* @property string icao
|
* @property string icao
|
||||||
* @property string registration
|
* @property string registration
|
||||||
@@ -24,6 +25,7 @@ use Carbon\Carbon;
|
|||||||
* @property int status
|
* @property int status
|
||||||
* @property int state
|
* @property int state
|
||||||
* @property Carbon landing_time
|
* @property Carbon landing_time
|
||||||
|
* @property float fuel_onboard
|
||||||
*/
|
*/
|
||||||
class Aircraft extends Model
|
class Aircraft extends Model
|
||||||
{
|
{
|
||||||
@@ -70,6 +72,14 @@ class Aircraft extends Model
|
|||||||
'zfw' => 'nullable|numeric',
|
'zfw' => 'nullable|numeric',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getIdentAttribute(): string
|
||||||
|
{
|
||||||
|
return $this->registration.' ('.$this->icao.')';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See if this aircraft is active
|
* See if this aircraft is active
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use App\Contracts\Model;
|
|||||||
use App\Models\Enums\JournalType;
|
use App\Models\Enums\JournalType;
|
||||||
use App\Models\Traits\FilesTrait;
|
use App\Models\Traits\FilesTrait;
|
||||||
use App\Models\Traits\JournalTrait;
|
use App\Models\Traits\JournalTrait;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Airline
|
* Class Airline
|
||||||
@@ -84,7 +85,7 @@ class Airline extends Model
|
|||||||
*/
|
*/
|
||||||
public function setIataAttribute($iata)
|
public function setIataAttribute($iata)
|
||||||
{
|
{
|
||||||
$this->attributes['iata'] = strtoupper($iata);
|
$this->attributes['iata'] = Str::upper($iata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,7 +95,7 @@ class Airline extends Model
|
|||||||
*/
|
*/
|
||||||
public function setIcaoAttribute($icao): void
|
public function setIcaoAttribute($icao): void
|
||||||
{
|
{
|
||||||
$this->attributes['icao'] = strtoupper($icao);
|
$this->attributes['icao'] = Str::upper($icao);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subfleets()
|
public function subfleets()
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class Days extends Enum
|
|||||||
*/
|
*/
|
||||||
public static function in($mask, $day): bool
|
public static function in($mask, $day): bool
|
||||||
{
|
{
|
||||||
return ($mask & $day) === $day;
|
return in_mask($mask, $day);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class PirepStatus extends Enum
|
|||||||
public const LANDED = 'LAN';
|
public const LANDED = 'LAN';
|
||||||
public const ARRIVED = 'ONB'; // On block
|
public const ARRIVED = 'ONB'; // On block
|
||||||
public const CANCELLED = 'DX';
|
public const CANCELLED = 'DX';
|
||||||
public const EMERG_DECENT = 'EMG';
|
public const EMERG_DESCENT = 'EMG';
|
||||||
|
|
||||||
protected static $labels = [
|
protected static $labels = [
|
||||||
self::INITIATED => 'pireps.status.initialized',
|
self::INITIATED => 'pireps.status.initialized',
|
||||||
@@ -58,6 +58,6 @@ class PirepStatus extends Enum
|
|||||||
self::LANDED => 'pireps.status.landed',
|
self::LANDED => 'pireps.status.landed',
|
||||||
self::ARRIVED => 'pireps.status.arrived',
|
self::ARRIVED => 'pireps.status.arrived',
|
||||||
self::CANCELLED => 'pireps.status.cancelled',
|
self::CANCELLED => 'pireps.status.cancelled',
|
||||||
self::EMERG_DECENT => 'pireps.status.emerg_decent',
|
self::EMERG_DESCENT => 'pireps.status.emerg_decent',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class UserState extends Enum
|
|||||||
public const REJECTED = 2;
|
public const REJECTED = 2;
|
||||||
public const ON_LEAVE = 3;
|
public const ON_LEAVE = 3;
|
||||||
public const SUSPENDED = 4;
|
public const SUSPENDED = 4;
|
||||||
|
public const DELETED = 5;
|
||||||
|
|
||||||
protected static $labels = [
|
protected static $labels = [
|
||||||
self::PENDING => 'user.state.pending',
|
self::PENDING => 'user.state.pending',
|
||||||
@@ -18,5 +19,6 @@ class UserState extends Enum
|
|||||||
self::REJECTED => 'user.state.rejected',
|
self::REJECTED => 'user.state.rejected',
|
||||||
self::ON_LEAVE => 'user.state.on_leave',
|
self::ON_LEAVE => 'user.state.on_leave',
|
||||||
self::SUSPENDED => 'user.state.suspended',
|
self::SUSPENDED => 'user.state.suspended',
|
||||||
|
self::DELETED => 'user.state.deleted',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use App\Models\Traits\ReferenceTrait;
|
|||||||
* @property string flight_type
|
* @property string flight_type
|
||||||
* @property string ref_model
|
* @property string ref_model
|
||||||
* @property string ref_model_id
|
* @property string ref_model_id
|
||||||
|
* @property bool charge_to_user
|
||||||
*
|
*
|
||||||
* @mixin \Illuminate\Database\Eloquent\Builder
|
* @mixin \Illuminate\Database\Eloquent\Builder
|
||||||
*/
|
*/
|
||||||
@@ -36,7 +37,7 @@ class Expense extends Model
|
|||||||
];
|
];
|
||||||
|
|
||||||
public static $rules = [
|
public static $rules = [
|
||||||
'active' => 'boolean',
|
'active' => 'bool',
|
||||||
'airline_id' => 'integer',
|
'airline_id' => 'integer',
|
||||||
'amount' => 'float',
|
'amount' => 'float',
|
||||||
'multiplier' => 'bool',
|
'multiplier' => 'bool',
|
||||||
|
|||||||
+8
-2
@@ -3,13 +3,19 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Contracts\Model;
|
use App\Contracts\Model;
|
||||||
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property string subject
|
* @property int id
|
||||||
* @property string body
|
* @property int|mixed user_id
|
||||||
|
* @property string subject
|
||||||
|
* @property string body
|
||||||
|
* @property User user
|
||||||
*/
|
*/
|
||||||
class News extends Model
|
class News extends Model
|
||||||
{
|
{
|
||||||
|
use Notifiable;
|
||||||
|
|
||||||
public $table = 'news';
|
public $table = 'news';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
|||||||
+17
-2
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Contracts\Model;
|
use App\Contracts\Model;
|
||||||
|
use App\Events\PirepStateChange;
|
||||||
|
use App\Events\PirepStatusChange;
|
||||||
use App\Models\Enums\AcarsType;
|
use App\Models\Enums\AcarsType;
|
||||||
use App\Models\Enums\PirepFieldSource;
|
use App\Models\Enums\PirepFieldSource;
|
||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
@@ -10,7 +12,9 @@ use App\Models\Traits\HashIdTrait;
|
|||||||
use App\Support\Units\Distance;
|
use App\Support\Units\Distance;
|
||||||
use App\Support\Units\Fuel;
|
use App\Support\Units\Fuel;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Kleemans\AttributeEvents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property string id
|
* @property string id
|
||||||
@@ -44,8 +48,9 @@ use Illuminate\Support\Collection;
|
|||||||
* @property Flight|null flight
|
* @property Flight|null flight
|
||||||
* @property Collection fields
|
* @property Collection fields
|
||||||
* @property string status
|
* @property string status
|
||||||
* @property bool state
|
* @property int state
|
||||||
* @property string source
|
* @property int source
|
||||||
|
* @property string source_name
|
||||||
* @property Carbon submitted_at
|
* @property Carbon submitted_at
|
||||||
* @property Carbon created_at
|
* @property Carbon created_at
|
||||||
* @property Carbon updated_at
|
* @property Carbon updated_at
|
||||||
@@ -56,7 +61,9 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
class Pirep extends Model
|
class Pirep extends Model
|
||||||
{
|
{
|
||||||
|
use AttributeEvents;
|
||||||
use HashIdTrait;
|
use HashIdTrait;
|
||||||
|
use Notifiable;
|
||||||
|
|
||||||
public $table = 'pireps';
|
public $table = 'pireps';
|
||||||
|
|
||||||
@@ -136,6 +143,14 @@ class Pirep extends Model
|
|||||||
'route' => 'nullable',
|
'route' => 'nullable',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-dispatch events for lifecycle state changes
|
||||||
|
*/
|
||||||
|
protected $dispatchesEvents = [
|
||||||
|
'status:*' => PirepStatusChange::class,
|
||||||
|
'state:*' => PirepStateChange::class,
|
||||||
|
];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a PIREP is in these states, then it can't be changed.
|
* If a PIREP is in these states, then it can't be changed.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use App\Models\Enums\PirepFieldSource;
|
|||||||
* @property string slug
|
* @property string slug
|
||||||
* @property string value
|
* @property string value
|
||||||
* @property string source
|
* @property string source
|
||||||
|
* @property Pirep pirep
|
||||||
*
|
*
|
||||||
* @method static updateOrCreate(array $array, array $array1)
|
* @method static updateOrCreate(array $array, array $array1)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ use App\Models\Traits\FilesTrait;
|
|||||||
* @property float cost_delay_minute
|
* @property float cost_delay_minute
|
||||||
* @property Airline airline
|
* @property Airline airline
|
||||||
* @property Airport hub
|
* @property Airport hub
|
||||||
|
* @property int fuel_type
|
||||||
*/
|
*/
|
||||||
class Subfleet extends Model
|
class Subfleet extends Model
|
||||||
{
|
{
|
||||||
|
|||||||
+11
-3
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Models\Enums\JournalType;
|
use App\Models\Enums\JournalType;
|
||||||
use App\Models\Enums\PirepState;
|
|
||||||
use App\Models\Traits\JournalTrait;
|
use App\Models\Traits\JournalTrait;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
@@ -33,11 +32,16 @@ use Laratrust\Traits\LaratrustUserTrait;
|
|||||||
* @property Rank rank
|
* @property Rank rank
|
||||||
* @property Journal journal
|
* @property Journal journal
|
||||||
* @property int rank_id
|
* @property int rank_id
|
||||||
|
* @property string discord_id
|
||||||
* @property int state
|
* @property int state
|
||||||
|
* @property string last_ip
|
||||||
* @property bool opt_in
|
* @property bool opt_in
|
||||||
|
* @property Pirep[] pireps
|
||||||
* @property string last_pirep_id
|
* @property string last_pirep_id
|
||||||
* @property Pirep last_pirep
|
* @property Pirep last_pirep
|
||||||
* @property UserFieldValue[] fields
|
* @property UserFieldValue[] fields
|
||||||
|
* @property Role[] roles
|
||||||
|
* @property Subfleet[] subfleets
|
||||||
*
|
*
|
||||||
* @mixin \Illuminate\Database\Eloquent\Builder
|
* @mixin \Illuminate\Database\Eloquent\Builder
|
||||||
* @mixin \Illuminate\Notifications\Notifiable
|
* @mixin \Illuminate\Notifications\Notifiable
|
||||||
@@ -64,6 +68,8 @@ class User extends Authenticatable
|
|||||||
'pilot_id',
|
'pilot_id',
|
||||||
'airline_id',
|
'airline_id',
|
||||||
'rank_id',
|
'rank_id',
|
||||||
|
'discord_id',
|
||||||
|
'discord_private_channel_id',
|
||||||
'api_key',
|
'api_key',
|
||||||
'country',
|
'country',
|
||||||
'home_airport_id',
|
'home_airport_id',
|
||||||
@@ -78,6 +84,7 @@ class User extends Authenticatable
|
|||||||
'status',
|
'status',
|
||||||
'toc_accepted',
|
'toc_accepted',
|
||||||
'opt_in',
|
'opt_in',
|
||||||
|
'last_ip',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
];
|
];
|
||||||
@@ -87,7 +94,9 @@ class User extends Authenticatable
|
|||||||
*/
|
*/
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'api_key',
|
'api_key',
|
||||||
|
'discord_id',
|
||||||
'password',
|
'password',
|
||||||
|
'last_ip',
|
||||||
'remember_token',
|
'remember_token',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -249,8 +258,7 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
public function pireps()
|
public function pireps()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Pirep::class, 'user_id')
|
return $this->hasMany(Pirep::class, 'user_id');
|
||||||
->where('state', '!=', PirepState::CANCELLED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rank()
|
public function rank()
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Channels\Discord;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Original is from https://gist.github.com/freekmurze/e4415090f650e070d3de8b905875cf78
|
||||||
|
*
|
||||||
|
* Markdown guide: https://birdie0.github.io/discord-webhooks-guide/other/discord_markdown.html
|
||||||
|
*/
|
||||||
|
class DiscordMessage
|
||||||
|
{
|
||||||
|
const COLOR_SUCCESS = '#0B6623';
|
||||||
|
const COLOR_WARNING = '#FD6A02';
|
||||||
|
const COLOR_ERROR = '#ED2939';
|
||||||
|
|
||||||
|
public $webhook_url;
|
||||||
|
|
||||||
|
protected $title;
|
||||||
|
protected $url;
|
||||||
|
protected $description;
|
||||||
|
protected $timestamp;
|
||||||
|
protected $footer;
|
||||||
|
protected $color;
|
||||||
|
protected $author = [];
|
||||||
|
protected $fields = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supply the webhook URL that this should be going to
|
||||||
|
*/
|
||||||
|
public function webhook(string $url): self
|
||||||
|
{
|
||||||
|
$this->webhook_url = $url;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title of the notification
|
||||||
|
*/
|
||||||
|
public function title(string $title): self
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function url(string $url): self
|
||||||
|
{
|
||||||
|
$this->url = $url;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array|string $descriptionLines
|
||||||
|
*/
|
||||||
|
public function description($descriptionLines): self
|
||||||
|
{
|
||||||
|
if (!is_array($descriptionLines)) {
|
||||||
|
$descriptionLines = [$descriptionLines];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->description = implode(PHP_EOL, $descriptionLines);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the author information:
|
||||||
|
* [
|
||||||
|
* 'name' => '',
|
||||||
|
* 'url' => '',
|
||||||
|
* 'icon_url' => '',
|
||||||
|
*/
|
||||||
|
public function author(array $author): self
|
||||||
|
{
|
||||||
|
$this->author = $author;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the fields
|
||||||
|
*/
|
||||||
|
public function fields(array $fields): self
|
||||||
|
{
|
||||||
|
$this->fields = [];
|
||||||
|
foreach ($fields as $name => $value) {
|
||||||
|
$this->fields[] = [
|
||||||
|
'name' => '**'.$name.'**', // bold
|
||||||
|
'value' => $value,
|
||||||
|
'inline' => true,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function footer(string $footer): self
|
||||||
|
{
|
||||||
|
$this->footer = $footer;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function success(): self
|
||||||
|
{
|
||||||
|
$this->color = static::COLOR_SUCCESS;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function warning(): self
|
||||||
|
{
|
||||||
|
$this->color = static::COLOR_WARNING;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function error(): self
|
||||||
|
{
|
||||||
|
$this->color = static::COLOR_ERROR;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
$embeds = [
|
||||||
|
'title' => $this->title,
|
||||||
|
'url' => $this->url,
|
||||||
|
'type' => 'rich',
|
||||||
|
'description' => $this->description,
|
||||||
|
'author' => $this->author,
|
||||||
|
'timestamp' => Carbon::now('UTC'),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($this->fields)) {
|
||||||
|
$embeds['fields'] = $this->fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($this->footer)) {
|
||||||
|
$embeds['footer'] = [
|
||||||
|
'text' => $this->footer,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'embeds' => [$embeds],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Channels\Discord;
|
||||||
|
|
||||||
|
use App\Contracts\Notification;
|
||||||
|
use App\Support\HttpClient;
|
||||||
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
use GuzzleHttp\Psr7;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class DiscordWebhook
|
||||||
|
{
|
||||||
|
private $httpClient;
|
||||||
|
|
||||||
|
public function __construct(HttpClient $httpClient)
|
||||||
|
{
|
||||||
|
$this->httpClient = $httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send($notifiable, Notification $notification)
|
||||||
|
{
|
||||||
|
$message = $notification->toDiscordChannel($notifiable);
|
||||||
|
if ($message === null || empty($message->webhook_url)) {
|
||||||
|
Log::debug('Discord notifications not configured, skipping');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$data = $message->toArray();
|
||||||
|
$this->httpClient->post($message->webhook_url, $data);
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
$request = Psr7\Message::toString($e->getRequest());
|
||||||
|
$response = Psr7\Message::toString($e->getResponse());
|
||||||
|
Log::error('Error sending Discord notification: request: '.$e->getMessage().', '.$request);
|
||||||
|
Log::error('Error sending Discord notification: response: '.$response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@ trait MailChannel
|
|||||||
* @param string $template Markdown template to use
|
* @param string $template Markdown template to use
|
||||||
* @param array $args Arguments to pass to the template
|
* @param array $args Arguments to pass to the template
|
||||||
*/
|
*/
|
||||||
public function setMailable($subject, $template, $args)
|
public function setMailable(string $subject, string $template, array $args)
|
||||||
{
|
{
|
||||||
$this->mailSubject = $subject;
|
$this->mailSubject = $subject;
|
||||||
$this->mailTemplate = $template;
|
$this->mailTemplate = $template;
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ namespace App\Notifications\Messages;
|
|||||||
|
|
||||||
use App\Contracts\Notification;
|
use App\Contracts\Notification;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordMessage;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordWebhook;
|
||||||
use App\Notifications\Channels\MailChannel;
|
use App\Notifications\Channels\MailChannel;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
class AdminUserRegistered extends Notification
|
class AdminUserRegistered extends Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
use MailChannel;
|
use MailChannel;
|
||||||
|
|
||||||
public $channels = ['mail'];
|
|
||||||
|
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +32,32 @@ class AdminUserRegistered extends Notification
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail', DiscordWebhook::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a Discord notification
|
||||||
|
*
|
||||||
|
* @param User $pirep
|
||||||
|
* @param mixed $user
|
||||||
|
*
|
||||||
|
* @return DiscordMessage|null
|
||||||
|
*/
|
||||||
|
public function toDiscordChannel($user): ?DiscordMessage
|
||||||
|
{
|
||||||
|
if (empty(setting('notifications.discord_private_webhook_url'))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dm = new DiscordMessage();
|
||||||
|
return $dm->webhook(setting('notifications.discord_private_webhook_url'))
|
||||||
|
->success()
|
||||||
|
->title('New User Registered: '.$user->ident)
|
||||||
|
->fields([]);
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray($notifiable)
|
public function toArray($notifiable)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ namespace App\Notifications\Messages;
|
|||||||
|
|
||||||
use App\Contracts\Notification;
|
use App\Contracts\Notification;
|
||||||
use App\Models\News;
|
use App\Models\News;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordMessage;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordWebhook;
|
||||||
use App\Notifications\Channels\MailChannel;
|
use App\Notifications\Channels\MailChannel;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
class NewsAdded extends Notification
|
class NewsAdded extends Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
use MailChannel;
|
use MailChannel;
|
||||||
|
|
||||||
public $channels = ['mail'];
|
|
||||||
public $requires_opt_in = true;
|
public $requires_opt_in = true;
|
||||||
|
|
||||||
private $news;
|
private $news;
|
||||||
@@ -27,6 +29,34 @@ class NewsAdded extends Notification
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail', DiscordWebhook::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param News $news
|
||||||
|
*
|
||||||
|
* @return DiscordMessage|null
|
||||||
|
*/
|
||||||
|
public function toDiscordChannel($news): ?DiscordMessage
|
||||||
|
{
|
||||||
|
if (empty(setting('notifications.discord_public_webhook_url'))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dm = new DiscordMessage();
|
||||||
|
return $dm->webhook(setting('notifications.discord_public_webhook_url'))
|
||||||
|
->success()
|
||||||
|
->title('News: '.$news->subject)
|
||||||
|
->author([
|
||||||
|
'name' => $news->user->ident.' - '.$news->user->name_private,
|
||||||
|
'url' => '',
|
||||||
|
'icon_url' => $news->user->resolveAvatarUrl(),
|
||||||
|
])
|
||||||
|
->description($news->body);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the array representation of the notification.
|
* Get the array representation of the notification.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,16 +5,15 @@ namespace App\Notifications\Messages;
|
|||||||
use App\Contracts\Notification;
|
use App\Contracts\Notification;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Notifications\Channels\MailChannel;
|
use App\Notifications\Channels\MailChannel;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the PIREP accepted message to a particular user
|
* Send the PIREP accepted message to a particular user, can also be sent to Discord
|
||||||
*/
|
*/
|
||||||
class PirepAccepted extends Notification
|
class PirepAccepted extends Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
use MailChannel;
|
use MailChannel;
|
||||||
|
|
||||||
public $channels = ['mail'];
|
|
||||||
|
|
||||||
private $pirep;
|
private $pirep;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,6 +34,11 @@ class PirepAccepted extends Notification
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the array representation of the notification.
|
* Get the array representation of the notification.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Messages;
|
||||||
|
|
||||||
|
use App\Contracts\Notification;
|
||||||
|
use App\Models\Pirep;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordMessage;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordWebhook;
|
||||||
|
use App\Support\Units\Distance;
|
||||||
|
use App\Support\Units\Time;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use PhpUnitsOfMeasure\Exception\NonNumericValue;
|
||||||
|
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the PIREP accepted message to a particular user, can also be sent to Discord
|
||||||
|
*/
|
||||||
|
class PirepPrefiled extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
private $pirep;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @param Pirep $pirep
|
||||||
|
*/
|
||||||
|
public function __construct(Pirep $pirep)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->pirep = $pirep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return [DiscordWebhook::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a Discord notification
|
||||||
|
*
|
||||||
|
* @param Pirep $pirep
|
||||||
|
*
|
||||||
|
* @return DiscordMessage|null
|
||||||
|
*/
|
||||||
|
public function toDiscordChannel($pirep): ?DiscordMessage
|
||||||
|
{
|
||||||
|
if (empty(setting('notifications.discord_public_webhook_url'))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = 'Flight '.$pirep->airline->code.$pirep->ident.' Prefiled';
|
||||||
|
$fields = [
|
||||||
|
'Flight' => $pirep->airline->code.$pirep->ident,
|
||||||
|
'Departure Airport' => $pirep->dpt_airport_id,
|
||||||
|
'Arrival Airport' => $pirep->arr_airport_id,
|
||||||
|
'Equipment' => $pirep->aircraft->ident,
|
||||||
|
'Flight Time (Planned)' => Time::minutesToTimeString($pirep->planned_flight_time),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($pirep->planned_distance) {
|
||||||
|
try {
|
||||||
|
$planned_distance = new Distance(
|
||||||
|
$pirep->planned_distance,
|
||||||
|
config('phpvms.internal_units.distance')
|
||||||
|
);
|
||||||
|
|
||||||
|
$pd = $planned_distance[$planned_distance->unit].' '.$planned_distance->unit;
|
||||||
|
$fields['Distance (Planned)'] = $pd;
|
||||||
|
} catch (NonNumericValue $e) {
|
||||||
|
} catch (NonStringUnitName $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$dm = new DiscordMessage();
|
||||||
|
return $dm->webhook(setting('notifications.discord_public_webhook_url'))
|
||||||
|
->success()
|
||||||
|
->title($title)
|
||||||
|
->description($pirep->user->discord_id ? 'Flight by <@'.$pirep->user->discord_id.'>' : '')
|
||||||
|
->url(route('frontend.pireps.show', [$pirep->id]))
|
||||||
|
->author([
|
||||||
|
'name' => $pirep->user->ident.' - '.$pirep->user->name_private,
|
||||||
|
'url' => route('frontend.profile.show', [$pirep->user_id]),
|
||||||
|
'icon_url' => $pirep->user->resolveAvatarUrl(),
|
||||||
|
])
|
||||||
|
->fields($fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'pirep_id' => $this->pirep->id,
|
||||||
|
'user_id' => $this->pirep->user_id,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,19 +5,18 @@ namespace App\Notifications\Messages;
|
|||||||
use App\Contracts\Notification;
|
use App\Contracts\Notification;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Notifications\Channels\MailChannel;
|
use App\Notifications\Channels\MailChannel;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
class PirepRejected extends Notification
|
class PirepRejected extends Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
use MailChannel;
|
use MailChannel;
|
||||||
|
|
||||||
public $channels = ['mail'];
|
|
||||||
|
|
||||||
private $pirep;
|
private $pirep;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new notification instance.
|
* Create a new notification instance.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Pirep $pirep
|
* @param Pirep $pirep
|
||||||
*/
|
*/
|
||||||
public function __construct(Pirep $pirep)
|
public function __construct(Pirep $pirep)
|
||||||
{
|
{
|
||||||
@@ -32,6 +31,11 @@ class PirepRejected extends Notification
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the array representation of the notification.
|
* Get the array representation of the notification.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications\Messages;
|
||||||
|
|
||||||
|
use App\Contracts\Notification;
|
||||||
|
use App\Models\Enums\PirepStatus;
|
||||||
|
use App\Models\Pirep;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordMessage;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordWebhook;
|
||||||
|
use App\Support\Units\Distance;
|
||||||
|
use App\Support\Units\Time;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use PhpUnitsOfMeasure\Exception\NonNumericValue;
|
||||||
|
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the PIREP accepted message to a particular user, can also be sent to Discord
|
||||||
|
*/
|
||||||
|
class PirepStatusChanged extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
private $pirep;
|
||||||
|
|
||||||
|
// TODO: Int'l languages for these
|
||||||
|
protected static $verbs = [
|
||||||
|
PirepStatus::INITIATED => 'is initialized',
|
||||||
|
PirepStatus::SCHEDULED => 'is scheduled',
|
||||||
|
PirepStatus::BOARDING => 'is boarding',
|
||||||
|
PirepStatus::RDY_START => 'is ready for start',
|
||||||
|
PirepStatus::PUSHBACK_TOW => 'is pushing back',
|
||||||
|
PirepStatus::DEPARTED => 'has departed',
|
||||||
|
PirepStatus::RDY_DEICE => 'is ready for de-icing',
|
||||||
|
PirepStatus::STRT_DEICE => 'is de-icing',
|
||||||
|
PirepStatus::GRND_RTRN => 'on ground return',
|
||||||
|
PirepStatus::TAXI => 'is taxiing',
|
||||||
|
PirepStatus::TAKEOFF => 'has taken off',
|
||||||
|
PirepStatus::INIT_CLIM => 'in initial climb',
|
||||||
|
PirepStatus::AIRBORNE => 'is enroute',
|
||||||
|
PirepStatus::ENROUTE => 'is enroute',
|
||||||
|
PirepStatus::DIVERTED => 'has diverted',
|
||||||
|
PirepStatus::APPROACH => 'on approach',
|
||||||
|
PirepStatus::APPROACH_ICAO => 'on approach',
|
||||||
|
PirepStatus::ON_FINAL => 'on final approach',
|
||||||
|
PirepStatus::LANDING => 'is landing',
|
||||||
|
PirepStatus::LANDED => 'has landed',
|
||||||
|
PirepStatus::ARRIVED => 'has arrived',
|
||||||
|
PirepStatus::CANCELLED => 'is cancelled',
|
||||||
|
PirepStatus::EMERG_DESCENT => 'in emergency descent',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @param Pirep $pirep
|
||||||
|
*/
|
||||||
|
public function __construct(Pirep $pirep)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->pirep = $pirep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return [DiscordWebhook::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a Discord notification
|
||||||
|
*
|
||||||
|
* @param Pirep $pirep
|
||||||
|
*
|
||||||
|
* @return DiscordMessage|null
|
||||||
|
*/
|
||||||
|
public function toDiscordChannel($pirep): ?DiscordMessage
|
||||||
|
{
|
||||||
|
if (empty(setting('notifications.discord_public_webhook_url'))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = 'Flight '.$pirep->airline->code.$pirep->ident.' '.self::$verbs[$pirep->status];
|
||||||
|
|
||||||
|
$fields = [
|
||||||
|
'Flight' => $pirep->airline->code.$pirep->ident,
|
||||||
|
'Departure Airport' => $pirep->dpt_airport_id,
|
||||||
|
'Arrival Airport' => $pirep->arr_airport_id,
|
||||||
|
'Equipment' => $pirep->aircraft->ident,
|
||||||
|
'Flight Time' => Time::minutesToTimeString($pirep->flight_time),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Show the distance, but include the planned distance if it's been set
|
||||||
|
if ($pirep->distance) {
|
||||||
|
$unit = config('phpvms.internal_units.distance');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$planned_distance = new Distance($pirep->distance, $unit);
|
||||||
|
$pd = $planned_distance[$planned_distance->unit];
|
||||||
|
$fields['Distance'] = $pd;
|
||||||
|
|
||||||
|
// Add the planned distance in
|
||||||
|
if ($pirep->planned_distance) {
|
||||||
|
try {
|
||||||
|
$planned_distance = new Distance($pirep->planned_distance, $unit);
|
||||||
|
$pd = $planned_distance[$planned_distance->unit];
|
||||||
|
$fields['Distance'] .= '/'.$pd;
|
||||||
|
} catch (NonNumericValue | NonStringUnitName $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields['Distance'] .= ' '.$planned_distance->unit;
|
||||||
|
} catch (NonNumericValue | NonStringUnitName $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$dm = new DiscordMessage();
|
||||||
|
return $dm->webhook(setting('notifications.discord_public_webhook_url'))
|
||||||
|
->success()
|
||||||
|
->title($title)
|
||||||
|
->description($pirep->user->discord_id ? 'Flight by <@'.$pirep->user->discord_id.'>' : '')
|
||||||
|
->url(route('frontend.pireps.show', [$pirep->id]))
|
||||||
|
->author([
|
||||||
|
'name' => $pirep->user->ident.' - '.$pirep->user->name_private,
|
||||||
|
'url' => route('frontend.profile.show', [$pirep->user_id]),
|
||||||
|
'icon_url' => $pirep->user->resolveAvatarUrl(),
|
||||||
|
])
|
||||||
|
->fields($fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'pirep_id' => $this->pirep->id,
|
||||||
|
'user_id' => $this->pirep->user_id,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,14 +4,19 @@ namespace App\Notifications\Messages;
|
|||||||
|
|
||||||
use App\Contracts\Notification;
|
use App\Contracts\Notification;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordMessage;
|
||||||
|
use App\Notifications\Channels\Discord\DiscordWebhook;
|
||||||
use App\Notifications\Channels\MailChannel;
|
use App\Notifications\Channels\MailChannel;
|
||||||
|
use App\Support\Units\Distance;
|
||||||
|
use App\Support\Units\Time;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use PhpUnitsOfMeasure\Exception\NonNumericValue;
|
||||||
|
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||||
|
|
||||||
class PirepSubmitted extends Notification
|
class PirepSubmitted extends Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
use MailChannel;
|
use MailChannel;
|
||||||
|
|
||||||
public $channels = ['mail'];
|
|
||||||
|
|
||||||
private $pirep;
|
private $pirep;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,6 +37,60 @@ class PirepSubmitted extends Notification
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail', DiscordWebhook::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a Discord notification
|
||||||
|
*
|
||||||
|
* @param Pirep $pirep
|
||||||
|
*
|
||||||
|
* @return DiscordMessage|null
|
||||||
|
*/
|
||||||
|
public function toDiscordChannel($pirep): ?DiscordMessage
|
||||||
|
{
|
||||||
|
if (empty(setting('notifications.discord_public_webhook_url'))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = 'Flight '.$pirep->airline->code.$pirep->ident.' Filed';
|
||||||
|
$fields = [
|
||||||
|
'Flight' => $pirep->airline->code.$pirep->ident,
|
||||||
|
'Departure Airport' => $pirep->dpt_airport_id,
|
||||||
|
'Arrival Airport' => $pirep->arr_airport_id,
|
||||||
|
'Equipment' => $pirep->aircraft->ident,
|
||||||
|
'Flight Time (Planned)' => Time::minutesToTimeString($pirep->planned_flight_time),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($pirep->planned_distance) {
|
||||||
|
try {
|
||||||
|
$planned_distance = new Distance(
|
||||||
|
$pirep->planned_distance,
|
||||||
|
config('phpvms.internal_units.distance')
|
||||||
|
);
|
||||||
|
|
||||||
|
$pd = $planned_distance[$planned_distance->unit].' '.$planned_distance->unit;
|
||||||
|
$fields['Distance (Planned)'] = $pd;
|
||||||
|
} catch (NonNumericValue | NonStringUnitName $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$dm = new DiscordMessage();
|
||||||
|
return $dm->webhook(setting('notifications.discord_public_webhook_url'))
|
||||||
|
->success()
|
||||||
|
->title($title)
|
||||||
|
->description($pirep->user->discord_id ? 'Flight by <@'.$pirep->user->discord_id.'>' : '')
|
||||||
|
->url(route('frontend.pireps.show', [$pirep->id]))
|
||||||
|
->author([
|
||||||
|
'name' => $pirep->user->ident.' - '.$pirep->user->name_private,
|
||||||
|
'url' => route('frontend.profile.show', [$pirep->user_id]),
|
||||||
|
'icon_url' => $pirep->user->resolveAvatarUrl(),
|
||||||
|
])
|
||||||
|
->fields($fields);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the array representation of the notification.
|
* Get the array representation of the notification.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,17 +5,16 @@ namespace App\Notifications\Messages;
|
|||||||
use App\Contracts\Notification;
|
use App\Contracts\Notification;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\Channels\MailChannel;
|
use App\Notifications\Channels\MailChannel;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
class UserPending extends Notification
|
class UserPending extends Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
use MailChannel;
|
use MailChannel;
|
||||||
|
|
||||||
public $channels = ['mail'];
|
|
||||||
|
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \App\Models\User $user
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
public function __construct(User $user)
|
public function __construct(User $user)
|
||||||
{
|
{
|
||||||
@@ -30,6 +29,11 @@ class UserPending extends Notification
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the array representation of the notification.
|
* Get the array representation of the notification.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,19 +5,18 @@ namespace App\Notifications\Messages;
|
|||||||
use App\Contracts\Notification;
|
use App\Contracts\Notification;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\Channels\MailChannel;
|
use App\Notifications\Channels\MailChannel;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
class UserRegistered extends Notification
|
class UserRegistered extends Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
use MailChannel;
|
use MailChannel;
|
||||||
|
|
||||||
public $channels = ['mail'];
|
|
||||||
|
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new notification instance.
|
* Create a new notification instance.
|
||||||
*
|
*
|
||||||
* @param \App\Models\User $user
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
public function __construct(User $user)
|
public function __construct(User $user)
|
||||||
{
|
{
|
||||||
@@ -32,6 +31,11 @@ class UserRegistered extends Notification
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray($notifiable)
|
public function toArray($notifiable)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ namespace App\Notifications\Messages;
|
|||||||
use App\Contracts\Notification;
|
use App\Contracts\Notification;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\Channels\MailChannel;
|
use App\Notifications\Channels\MailChannel;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
class UserRejected extends Notification
|
class UserRejected extends Notification implements ShouldQueue
|
||||||
{
|
{
|
||||||
|
use Queueable;
|
||||||
use MailChannel;
|
use MailChannel;
|
||||||
|
|
||||||
public $channels = ['mail'];
|
|
||||||
|
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,6 +31,11 @@ class UserRejected extends Notification
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the array representation of the notification.
|
* Get the array representation of the notification.
|
||||||
*
|
*
|
||||||
|
|||||||
+54
-22
@@ -6,13 +6,13 @@ use App\Contracts\Listener;
|
|||||||
use App\Events\NewsAdded;
|
use App\Events\NewsAdded;
|
||||||
use App\Events\PirepAccepted;
|
use App\Events\PirepAccepted;
|
||||||
use App\Events\PirepFiled;
|
use App\Events\PirepFiled;
|
||||||
|
use App\Events\PirepPrefiled;
|
||||||
use App\Events\PirepRejected;
|
use App\Events\PirepRejected;
|
||||||
|
use App\Events\PirepStatusChange;
|
||||||
use App\Events\UserRegistered;
|
use App\Events\UserRegistered;
|
||||||
use App\Events\UserStateChanged;
|
use App\Events\UserStateChanged;
|
||||||
use App\Models\Enums\UserState;
|
use App\Models\Enums\UserState;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\Messages\PirepSubmitted;
|
|
||||||
use App\Notifications\Messages\UserPending;
|
|
||||||
use App\Notifications\Messages\UserRejected;
|
use App\Notifications\Messages\UserRejected;
|
||||||
use App\Notifications\Notifiables\Broadcast;
|
use App\Notifications\Notifiables\Broadcast;
|
||||||
use Exception;
|
use Exception;
|
||||||
@@ -23,17 +23,19 @@ use Illuminate\Support\Facades\Notification;
|
|||||||
/**
|
/**
|
||||||
* Listen for different events and map them to different notifications
|
* Listen for different events and map them to different notifications
|
||||||
*/
|
*/
|
||||||
class EventHandler extends Listener
|
class NotificationEventsHandler extends Listener
|
||||||
{
|
{
|
||||||
private static $broadcastNotifyable;
|
private static $broadcastNotifyable;
|
||||||
|
|
||||||
public static $callbacks = [
|
public static $callbacks = [
|
||||||
NewsAdded::class => 'onNewsAdded',
|
NewsAdded::class => 'onNewsAdded',
|
||||||
PirepAccepted::class => 'onPirepAccepted',
|
PirepPrefiled::class => 'onPirepPrefile',
|
||||||
PirepFiled::class => 'onPirepFile',
|
PirepStatusChange::class => 'onPirepStatusChange',
|
||||||
PirepRejected::class => 'onPirepRejected',
|
PirepAccepted::class => 'onPirepAccepted',
|
||||||
UserRegistered::class => 'onUserRegister',
|
PirepFiled::class => 'onPirepFile',
|
||||||
UserStateChanged::class => 'onUserStateChange',
|
PirepRejected::class => 'onPirepRejected',
|
||||||
|
UserRegistered::class => 'onUserRegister',
|
||||||
|
UserStateChanged::class => 'onUserStateChange',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@@ -46,7 +48,7 @@ class EventHandler extends Listener
|
|||||||
*
|
*
|
||||||
* @param \App\Contracts\Notification $notification
|
* @param \App\Contracts\Notification $notification
|
||||||
*/
|
*/
|
||||||
protected function notifyAdmins($notification)
|
protected function notifyAdmins(\App\Contracts\Notification $notification)
|
||||||
{
|
{
|
||||||
$admin_users = User::whereRoleIs('admin')->get();
|
$admin_users = User::whereRoleIs('admin')->get();
|
||||||
|
|
||||||
@@ -56,7 +58,8 @@ class EventHandler extends Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Notification::send([$user], $notification);
|
$this->notifyUser($user, $notification);
|
||||||
|
// Notification::send([$user], $notification);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::emergency('Error emailing admin ('.$user->email.'). Error='.$e->getMessage());
|
Log::emergency('Error emailing admin ('.$user->email.'). Error='.$e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -67,8 +70,12 @@ class EventHandler extends Listener
|
|||||||
* @param User $user
|
* @param User $user
|
||||||
* @param \App\Contracts\Notification $notification
|
* @param \App\Contracts\Notification $notification
|
||||||
*/
|
*/
|
||||||
protected function notifyUser($user, $notification)
|
protected function notifyUser(User $user, \App\Contracts\Notification $notification)
|
||||||
{
|
{
|
||||||
|
if ($user->state === UserState::DELETED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user->notify($notification);
|
$user->notify($notification);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -90,7 +97,7 @@ class EventHandler extends Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var Collection $users */
|
/** @var Collection $users */
|
||||||
$users = User::where($where)->get();
|
$users = User::where($where)->where('state', '<>', UserState::DELETED)->get();
|
||||||
if (empty($users) || $users->count() === 0) {
|
if (empty($users) || $users->count() === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -113,19 +120,24 @@ class EventHandler extends Listener
|
|||||||
.$event->user->ident.' is '
|
.$event->user->ident.' is '
|
||||||
.UserState::label($event->user->state).', sending active email');
|
.UserState::label($event->user->state).', sending active email');
|
||||||
|
|
||||||
/*
|
|
||||||
* Send all of the admins a notification that a new user registered
|
|
||||||
*/
|
|
||||||
$this->notifyAdmins(new Messages\AdminUserRegistered($event->user));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send the user a confirmation email
|
* Send the user a confirmation email
|
||||||
*/
|
*/
|
||||||
if ($event->user->state === UserState::ACTIVE) {
|
if ($event->user->state === UserState::ACTIVE) {
|
||||||
$this->notifyUser($event->user, new Messages\UserRegistered($event->user));
|
$this->notifyUser($event->user, new Messages\UserRegistered($event->user));
|
||||||
} elseif ($event->user->state === UserState::PENDING) {
|
} elseif ($event->user->state === UserState::PENDING) {
|
||||||
$this->notifyUser($event->user, new UserPending($event->user));
|
$this->notifyUser($event->user, new Messages\UserPending($event->user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send all of the admins a notification that a new user registered
|
||||||
|
*/
|
||||||
|
$this->notifyAdmins(new Messages\AdminUserRegistered($event->user));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discord and other notifications
|
||||||
|
*/
|
||||||
|
Notification::send([$event->user], new Messages\AdminUserRegistered($event->user));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -148,15 +160,34 @@ class EventHandler extends Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prefile notification
|
||||||
|
*/
|
||||||
|
public function onPirepPrefile(PirepPrefiled $event): void
|
||||||
|
{
|
||||||
|
Log::info('NotificationEvents::onPirepPrefile: '.$event->pirep->id.' prefiled');
|
||||||
|
Notification::send([$event->pirep], new Messages\PirepPrefiled($event->pirep));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status Change notification
|
||||||
|
*/
|
||||||
|
public function onPirepStatusChange(PirepStatusChange $event): void
|
||||||
|
{
|
||||||
|
Log::info('NotificationEvents::onPirepStatusChange: '.$event->pirep->id.' prefiled');
|
||||||
|
Notification::send([$event->pirep], new Messages\PirepStatusChanged($event->pirep));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the admins that a new PIREP has been filed
|
* Notify the admins that a new PIREP has been filed
|
||||||
*
|
*
|
||||||
* @param \App\Events\PirepFiled $event
|
* @param PirepFiled $event
|
||||||
*/
|
*/
|
||||||
public function onPirepFile(PirepFiled $event): void
|
public function onPirepFile(PirepFiled $event): void
|
||||||
{
|
{
|
||||||
Log::info('NotificationEvents::onPirepFile: '.$event->pirep->id.' filed ');
|
Log::info('NotificationEvents::onPirepFile: '.$event->pirep->id.' filed');
|
||||||
$this->notifyAdmins(new PirepSubmitted($event->pirep));
|
$this->notifyAdmins(new Messages\PirepSubmitted($event->pirep));
|
||||||
|
Notification::send([$event->pirep], new Messages\PirepSubmitted($event->pirep));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -190,5 +221,6 @@ class EventHandler extends Listener
|
|||||||
{
|
{
|
||||||
Log::info('NotificationEvents::onNewsAdded');
|
Log::info('NotificationEvents::onNewsAdded');
|
||||||
$this->notifyAllUsers(new Messages\NewsAdded($event->news));
|
$this->notifyAllUsers(new Messages\NewsAdded($event->news));
|
||||||
|
Notification::send([$event->news], new Messages\NewsAdded($event->news));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Cron\Hourly\ClearExpiredSimbrief;
|
||||||
use App\Cron\Hourly\DeletePireps;
|
use App\Cron\Hourly\DeletePireps;
|
||||||
use App\Cron\Hourly\RemoveExpiredBids;
|
use App\Cron\Hourly\RemoveExpiredBids;
|
||||||
use App\Cron\Hourly\RemoveExpiredLiveFlights;
|
use App\Cron\Hourly\RemoveExpiredLiveFlights;
|
||||||
use App\Cron\Nightly\ApplyExpenses;
|
use App\Cron\Nightly\ApplyExpenses;
|
||||||
use App\Cron\Nightly\ClearExpiredSimbrief;
|
|
||||||
use App\Cron\Nightly\NewVersionCheck;
|
use App\Cron\Nightly\NewVersionCheck;
|
||||||
use App\Cron\Nightly\PilotLeave;
|
use App\Cron\Nightly\PilotLeave;
|
||||||
use App\Cron\Nightly\RecalculateBalances;
|
use App\Cron\Nightly\RecalculateBalances;
|
||||||
@@ -31,7 +31,6 @@ class CronServiceProvider extends ServiceProvider
|
|||||||
SetActiveFlights::class,
|
SetActiveFlights::class,
|
||||||
RecalculateStats::class,
|
RecalculateStats::class,
|
||||||
NewVersionCheck::class,
|
NewVersionCheck::class,
|
||||||
ClearExpiredSimbrief::class,
|
|
||||||
],
|
],
|
||||||
|
|
||||||
CronWeekly::class => [
|
CronWeekly::class => [
|
||||||
@@ -45,6 +44,7 @@ class CronServiceProvider extends ServiceProvider
|
|||||||
DeletePireps::class,
|
DeletePireps::class,
|
||||||
RemoveExpiredBids::class,
|
RemoveExpiredBids::class,
|
||||||
RemoveExpiredLiveFlights::class,
|
RemoveExpiredLiveFlights::class,
|
||||||
|
ClearExpiredSimbrief::class,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use App\Listeners\ExpenseListener;
|
|||||||
use App\Listeners\FinanceEventHandler;
|
use App\Listeners\FinanceEventHandler;
|
||||||
use App\Listeners\PirepEventsHandler;
|
use App\Listeners\PirepEventsHandler;
|
||||||
use App\Listeners\UserStateListener;
|
use App\Listeners\UserStateListener;
|
||||||
use App\Notifications\EventHandler;
|
use App\Notifications\NotificationEventsHandler;
|
||||||
use Codedge\Updater\Events\UpdateAvailable;
|
use Codedge\Updater\Events\UpdateAvailable;
|
||||||
use Codedge\Updater\Events\UpdateSucceeded;
|
use Codedge\Updater\Events\UpdateSucceeded;
|
||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
@@ -39,12 +39,17 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
UpdateAvailable::class => [],
|
UpdateAvailable::class => [],
|
||||||
UpdateSucceeded::class => [],
|
UpdateSucceeded::class => [],
|
||||||
|
|
||||||
|
// Log messages out to the console if running there
|
||||||
|
'Illuminate\Log\Events\MessageLogged' => [
|
||||||
|
'App\Listeners\MessageLoggedListener',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $subscribe = [
|
protected $subscribe = [
|
||||||
BidEventHandler::class,
|
BidEventHandler::class,
|
||||||
FinanceEventHandler::class,
|
FinanceEventHandler::class,
|
||||||
EventHandler::class,
|
NotificationEventsHandler::class,
|
||||||
AwardHandler::class,
|
AwardHandler::class,
|
||||||
PirepEventsHandler::class,
|
PirepEventsHandler::class,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -90,10 +90,6 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Route::post('/run-migrations', 'UpdateController@run_migrations')->name('run_migrations');
|
Route::post('/run-migrations', 'UpdateController@run_migrations')->name('run_migrations');
|
||||||
Route::get('/complete', 'UpdateController@complete')->name('complete');
|
Route::get('/complete', 'UpdateController@complete')->name('complete');
|
||||||
|
|
||||||
// Routes for the update downloader
|
|
||||||
Route::get('/downloader', 'UpdateController@updater')->name('updater');
|
|
||||||
Route::post('/downloader', 'UpdateController@update_download')->name('update_download');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +140,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
Route::get('simbrief/generate', 'SimBriefController@generate')->name('simbrief.generate');
|
Route::get('simbrief/generate', 'SimBriefController@generate')->name('simbrief.generate');
|
||||||
Route::post('simbrief/apicode', 'SimBriefController@api_code')->name('simbrief.api_code');
|
Route::post('simbrief/apicode', 'SimBriefController@api_code')->name('simbrief.api_code');
|
||||||
Route::get('simbrief/check_ofp', 'SimBriefController@check_ofp')->name('simbrief.check_ofp');
|
Route::get('simbrief/check_ofp', 'SimBriefController@check_ofp')->name('simbrief.check_ofp');
|
||||||
|
Route::get('simbrief/update_ofp', 'SimBriefController@update_ofp')->name('simbrief.update_ofp');
|
||||||
Route::get('simbrief/{id}', 'SimBriefController@briefing')->name('simbrief.briefing');
|
Route::get('simbrief/{id}', 'SimBriefController@briefing')->name('simbrief.briefing');
|
||||||
Route::get('simbrief/{id}/prefile', 'SimBriefController@prefile')->name('simbrief.prefile');
|
Route::get('simbrief/{id}/prefile', 'SimBriefController@prefile')->name('simbrief.prefile');
|
||||||
Route::get('simbrief/{id}/cancel', 'SimBriefController@cancel')->name('simbrief.cancel');
|
Route::get('simbrief/{id}/cancel', 'SimBriefController@cancel')->name('simbrief.cancel');
|
||||||
@@ -537,6 +534,9 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
Route::get('fleet', 'FleetController@index');
|
Route::get('fleet', 'FleetController@index');
|
||||||
Route::get('fleet/aircraft/{id}', 'FleetController@get_aircraft');
|
Route::get('fleet/aircraft/{id}', 'FleetController@get_aircraft');
|
||||||
|
|
||||||
|
Route::get('subfleet', 'FleetController@index');
|
||||||
|
Route::get('subfleet/aircraft/{id}', 'FleetController@get_aircraft');
|
||||||
|
|
||||||
Route::get('flights', 'FlightController@index');
|
Route::get('flights', 'FlightController@index');
|
||||||
Route::get('flights/search', 'FlightController@search');
|
Route::get('flights/search', 'FlightController@search');
|
||||||
Route::get('flights/{id}', 'FlightController@get');
|
Route::get('flights/{id}', 'FlightController@get');
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class SubfleetRepository extends Repository implements CacheableInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($items as $i) {
|
foreach ($items as $i) {
|
||||||
$retval[$i->id] = $i->name;
|
$retval[$i->id] = $i->name.' | '.$i->airline->icao;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $retval;
|
return $retval;
|
||||||
|
|||||||
@@ -292,14 +292,14 @@ class FareService extends Service
|
|||||||
/**
|
/**
|
||||||
* Save the list of fares
|
* Save the list of fares
|
||||||
*
|
*
|
||||||
* @param Pirep $pirep
|
* @param Pirep $pirep
|
||||||
* @param array $fares ['fare_id', 'count']
|
* @param PirepFare[] $fares
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function saveForPirep(Pirep $pirep, array $fares)
|
public function saveForPirep(Pirep $pirep, array $fares)
|
||||||
{
|
{
|
||||||
if (!$fares) {
|
if (!$fares || empty($fares)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,13 +308,9 @@ class FareService extends Service
|
|||||||
|
|
||||||
// Add them in
|
// Add them in
|
||||||
foreach ($fares as $fare) {
|
foreach ($fares as $fare) {
|
||||||
$fare['pirep_id'] = $pirep->id;
|
$fare->pirep_id = $pirep->id;
|
||||||
// other fields: ['fare_id', 'count']
|
|
||||||
|
|
||||||
Log::info('Saving fare pirep='.$pirep->id.', fare='.$fare['count']);
|
Log::info('Saving fare pirep='.$pirep->id.', fare='.$fare['count']);
|
||||||
|
$fare->save();
|
||||||
$field = new PirepFare($fare);
|
|
||||||
$field->save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ use App\Models\Aircraft;
|
|||||||
use App\Models\Airport;
|
use App\Models\Airport;
|
||||||
use App\Models\Enums\ExpenseType;
|
use App\Models\Enums\ExpenseType;
|
||||||
use App\Models\Enums\FareType;
|
use App\Models\Enums\FareType;
|
||||||
|
use App\Models\Enums\FuelType;
|
||||||
use App\Models\Enums\PirepSource;
|
use App\Models\Enums\PirepSource;
|
||||||
|
use App\Models\Enums\PirepState;
|
||||||
|
use App\Models\Enums\PirepStatus;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Models\Subfleet;
|
use App\Models\Subfleet;
|
||||||
@@ -151,18 +154,39 @@ class PirepFinanceService extends Service
|
|||||||
*/
|
*/
|
||||||
public function payFuelCosts(Pirep $pirep): void
|
public function payFuelCosts(Pirep $pirep): void
|
||||||
{
|
{
|
||||||
|
// Get Airport Fuel Prices or Use Defaults
|
||||||
$ap = $pirep->dpt_airport;
|
$ap = $pirep->dpt_airport;
|
||||||
// Get Airport Fuel Cost or revert back to settings
|
|
||||||
if (empty($ap->fuel_jeta_cost)) {
|
// Get Aircraft Fuel Type from Subfleet
|
||||||
$fuel_cost = setting('airports.default_jet_a_fuel_cost');
|
// And set $fuel_cost according to type (Failsafe is Jet A)
|
||||||
|
$sf = $pirep->aircraft->subfleet;
|
||||||
|
if ($sf) {
|
||||||
|
$fuel_type = $sf->fuel_type;
|
||||||
} else {
|
} else {
|
||||||
$fuel_cost = $ap->fuel_jeta_cost;
|
$fuel_type = FuelType::JET_A;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fuel_type === FuelType::LOW_LEAD) {
|
||||||
|
$fuel_cost = !empty($ap->fuel_100ll_cost) ? $ap->fuel_100ll_cost : setting('airports.default_100ll_fuel_cost');
|
||||||
|
} elseif ($fuel_type === FuelType::MOGAS) {
|
||||||
|
$fuel_cost = !empty($ap->fuel_mogas_cost) ? $ap->fuel_mogas_cost : setting('airports.default_mogas_fuel_cost');
|
||||||
|
} else { // Default to JetA
|
||||||
|
$fuel_cost = !empty($ap->fuel_jeta_cost) ? $ap->fuel_jeta_cost : setting('airports.default_jet_a_fuel_cost');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setting('pireps.advanced_fuel', false)) {
|
if (setting('pireps.advanced_fuel', false)) {
|
||||||
$ac = $pirep->aircraft;
|
|
||||||
// Reading second row by skip(1) to reach the previous accepted pirep. Current pirep is at the first row
|
// Reading second row by skip(1) to reach the previous accepted pirep. Current pirep is at the first row
|
||||||
$prev_flight = Pirep::where('aircraft_id', $ac->id)->where('state', 2)->where('status', 'ONB')->orderby('submitted_at', 'desc')->skip(1)->first();
|
// To get proper fuel values, we need to fetch current pirep and older ones only. Scenario: ReCalculating finances
|
||||||
|
$prev_flight = Pirep::where([
|
||||||
|
'aircraft_id' => $pirep->aircraft->id,
|
||||||
|
'state' => PirepState::ACCEPTED,
|
||||||
|
'status' => PirepStatus::ARRIVED,
|
||||||
|
])
|
||||||
|
->where('submitted_at', '<=', $pirep->submitted_at)
|
||||||
|
->orderby('submitted_at', 'desc')
|
||||||
|
->skip(1)
|
||||||
|
->first();
|
||||||
|
|
||||||
if ($prev_flight) {
|
if ($prev_flight) {
|
||||||
// If there is a pirep use its values to calculate the remaining fuel
|
// If there is a pirep use its values to calculate the remaining fuel
|
||||||
// and calculate the uplifted fuel amount for this pirep
|
// and calculate the uplifted fuel amount for this pirep
|
||||||
@@ -181,8 +205,7 @@ class PirepFinanceService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
$debit = Money::createFromAmount($fuel_amount * $fuel_cost);
|
$debit = Money::createFromAmount($fuel_amount * $fuel_cost);
|
||||||
Log::info('Finance: Fuel cost, (fuel='.$fuel_amount.', cost='.$fuel_cost.') D='
|
Log::info('Finance: Fuel cost, (fuel='.$fuel_amount.', cost='.$fuel_cost.') D='.$debit->getAmount());
|
||||||
.$debit->getAmount());
|
|
||||||
|
|
||||||
$this->financeSvc->debitFromJournal(
|
$this->financeSvc->debitFromJournal(
|
||||||
$pirep->airline->journal,
|
$pirep->airline->journal,
|
||||||
@@ -283,20 +306,29 @@ class PirepFinanceService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Form the memo, with some specific ones depending on the group
|
// Form the memo, with some specific ones depending on the group
|
||||||
if ($expense->ref_model === Subfleet::class
|
if ($expense->ref_model === Subfleet::class) {
|
||||||
&& $expense->ref_model_id === $pirep->aircraft->subfleet->id
|
if ((int) ($expense->ref_model_id) === $pirep->aircraft->subfleet->id) {
|
||||||
) {
|
$memo = "Subfleet Expense: $expense->name ({$pirep->aircraft->subfleet->name}) dd";
|
||||||
$memo = "Subfleet Expense: {$expense->name} ({$pirep->aircraft->subfleet->name})";
|
$transaction_group = "Subfleet: $expense->name ({$pirep->aircraft->subfleet->name})";
|
||||||
$transaction_group = "Subfleet: {$expense->name} ({$pirep->aircraft->subfleet->name})";
|
} else { // Skip any subfleets that weren't used for this flight
|
||||||
} elseif ($expense->ref_model === Aircraft::class
|
return;
|
||||||
&& $expense->ref_model_id === $pirep->aircraft->id
|
}
|
||||||
) {
|
} elseif ($expense->ref_model === Aircraft::class) {
|
||||||
$memo = "Aircraft Expense: {$expense->name} ({$pirep->aircraft->name})";
|
if ((int) ($expense->ref_model_id) === $pirep->aircraft->id) {
|
||||||
$transaction_group = "Aircraft: {$expense->name} "
|
$memo = "Aircraft Expense: $expense->name ({$pirep->aircraft->name})";
|
||||||
."({$pirep->aircraft->name}-{$pirep->aircraft->registration})";
|
$transaction_group = "Aircraft: $expense->name "
|
||||||
|
."({$pirep->aircraft->name}-{$pirep->aircraft->registration})";
|
||||||
|
} else { // Skip any aircraft expenses that weren't used for this flight
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$memo = "Expense: {$expense->name}";
|
// Skip any expenses that aren't for the airline this flight was for
|
||||||
$transaction_group = "Expense: {$expense->name}";
|
if ($expense->airline_id && $expense->airline_id !== $pirep->airline_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$memo = "Expense: $expense->name";
|
||||||
|
$transaction_group = "Expense: $expense->name";
|
||||||
}
|
}
|
||||||
|
|
||||||
$debit = Money::createFromAmount($expense->amount);
|
$debit = Money::createFromAmount($expense->amount);
|
||||||
@@ -339,8 +371,8 @@ class PirepFinanceService extends Service
|
|||||||
$expenses->map(function (Expense $expense, $i) use ($pirep) {
|
$expenses->map(function (Expense $expense, $i) use ($pirep) {
|
||||||
Log::info('Finance: PIREP: '.$pirep->id.', airport expense:', $expense->toArray());
|
Log::info('Finance: PIREP: '.$pirep->id.', airport expense:', $expense->toArray());
|
||||||
|
|
||||||
$memo = "Airport Expense: {$expense->name} ({$expense->ref_model_id})";
|
$memo = "Airport Expense: $expense->name ($expense->ref_model_id)";
|
||||||
$transaction_group = "Airport: {$expense->ref_model_id}";
|
$transaction_group = "Airport: $expense->ref_model_id";
|
||||||
|
|
||||||
$debit = Money::createFromAmount($expense->amount);
|
$debit = Money::createFromAmount($expense->amount);
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ class FlightImporter extends ImportExport
|
|||||||
'flight_number' => $row['flight_number'],
|
'flight_number' => $row['flight_number'],
|
||||||
'route_code' => $row['route_code'],
|
'route_code' => $row['route_code'],
|
||||||
'route_leg' => $row['route_leg'],
|
'route_leg' => $row['route_leg'],
|
||||||
'visible' => true,
|
|
||||||
], $row);
|
], $row);
|
||||||
|
|
||||||
$row['dpt_airport'] = strtoupper($row['dpt_airport']);
|
$row['dpt_airport'] = strtoupper($row['dpt_airport']);
|
||||||
@@ -99,6 +98,10 @@ class FlightImporter extends ImportExport
|
|||||||
$flight->setAttribute('alt_airport_id', $row['alt_airport']);
|
$flight->setAttribute('alt_airport_id', $row['alt_airport']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle Route and Level Fields
|
||||||
|
$flight->setAttribute('route', strtoupper($row['route']));
|
||||||
|
$flight->setAttribute('level', $row['level']);
|
||||||
|
|
||||||
// Any specific transformations
|
// Any specific transformations
|
||||||
|
|
||||||
// Check for a valid value
|
// Check for a valid value
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
|||||||
class ConfigService extends Service
|
class ConfigService extends Service
|
||||||
{
|
{
|
||||||
protected static $defaultValues = [
|
protected static $defaultValues = [
|
||||||
'APP_ENV' => 'prod',
|
'APP_ENV' => 'production',
|
||||||
'APP_KEY' => '',
|
'APP_KEY' => '',
|
||||||
'APP_DEBUG' => true,
|
'APP_DEBUG' => false,
|
||||||
'APP_LOCALE' => 'en',
|
'APP_LOCALE' => 'en',
|
||||||
'DEBUG_TOOLBAR' => false,
|
'DEBUG_TOOLBAR' => false,
|
||||||
'SITE_NAME' => '',
|
'SITE_NAME' => '',
|
||||||
'SITE_URL' => 'http://phpvms.test',
|
'APP_URL' => 'http://phpvms.test',
|
||||||
'DB_CONNECTION' => '',
|
'DB_CONNECTION' => '',
|
||||||
'DB_HOST' => '',
|
'DB_HOST' => '',
|
||||||
'DB_PORT' => 3306,
|
'DB_PORT' => 3306,
|
||||||
@@ -93,7 +93,7 @@ class ConfigService extends Service
|
|||||||
'APP_LOCALE' => config('app.locale'),
|
'APP_LOCALE' => config('app.locale'),
|
||||||
'DEBUG_TOOLBAR' => config('app.debug_toolbar') ? 'true' : 'false',
|
'DEBUG_TOOLBAR' => config('app.debug_toolbar') ? 'true' : 'false',
|
||||||
'SITE_NAME' => config('app.name'),
|
'SITE_NAME' => config('app.name'),
|
||||||
'SITE_URL' => config('app.url'),
|
'APP_URL' => config('app.url'),
|
||||||
'DB_CONNECTION' => config('database.default'),
|
'DB_CONNECTION' => config('database.default'),
|
||||||
'DB_HOST' => config('database.connections.mysql.host'),
|
'DB_HOST' => config('database.connections.mysql.host'),
|
||||||
'DB_PORT' => config('database.connections.mysql.port'),
|
'DB_PORT' => config('database.connections.mysql.port'),
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class MigrationService extends Service
|
|||||||
$availMigrations[] = $filepath;
|
$availMigrations[] = $filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info('Migrations available: '.count($availMigrations));
|
//Log::info('Migrations available: '.count($availMigrations));
|
||||||
|
|
||||||
return $availMigrations;
|
return $availMigrations;
|
||||||
}
|
}
|
||||||
@@ -77,12 +77,12 @@ class MigrationService extends Service
|
|||||||
* Run all of the migrations that are available. Just call artisan since
|
* Run all of the migrations that are available. Just call artisan since
|
||||||
* it looks into all of the module directories, etc
|
* it looks into all of the module directories, etc
|
||||||
*/
|
*/
|
||||||
public function runAllMigrations()
|
public function runAllMigrations(): string
|
||||||
{
|
{
|
||||||
// A little ugly, run the main migration first, this makes sure the migration table is there
|
// A little ugly, run the main migration first, this makes sure the migration table is there
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
Artisan::call('migrate');
|
Artisan::call('migrate', ['--force' => true]);
|
||||||
$output .= trim(Artisan::output());
|
$output .= trim(Artisan::output());
|
||||||
|
|
||||||
// Then get any remaining migrations that are left over
|
// Then get any remaining migrations that are left over
|
||||||
@@ -92,10 +92,14 @@ class MigrationService extends Service
|
|||||||
$migrator = $this->getMigrator();
|
$migrator = $this->getMigrator();
|
||||||
$availMigrations = $this->migrationsAvailable();
|
$availMigrations = $this->migrationsAvailable();
|
||||||
|
|
||||||
Log::info('Running '.count($availMigrations).' available migrations');
|
if (count($availMigrations) > 0) {
|
||||||
$ret = $migrator->run($availMigrations);
|
Log::info('Running '.count($availMigrations).' available migrations');
|
||||||
Log::info('Ran '.count($ret).' migrations');
|
$ret = $migrator->run($availMigrations);
|
||||||
|
Log::info('Ran '.count($ret).' migrations');
|
||||||
|
|
||||||
return $output."\n".implode("\n", $ret);
|
return $output."\n".implode("\n", $ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ class SeederService extends Service
|
|||||||
private $offsets = [];
|
private $offsets = [];
|
||||||
|
|
||||||
// Map an environment to a seeder directory, if we want to share
|
// Map an environment to a seeder directory, if we want to share
|
||||||
public static $seed_mapper = [];
|
public static $seed_mapper = [
|
||||||
|
'local' => 'dev',
|
||||||
|
'production' => 'prod',
|
||||||
|
];
|
||||||
|
|
||||||
public function __construct(DatabaseService $databaseSvc)
|
public function __construct(DatabaseService $databaseSvc)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ class AviationWeather extends Metar
|
|||||||
$res = $this->httpClient->get($url, []);
|
$res = $this->httpClient->get($url, []);
|
||||||
$xml = simplexml_load_string($res);
|
$xml = simplexml_load_string($res);
|
||||||
|
|
||||||
|
if ($xml->errors && count($xml->errors->children()) > 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$attrs = $xml->data->attributes();
|
$attrs = $xml->data->attributes();
|
||||||
if (!isset($attrs['num_results'])) {
|
if (!isset($attrs['num_results'])) {
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
@@ -126,7 +126,11 @@ class ModuleService extends Service
|
|||||||
'enabled' => 1,
|
'enabled' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Artisan::call('module:migrate '.$module_name);
|
try {
|
||||||
|
Artisan::call('module:migrate '.$module_name, ['--force' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error('Error running migration for '.$module_name.'; error='.$e);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -225,7 +229,7 @@ class ModuleService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
Artisan::call('config:cache');
|
Artisan::call('config:cache');
|
||||||
Artisan::call('module:migrate '.$module);
|
Artisan::call('module:migrate '.$module, ['--force' => true]);
|
||||||
|
|
||||||
return flash()->success('Module Installed');
|
return flash()->success('Module Installed');
|
||||||
}
|
}
|
||||||
@@ -246,7 +250,7 @@ class ModuleService extends Service
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if ($status === true) {
|
if ($status === true) {
|
||||||
Artisan::call('module:migrate '.$module->name);
|
Artisan::call('module:migrate '.$module->name, ['--force' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+133
-37
@@ -11,13 +11,16 @@ use App\Events\PirepRejected;
|
|||||||
use App\Events\UserStatsChanged;
|
use App\Events\UserStatsChanged;
|
||||||
use App\Exceptions\AircraftInvalid;
|
use App\Exceptions\AircraftInvalid;
|
||||||
use App\Exceptions\AircraftNotAtAirport;
|
use App\Exceptions\AircraftNotAtAirport;
|
||||||
|
use App\Exceptions\AircraftNotAvailable;
|
||||||
use App\Exceptions\AircraftPermissionDenied;
|
use App\Exceptions\AircraftPermissionDenied;
|
||||||
use App\Exceptions\AirportNotFound;
|
use App\Exceptions\AirportNotFound;
|
||||||
use App\Exceptions\PirepCancelNotAllowed;
|
use App\Exceptions\PirepCancelNotAllowed;
|
||||||
|
use App\Exceptions\PirepError;
|
||||||
use App\Exceptions\UserNotAtAirport;
|
use App\Exceptions\UserNotAtAirport;
|
||||||
use App\Models\Acars;
|
use App\Models\Acars;
|
||||||
use App\Models\Aircraft;
|
use App\Models\Aircraft;
|
||||||
use App\Models\Enums\AcarsType;
|
use App\Models\Enums\AcarsType;
|
||||||
|
use App\Models\Enums\AircraftState;
|
||||||
use App\Models\Enums\FlightType;
|
use App\Models\Enums\FlightType;
|
||||||
use App\Models\Enums\PirepSource;
|
use App\Models\Enums\PirepSource;
|
||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
@@ -33,7 +36,6 @@ use App\Repositories\AircraftRepository;
|
|||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use function count;
|
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@@ -42,16 +44,18 @@ class PirepService extends Service
|
|||||||
private $aircraftRepo;
|
private $aircraftRepo;
|
||||||
private $airportRepo;
|
private $airportRepo;
|
||||||
private $airportSvc;
|
private $airportSvc;
|
||||||
|
private $fareSvc;
|
||||||
private $geoSvc;
|
private $geoSvc;
|
||||||
private $pirepRepo;
|
private $pirepRepo;
|
||||||
private $simBriefSvc;
|
private $simBriefSvc;
|
||||||
private $userSvc;
|
private $userSvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param AircraftRepository $aircraftRepo
|
|
||||||
* @param GeoService $geoSvc
|
|
||||||
* @param AirportRepository $airportRepo
|
* @param AirportRepository $airportRepo
|
||||||
* @param AirportService $airportSvc
|
* @param AirportService $airportSvc
|
||||||
|
* @param AircraftRepository $aircraftRepo
|
||||||
|
* @param FareService $fareSvc
|
||||||
|
* @param GeoService $geoSvc
|
||||||
* @param PirepRepository $pirepRepo
|
* @param PirepRepository $pirepRepo
|
||||||
* @param SimBriefService $simBriefSvc
|
* @param SimBriefService $simBriefSvc
|
||||||
* @param UserService $userSvc
|
* @param UserService $userSvc
|
||||||
@@ -60,6 +64,7 @@ class PirepService extends Service
|
|||||||
AirportRepository $airportRepo,
|
AirportRepository $airportRepo,
|
||||||
AirportService $airportSvc,
|
AirportService $airportSvc,
|
||||||
AircraftRepository $aircraftRepo,
|
AircraftRepository $aircraftRepo,
|
||||||
|
FareService $fareSvc,
|
||||||
GeoService $geoSvc,
|
GeoService $geoSvc,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
SimBriefService $simBriefSvc,
|
SimBriefService $simBriefSvc,
|
||||||
@@ -68,6 +73,7 @@ class PirepService extends Service
|
|||||||
$this->airportRepo = $airportRepo;
|
$this->airportRepo = $airportRepo;
|
||||||
$this->airportSvc = $airportSvc;
|
$this->airportSvc = $airportSvc;
|
||||||
$this->aircraftRepo = $aircraftRepo;
|
$this->aircraftRepo = $aircraftRepo;
|
||||||
|
$this->fareSvc = $fareSvc;
|
||||||
$this->geoSvc = $geoSvc;
|
$this->geoSvc = $geoSvc;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
$this->simBriefSvc = $simBriefSvc;
|
$this->simBriefSvc = $simBriefSvc;
|
||||||
@@ -77,15 +83,17 @@ class PirepService extends Service
|
|||||||
/**
|
/**
|
||||||
* Create a prefiled PIREP
|
* Create a prefiled PIREP
|
||||||
*
|
*
|
||||||
* @param \App\Models\User $user
|
* @param User $user
|
||||||
* @param array $attrs
|
* @param array $attrs
|
||||||
|
* @param PirepFieldValue[] $fields
|
||||||
|
* @param PirepFare[] $fares
|
||||||
*
|
*
|
||||||
* @throws AirportNotFound If one of the departure or arrival airports isn't found locally
|
* @throws AirportNotFound If one of the departure or arrival airports isn't found locally
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*
|
*
|
||||||
* @return \App\Models\Pirep
|
* @return \App\Models\Pirep
|
||||||
*/
|
*/
|
||||||
public function prefile(User $user, array $attrs): Pirep
|
public function prefile(User $user, array $attrs, array $fields = [], array $fares = []): Pirep
|
||||||
{
|
{
|
||||||
$attrs['user_id'] = $user->id;
|
$attrs['user_id'] = $user->id;
|
||||||
$attrs['state'] = PirepState::IN_PROGRESS;
|
$attrs['state'] = PirepState::IN_PROGRESS;
|
||||||
@@ -131,13 +139,33 @@ class PirepService extends Service
|
|||||||
throw new AircraftPermissionDenied($user, $pirep->aircraft);
|
throw new AircraftPermissionDenied($user, $pirep->aircraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if this aircraft is at the departure airport
|
// See if this aircraft is valid
|
||||||
/** @var Aircraft $aircraft */
|
/** @var Aircraft $aircraft */
|
||||||
$aircraft = $this->aircraftRepo->findWithoutFail($pirep->aircraft_id);
|
$aircraft = $this->aircraftRepo->findWithoutFail($pirep->aircraft_id);
|
||||||
if ($aircraft === null) {
|
if ($aircraft === null) {
|
||||||
throw new AircraftInvalid($aircraft);
|
throw new AircraftInvalid($aircraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See if this aircraft is available for flight
|
||||||
|
/** @var Aircraft $aircraft */
|
||||||
|
$aircraft = $this->aircraftRepo->where('id', $pirep->aircraft_id)->where('state', AircraftState::PARKED)->first();
|
||||||
|
if ($aircraft === null) {
|
||||||
|
throw new AircraftNotAvailable($pirep->aircraft);
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if this aircraft is being used by another user's active simbrief ofp
|
||||||
|
if (setting('simbrief.block_aircraft', false)) {
|
||||||
|
$sb_aircraft = SimBrief::select('aircraft_id')
|
||||||
|
->where('aircraft_id', $pirep->aircraft_id)
|
||||||
|
->where('user_id', '!=', $pirep->user_id)
|
||||||
|
->whereNotNull('flight_id')
|
||||||
|
->count();
|
||||||
|
if ($sb_aircraft > 0) {
|
||||||
|
throw new AircraftNotAvailable($pirep->aircraft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if this aircraft is at the departure airport
|
||||||
/* @noinspection NotOptimalIfConditionsInspection */
|
/* @noinspection NotOptimalIfConditionsInspection */
|
||||||
if (setting('pireps.only_aircraft_at_dpt_airport') && $aircraft->airport_id !== $pirep->dpt_airport_id) {
|
if (setting('pireps.only_aircraft_at_dpt_airport') && $aircraft->airport_id !== $pirep->dpt_airport_id) {
|
||||||
throw new AircraftNotAtAirport($pirep->aircraft);
|
throw new AircraftNotAtAirport($pirep->aircraft);
|
||||||
@@ -147,14 +175,30 @@ class PirepService extends Service
|
|||||||
$dupe_pirep = $this->findDuplicate($pirep);
|
$dupe_pirep = $this->findDuplicate($pirep);
|
||||||
if ($dupe_pirep !== false) {
|
if ($dupe_pirep !== false) {
|
||||||
$pirep = $dupe_pirep;
|
$pirep = $dupe_pirep;
|
||||||
|
Log::info('Found duplicate PIREP, id='.$dupe_pirep->id);
|
||||||
if ($pirep->cancelled) {
|
if ($pirep->cancelled) {
|
||||||
throw new \App\Exceptions\PirepCancelled($pirep);
|
throw new \App\Exceptions\PirepCancelled($pirep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event(new PirepPrefiled($pirep));
|
$pirep->status = PirepStatus::INITIATED;
|
||||||
|
|
||||||
$pirep->save();
|
$pirep->save();
|
||||||
|
$pirep->refresh();
|
||||||
|
|
||||||
|
// Check if there is a simbrief_id, update it to have the pirep_id
|
||||||
|
// Keep the flight_id until the end of flight (pirep file)
|
||||||
|
if (array_key_exists('simbrief_id', $attrs)) {
|
||||||
|
/** @var SimBrief $simbrief */
|
||||||
|
$simbrief = SimBrief::find($attrs['simbrief_id']);
|
||||||
|
if ($simbrief) {
|
||||||
|
$this->simBriefSvc->attachSimbriefToPirep($pirep, $simbrief, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->updateCustomFields($pirep->id, $fields);
|
||||||
|
$this->fareSvc->saveForPirep($pirep, $fares);
|
||||||
|
|
||||||
|
event(new PirepPrefiled($pirep));
|
||||||
|
|
||||||
return $pirep;
|
return $pirep;
|
||||||
}
|
}
|
||||||
@@ -167,10 +211,10 @@ class PirepService extends Service
|
|||||||
*
|
*
|
||||||
* @return Pirep
|
* @return Pirep
|
||||||
*/
|
*/
|
||||||
public function create(Pirep $pirep, array $field_values = []): Pirep
|
public function create(Pirep $pirep, array $fields = []): Pirep
|
||||||
{
|
{
|
||||||
if (empty($field_values)) {
|
if (empty($fields)) {
|
||||||
$field_values = [];
|
$fields = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the block times. If a block on (arrival) time isn't
|
// Check the block times. If a block on (arrival) time isn't
|
||||||
@@ -206,9 +250,23 @@ class PirepService extends Service
|
|||||||
$pirep->save();
|
$pirep->save();
|
||||||
$pirep->refresh();
|
$pirep->refresh();
|
||||||
|
|
||||||
if (count($field_values) > 0) {
|
$this->updateCustomFields($pirep->id, $fields);
|
||||||
$this->updateCustomFields($pirep->id, $field_values);
|
|
||||||
}
|
return $pirep;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PirepFieldValue[] $fields
|
||||||
|
* @param PirepFare[] $fares
|
||||||
|
*
|
||||||
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function update(string $pirep_id, array $attrs, array $fields = [], array $fares = []): Pirep
|
||||||
|
{
|
||||||
|
$pirep = $this->pirepRepo->update($attrs, $pirep_id);
|
||||||
|
$this->updateCustomFields($pirep_id, $fields);
|
||||||
|
$this->fareSvc->saveForPirep($pirep, $fares);
|
||||||
|
|
||||||
return $pirep;
|
return $pirep;
|
||||||
}
|
}
|
||||||
@@ -216,18 +274,31 @@ class PirepService extends Service
|
|||||||
/**
|
/**
|
||||||
* Finalize a PIREP (meaning it's been filed)
|
* Finalize a PIREP (meaning it's been filed)
|
||||||
*
|
*
|
||||||
* @param Pirep $pirep
|
* @param Pirep $pirep
|
||||||
* @param array $attrs
|
* @param array $attrs
|
||||||
* @param array PirepFieldValue[] $field_values
|
* @param PirepFieldValue[] $fields
|
||||||
|
* @param PirepFare[] $fares
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*
|
*
|
||||||
* @return Pirep
|
* @return Pirep
|
||||||
*/
|
*/
|
||||||
public function file(Pirep $pirep, array $attrs = [], array $field_values = []): Pirep
|
public function file(Pirep $pirep, array $attrs = [], array $fields = [], array $fares = []): Pirep
|
||||||
{
|
{
|
||||||
if (empty($field_values)) {
|
if (empty($fields)) {
|
||||||
$field_values = [];
|
$fields = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the PIREP has already been submitted
|
||||||
|
$is_already_submitted = in_array($pirep->state, [
|
||||||
|
PirepState::PENDING,
|
||||||
|
PirepState::ACCEPTED,
|
||||||
|
PirepState::CANCELLED,
|
||||||
|
PirepState::REJECTED,
|
||||||
|
], true);
|
||||||
|
|
||||||
|
if ($is_already_submitted) {
|
||||||
|
throw new PirepError($pirep, 'PIREP has already been submitted');
|
||||||
}
|
}
|
||||||
|
|
||||||
$attrs['state'] = PirepState::PENDING;
|
$attrs['state'] = PirepState::PENDING;
|
||||||
@@ -272,9 +343,8 @@ class PirepService extends Service
|
|||||||
$pirep->save();
|
$pirep->save();
|
||||||
$pirep->refresh();
|
$pirep->refresh();
|
||||||
|
|
||||||
if (count($field_values) > 0) {
|
$this->updateCustomFields($pirep->id, $fields);
|
||||||
$this->updateCustomFields($pirep->id, $field_values);
|
$this->fareSvc->saveForPirep($pirep, $fares);
|
||||||
}
|
|
||||||
|
|
||||||
return $pirep;
|
return $pirep;
|
||||||
}
|
}
|
||||||
@@ -293,9 +363,11 @@ class PirepService extends Service
|
|||||||
$time_limit = Carbon::now('UTC')->subMinutes($minutes)->toDateTimeString();
|
$time_limit = Carbon::now('UTC')->subMinutes($minutes)->toDateTimeString();
|
||||||
|
|
||||||
$where = [
|
$where = [
|
||||||
'user_id' => $pirep->user_id,
|
'user_id' => $pirep->user_id,
|
||||||
'airline_id' => $pirep->airline_id,
|
'airline_id' => $pirep->airline_id,
|
||||||
'flight_number' => $pirep->flight_number,
|
'flight_number' => $pirep->flight_number,
|
||||||
|
'dpt_airport_id' => $pirep->dpt_airport_id,
|
||||||
|
'arr_airport_id' => $pirep->arr_airport_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (filled($pirep->route_code)) {
|
if (filled($pirep->route_code)) {
|
||||||
@@ -401,6 +473,19 @@ class PirepService extends Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if there is a simbrief_id, change it to be set to the PIREP
|
||||||
|
// at the end of the flight when it's been submitted finally.
|
||||||
|
// Prefile, Save (as draft) and File already have this but the Submit button
|
||||||
|
// visible at pireps.show blade uses this function so Simbrief also needs to
|
||||||
|
// checked here too (to remove the flight_id and release the aircraft)
|
||||||
|
if (!empty($pirep->simbrief)) {
|
||||||
|
/** @var SimBrief $simbrief */
|
||||||
|
$simbrief = SimBrief::find($pirep->simbrief->id);
|
||||||
|
if ($simbrief) {
|
||||||
|
$this->simBriefSvc->attachSimbriefToPirep($pirep, $simbrief);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log::info('New PIREP filed', [$pirep]);
|
Log::info('New PIREP filed', [$pirep]);
|
||||||
event(new PirepFiled($pirep));
|
event(new PirepFiled($pirep));
|
||||||
|
|
||||||
@@ -456,30 +541,41 @@ class PirepService extends Service
|
|||||||
*/
|
*/
|
||||||
public function delete(Pirep $pirep): void
|
public function delete(Pirep $pirep): void
|
||||||
{
|
{
|
||||||
|
$user_id = $pirep->user_id;
|
||||||
|
|
||||||
$w = ['pirep_id' => $pirep->id];
|
$w = ['pirep_id' => $pirep->id];
|
||||||
PirepComment::where($w)->forceDelete();
|
PirepComment::where($w)->forceDelete();
|
||||||
PirepFare::where($w)->forceDelete();
|
PirepFare::where($w)->forceDelete();
|
||||||
PirepFieldValue::where($w)->forceDelete();
|
PirepFieldValue::where($w)->forceDelete();
|
||||||
SimBrief::where($w)->forceDelete();
|
SimBrief::where($w)->forceDelete();
|
||||||
$pirep->forceDelete();
|
$pirep->forceDelete();
|
||||||
|
|
||||||
|
// Update the user's last PIREP
|
||||||
|
$last_pirep = Pirep::where(['user_id' => $user_id, 'state' => PirepState::ACCEPTED])
|
||||||
|
->latest('submitted_at')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$user = User::find($user_id);
|
||||||
|
$user->last_pirep_id = !empty($last_pirep) ? $last_pirep->id : null;
|
||||||
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update any custom PIREP fields
|
* Update any custom PIREP fields
|
||||||
*
|
*
|
||||||
* @param $pirep_id
|
* @param string $pirep_id
|
||||||
* @param array $field_values
|
* @param PirepFieldValue[] $field_values
|
||||||
*/
|
*/
|
||||||
public function updateCustomFields($pirep_id, array $field_values)
|
public function updateCustomFields(string $pirep_id, array $field_values): void
|
||||||
{
|
{
|
||||||
|
if (!$field_values || empty($field_values)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($field_values as $fv) {
|
foreach ($field_values as $fv) {
|
||||||
PirepFieldValue::updateOrCreate(
|
PirepFieldValue::updateOrCreate(
|
||||||
['pirep_id' => $pirep_id,
|
['pirep_id' => $pirep_id, 'name' => $fv->name],
|
||||||
'name' => $fv['name'],
|
['value' => $fv->value, 'source' => $fv->source]
|
||||||
],
|
|
||||||
['value' => $fv['value'],
|
|
||||||
'source' => $fv['source'],
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -492,7 +588,7 @@ class PirepService extends Service
|
|||||||
*
|
*
|
||||||
* @return Pirep
|
* @return Pirep
|
||||||
*/
|
*/
|
||||||
public function changeState(Pirep $pirep, int $new_state)
|
public function changeState(Pirep $pirep, int $new_state): Pirep
|
||||||
{
|
{
|
||||||
Log::info('PIREP '.$pirep->id.' state change from '.$pirep->state.' to '.$new_state);
|
Log::info('PIREP '.$pirep->id.' state change from '.$pirep->state.' to '.$new_state);
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ class SimBriefService extends Service
|
|||||||
* Check to see if the OFP exists server-side. If it does, download it and
|
* Check to see if the OFP exists server-side. If it does, download it and
|
||||||
* cache it immediately
|
* cache it immediately
|
||||||
*
|
*
|
||||||
* @param string $user_id User who generated this
|
* @param string $user_id User who generated this
|
||||||
* @param string $ofp_id The SimBrief OFP ID
|
* @param string $ofp_id The SimBrief OFP ID
|
||||||
* @param string $flight_id The flight ID
|
* @param string $flight_id The flight ID
|
||||||
* @param string $ac_id The aircraft ID
|
* @param string $ac_id The aircraft ID
|
||||||
* @param array $fares Full list of fares for the flightß
|
* @param array $fares Full list of fares for the flight
|
||||||
|
* @param string $sb_userid User's Simbrief ID (Used for Update)
|
||||||
|
* @param string $sb_static_id Static ID for the generated OFP (Used for Update)
|
||||||
*
|
*
|
||||||
* @return SimBrief|null
|
* @return SimBrief|null
|
||||||
*/
|
*/
|
||||||
@@ -39,10 +41,18 @@ class SimBriefService extends Service
|
|||||||
string $ofp_id,
|
string $ofp_id,
|
||||||
string $flight_id,
|
string $flight_id,
|
||||||
string $ac_id,
|
string $ac_id,
|
||||||
array $fares = []
|
array $fares = [],
|
||||||
|
string $sb_user_id = null,
|
||||||
|
string $sb_static_id = null
|
||||||
) {
|
) {
|
||||||
$uri = str_replace('{id}', $ofp_id, config('phpvms.simbrief_url'));
|
$uri = str_replace('{id}', $ofp_id, config('phpvms.simbrief_url'));
|
||||||
|
|
||||||
|
if ($sb_user_id && $sb_static_id) {
|
||||||
|
// $uri = str_replace('{sb_user_id}', $sb_user_id, config('phpvms.simbrief_update_url'));
|
||||||
|
// $uri = str_replace('{sb_static_id}', $sb_static_id, $uri);
|
||||||
|
$uri = 'https://www.simbrief.com/api/xml.fetcher.php?userid='.$sb_user_id.'&static_id='.$sb_static_id;
|
||||||
|
}
|
||||||
|
|
||||||
$opts = [
|
$opts = [
|
||||||
'connect_timeout' => 2, // wait two seconds by default
|
'connect_timeout' => 2, // wait two seconds by default
|
||||||
'allow_redirects' => false,
|
'allow_redirects' => false,
|
||||||
@@ -132,21 +142,23 @@ class SimBriefService extends Service
|
|||||||
*
|
*
|
||||||
* 1. Read from the XML the basic PIREP info (dep, arr), and then associate the PIREP
|
* 1. Read from the XML the basic PIREP info (dep, arr), and then associate the PIREP
|
||||||
* to the flight ID
|
* to the flight ID
|
||||||
* 2. Remove the flight ID from the SimBrief field and assign the pirep_id to the row
|
* 2. Remove the flight ID from the SimBrief model and assign the pirep ID to the row
|
||||||
|
* at the end of the flight. Keep flight ID until the flight ends (pirep file).
|
||||||
* 3. Update the planned flight route in the acars table
|
* 3. Update the planned flight route in the acars table
|
||||||
* 4. Add additional flight fields (ones which match ACARS)
|
* 4. Add additional flight fields (ones which match ACARS)
|
||||||
*
|
*
|
||||||
* @param $pirep
|
* @param $pirep
|
||||||
* @param SimBrief $simBrief The briefing to create the PIREP from
|
* @param SimBrief $simBrief The briefing to create the PIREP from
|
||||||
|
* @param bool $keep_flight True keeps the flight_id, default is false
|
||||||
*
|
*
|
||||||
* @return \App\Models\Pirep
|
* @return \App\Models\Pirep
|
||||||
*/
|
*/
|
||||||
public function attachSimbriefToPirep($pirep, SimBrief $simBrief): Pirep
|
public function attachSimbriefToPirep($pirep, SimBrief $simBrief, $keep_flight = false): Pirep
|
||||||
{
|
{
|
||||||
$this->addRouteToPirep($pirep, $simBrief);
|
$this->addRouteToPirep($pirep, $simBrief);
|
||||||
|
|
||||||
$simBrief->pirep_id = $pirep->id;
|
$simBrief->pirep_id = $pirep->id;
|
||||||
$simBrief->flight_id = null;
|
$simBrief->flight_id = !empty($keep_flight) ? $pirep->flight_id : null;
|
||||||
$simBrief->save();
|
$simBrief->save();
|
||||||
|
|
||||||
return $pirep;
|
return $pirep;
|
||||||
@@ -185,24 +197,24 @@ class SimBriefService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove any expired entries from the SimBrief table. Expired means there's
|
* Remove any expired entries from the SimBrief table.
|
||||||
* a flight_id attached to it, but no pirep_id (meaning it was never used for
|
* Expired means there's a flight_id attached to it, but no pirep_id
|
||||||
* an actual flight)
|
* (meaning it was never used for an actual flight)
|
||||||
*/
|
*/
|
||||||
public function removeExpiredEntries(): void
|
public function removeExpiredEntries(): void
|
||||||
{
|
{
|
||||||
$expire_days = setting('simbrief.expire_days', 5);
|
$expire_hours = setting('simbrief.expire_hours', 6);
|
||||||
$expire_time = Carbon::now('UTC')->subDays($expire_days)->toDateTimeString();
|
$expire_time = Carbon::now('UTC')->subHours($expire_hours);
|
||||||
|
|
||||||
$briefs = SimBrief::where([
|
$briefs = SimBrief::where([
|
||||||
['pirep_id', '=', ''],
|
['pirep_id', null],
|
||||||
['created_at', '<', $expire_time],
|
['created_at', '<=', $expire_time],
|
||||||
])->get();
|
])->get();
|
||||||
|
|
||||||
foreach ($briefs as $brief) {
|
foreach ($briefs as $brief) {
|
||||||
$brief->delete();
|
$brief->delete();
|
||||||
|
|
||||||
// TODO: Delete any assets
|
// TODO: Delete any assets (Which assets ?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ use App\Events\UserStatsChanged;
|
|||||||
use App\Exceptions\PilotIdNotFound;
|
use App\Exceptions\PilotIdNotFound;
|
||||||
use App\Exceptions\UserPilotIdExists;
|
use App\Exceptions\UserPilotIdExists;
|
||||||
use App\Models\Airline;
|
use App\Models\Airline;
|
||||||
|
use App\Models\Bid;
|
||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
use App\Models\Enums\UserState;
|
use App\Models\Enums\UserState;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Models\Rank;
|
use App\Models\Rank;
|
||||||
use App\Models\Role;
|
use App\Models\Role;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\UserFieldValue;
|
||||||
use App\Repositories\AircraftRepository;
|
use App\Repositories\AircraftRepository;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\SubfleetRepository;
|
use App\Repositories\SubfleetRepository;
|
||||||
@@ -23,6 +25,7 @@ use App\Support\Units\Time;
|
|||||||
use App\Support\Utils;
|
use App\Support\Utils;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
|
|
||||||
@@ -60,14 +63,23 @@ class UserService extends Service
|
|||||||
*
|
*
|
||||||
* @param $user_id
|
* @param $user_id
|
||||||
*
|
*
|
||||||
* @return User
|
* @return User|null
|
||||||
*/
|
*/
|
||||||
public function getUser($user_id): User
|
public function getUser($user_id): ?User
|
||||||
{
|
{
|
||||||
|
/** @var User $user */
|
||||||
$user = $this->userRepo
|
$user = $this->userRepo
|
||||||
->with(['airline', 'bids', 'rank'])
|
->with(['airline', 'bids', 'rank'])
|
||||||
->find($user_id);
|
->find($user_id);
|
||||||
|
|
||||||
|
if (empty($user)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->state === UserState::DELETED) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Load the proper subfleets to the rank
|
// Load the proper subfleets to the rank
|
||||||
$user->rank->subfleets = $this->getAllowableSubfleets($user);
|
$user->rank->subfleets = $this->getAllowableSubfleets($user);
|
||||||
$user->subfleets = $user->rank->subfleets;
|
$user->subfleets = $user->rank->subfleets;
|
||||||
@@ -117,6 +129,38 @@ class UserService extends Service
|
|||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the user. But don't actually delete them - set the name to deleted, email to
|
||||||
|
* something random
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function removeUser(User $user)
|
||||||
|
{
|
||||||
|
// Detach all roles from this user
|
||||||
|
$user->detachRoles($user->roles);
|
||||||
|
|
||||||
|
// Delete any fields which might have personal information
|
||||||
|
UserFieldValue::where('user_id', $user->id)->delete();
|
||||||
|
|
||||||
|
// Remove any bids
|
||||||
|
Bid::where('user_id', $user->id)->delete();
|
||||||
|
|
||||||
|
// If this user has PIREPs, do a soft delete. Otherwise, just delete them outright
|
||||||
|
if ($user->pireps->count() > 0) {
|
||||||
|
$user->name = 'Deleted User';
|
||||||
|
$user->email = Utils::generateApiKey().'@deleted-user.com';
|
||||||
|
$user->api_key = Utils::generateApiKey();
|
||||||
|
$user->password = Hash::make(Utils::generateApiKey());
|
||||||
|
$user->state = UserState::DELETED;
|
||||||
|
$user->save();
|
||||||
|
} else {
|
||||||
|
$user->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a user to a given role
|
* Add a user to a given role
|
||||||
*
|
*
|
||||||
@@ -125,7 +169,7 @@ class UserService extends Service
|
|||||||
*
|
*
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
public function addUserToRole(User $user, $roleName): User
|
public function addUserToRole(User $user, string $roleName): User
|
||||||
{
|
{
|
||||||
$role = Role::where(['name' => $roleName])->first();
|
$role = Role::where(['name' => $roleName])->first();
|
||||||
$user->attachRole($role);
|
$user->attachRole($role);
|
||||||
@@ -260,49 +304,41 @@ class UserService extends Service
|
|||||||
* currently active users. If the user doesn't have a PIREP, then the creation date
|
* currently active users. If the user doesn't have a PIREP, then the creation date
|
||||||
* of the user record is used to determine the difference
|
* of the user record is used to determine the difference
|
||||||
*/
|
*/
|
||||||
public function findUsersOnLeave(): array
|
public function findUsersOnLeave()
|
||||||
{
|
{
|
||||||
$leave_days = setting('pilots.auto_leave_days');
|
$leave_days = setting('pilots.auto_leave_days');
|
||||||
if ($leave_days === 0) {
|
if ($leave_days === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$return_users = [];
|
|
||||||
|
|
||||||
$date = Carbon::now('UTC');
|
$date = Carbon::now('UTC');
|
||||||
$users = User::with(['last_pirep'])->where('state', UserState::ACTIVE)->get();
|
$users = User::where('state', UserState::ACTIVE)->get();
|
||||||
|
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
foreach ($users as $user) {
|
return $users->filter(function ($user, $i) use ($date, $leave_days) {
|
||||||
// If they haven't submitted a PIREP, use the date that the user was created
|
|
||||||
if (!$user->last_pirep) {
|
|
||||||
$diff_date = $user->created_at;
|
|
||||||
} else {
|
|
||||||
$diff_date = $user->last_pirep->submitted_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
// See if the difference is larger than what the setting calls for
|
|
||||||
if ($date->diffInDays($diff_date) <= $leave_days) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$skip = false;
|
|
||||||
// If any role for this user has the "disable_activity_check" feature activated, skip this user
|
// If any role for this user has the "disable_activity_check" feature activated, skip this user
|
||||||
foreach ($user->roles()->get() as $role) {
|
foreach ($user->roles()->get() as $role) {
|
||||||
/** @var Role $role */
|
/** @var Role $role */
|
||||||
if ($role->disable_activity_checks) {
|
if ($role->disable_activity_checks) {
|
||||||
$skip = true;
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($skip) {
|
// If they haven't submitted a PIREP, use the date that the user was created
|
||||||
continue;
|
$last_pirep = Pirep::where(['user_id' => $user->id])->latest('submitted_at')->first();
|
||||||
|
if (!$last_pirep) {
|
||||||
|
$diff_date = $user->created_at;
|
||||||
|
} else {
|
||||||
|
$diff_date = $last_pirep->created_at;
|
||||||
}
|
}
|
||||||
$return_users[] = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return_users;
|
// See if the difference is larger than what the setting calls for
|
||||||
|
if ($date->diffInDays($diff_date) <= $leave_days) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class Discord
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get a user's private channel ID from Discord
|
||||||
|
*
|
||||||
|
* @param string $discord_id
|
||||||
|
*/
|
||||||
|
public static function getPrivateChannelId(string $discord_id)
|
||||||
|
{
|
||||||
|
/** @var HttpClient $httpClient */
|
||||||
|
$httpClient = app(HttpClient::class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $httpClient->post(
|
||||||
|
'https://discord.com/api/users/@me/channels',
|
||||||
|
[
|
||||||
|
'recipient_id' => $discord_id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
dd($response);
|
||||||
|
return $response->id;
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
dd($ex);
|
||||||
|
Log::error('Could not get private channel id for '.$discord_id.';'.$ex->getMessage());
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Support;
|
namespace App\Support;
|
||||||
|
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
|
use GuzzleHttp\RequestOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for HTTP stuff
|
* Helper for HTTP stuff
|
||||||
@@ -11,9 +12,8 @@ class HttpClient
|
|||||||
{
|
{
|
||||||
private $httpClient;
|
private $httpClient;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(GuzzleClient $httpClient)
|
||||||
GuzzleClient $httpClient
|
{
|
||||||
) {
|
|
||||||
$this->httpClient = $httpClient;
|
$this->httpClient = $httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +45,29 @@ class HttpClient
|
|||||||
return $body;
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $uri
|
||||||
|
* @param $body
|
||||||
|
* @param array $opts
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function post($uri, $body, array $opts = [])
|
||||||
|
{
|
||||||
|
$opts = array_merge([
|
||||||
|
'connect_timeout' => 2,
|
||||||
|
RequestOptions::JSON => $body,
|
||||||
|
], $opts);
|
||||||
|
|
||||||
|
$response = $this->httpClient->post($uri, $opts);
|
||||||
|
$content_type = $response->getHeaderLine('content-type');
|
||||||
|
if (strpos($content_type, 'application/json') !== false) {
|
||||||
|
$body = \GuzzleHttp\json_decode($body, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download a file to a given path
|
* Download a file to a given path
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||||
|
use Illuminate\Pagination\AbstractPaginator;
|
||||||
|
|
||||||
|
class CustomAnonymousResourceCollection extends AnonymousResourceCollection
|
||||||
|
{
|
||||||
|
public function toResponse($request)
|
||||||
|
{
|
||||||
|
return $this->resource instanceof AbstractPaginator
|
||||||
|
? (new CustomPaginatedResourceResponse($this))->toResponse($request)
|
||||||
|
: parent::toResponse($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\PaginatedResourceResponse;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
|
class CustomPaginatedResourceResponse extends PaginatedResourceResponse
|
||||||
|
{
|
||||||
|
protected function paginationLinks($paginated)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'first' => null,
|
||||||
|
'last' => null,
|
||||||
|
'prev' => null,
|
||||||
|
'next' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function meta($paginated)
|
||||||
|
{
|
||||||
|
$meta = Arr::except($paginated, [
|
||||||
|
'data',
|
||||||
|
'first_page_url',
|
||||||
|
'last_page_url',
|
||||||
|
'prev_page_url',
|
||||||
|
'next_page_url',
|
||||||
|
'links',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$meta['path'] = $meta['path'] + request()->query();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Widgets;
|
namespace App\Widgets;
|
||||||
|
|
||||||
use App\Contracts\Widget;
|
use App\Contracts\Widget;
|
||||||
|
use App\Models\Enums\UserState;
|
||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,10 +21,11 @@ class LatestPilots extends Widget
|
|||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$userRepo = app(UserRepository::class);
|
$userRepo = app(UserRepository::class);
|
||||||
|
$userRepo = $userRepo->where('state', '!=', UserState::DELETED)->orderby('created_at', 'desc')->take($this->config['count'])->get();
|
||||||
|
|
||||||
return view('widgets.latest_pilots', [
|
return view('widgets.latest_pilots', [
|
||||||
'config' => $this->config,
|
'config' => $this->config,
|
||||||
'users' => $userRepo->with(['airline'])->recent($this->config['count']),
|
'users' => $userRepo,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -30,6 +30,10 @@ if (!function_exists('in_mask')) {
|
|||||||
*/
|
*/
|
||||||
function in_mask($mask, $value)
|
function in_mask($mask, $value)
|
||||||
{
|
{
|
||||||
|
if (empty($mask)) {
|
||||||
|
$mask = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ($mask & $value) === $value;
|
return ($mask & $value) === $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,7 +369,7 @@ if (!function_exists('secstohhmm')) {
|
|||||||
*/
|
*/
|
||||||
function secstohhmm($seconds)
|
function secstohhmm($seconds)
|
||||||
{
|
{
|
||||||
$seconds = round($seconds);
|
$seconds = round((float) $seconds);
|
||||||
$hhmm = sprintf('%02d%02d', ($seconds / 3600), ($seconds / 60 % 60));
|
$hhmm = sprintf('%02d%02d', ($seconds / 3600), ($seconds / 60 % 60));
|
||||||
echo $hhmm;
|
echo $hhmm;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -15,10 +15,14 @@
|
|||||||
"ext-bcmath": "*",
|
"ext-bcmath": "*",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
"ext-intl": "*",
|
"ext-intl": "*",
|
||||||
|
"symfony/polyfill-intl-icu": "*",
|
||||||
|
"symfony/polyfill-intl-idn": "*",
|
||||||
|
"symfony/polyfill-mbstring": "*",
|
||||||
|
"symfony/polyfill-php74": "*",
|
||||||
|
"symfony/polyfill-php80": "*",
|
||||||
"composer/composer": "~1.0",
|
"composer/composer": "~1.0",
|
||||||
"composer/installers": "~1.0",
|
"composer/installers": "~1.0",
|
||||||
"laravel/framework": "~8.0",
|
"laravel/framework": "~8.0",
|
||||||
"akaunting/money": "^1.0",
|
|
||||||
"anhskohbo/no-captcha": "^3.0",
|
"anhskohbo/no-captcha": "^3.0",
|
||||||
"appstract/laravel-opcache": "^4.0",
|
"appstract/laravel-opcache": "^4.0",
|
||||||
"arrilot/laravel-widgets": "~3.13.0",
|
"arrilot/laravel-widgets": "~3.13.0",
|
||||||
@@ -29,7 +33,7 @@
|
|||||||
"guzzlehttp/guzzle": "~6.5",
|
"guzzlehttp/guzzle": "~6.5",
|
||||||
"hashids/hashids": "^4.1.0",
|
"hashids/hashids": "^4.1.0",
|
||||||
"igaster/laravel-theme": "^2.0",
|
"igaster/laravel-theme": "^2.0",
|
||||||
"intervention/image": "2.4.*",
|
"intervention/image": "^2.4",
|
||||||
"irazasyed/laravel-gamp": "^1.8",
|
"irazasyed/laravel-gamp": "^1.8",
|
||||||
"jmikola/geojson": "1.0.*",
|
"jmikola/geojson": "1.0.*",
|
||||||
"joshbrw/laravel-module-installer": "^2.0",
|
"joshbrw/laravel-module-installer": "^2.0",
|
||||||
@@ -49,7 +53,6 @@
|
|||||||
"pragmarx/version": ">=v1.2.3",
|
"pragmarx/version": ">=v1.2.3",
|
||||||
"prettus/l5-repository": "~2.7.0",
|
"prettus/l5-repository": "~2.7.0",
|
||||||
"santigarcor/laratrust": "~6.3",
|
"santigarcor/laratrust": "~6.3",
|
||||||
"sebastiaanluca/laravel-helpers": "~6.0",
|
|
||||||
"semver/semver": "~1.1.0",
|
"semver/semver": "~1.1.0",
|
||||||
"spatie/valuestore": "~1.2",
|
"spatie/valuestore": "~1.2",
|
||||||
"symfony/polyfill-iconv": "~1.22.0",
|
"symfony/polyfill-iconv": "~1.22.0",
|
||||||
@@ -61,8 +64,11 @@
|
|||||||
"madnest/madzipper": "^1.1.0",
|
"madnest/madzipper": "^1.1.0",
|
||||||
"elcobvg/laravel-opcache": "^0.4.1",
|
"elcobvg/laravel-opcache": "^0.4.1",
|
||||||
"laravel/legacy-factories": "^1.1",
|
"laravel/legacy-factories": "^1.1",
|
||||||
"fakerphp/faker": "^1.13",
|
"fakerphp/faker": "^v1.14",
|
||||||
"wildbit/swiftmailer-postmark": "^3.3"
|
"wildbit/swiftmailer-postmark": "^3.3",
|
||||||
|
"queueworker/sansdaemon": "^1.2",
|
||||||
|
"jpkleemans/attribute-events": "^1.1",
|
||||||
|
"akaunting/laravel-money": "^1.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-debugbar": "^3.5",
|
"barryvdh/laravel-debugbar": "^3.5",
|
||||||
|
|||||||
Generated
+887
-613
File diff suppressed because it is too large
Load Diff
@@ -66,7 +66,6 @@ return [
|
|||||||
Collective\Html\HtmlServiceProvider::class,
|
Collective\Html\HtmlServiceProvider::class,
|
||||||
Laracasts\Flash\FlashServiceProvider::class,
|
Laracasts\Flash\FlashServiceProvider::class,
|
||||||
Prettus\Repository\Providers\RepositoryServiceProvider::class,
|
Prettus\Repository\Providers\RepositoryServiceProvider::class,
|
||||||
SebastiaanLuca\Helpers\Collections\CollectionMacrosServiceProvider::class,
|
|
||||||
Irazasyed\LaravelGAMP\LaravelGAMPServiceProvider::class,
|
Irazasyed\LaravelGAMP\LaravelGAMPServiceProvider::class,
|
||||||
Igaster\LaravelTheme\themeServiceProvider::class,
|
Igaster\LaravelTheme\themeServiceProvider::class,
|
||||||
Nwidart\Modules\LaravelModulesServiceProvider::class,
|
Nwidart\Modules\LaravelModulesServiceProvider::class,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user