/** * Set context widgets * @param array $widgets * @return bool */ public function setWidgets(array $widgets = array()) { foreach ($widgets as $order => $widgetId) { $widget = new WidgetManagerDecorator($widgetId); $widget->update(array('fk_widgetcontext_id' => $this->getId(), 'order' => $order)); } return TRUE; }
/** * Get property value * @param string $name * @param array $arguments * @return mixed */ public function __call($name, $arguments) { $matches = array(); if (!preg_match('/^get([A-Z][a-zA-Z0-9_-]+)$/', $name, $matches)) { return NULL; } // extract name $property = $matches[1]; $property[0] = strtolower($property[0]); // lowercase 1st // get value from db $value = $this->getSetting($property); // get value from property if (empty($value) && property_exists($this, $property)) { $value = $this->{$property}; } // get value from annotation if (empty($value)) { $value = $this->getAnnotation($property); } // get value from ini file if (empty($value)) { $value = $this->manager->getMeta($property); } // return value // TODO set type by property if exists return $value; }
/** * Add widget to user dashboard * @param int $widgetId * @param string|IWidgetContext $contextName * @param int $uid * @param int $order * @return bool */ public static function AddWidget($widgetId, $context, $uid = NULL, $order = NULL) { global $g_ado_db, $g_user; // get context object if (is_string($context)) { $context = new WidgetContext($context); } // set uid if (empty($uid)) { $uid = $g_user->getId(); } if ($order === NULL) { // set order to be on top $sql = 'SELECT MIN(`order`) FROM ' . WidgetManagerDecorator::TABLE . ' WHERE fk_user_id = ' . (int) $uid . ' AND fk_widgetcontext_id = ' . $context->getId(); $order = $g_ado_db->getOne($sql) - 1; } // generate uniq id $id = 'w' . substr(sha1(uniqid() . $g_user->getId()), -12); // add widget $widget = new WidgetManagerDecorator(array('id' => $id, 'fk_widget_id' => (int) $widgetId, 'fk_widgetcontext_id' => $context->getId(), 'fk_user_id' => (int) $uid, 'order' => (int) $order)); $widget->create(); return $id; }