File: D:/HostingSpaces/SBogers10/rentman.komma.pro/app/Komma/Projects/ProjectController.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Projects;
use Komma\Blocks\BlockService;
use Komma\Images\ImageService;
use Komma\LanguageService;
use Komma\Pages\PageService;
class ProjectController extends \BaseController
{
public $data;
protected $pageService;
protected $blockService;
protected $projectService;
public $languageService;
public function __construct(PageService $pageService, BlockService $blockService, ProjectService $projectService, LanguageService $languageService)
{
parent::__construct();
$this->pageService = $pageService;
$this->blockService = $blockService;
$this->projectService = $projectService;
$this->languageService = $languageService;
$this->data = (object)[];
}
//Project index page
public function index(){
$this->languageService->checkRouteWithSetLanguage();
$page = $this->pageService->getPageByCodeName('features');
$this->data->content = $page;
$this->data->id = $this->data->content->id;
$this->data->links = $this->pageService->getAllRoutes();
$blocks = $this->blockService->getBlocksWhere('type', 'features')->keyBy('code_name');
//get the (translation) route of the linked feature
foreach ($blocks as $block){
if(!isset($block->link)) continue;
$project = $this->projectService->getProject($block->link);
$block->link = $project->translation->route->route;
}
$otherLanguages = $this->pageService->getOtherLanguageRoutes($this->data->id);
return \View::make('layouts.pages.projectsOverview')
->with('data', $this->data)
->with('blocks', $blocks)
->with('projects', $this->projectService->getAllProjects())
->with('otherLanguages', $otherLanguages->allTranslations);
}
public function show($projectId){
$this->languageService->checkRouteWithSetLanguage();
$this->data = $this->projectService->getProject($projectId);
//encode the dynamic page
$this->data->translation->description = json_decode($this->data->translation->description);
$this->data->content = (object)['code_name' => $this->data->code_name];
$this->data->links = $this->pageService->getAllRoutes();
$otherLanguages = $this->projectService->getOtherLanguageRoutes($this->data->id);
$featurePage = $this->pageService->getPageByCodeName('features');
$this->data->meta_title = $this->data->translation->title.' | '.$featurePage->translation->meta_title;
$this->data->meta_description = strip_tags($this->data->translation->meta_description);
$this->data->translation->nav_name = $featurePage->translation->name;
$projects = $this->projectService->getAllProjects();
$projects2 = $projects->keyBy('id');
//prepare random features by getting all the unused features
$keys = $projects2->keys();
unset($keys[array_search($projectId, $keys)]);
//load the load the linked features to selected feature
$linked = [];
foreach ($this->data->categories as $category)
{
$linked[] = $projects2[$category->id];
//remove this key from the random features
if(($key = array_search($category->id, $keys)) !== false) {
unset($keys[$key]);
}
}
//if there aren't 3 features linked get the rest random till there are 3
shuffle($keys);
if(sizeof($linked)< 3){
$filled = sizeof($linked);
for($i =0; $i < (3-$filled); $i++){
if(isset($keys[$i])) $linked[] = $projects2[$keys[$i]];
}
}
$this->data->otherFeatures = $linked;
return \View::make('layouts.pages.projectDetail')
->with('data', $this->data)
->with('projects', $projects)
->with('otherLanguages', $otherLanguages->allTranslations);
}
}