-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
158 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models\Problems; | ||
|
||
use DateTime; | ||
|
||
class SeriesModel | ||
{ | ||
public string $deadline; | ||
public int $year; | ||
public int $series; | ||
/** | ||
* @var int[] | ||
*/ | ||
public array $problems; | ||
|
||
public function getDeadline() { | ||
return new DateTime($this->deadline); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models\Problems; | ||
|
||
use Fykosak\FKSDBDownloaderCore\Requests\Request; | ||
|
||
class SeriesRequest implements Request | ||
{ | ||
protected string $contest; | ||
protected int $year; | ||
protected int $series; | ||
|
||
public function __construct(string $contest, int $year, int $series) | ||
{ | ||
$this->contest = $contest; | ||
$this->year = $year; | ||
$this->series = $series; | ||
} | ||
|
||
public function getCacheKey(): string | ||
{ | ||
return sprintf('series.%s.%d.%d', $this->contest, $this->year, $this->series); | ||
} | ||
|
||
public function getParams(): array | ||
{ | ||
return []; | ||
} | ||
|
||
final public function getMethod(): string | ||
{ | ||
return sprintf('series.json'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models\Problems; | ||
use Nette\Caching\Cache; | ||
|
||
use Fykosak\NetteFKSDBDownloader\ORM\Services\AbstractJSONService; | ||
|
||
final class SeriesService extends AbstractJSONService | ||
{ | ||
public function getSeries( | ||
string $contest, | ||
int $year, | ||
int $series, | ||
?string $explicitExpiration = null | ||
): SeriesModel { | ||
return $this->getItem( | ||
new SeriesRequest($contest, $year, $series), | ||
[(string)$year, (string)$series], | ||
SeriesModel::class, | ||
false, | ||
$explicitExpiration | ||
); | ||
} | ||
|
||
public function getLatestSeries(string $contest): SeriesModel { | ||
return $this->cache->load( | ||
sprintf("lastSeries_%s", $contest), | ||
function (&$dependencies) use ($contest) { | ||
$dependencies[Cache::EXPIRE] = $this->expiration; | ||
$jsonText = $this->downloader->download(new SeriesRequest($contest, 0, 0)); // 0, 0 are dummy data | ||
$json = json_decode($jsonText); | ||
|
||
$yearArray = get_object_vars($json); | ||
$year = end($yearArray); | ||
|
||
$seriesArray = get_object_vars($year); | ||
$series = end($seriesArray); | ||
|
||
$mapper = new \JsonMapper(); | ||
return $mapper->map($series, new SeriesModel()); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters