File: D:/HostingSpaces/SBogers10/debierbaron.komma.pro/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 box 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($maxItems = null)
{
$boxes = Boxes::where('active', '=', 1)
->with('translations')
->whereHas('translations', function ($query) {
//Todo: taal ophalen
$query->where('language_id', '=', $this->language_id);
})
->orderBy('lft');
if ($maxItems) $boxes->limit($maxItems);
$boxes = $boxes->get();
foreach ($boxes as $key => $box) {
$box[$key] = $this->prepareBox($box);
}
return $boxes;
}
public function getLastBox()
{
if (!$boxes = $this->getBoxes(1)) return null;
if ($boxes->count() == 0) return null;
return $boxes->first();
}
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;
}
}