Skip to content

Instantly share code, notes, and snippets.

@K4T

K4T/fefw.php Secret

Created August 19, 2019 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save K4T/3d88fbb23733ad935f60e46d77aa004c to your computer and use it in GitHub Desktop.
Save K4T/3d88fbb23733ad935f60e46d77aa004c to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use Cake\I18n\Time;
use Cake\ORM\TableRegistry;
class HtmlEditionsController extends AppController
{
public function index()
{
$regions = TableRegistry::get('Regions')->find('availableRegions')->all();
$currentRegion = $regions->first();
$editions = TableRegistry::get('EditionsPub')->find('availableEditions')->all();
$currentEdition = $editions->first();
$this->set('regions', $regions);
$this->set('currentRegion', $currentRegion);
$this->set('editions', $editions);
$this->set('currentEdition', $currentEdition);
return $this->render('view');
}
public function viewRegion($regionSlug)
{
$regions = TableRegistry::get('Regions')->find('availableRegions')->all();
$currentRegion = $regions->firstMatch(['slug' => $regionSlug]);
$editions = TableRegistry::get('EditionsPub')->find('availableEditions')->all();
$currentEdition = $editions->first();
$this->set('regions', $regions);
$this->set('currentRegion', $currentRegion);
$this->set('editions', $editions);
$this->set('currentEdition', $currentEdition);
return $this->render('view');
}
public function viewReleaseDate($regionSlug, $releaseDate)
{
$regions = TableRegistry::get('Regions')->find('availableRegions')->all();
$currentRegion = $regions->firstMatch(['slug' => $regionSlug]);
$editions = TableRegistry::get('EditionsPub')->find('availableEditions')->all();
$currentEdition = $editions->firstMatch([
'release_date' => Time::createFromFormat('!d.m.Y', $releaseDate)
]);
$this->set('regions', $regions);
$this->set('currentRegion', $currentRegion);
$this->set('editions', $editions);
$this->set('currentEdition', $currentEdition);
return $this->render('view');
}
}
// ROUTES
$routes->connect(
'/',
['controller' => 'HtmlEditions', 'action' => 'index'],
['_name' => 'HtmlEditions::index']
);
$routes->connect(
'/:regionSlug',
['controller' => 'HtmlEditions', 'action' => 'viewRegion'],
[
'pass' => ['regionSlug'],
'regionSlug' => '[\w-]+',
'_name' => 'HtmlEditions::viewRegion'
]
);
$routes->connect(
'/:regionSlug/:releaseDate',
['controller' => 'HtmlEditions', 'action' => 'viewReleaseDate'],
[
'pass' => ['regionSlug', 'releaseDate'],
'regionSlug' => '[\w-]+',
'releaseDate' => '\d{2}.\d{2}.\d{4}',
'_name' => 'HtmlEditions::viewReleaseDate'
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment