File: D:/HostingSpaces/SBogers10/zuiderbos.komma.pro/Komma/PhotoAlbums/PhotoAlbumController.php
<?php
namespace Komma\PhotoAlbums;
use Komma\Kms\Schools\School;
use Komma\LanguageService;
use Komma\Pages\PageService;
class PhotoAlbumController extends \BaseController
{
public $data;
protected $pageService;
protected $referenceService;
protected $photoAlbumService;
public $languageService;
public function __construct(PageService $pageService, LanguageService $languageService, PhotoAlbumService $photoAlbumService)
{
parent::__construct();
$this->pageService = $pageService;
$this->languageService = $languageService;
$this->photoAlbumService = $photoAlbumService;
}
//Overview page
public function index($page = null){
if($page == null){
//Check if language matches the url before loading the content
$this->languageService->checkRouteWithSetLanguage();
//get content of page by route because of the multiple news overviews all page links
$page = $this->pageService->getPageByRoute(\Request::path());
// Get root parent and append code_name to page
// So we can find out to which branch/school the page belongs
if($page->getDepth() != 1)
{
$page->root = $this->pageService->getRootParent($page);
}
else
{
// The page itself is the root branch, so to prevent writing if/else statements append it as branch
$page->root = $page;
}
// Load school to page
$page->school = School::where('type', $page->root->code_name)->first();
}
$links = $this->pageService->getAllRoutes();
return \View::make('layouts.pages.photoAlbums.index')
->with('page', $page)
->with('links', $links);
}
public function show($photoAlbumId){
//Check if language matches the url before loading content
$this->languageService->checkRouteWithSetLanguage();
//Load post content and translation of this reference
$photoAlbum = $this->photoAlbumService->getPhotoAlbum($photoAlbumId);
$links = $this->pageService->getAllRoutes();
// Get Page by route because we can't use the rest_root 'news' to get it
// This is because there are multiple news overviews
$segments = \Request::segments();
$parentRoute = '';
for($i = 0; $i <= (sizeof($segments) - 2); $i++){
$parentRoute .= $segments[$i].'/';
}
$parentRoute = rtrim($parentRoute, '/');
$page = $this->pageService->getPageByRoute($parentRoute);
$page->root = $this->pageService->getRootParent($page);
$page->school = School::where('type', $page->root->code_name)->first();
// Check if photo album is protected by an password
if($photoAlbum->password != ''){
// Set access to false
$photoAlbum->accessGranted = false;
// First check if there is an photo album session with the right password
if(\Session::get('photoAlbums.'.$photoAlbum->code_name, null) == $photoAlbum->password) $photoAlbum->accessGranted = true;
// Else check if there is an input with right password
elseif( \Input::get('password', null) == $photoAlbum->password ){
$photoAlbum->accessGranted = true;
\Session::put('photoAlbums.'.$photoAlbum->code_name, $photoAlbum->password);
}
}
else $photoAlbum->accessGranted = true;
return \View::make('layouts.pages.photoAlbums.show')
->with('page', $page)
->with('photoAlbum', $photoAlbum)
->with('links', $links);
}
}