misc_pterodactyl-panel/app/Repositories/Eloquent/TaskRepository.php

55 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2017-09-26 02:43:01 +00:00
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Task;
use Webmozart\Assert\Assert;
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
class TaskRepository extends EloquentRepository implements TaskRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function model()
{
return Task::class;
}
/**
* {@inheritdoc}
*/
2017-09-17 04:10:00 +00:00
public function getTaskWithServer($id)
{
2017-09-17 04:10:00 +00:00
Assert::integerish($id, 'First argument passed to getTaskWithServer must be numeric, received %s.');
$instance = $this->getBuilder()->with('server.user')->find($id, $this->getColumns());
2017-09-17 04:10:00 +00:00
if (! $instance) {
throw new RecordNotFoundException;
}
return $instance;
}
/**
* {@inheritdoc}
*/
2017-09-17 04:10:00 +00:00
public function getNextTask($schedule, $index)
{
2017-09-17 04:10:00 +00:00
Assert::integerish($schedule, 'First argument passed to getNextTask must be integer, received %s.');
Assert::integerish($index, 'Second argument passed to getNextTask must be integer, received %s.');
2017-09-17 04:10:00 +00:00
return $this->getBuilder()->where('schedule_id', '=', $schedule)
->where('sequence_id', '=', $index + 1)
->first($this->getColumns());
}
}