/**
  * Validate the Joppa node configuration values
  * @param NodeSettings $nodeSettings
  * @return null
  * @throws zibo\library\validation\exception\ValidationException when a Joppa configuration setting in not validated
  */
 public function validateNodeSettings(NodeSettings $nodeSettings)
 {
     $validationException = new ValidationException();
     $publishStart = $nodeSettings->get(NodeSettingModel::SETTING_PUBLISH_START, null, false);
     $publishStop = $nodeSettings->get(NodeSettingModel::SETTING_PUBLISH_STOP, null, false);
     $isPublishStartEmpty = empty($publishStart);
     $isPublishStopEmpty = empty($publishStop);
     if (!$isPublishStartEmpty) {
         if ($date = $this->validateDate($publishStart, $validationException, NodeSettingModel::SETTING_PUBLISH_START)) {
             $nodeSettings->set(NodeSettingModel::SETTING_PUBLISH_START, $date);
         }
     }
     if (!$isPublishStopEmpty) {
         if ($date = $this->validateDate($publishStop, $validationException, NodeSettingModel::SETTING_PUBLISH_STOP)) {
             $nodeSettings->set(NodeSettingModel::SETTING_PUBLISH_STOP, $date);
         }
     }
     if (!$isPublishStartEmpty && !$isPublishStopEmpty && $publishStart >= $publishStop) {
         $error = new ValidationError('joppa.error.date.publish.negative', 'Publish stop date cannot be smaller or equal to publish start date');
         $validationException->addErrors(NodeSettingModel::SETTING_PUBLISH_STOP, array($error));
     }
     $permissions = $nodeSettings->get(NodeSettingModel::SETTING_PERMISSIONS, null, false);
     if ($permissions) {
         if ($permissions = $this->validatePermissions($permissions, $validationException)) {
             $nodeSettings->set(NodeSettingModel::SETTING_PERMISSIONS, $permissions);
         }
     }
     if ($validationException->hasErrors()) {
         throw $validationException;
     }
 }
Exemplo n.º 2
0
 /**
  * Order the widgets of a region
  * @param string $region name of the region
  * @param string|array $widgets array with widget ids or a string with widget ids separated by a comma.
  * @return null
  * @throws zibo\ZiboException when the $widgets variable does not contain the same widgets as the current widgets
  * @throws zibo\ZiboException when the NodeSettings are not set to this node
  */
 public function orderWidgets($region, $widgets)
 {
     $this->checkSettings();
     if (!is_array($widgets)) {
         $widgets = explode(',', $widgets);
     }
     $widgetsKey = NodeSettingModel::SETTING_WIDGETS . '.' . $region;
     $currentWidgets = explode(NodeSettingModel::WIDGETS_SEPARATOR, $this->settings->get($widgetsKey, '', false));
     $widgetsValue = '';
     foreach ($widgets as $widgetId) {
         $widgetId = trim($widgetId);
         $key = array_search($widgetId, $currentWidgets);
         if ($key === false) {
             throw new ZiboException('Widget ' . $widgetId . ' is not currently set to region ' . $region);
         }
         $widgetsValue .= ($widgetsValue ? NodeSettingModel::WIDGETS_SEPARATOR : '') . $widgetId;
         unset($currentWidgets[$key]);
     }
     $numCurrentWidgets = count($currentWidgets);
     if ($numCurrentWidgets) {
         if ($numCurrentWidgets > 1) {
             throw new ZiboException('Widgets ' . implode(NodeSettingModel::WIDGETS_SEPARATOR, $currentWidgets) . ' are not found in the new widget order');
         }
         $widget = array_pop($currentWidgets);
         throw new ZiboException('Widget ' . $widget . ' is not found in the new widget order');
     }
     $this->settings->set($widgetsKey, $widgetsValue);
 }
Exemplo n.º 3
0
 /**
  * Get a value for a setting key
  * @param string $key key of the setting
  * @param mixed $default default value for when the setting is not set
  * @param boolean $inherited true to look in inherited settings, false to only look in this container
  * @param boolean $inheritedSettingRequired true to only return the value if the setting will inherit, needed internally for recursive lookup
  * @return mixed the value of the settings key if found, the provided default value otherwise
  * @throws zibo\ZiboException when an invalid key is provided
  */
 public function get($key, $default = null, $inherited = true, $inheritedSettingRequired = false)
 {
     $this->checkKey($key);
     if (array_key_exists($key, $this->settings) && (!$inheritedSettingRequired || $inheritedSettingRequired && $this->settings[$key]->inherit)) {
         return $this->settings[$key]->value;
     }
     if ($inherited && $this->inheritedSettings) {
         return $this->inheritedSettings->get($key, $default, true, true);
     }
     return $default;
 }
 /**
  * Get a suffix for the permission inherit label based on the inherited settings
  * @param joppa\model\NodeSettings $nodeSettings
  * @param zibo\library\i18n\translation\Translator $translator
  * @return string if a permission setting is found the suffix will be " ($securityLevel)"
  */
 private function getPermissionInheritSuffix(NodeSettings $nodeSettings, Translator $translator)
 {
     $permission = $nodeSettings->get(NodeSettingModel::SETTING_PERMISSIONS, NodeSettingModel::AUTHENTICATION_STATUS_EVERYBODY, true, true);
     if ($permission == null) {
         return '';
     }
     $suffix = ' (';
     if ($permission == NodeSettingModel::AUTHENTICATION_STATUS_ANONYMOUS) {
         $suffix .= $translator->translate(self::TRANSLATION_ANONYMOUS);
     } elseif ($permission == NodeSettingModel::AUTHENTICATION_STATUS_AUTHENTICATED) {
         $suffix .= $translator->translate(self::TRANSLATION_AUTHENTICATED);
     } elseif ($permission == NodeSettingModel::AUTHENTICATION_STATUS_EVERYBODY) {
         $suffix .= $translator->translate(self::TRANSLATION_EVERYBODY);
     } else {
         $suffix .= $permission;
     }
     $suffix .= ')';
     return $suffix;
 }
Exemplo n.º 5
0
 /**
  * Get a suffix for the theme inherit label based on the inherited settings
  * @param joppa\model\NodeSettings $nodeSettings
  * @return string if a theme is found the suffix will be " ($theme)"
  */
 private function getLocalesInheritSuffix(NodeSettings $nodeSettings)
 {
     $locales = $nodeSettings->get(NodeSettingModel::SETTING_LOCALES, null, true, true);
     if ($locales !== null) {
         return ' (' . $locales . ')';
     }
     return null;
 }