File: D:/HostingSpaces/SBogers10/debierbaron.komma.pro/data/app/Komma/Boxes/BoxService.php
<?php
/**
* Short description for the file.
*
* @author Tim Van Samang <timvansamang@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Boxes;
use Komma\Kms\Boxes\Models\Boxes;
class BoxService
{
public $language_id = 104;
public function getBox($boxId)
{
//Get the blog item
if (!$box = Boxes::where('id', '=', $boxId)
->where('active', '=', 1)
->with('translations')
->whereHas('translations', function ($query) {
//Todo: taal ophalen
$query->where('language_id', '=', $this->language_id);
})
->first()
) return false;
$box= $this->prepareBox($box);
return $box;
}
public function getBoxes()
{
$boxes= Boxes::where('active', '=', 1)
->with('translations')
->whereHas('translations', function ($query) {
//Todo: taal ophalen
$query->where('language_id', '=', $this->language_id);
})
->orderBy('lft')
->get();
foreach ($boxes as $key => $box) {
$box[$key] = $this->prepareBox($box);
}
return $boxes;
}
private function prepareBox($box)
{
$translations = $box->translations->keyBy('language_id');
$box->name = $translations[$this->language_id]->name;
$box->description = $translations[$this->language_id]->description;
$box->meta_title = $translations[$this->language_id]->meta_title;
$box->meta_description = $translations[$this->language_id]->meta_description;
//Get the routes
$box->route = null;
if ($route = $translations[$this->language_id]->routes->first()) $box->route = $route->route;
return $box;
}
}