Ejemplo n.º 1
0
 /**
  * Constructs a new localize view
  * @param $meta
  * @param $id
  * @param $action
  * @param $field
  * @return null
  */
 public function __construct(ModelMeta $meta, $data, $action = null)
 {
     parent::__construct(self::TEMPLATE);
     $localizedModel = $meta->getLocalizedModel();
     $localizedFields = $meta->getLocalizedFields();
     $currentLocale = LocalizeController::getLocale();
     $allLocales = I18n::getInstance()->getAllLocales();
     unset($allLocales[$currentLocale]);
     $locales = array();
     foreach ($allLocales as $locale) {
         $locale = $locale->getCode();
         $localizedId = $localizedModel->getLocalizedId($data->id, $locale);
         if ($localizedId === null) {
             $locales[$locale] = null;
             continue;
         }
         $localesData = clone $data;
         $localizedData = $localizedModel->findById($localizedId);
         foreach ($localizedFields as $fieldName => $localizedField) {
             $localesData->{$fieldName} = $localizedData->{$fieldName};
         }
         $localesData->localizedLabel = $meta->formatData($localesData);
         $locales[$locale] = $localesData;
     }
     $this->set('locales', $locales);
     $this->set('action', $action);
 }
Ejemplo n.º 2
0
 /**
  * Gets the data object from the provided form
  * @param zibo\library\html\form\Form $form
  * @return mixed Data object
  */
 protected function getFormData(Form $form)
 {
     $data = $form->getData();
     if (!$data->id) {
         $data->locale = LocalizeController::getLocale();
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * Constructs a new localize decorator
  * @param zibo\library\orm\model\Model $model Model of the data
  * @param string $action URL where the locale code should point to
  * @return null
  */
 public function __construct(Model $model, $action = null)
 {
     $this->action = $action;
     $this->meta = $model->getMeta();
     $this->localizedModel = $this->meta->getLocalizedModel();
     $this->currentLocale = LocalizeController::getLocale();
     $this->locales = I18n::getInstance()->getLocaleCodeList();
     unset($this->locales[$this->currentLocale]);
 }
Ejemplo n.º 4
0
 /**
  * Constructs a new localize panel form
  * @return null
  */
 public function __construct()
 {
     $request = Zibo::getInstance()->getRequest();
     $factory = FieldFactory::getInstance();
     parent::__construct($request->getBaseUrl() . Request::QUERY_SEPARATOR . Module::ROUTE_LOCALIZE, self::NAME);
     $this->removeFromClass(Form::STYLE_FORM);
     $localeCode = LocalizeController::getLocale();
     $localeField = $factory->createField(FieldFactory::TYPE_LOCALE, self::FIELD_LOCALE, $localeCode);
     $this->addField($localeField);
 }
Ejemplo n.º 5
0
 /**
  * Render this view
  * @param boolean $return Set to false to output the rendered view
  * @return null|string The rendered view if $return is set to true, null otherwise
  */
 public function render($return = true)
 {
     $this->baseUrl = Zibo::getInstance()->getRequest()->getBaseUrl() . '/';
     $this->nodeTypeFacade = NodeTypeFacade::getInstance();
     $this->locale = LocalizeController::getLocale();
     $this->translator = I18n::getInstance()->getTranslator();
     $defaultNodeId = null;
     if ($this->site->defaultNode) {
         $defaultNodeId = $this->site->defaultNode->id;
     }
     $siteModel = ModelManager::getInstance()->getModel(SiteModel::NAME);
     $this->site->node->children = $siteModel->getNodeTreeForSite($this->site, null, null, $this->locale, true);
     $nodeTree = array($this->site->node->id => $this->site->node);
     $output = $this->getNodeTreeHtml($nodeTree, $defaultNodeId, $this->site->localizationMethod == SiteModel::LOCALIZATION_METHOD_COPY, $this->node);
     if ($return) {
         return $output;
     }
     echo $output;
 }
Ejemplo n.º 6
0
 /**
  * Get the node which has an expired route which matches the array routes
  *
  * If recieve the query home/info1/action1/parameter, the routes array should be like:
  * <ul>
  * <li>home/info1/action1/parameter</li>
  * <li>home/info1/action1</li>
  * <li>home/info1</li>
  * <li>home</li>
  * </ul>
  *
  * @param array $routes Array with routes to match.
  * @return Node
  */
 public function getNodeByRoutes(array $routes, $site, $locale = null)
 {
     if (empty($routes) || count($routes) == 1 && empty($routes[0])) {
         return null;
     }
     if ($locale === null) {
         $locale = LocalizeController::getLocale();
     }
     $query = $this->createQuery(0);
     $query->addCondition('{node.parent} = %1% OR {node.parent} LIKE %2%', $site->node, $site->node . NodeModel::PATH_SEPARATOR . '%');
     $condition = '';
     foreach ($routes as $index => $route) {
         $condition .= ($condition ? ' OR ' : '') . '{route} = %' . $index . '%';
     }
     $query->addConditionWithVariables($condition, $routes);
     $query->addOrderBy('{route} DESC');
     $expiredRoutes = $query->query();
     if (!$expiredRoutes) {
         return null;
     }
     $nodeModel = $this->getModel(NodeModel::NAME);
     $route = null;
     foreach ($expiredRoutes as $expiredRoute) {
         if (!$route) {
             $route = $expiredRoute->route;
         } elseif ($expiredRoute->route != $route) {
             break;
         }
         $node = $nodeModel->createData(false);
         $node->id = $expiredRoute->node;
         $node->route = $expiredRoute->route;
         $node->dataLocale = $expiredRoute->locale;
         if ($node->dataLocale === $locale) {
             break;
         }
     }
     return $node;
 }
Ejemplo n.º 7
0
 /**
  * Constructs a new scaffold table
  * @param zibo\library\orm\model\Model $model Model for the data of the table
  * @param string $basePath URL to the base path of the table, this is also the URL where the form of the table will point to
  * @param boolean|array $search False to disable search, True to search all properties or an array with the fields to query
  * @param boolean|array $order False to disable order, True to order all properties or an array with the fields to order
  * @return null
  */
 public function __construct(Model $model, $basePath, $search = true, $order = true)
 {
     $this->basePath = $basePath;
     parent::__construct($model, $this->basePath);
     $this->meta = $model->getMeta();
     if ($this->meta->isLocalized()) {
         $this->query->setLocale(LocalizeController::getLocale());
         $this->query->setWillIncludeUnlocalizedData(ModelQuery::INCLUDE_UNLOCALIZED_FETCH);
         $this->query->setWillAddIsLocalizedOrder(true);
     }
     if ($search) {
         if ($search === true) {
             $search = array();
         }
         $this->setSearchFields($search);
     }
     if ($order) {
         if ($order === true) {
             $order = array();
         }
         $this->setOrderFields($order);
     }
 }
Ejemplo n.º 8
0
 /**
  * Get the dispatcher of a node. This method uses the Joppa cache to store the dispatcher.
  * @param int $id id of the node
  * @param string $baseUrl base url of the site
  * @return mixed null no node found or the node is not available in the frontend;
  *               string class name of the node's frontend controller;
  *               joppa\controller\frontend\NodeDispatcher a node dispatcher
  */
 private function getNodeDispatcher($id, $baseUrl)
 {
     $cache = Module::getCache();
     $locale = LocalizeController::getLocale();
     $cacheKey = md5($baseUrl) . '-' . $id . '-' . $locale;
     $nodeDispatcher = $cache->get(Module::CACHE_TYPE_NODE_DISPATCHER, $cacheKey);
     if ($nodeDispatcher) {
         return $nodeDispatcher;
     }
     $node = $this->request->getNode();
     $frontendController = NodeTypeFacade::getInstance()->getFrontendController($node->type);
     if ($frontendController) {
         $cache->set(Module::CACHE_TYPE_NODE_DISPATCHER, $cacheKey, $frontendController);
         return $frontendController;
     }
     $breadcrumbs = $this->models[NodeModel::NAME]->getBreadcrumbsForNode($node, $baseUrl);
     $rootNode = $node->getRootNode();
     $nodeView = new NodeView($node, $rootNode->name);
     $nodeDispatcher = new NodeDispatcher($node, $nodeView);
     $nodeDispatcher->setBreadcrumbs($breadcrumbs);
     $cache->set(Module::CACHE_TYPE_NODE_DISPATCHER, $cacheKey, $nodeDispatcher);
     return $nodeDispatcher;
 }
Ejemplo n.º 9
0
 /**
  * Get a node by it's id
  * @param int $id id of the node
  * @return joppa\model\Node
  */
 protected function getNode($id, $includeUnlocalized = null)
 {
     $locale = LocalizeController::getLocale();
     return $this->models[NodeModel::NAME]->getNode($id, 1, $locale, $includeUnlocalized);
 }
Ejemplo n.º 10
0
 /**
  * Action to dispatch to the properties of a widget
  * @param string $id id of the widget
  * @return null
  */
 public function propertiesAction($id)
 {
     $widgetSettings = new WidgetSettings($id, $this->node->settings);
     $widget = $this->models['Widget']->getWidget($id);
     $widget->setProperties($widgetSettings);
     $widget->setLocale(LocalizeController::getLocale());
     $baseUrl = $this->request->getBasePath();
     $basePath = $baseUrl . '/properties/' . $id;
     $controller = get_class($widget);
     $action = Widget::METHOD_PROPERTIES;
     $parameters = func_get_args();
     array_shift($parameters);
     $request = new Request($baseUrl, $basePath, $controller, $action, $parameters);
     $widgetDispatcher = new WidgetDispatcher();
     $widgetDispatcher->setWidget($widget);
     if ($widgetDispatcher->dispatch($request, $this->response, false)) {
         $this->models['NodeSetting']->setNodeSettings($widgetSettings);
         $this->clearCache();
     }
     $propertiesView = $this->response->getView();
     $view = new WidgetPropertiesView($this->getSiteSelectForm(), $this->site, $this->node, $widget, $propertiesView);
     $this->response->setView($view);
 }
Ejemplo n.º 11
0
 /**
  * Get the route of this node. The route is used in the frontend as an url alias.
  * @return string
  * @throws zibo\ZiboException when the node has not been saved
  */
 public function getRoute()
 {
     if (!$this->id) {
         throw new ZiboException('This is a new node, a new node does not have a route');
     }
     if ($this->route && $this->dataLocale == LocalizeController::getLocale()) {
         return $this->route;
     }
     return Module::ROUTE_NODE . '/' . $this->id;
 }
Ejemplo n.º 12
0
 /**
  * Get a list of the sites
  * @param string $locale
  * @return array Array with site id as key and the site name as value
  */
 public function getSiteList($locale = null)
 {
     if ($locale === null) {
         $locale = LocalizeController::getLocale();
     }
     $query = $this->createQuery(1, $locale, ModelQuery::INCLUDE_UNLOCALIZED_FETCH);
     $query->setFields('{id}, {node}, {isDefault}');
     $query->addOrderBy('{node.name} ASC');
     $sites = $query->query();
     $list = array();
     foreach ($sites as $site) {
         $list[$site->id] = $site->node->name . ($site->isDefault ? ' «' : '');
     }
     return $list;
 }
Ejemplo n.º 13
0
 /**
  * Get a site by the node's id
  * @param int $id id of the node
  * @param int $recursiveDepth
  * @return joppa\model\Site
  */
 private function getSite($id, $recursiveDepth = 1, $includeUnlocalized = null)
 {
     $locale = LocalizeController::getLocale();
     return $this->models[SiteModel::NAME]->getSite($id, $recursiveDepth, $locale, $includeUnlocalized);
 }
Ejemplo n.º 14
0
 /**
  * Get the nodes with their nested children for a parent node
  * @param Node $parent
  * @param string|array $excludes
  * @param int $maxDepth
  * @param NodeSettingModel $nodeSettingModel pass this model to load the NodeSettings object for the nodes
  * @param boolean $isFrontend Set to true to get only the nodes available in the frontend
  * @return array Array with the node id as key and the Node object with nested children as value
  */
 private function getNodes(Node $parent, $excludes = null, $maxDepth = null, $locale = null, $includeUnlocalized = null, NodeSettingModel $nodeSettingsModel = null, $isFrontend = false)
 {
     if ($locale === null) {
         $locale = LocalizeController::getLocale();
     }
     if ($includeUnlocalized === null) {
         $includeUnlocalized = ModelQuery::INCLUDE_UNLOCALIZED_FETCH;
     }
     $path = $parent->getPath();
     $query = $this->createQuery(0, $locale, $includeUnlocalized);
     $query->addCondition('{parent} = %1% OR {parent} LIKE %2%', $path, $path . self::PATH_SEPARATOR . '%');
     if ($maxDepth !== null) {
         $maxDepth = $parent->getLevel() + $maxDepth;
         $query->addCondition('(LENGTH({parent}) - LENGTH(REPLACE({parent}, %1%, %2%))) <= %3%', self::PATH_SEPARATOR, '', $maxDepth);
     }
     if ($excludes) {
         if (!is_array($excludes)) {
             $excludes = array($excludes);
         }
         $query->addCondition('{id} NOT IN (%1%)', implode(', ', $excludes));
     }
     $query->addOrderBy('{parent} ASC, {orderIndex} ASC');
     $nodes = $query->query();
     if ($isFrontend) {
         $nodeTypeFacade = NodeTypeFacade::getInstance();
     }
     // create an array by path
     $nodesByParent = array();
     foreach ($nodes as $node) {
         if ($isFrontend && !$nodeTypeFacade->isAvailableInFrontend($node->type)) {
             continue;
         }
         if (!array_key_exists($node->parent, $nodesByParent)) {
             $nodesByParent[$node->parent] = array();
         }
         $nodesByParent[$node->parent][$node->id] = $node;
     }
     // link the nested nodes
     $nodes = array();
     foreach ($nodesByParent as $nodePath => $pathNodes) {
         if ($nodePath == $path) {
             $nodes = $pathNodes;
         }
         foreach ($pathNodes as $pathNode) {
             if ($nodeSettingsModel) {
                 $pathNode->settings = $nodeSettingsModel->getNodeSettings($pathNode);
                 $pathNode->settings->isPublished();
             }
             $pathNodePath = $pathNode->getPath();
             if (!array_key_exists($pathNodePath, $nodesByParent)) {
                 continue;
             }
             $pathNode->children = $nodesByParent[$pathNodePath];
         }
     }
     return $nodes;
 }
Ejemplo n.º 15
0
 /**
  * Set the values of a node to the form
  * @param joppa\model\Node $node
  * @return null
  */
 protected function setValues(Node $node)
 {
     $localeSuffix = '.' . LocalizeController::getLocale();
     $this->setValue(self::FIELD_ID, $node->id);
     $this->setValue(self::FIELD_VERSION, $node->version);
     $this->setValue(self::FIELD_NAME, $node->name);
     $this->setValue(self::FIELD_ROUTE, $node->route);
     $this->setValue(self::FIELD_THEME, $node->settings->get(NodeSettingModel::SETTING_THEME, null, false));
     $this->setValue(self::FIELD_META_DESCRIPTION, $node->settings->get(NodeSettingModel::SETTING_META_DESCRIPTION . $localeSuffix, null, false));
     $this->setValue(self::FIELD_META_KEYWORDS, $node->settings->get(NodeSettingModel::SETTING_META_KEYWORDS . $localeSuffix, null, false));
     $this->setValue(self::FIELD_PARENT, $node->parent);
     $availableLocales = $node->settings->get(NodeSettingModel::SETTING_LOCALES, '', false);
     if (!$availableLocales && !$node->settings->getInheritedNodeSettings()) {
         $availableLocales = NodeSettingModel::LOCALES_ALL;
     } elseif ($availableLocales && $availableLocales != NodeSettingModel::LOCALES_ALL) {
         $locales = explode(NodeSettingModel::LOCALES_SEPARATOR, $availableLocales);
         $availableLocales = array();
         foreach ($locales as $locale) {
             $locale = trim($locale);
             $availableLocales[$locale] = $locale;
         }
     }
     $this->setValue(self::FIELD_LOCALES, $availableLocales);
 }
Ejemplo n.º 16
0
 /**
  * Gets the data for the edit action
  * @param integer $id Primary key of the data to retrieve
  * @return mixed Data object for the provided id
  */
 protected function getData($id)
 {
     if (!$this->isLocalized) {
         return $this->model->findById($id, $this->recursiveDepth);
     }
     $locale = LocalizeController::getLocale();
     return $this->model->findById($id, $this->recursiveDepth, $locale, true);
 }
Ejemplo n.º 17
0
 /**
  * Look up the node which matches the query
  * @param string $query
  * @return null|zibo\core\Request Request object to dispatch a node if found, null otherwise
  */
 private function getRequestFromQuery($query)
 {
     try {
         $modelManager = ModelManager::getInstance();
         $nodeModel = $modelManager->getModel(NodeModel::NAME);
         $siteModel = $modelManager->getModel(SiteModel::NAME);
     } catch (OrmException $e) {
         return null;
     }
     $baseUrl = Url::getBaseUrl();
     try {
         $siteUrls = $siteModel->getSiteUrls();
     } catch (DatabaseException $exception) {
         return null;
     }
     if (array_key_exists($baseUrl, $siteUrls)) {
         $site = $siteUrls[$baseUrl];
     } elseif (array_key_exists(0, $siteUrls)) {
         $site = $siteUrls[0];
     } else {
         return null;
     }
     $routes = $this->getRoutesFromQuery($query);
     $node = $nodeModel->getNodeByRoutes($routes, $query, $site);
     if (!$node) {
         return $this->getRequestFromExpiredQuery($routes, $query, $site);
     }
     if ($node->dataLocale) {
         LocalizeController::setLocale($node->dataLocale);
         $i18n = I18n::getInstance();
         $locale = $i18n->getLocale($node->dataLocale);
         $i18n->setCurrentLocale($locale);
     }
     $route = $node->getRoute();
     $parameters = $this->getParametersFromQuery($query, $route);
     array_unshift($parameters, $node->id);
     return new JoppaRequest($baseUrl, $node, self::FRONTEND_CONTROLLER, IndexController::ACTION_NODE, $parameters);
 }
Ejemplo n.º 18
0
 public function indexAction($modelName, $id)
 {
     $logs = $this->models[LogModel::NAME]->getLog($modelName, $id, null, LocalizeController::getLocale());
     $view = new LogDataView($logs);
     $this->response->setView($view);
 }