aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-19 12:43:51 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-19 12:43:51 +0000
commitb70654070d83323853f808beccc6780cfcd51ce4 (patch)
tree167e1ba85535a50107d85be5ca51689968026e74
parent4533dcf9aeead704f346db038c5b692512aab890 (diff)
downloadelgg-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
-rw-r--r--actions/widgets/add.php3
-rw-r--r--actions/widgets/move.php2
-rw-r--r--engine/classes/ElggWidget.php67
-rw-r--r--engine/lib/widgets.php52
4 files changed, 75 insertions, 49 deletions
diff --git a/actions/widgets/add.php b/actions/widgets/add.php
index 33a818e54..eebbd1438 100644
--- a/actions/widgets/add.php
+++ b/actions/widgets/add.php
@@ -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);
diff --git a/actions/widgets/move.php b/actions/widgets/move.php
index 2747c149f..276dcb55e 100644
--- a/actions/widgets/move.php
+++ b/actions/widgets/move.php
@@ -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);
}
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
diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php
index f75f57141..9c6e68b53 100644
--- a/engine/lib/widgets.php
+++ b/engine/lib/widgets.php
@@ -86,52 +86,6 @@ function elgg_create_widget($owner_guid, $handler, $access_id = null) {
}
/**
- * 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
*
* @param int $user_guid The GUID of the user or 0 for logged in user
@@ -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;
}