]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
moved some widget functionality into ElggWidget class
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 19 Nov 2010 12:43:51 +0000 (12:43 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 19 Nov 2010 12:43:51 +0000 (12:43 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7348 36083f99-b078-4883-b0ff-0f9b5a30f544

actions/widgets/add.php
actions/widgets/move.php
engine/classes/ElggWidget.php
engine/lib/widgets.php

index 33a818e549a91592c5c802337a1c0db5793d6586..eebbd14386380423b62d95e62b66bee3b96f5aa9 100644 (file)
@@ -18,7 +18,8 @@ if (!empty($user_guid)) {
                $guid = elgg_create_widget($user->getGUID(), $handler);
                if ($guid) {
                        $widget = get_entity($guid);
-                       elgg_move_widget($widget, $context, $column, 0);
+                       $widget->setContext($context);
+                       $widget->move($column, 0);
 
                        // send widget html for insertion
                        echo elgg_view_entity($widget);
index 2747c149fe5c14d6e6c0b27c2a4702290b7734c9..276dcb55ea951f501ac4931792335f68b7c9abd6 100644 (file)
@@ -14,7 +14,7 @@ $user = get_loggedin_user();
 
 $widget = get_entity($guid);
 if ($widget && $user->canEdit()) {
-       elgg_move_widget($widget, $widget->context, $column, $position);
+       $widget->move($column, $position);
        forward(REFERER);
 }
 
index c9a65967c6937243b341b5da242fc50deda6de45..21ad8c5dd44665ce87ca20e756572e7e1439a24d 100644 (file)
@@ -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
index f75f57141013345d269486096899149cfb0965d9..9c6e68b53f643119c68b007b0cb8af355d23d9e3 100644 (file)
@@ -85,52 +85,6 @@ function elgg_create_widget($owner_guid, $handler, $access_id = null) {
        return $widget->getGUID();
 }
 
-/**
- * Move a widget to a location in a widget layout
- *
- * @param ElggWidget $widget The widget to move
- * @param int        $column The widget column
- * @param int        $rank   Zero-based rank from the top of the column
- * @return none
- * @since 1.8.0
- */
-function elgg_move_widget($widget, $context, $column, $rank) {
-       $options = array(
-               'type' => 'object',
-               'subtype' => 'widget',
-               'private_setting_name_value_pairs' => array(
-                       array('name' => 'context', 'value' => $context),
-                       array('name' => 'column', 'value' => $column)
-               )
-       );
-       $widgets = elgg_get_entities_from_private_settings($options);
-       if (!$widgets) {
-               $widget->column = $column;
-               $widget->order = 0;
-               return;
-       }
-
-       usort($widgets, create_function('$a,$b','return (int)$a->order > (int)$b->order;'));
-
-       if ($rank == 0) {
-               // top of the column
-               $widget->order = $widgets[0]->order - 10;
-       } elseif ($rank == count($widgets)) {
-               // bottom of the column
-               $widget->order = end($widgets)->order + 10;
-       } else {
-               // reorder widgets that are below
-               $widget->order = $widgets[$rank]->order;
-               for ($index = $rank; $index < count($widgets); $index++) {
-                       if ($widgets[$index]->guid != $widget->guid) {
-                               $widgets[$index]-> order += 10;
-                       }
-               }
-       }
-       $widget->column = $column;
-       $widget->context = $context;
-}
-
 /**
  * Can the user edit the widgets
  *
@@ -159,8 +113,10 @@ function elgg_can_edit_widgets($user_guid = 0) {
  * @param int        $column The column (1, 2 or 3)
  *
  * @return bool Depending on success
+ * @deprecated 1.8 use ElggWidget::move()
  */
 function save_widget_location(ElggObject $widget, $order, $column) {
+       elgg_deprecated_notice('save_widget_location() is deprecated', 1.8);
        if ($widget instanceof ElggObject) {
                if ($widget->subtype == "widget") {
                        // If you can't move the widget, don't save a new location
@@ -220,8 +176,10 @@ function save_widget_location(ElggObject $widget, $order, $column) {
  * @param int    $column    The column (1 or 2)
  *
  * @return array|false An array of widget ElggObjects, or false
+ * @deprecated 1.8 Use elgg_get_widgets()
  */
 function get_widgets($user_guid, $context, $column) {
+       elgg_deprecated_notice('get_widgets is depecated for elgg_get_widgets', 1.8);
        $params = array(
                'column' => $column,
                'context' => $context
@@ -258,8 +216,10 @@ function get_widgets($user_guid, $context, $column) {
  * @param int    $access_id   If not specified, it is set to the default access level
  *
  * @return int|false Widget GUID or false on failure
+ * @deprecated 1.8 use elgg_create_widget()
  */
 function add_widget($entity_guid, $handler, $context, $order = 0, $column = 1, $access_id = null) {
+       elgg_deprecated_notice('add_widget has been deprecated for elgg_create_widget', 1.8);
        if (empty($entity_guid) || empty($context) || empty($handler) || !widget_type_exists($handler)) {
                return false;
        }