Skip to content

Commit

Permalink
Updating modules/backend/traits
Browse files Browse the repository at this point in the history
  • Loading branch information
stefantalen committed Oct 10, 2014
1 parent 75510ed commit aa68d16
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
11 changes: 7 additions & 4 deletions modules/backend/traits/CollapsableWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ public function onGroupStatusUpdate()

protected function getGroupStatuses()
{
if ($this->groupStatusCache !== false)
if ($this->groupStatusCache !== false) {
return $this->groupStatusCache;
}

$groups = $this->getSession('groups', []);
if (!is_array($groups))
if (!is_array($groups)) {
return $this->groupStatusCache = [];
}

return $this->groupStatusCache = $groups;
}
Expand All @@ -47,9 +49,10 @@ protected function setGroupStatus($group, $status)
protected function getGroupStatus($group)
{
$statuses = $this->getGroupStatuses();
if (array_key_exists($group, $statuses))
if (array_key_exists($group, $statuses)) {
return $statuses[$group];
}

return true;
}
}
}
16 changes: 10 additions & 6 deletions modules/backend/traits/InspectableContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,28 @@ trait InspectableContainer
public function onInspectableGetOptions()
{
$property = trim(Request::input('inspectorProperty'));
if (!$property)
if (!$property) {
throw new ApplicationException('The property name is not specified.');
}

$className = trim(Request::input('inspectorClassName'));
if (!$className)
if (!$className) {
throw new ApplicationException('The inspectable class name is not specified.');
}

$traitFound = in_array('System\Traits\PropertyContainer', class_uses_recursive($className));
if (!$traitFound)
if (!$traitFound) {
throw new ApplicationException('The options cannot be loaded for the specified class.');
}

$obj = new $className(null);

$methodName = 'get'.ucfirst($property).'Options';
if (method_exists($obj, $methodName))
if (method_exists($obj, $methodName)) {
$options = $obj->$methodName();
else
} else {
$options = $obj->getPropertyOptions($property);
}

/*
* Convert to array to retain the sort order in JavaScript
Expand All @@ -48,4 +52,4 @@ public function onInspectableGetOptions()
'options' => $optionsArray
];
}
}
}
8 changes: 5 additions & 3 deletions modules/backend/traits/SearchableWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ protected function textMatchesSearch(&$words, $text)
{
foreach ($words as $word) {
$word = trim($word);
if (!strlen($word))
if (!strlen($word)) {
continue;
}

if (Str::contains(Str::lower($text), $word))
if (Str::contains(Str::lower($text), $word)) {
return true;
}
}

return false;
}
}
}
11 changes: 7 additions & 4 deletions modules/backend/traits/SelectableWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public function onSelect()

protected function getSelectedItems()
{
if ($this->selectedItemsCache !== false)
if ($this->selectedItemsCache !== false) {
return $this->selectedItemsCache;
}

$items = $this->getSession('selected', []);
if (!is_array($items))
if (!is_array($items)) {
return $this->selectedItemsCache = [];
}

return $this->selectedItemsCache = $items;
}
Expand All @@ -54,9 +56,10 @@ protected function resetSelection()
protected function isItemSelected($itemId)
{
$selectedItems = $this->getSelectedItems();
if (!is_array($selectedItems) || !isset($selectedItems[$itemId]))
if (!is_array($selectedItems) || !isset($selectedItems[$itemId])) {
return false;
}

return $selectedItems[$itemId];
}
}
}
2 changes: 1 addition & 1 deletion modules/backend/traits/WidgetMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public function makeWidget($class, $configuration = null)
$widget = $manager->makeWidget($class, $controller, $configuration);
return $widget;
}
}
}

0 comments on commit aa68d16

Please sign in to comment.