123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- class ElggWidget extends \ElggObject {
-
- protected function initializeAttributes() {
- parent::initializeAttributes();
- $this->attributes['subtype'] = "widget";
- }
-
- public function __get($name) {
-
- if (array_key_exists($name, $this->attributes)) {
- return $this->attributes[$name];
- }
-
-
- $meta = $this->getPrivateSetting($name);
- if ($meta) {
- return $meta;
- }
-
- return null;
- }
-
- public function get($name) {
- elgg_deprecated_notice("Use -> instead of get()", 1.9);
- return $this->__get($name);
- }
-
- public function __set($name, $value) {
- if (array_key_exists($name, $this->attributes)) {
-
- if ((array_key_exists('guid', $this->attributes)) && ($name == 'guid')) {
- return;
- }
- $this->attributes[$name] = $value;
- } else {
- $this->setPrivateSetting($name, $value);
- }
- }
-
- public function set($name, $value) {
- elgg_deprecated_notice("Use -> instead of set()", 1.9);
- $this->__set($name, $value);
- return true;
- }
-
- public function setContext($context) {
- return $this->setPrivateSetting('context', $context);
- }
-
- public function getContext() {
- return $this->getPrivateSetting('context');
- }
-
- public function getTitle() {
- $title = $this->title;
- if (!$title) {
- $title = _elgg_services()->widgets->getNameByType($this->handler);
- }
- return $title;
- }
-
- public function move($column, $rank) {
- $options = array(
- 'type' => 'object',
- 'subtype' => 'widget',
- 'container_guid' => $this->container_guid,
- 'limit' => false,
- '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 = (int)$column;
- $this->order = 0;
- return;
- }
- usort($widgets, create_function('$a,$b','return (int)$a->order > (int)$b->order;'));
-
- $widget_types = elgg_get_widget_types($this->context);
- $inactive_widgets = array();
- foreach ($widgets as $index => $widget) {
- if (!array_key_exists($widget->handler, $widget_types)) {
- $inactive_widgets[] = $widget;
- unset($widgets[$index]);
- }
- }
- $bottom_rank = count($widgets);
- if ($column == $this->column) {
- $bottom_rank--;
- }
-
- if ($rank == 0) {
-
- $this->order = reset($widgets)->order - 10;
- } elseif ($rank == $bottom_rank) {
-
- $this->order = end($widgets)->order + 10;
- } else {
-
-
- foreach ($widgets as $index => $widget) {
- if ($widget->guid == $this->guid) {
- unset($widgets[$index]);
- }
- }
-
- $before = array_slice($widgets, 0, $rank);
- array_push($before, $this);
- $after = array_slice($widgets, $rank);
- $widgets = array_merge($before, $after);
- ksort($widgets);
- $order = 0;
- foreach ($widgets as $widget) {
- $widget->order = $order;
- $order += 10;
- }
- }
-
- if ($inactive_widgets) {
- $bottom = 0;
- foreach ($widgets as $widget) {
- if ($widget->order > $bottom) {
- $bottom = $widget->order;
- }
- }
- $bottom += 10;
- foreach ($inactive_widgets as $widget) {
- $widget->order = $bottom;
- $bottom += 10;
- }
- }
- $this->column = $column;
- }
-
- public function saveSettings($params) {
- if (!$this->canEdit()) {
- return false;
- }
-
-
- $hook_params = array(
- 'widget' => $this,
- 'params' => $params
- );
- if (_elgg_services()->hooks->trigger('widget_settings', $this->handler, $hook_params, false) == true) {
- return true;
- }
- if (is_array($params) && count($params) > 0) {
- foreach ($params as $name => $value) {
- if (is_array($value)) {
-
- return false;
- } else {
- $this->$name = $value;
- }
- }
- $this->save();
- }
- return true;
- }
- }
|