From b70654070d83323853f808beccc6780cfcd51ce4 Mon Sep 17 00:00:00 2001 From: cash Date: Fri, 19 Nov 2010 12:43:51 +0000 Subject: moved some widget functionality into ElggWidget class git-svn-id: http://code.elgg.org/elgg/trunk@7348 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggWidget.php | 67 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'engine/classes/ElggWidget.php') diff --git a/engine/classes/ElggWidget.php b/engine/classes/ElggWidget.php index c9a65967c..21ad8c5dd 100644 --- a/engine/classes/ElggWidget.php +++ b/engine/classes/ElggWidget.php @@ -1,7 +1,7 @@ guid, 'context', $context); + } + + /** + * Get the widget context + * + * @return string + * @since 1.8.0 + */ + public function getContext() { + return get_private_setting($this->guid, 'context'); + } + + /** + * Move the widget + * + * @param int $column The widget column + * @param int $rank Zero-based rank from the top of the column + * @return void + * @since 1.8.0 + */ + public function move($column, $position) { + $options = array( + 'type' => 'object', + 'subtype' => 'widget', + 'private_setting_name_value_pairs' => array( + array('name' => 'context', 'value' => $this->getContext()), + array('name' => 'column', 'value' => $column) + ) + ); + $widgets = elgg_get_entities_from_private_settings($options); + if (!$widgets) { + $this->column = $column; + $this->order = 0; + return; + } + + usort($widgets, create_function('$a,$b','return (int)$a->order > (int)$b->order;')); + + if ($rank == 0) { + // top of the column + $this->order = $widgets[0]->order - 10; + } elseif ($rank == count($widgets)) { + // bottom of the column + $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; + } + } + } + $this->column = $column; + } } \ No newline at end of file -- cgit v1.2.3