Create withComponent() filter for CmsObjects

This commit is contained in:
Samuel Georges 2015-04-04 10:34:25 +11:00
parent 67ba31b946
commit 9d4bc8eee6
2 changed files with 33 additions and 1 deletions

View File

@ -1,7 +1,7 @@
<?php namespace Cms\Classes;
use Illuminate\Support\Collection as CollectionBase;
use ApplicationException;
use Illuminate\Support\Collection as CollectionBase;
/**
* This class represents a collection of Cms Objects.
@ -11,4 +11,24 @@ use ApplicationException;
*/
class CmsObjectCollection extends CollectionBase
{
/**
* Returns objects that use the supplied component.
* @param string|array $components
* @return static
*/
public function withComponent($components)
{
return $this->filter(function($object) use ($components) {
$hasComponent = false;
foreach ((array) $components as $component) {
if ($object->hasComponent($component)) {
$hasComponent = true;
}
}
return $hasComponent;
});
}
}

View File

@ -5,6 +5,18 @@ use ApplicationException;
/**
* This class provides helper methods to make the CmsObject behave like a Model
*
* Some examples:
*
* Page::find('blog/post');
*
* Page::all();
*
* Page::inEditTheme()->useCache()->all();
*
* Page::withComponent('blogPost')
* ->sortBy('baseFileName')
* ->lists('baseFileName', 'baseFileName');
*
* @package october\cms
* @author Alexey Bobkov, Samuel Georges
*/