aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggWidget.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/classes/ElggWidget.php')
-rw-r--r--engine/classes/ElggWidget.php67
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