diff options
Diffstat (limited to 'engine/classes/ElggWidget.php')
| -rw-r--r-- | engine/classes/ElggWidget.php | 79 |
1 files changed, 65 insertions, 14 deletions
diff --git a/engine/classes/ElggWidget.php b/engine/classes/ElggWidget.php index 60f2b6be4..66191bf47 100644 --- a/engine/classes/ElggWidget.php +++ b/engine/classes/ElggWidget.php @@ -7,6 +7,11 @@ * * @package Elgg.Core * @subpackage Widgets + * + * @property-read string $handler internal, do not use + * @property-read string $column internal, do not use + * @property-read string $order internal, do not use + * @property-read string $context internal, do not use */ class ElggWidget extends ElggObject { @@ -30,12 +35,12 @@ class ElggWidget extends ElggObject { */ public function get($name) { // See if its in our base attribute - if (isset($this->attributes[$name])) { + if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } // No, so see if its in the private data store. - $meta = get_private_setting($this->guid, $name); + $meta = $this->getPrivateSetting($name); if ($meta) { return $meta; } @@ -61,7 +66,7 @@ class ElggWidget extends ElggObject { $this->attributes[$name] = $value; } else { - return set_private_setting($this->guid, $name, $value); + return $this->setPrivateSetting($name, $value); } return true; @@ -75,7 +80,7 @@ class ElggWidget extends ElggObject { * @since 1.8.0 */ public function setContext($context) { - return set_private_setting($this->guid, 'context', $context); + return $this->setPrivateSetting('context', $context); } /** @@ -85,7 +90,7 @@ class ElggWidget extends ElggObject { * @since 1.8.0 */ public function getContext() { - return get_private_setting($this->guid, 'context'); + return $this->getPrivateSetting('context'); } /** @@ -115,6 +120,8 @@ class ElggWidget extends ElggObject { $options = array( 'type' => 'object', 'subtype' => 'widget', + 'container_guid' => $this->container_guid, + 'limit' => false, 'private_setting_name_value_pairs' => array( array('name' => 'context', 'value' => $this->getContext()), array('name' => 'column', 'value' => $column) @@ -129,21 +136,65 @@ class ElggWidget extends ElggObject { usort($widgets, create_function('$a,$b','return (int)$a->order > (int)$b->order;')); + // remove widgets from inactive plugins + $widget_types = elgg_get_widget_types($this->context); + $inactive_widgets = array(); + foreach ($widgets as $index => $widget) { + if (!array_key_exists($widget->handler, $widget_types)) { + $inactive_widgets[] = $widget; + unset($widgets[$index]); + } + } + + $bottom_rank = count($widgets); + if ($column == $this->column) { + $bottom_rank--; + } + if ($rank == 0) { // top of the column - $this->order = $widgets[0]->order - 10; - } elseif ($rank == count($widgets)) { - // bottom of the column + $this->order = reset($widgets)->order - 10; + } elseif ($rank == $bottom_rank) { + // bottom of the column of active widgets $this->order = end($widgets)->order + 10; } else { - // reorder widgets that are below - $this->order = $widgets[$rank]->order; - for ($index = $rank; $index < count($widgets); $index++) { - if ($widgets[$index]->guid != $this->guid) { - $widgets[$index]-> order += 10; + // reorder widgets + + // remove the widget that's being moved from the array + foreach ($widgets as $index => $widget) { + if ($widget->guid == $this->guid) { + unset($widgets[$index]); } } + + // split the array in two and recombine with the moved widget in middle + $before = array_slice($widgets, 0, $rank); + array_push($before, $this); + $after = array_slice($widgets, $rank); + $widgets = array_merge($before, $after); + ksort($widgets); + $order = 0; + foreach ($widgets as $widget) { + $widget->order = $order; + $order += 10; + } } + + // put inactive widgets at the bottom + if ($inactive_widgets) { + $bottom = 0; + foreach ($widgets as $widget) { + if ($widget->order > $bottom) { + $bottom = $widget->order; + } + } + $bottom += 10; + foreach ($inactive_widgets as $widget) { + $widget->order = $bottom; + $bottom += 10; + } + } + $this->column = $column; } @@ -191,4 +242,4 @@ class ElggWidget extends ElggObject { return true; } -}
\ No newline at end of file +} |
