diff options
author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-11-19 12:43:51 +0000 |
---|---|---|
committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-11-19 12:43:51 +0000 |
commit | b70654070d83323853f808beccc6780cfcd51ce4 (patch) | |
tree | 167e1ba85535a50107d85be5ca51689968026e74 /engine/classes | |
parent | 4533dcf9aeead704f346db038c5b692512aab890 (diff) | |
download | elgg-b70654070d83323853f808beccc6780cfcd51ce4.tar.gz elgg-b70654070d83323853f808beccc6780cfcd51ce4.tar.bz2 |
moved some widget functionality into ElggWidget class
git-svn-id: http://code.elgg.org/elgg/trunk@7348 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes')
-rw-r--r-- | engine/classes/ElggWidget.php | 67 |
1 files changed, 66 insertions, 1 deletions
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 @@ <?php /** - * Override ElggObject in order to store widget data in ultra-private stores. + * Override ElggObject in order to store widget data in private stores. * * @package Elgg.Core * @subpackage Widgets @@ -77,4 +77,69 @@ class ElggWidget extends ElggObject { return true; } + + /** + * Set the widget context + * + * @param string $context The widget context + * @return bool + * @since 1.8.0 + */ + public function setContext($context) { + return set_private_setting($this->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 |