/** * Add a new widget to the model * @param string $namespace namespace of the widget * @param string $name name of the widget * @return mixed widget with a new id */ public function addWidget($namespace, $name) { ZiboWidgetModel::getInstance()->getWidget($namespace, $name); $widget = $this->createData(); $widget->namespace = $namespace; $widget->name = $name; $this->save($widget); return $widget; }
/** * Handle region selection and show an overview of the content of the selected region * @return null */ public function indexAction() { $url = $this->request->getBasePath(); $theme = $this->node->getTheme(); if ($theme->hasRegion($this->lastRegion)) { $this->region = $this->lastRegion; } $regionSelectForm = new RegionSelectForm($url, $theme, $this->region); if ($regionSelectForm->isSubmitted()) { $this->region = $regionSelectForm->getRegion(); $this->response->setRedirect($url); return; } $regions = $theme->getRegions(); if (!$this->region && count($regions) == 1) { $region = each($regions); $this->region = $region['key']; $this->response->setRedirect($url); return; } $availableWidgets = WidgetModel::getInstance()->getWidgets(); if ($this->region) { $zibo = Zibo::getInstance(); $regionWidgets = $this->node->getWidgets($this->region); foreach ($regionWidgets as $widgetId => $widget) { $widget->setProperties(new WidgetSettings($widgetId, $this->node->settings)); $widget->setLocale(LocalizeController::getLocale()); $zibo->runEvent(Dispatcher::EVENT_PRE_DISPATCH, $widget, 'propertiesView', array()); } } else { $regionWidgets = array(); } $translator = $this->getTranslator(); $widgetDeleteMessage = $translator->translate(self::TRANSLATION_WIDGET_DELETE_CONFIRM); $view = new NodeContentView($this->getSiteSelectForm(), $regionSelectForm, $this->site, $this->node, $this->region, $availableWidgets, $regionWidgets, $widgetDeleteMessage); $this->response->setView($view); }
private function dispatchColumns(Request $request, Response $response, WidgetDispatcher $dispatcher) { $locale = I18n::getInstance()->getLocale(); $locale = $locale->getCode(); $widgetModel = WidgetModel::getInstance(); $views = array(); foreach ($this->order as $columnNumber => $widgetIds) { $views[$columnNumber] = array(); foreach ($widgetIds as $widgetId) { $widget = $this->getWidget($widgetId); $instance = $widgetModel->getWidget($widget->getNamespace(), $widget->getName()); $instance->setIdentifier($widgetId); $instance->setProperties($widget->getWidgetProperties()); $instance->setLocale($locale); $widget->setTitle($instance->getName()); $widget->setHasProperties($instance->hasProperties()); $dispatcher->setWidget($instance); $dispatcher->dispatch($request, $response); if ($response->willRedirect()) { break 2; } $view = $response->getView(); $response->setView(null); if ($view instanceof FileView) { return $view; } $views[$columnNumber][$widgetId] = $view; } } return $views; }
/** * Action to edit the properties of a widget * @param string $widgetId Id of the widget * @return null */ public function propertiesAction($widgetId) { $locale = I18n::getInstance()->getLocale(); $locale = $locale->getCode(); $widgetModel = WidgetModel::getInstance(); $widget = $this->dashboard->getWidget($widgetId); $instance = $widgetModel->getWidget($widget->getNamespace(), $widget->getName()); $instance->setProperties($widget->getWidgetProperties()); $instance->setLocale($locale); $baseUrl = $this->request->getBasePath(); $basePath = $this->request->getBasePath() . '/properties/' . $widgetId; $controller = get_class($instance); $action = Widget::METHOD_PROPERTIES; $parameters = array_slice(func_get_args(), 2); $request = new Request($baseUrl, $basePath, $controller, $action, $parameters); $widgetDispatcher = new WidgetDispatcher(); $widgetDispatcher->setWidget($instance); $widgetDispatcher->dispatch($request, $this->response, false); if ($this->response->willRedirect()) { $this->response->setView(null); return; } $propertiesView = $this->response->getView(); $view = new WidgetPropertiesView($instance->getName(), $propertiesView); $this->response->setView($view); }
/** * Get the widgets for a region * @param string $region name of the region * @return array Array with zibo\library\widget\controller\Widget objects * @throws zibo\ZiboException when the NodeSettings are not set to this node * @throws zibo\ZiboException when a widget could not be found */ public function getWidgets($region) { $cache = Module::getCache(); $cacheKey = $this->id . '-' . $region; $widgets = $cache->get(Module::CACHE_TYPE_NODE_WIDGETS, $cacheKey); if ($widgets !== null) { return $widgets; } $this->checkSettings(); $widgets = array(); $widgetString = $this->settings->get(NodeSettingModel::SETTING_WIDGETS . '.' . $region); if (!$widgetString) { $cache->set(Module::CACHE_TYPE_NODE_WIDGETS, $cacheKey, $widgets); return $widgets; } $widgetIdModel = ModelManager::getInstance()->getModel(WidgetModel::NAME); $widgetObjectModel = ZiboWidgetModel::getInstance(); $widgetIds = explode(NodeSettingModel::WIDGETS_SEPARATOR, $widgetString); foreach ($widgetIds as $widgetId) { $widgetId = trim($widgetId); $widget = $widgetIdModel->findById($widgetId); if (!$widget) { throw new ZiboException('No widget found for id ' . $widgetId); } $widget = $widgetObjectModel->getWidget($widget->namespace, $widget->name); $widgets[$widgetId] = $widget; } $cache->set(Module::CACHE_TYPE_NODE_WIDGETS, $cacheKey, $widgets); return $widgets; }