/**
  * 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;
     }
 }
示例#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);
 }
 /**
  * Set the values from this form to the NodeSettings
  * @param joppa\model\NodeSettings $nodeSettings container to set the values from this form to
  * @return null
  */
 private function getValues(NodeSettings $nodeSettings)
 {
     $published = $this->getValue(self::FIELD_PUBLISHED);
     if ($published == self::INHERIT) {
         $published = null;
     } elseif ($published == self::PUBLISH_YES) {
         $published = 1;
     } else {
         $published = 0;
     }
     $publishStart = $this->getValue(self::FIELD_PUBLISH_START);
     $publishStop = $this->getValue(self::FIELD_PUBLISH_STOP);
     $publishStart = $this->getConfigurationDate($publishStart);
     $publishStop = $this->getConfigurationDate($publishStop);
     $authenticationStatus = $this->getValue(self::FIELD_AUTHENTICATION_STATUS);
     $permissions = $this->getValue(self::FIELD_PERMISSIONS);
     $permissions = $this->getConfigurationPermissions($authenticationStatus, $permissions);
     $nodeSettings->set(NodeSettingModel::SETTING_PUBLISH, $published);
     $nodeSettings->set(NodeSettingModel::SETTING_PUBLISH_START, $publishStart);
     $nodeSettings->set(NodeSettingModel::SETTING_PUBLISH_STOP, $publishStop);
     $nodeSettings->set(NodeSettingModel::SETTING_PERMISSIONS, $permissions);
 }
 /**
  * Get the node settings from this form
  * @param boolean $updateValues set to true to get the submitted node settings, false to get the initial node settings
  * @return joppa\model\NodeSettings
  * @throws zibo\ZiboException when the form is not submitted and $updateValues is set to true
  * @throws zibo\library\validation\exception\ValidationException when the submitted settings are not valid and $updateValues is set to true
  */
 public function getNodeSettings($updateValues = true)
 {
     if (!$updateValues) {
         return $this->nodeSettings;
     }
     if (!$this->isSubmitted()) {
         throw new ZiboException('Form not submitted');
     }
     $settings = @parse_ini_string($this->getValue(self::FIELD_SETTINGS));
     if ($settings === false) {
         $error = error_get_last();
         $error = new ValidationError('error', '%error%', array('error' => $error['message']));
         $exception = new ValidationException();
         $exception->addErrors(self::FIELD_SETTINGS, array($error));
         throw $exception;
     }
     $nodeSettings = new NodeSettings($this->nodeSettings->getNode(), $this->nodeSettings->getInheritedNodeSettings());
     // set the values from the form
     $inheritPrefixLength = strlen(NodeSettings::INHERIT_PREFIX);
     foreach ($settings as $key => $value) {
         $inherit = false;
         if (strlen($key) > $inheritPrefixLength && strncmp($key, NodeSettings::INHERIT_PREFIX, $inheritPrefixLength) == 0) {
             $key = substr($key, $inheritPrefixLength);
             $inherit = true;
         }
         $nodeSettings->set($key, $value, $inherit);
     }
     return $nodeSettings;
 }