sko6
<?php namespace Author\Plugin\Components;
use Cms\Classes\ComponentBase;
use Author\Plugin\Models\Item;
class Catalog extends ComponentBase
{
public function componentDetails()
{
return [
'name' => 'Projects Component',
'description' => 'No description provided yet...'
];
}
public function defineProperties()
{
return [
'items' => [
'title' => 'Количество',
'description' => 'Количество элементов на одной странице',
'default' => '10',
'validationPattern' => '^[0-9]+$',
'validationMessage' => 'Only numbers allowed'
],
'sortOrder' => [
'title' => 'Сортировка',
'description' => 'Сортировать по',
'type' => 'dropdown',
'default' => 'name desc'
]
];
}
public function getSortOrderOptions(){
return [
'name asc' => 'name (ASC)',
'name desc' => 'name (DESC)'
];
}
protected function loadItems(){
if($this->property('sortOrder') == 'name asc'){
$query = Item::orderBy('name','asc')->get();
}
if($this->property('sortOrder') == 'name desc'){
$query = Item::orderBy('name','desc')->get();
}
return $query;
}
public function onRun(){
$this->page['items'] = $this->loadItems;
//$this->page['items'] = \Author\Plugin\Models\Item::paginate($this->property('items'));
$this->page['categories'] = \Author\Plugin\Models\Category::get();
//dd($this->property('sortOrder'));
}
}