File: D:/HostingSpaces/PDeckers/opelkapitan.nl/app/Komma/Blocks/BlockService.php
<?php
namespace Komma\Blocks;
use Illuminate\Support\Collection;
use Komma\Blocks\Models\Block;
use Komma\Images\ImageService;
/**
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
class BlockService
{
private $imageService;
/**
* Inject the dependencies.
* Ex. the imageService.
*
* BlockService constructor.
* @param ImageService $imageService
*/
public function __construct(ImageService $imageService)
{
$this->imageService = $imageService;
}
/**
* This method gets the blocks with an IN
*
* @param $field | string, field for the in
* @param $values | array, values for the in
* @return mixed
*/
public function getBlocksIn($field, $values)
{
//Only get the active blocks
$blocks = Block::where('active', '=', 1)
//Where in with field and values
->whereIn($field, $values)
//Also load the translation
->with('translation')
->with('images')
->get()
->keyBy($field);
return $blocks;
}
/**
* This method gets the blocks where
*
* @param $field | string, field for the where
* @param $values | array, value for the where
* @return mixed
*/
public function getBlocksWhere($field, $values)
{
//Only get the active blocks
$blocks = Block::where('active', '=', 1)
//Where field is value
->where($field, '=', $values)
//Also load the translation
->with('translation')
->with('images')
->get();
return $blocks;
}
/**
* This method invokes the getBlocksIn
* With code_name as field
*
* @param $code_names
* @return mixed
*/
public function getBlocksByCodeName($code_names)
{
return $this->getBlocksIn('code_name', $code_names);
}
/**
* This method invokes the getBlocksIn
* With id as field
*
* @param $ids
* @return mixed
*/
public function getBlocksById($ids)
{
return $this->getBlocksIn('id', $ids);
}
}