-
-
Save K4T/3d88fbb23733ad935f60e46d77aa004c to your computer and use it in GitHub Desktop.
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
<?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