ORIENT/modules/backend/traits/CollapsableWidget.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2014-09-11 03:48:53 +00:00
<?php namespace Backend\Traits;
use Str;
use File;
use Lang;
use Input;
use Block;
2015-01-28 07:03:35 +00:00
use SystemException;
2014-09-11 03:48:53 +00:00
/**
* Collapsable Widget Trait
* Adds collapse/expand item features to back-end widgets
*
* @package october\backend
* @author Alexey Bobkov, Samuel Georges
*/
trait CollapsableWidget
{
protected $groupStatusCache = false;
public function onGroupStatusUpdate()
{
$this->setGroupStatus(Input::get('group'), Input::get('status'));
}
protected function getGroupStatuses()
{
2014-10-10 22:07:30 +00:00
if ($this->groupStatusCache !== false) {
2014-09-11 03:48:53 +00:00
return $this->groupStatusCache;
2014-10-10 22:07:30 +00:00
}
2014-09-11 03:48:53 +00:00
$groups = $this->getSession('groups', []);
2014-10-10 22:07:30 +00:00
if (!is_array($groups)) {
2014-09-11 03:48:53 +00:00
return $this->groupStatusCache = [];
2014-10-10 22:07:30 +00:00
}
2014-09-11 03:48:53 +00:00
return $this->groupStatusCache = $groups;
}
protected function setGroupStatus($group, $status)
{
$statuses = $this->getGroupStatuses();
$statuses[$group] = $status;
$this->groupStatusCache = $statuses;
$this->putSession('groups', $statuses);
}
protected function getGroupStatus($group)
{
$statuses = $this->getGroupStatuses();
2014-10-10 22:07:30 +00:00
if (array_key_exists($group, $statuses)) {
2014-09-11 03:48:53 +00:00
return $statuses[$group];
2014-10-10 22:07:30 +00:00
}
2014-09-11 03:48:53 +00:00
return true;
}
2014-10-10 22:07:30 +00:00
}