ORIENT/modules/backend/traits/CollapsableWidget.php

54 lines
1.2 KiB
PHP
Raw Normal View History

2014-09-11 03:48:53 +00:00
<?php namespace Backend\Traits;
use Input;
/**
* 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);
}
2016-03-28 13:47:29 +00:00
protected function getGroupStatus($group, $default = true)
2014-09-11 03:48:53 +00:00
{
$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
2016-03-28 13:47:29 +00:00
return $default;
2014-09-11 03:48:53 +00:00
}
2014-10-10 22:07:30 +00:00
}