/** * 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; }
/** * Get a html representation of a NodeSettings object * @param joppa\model\NodeSettings $nodesettings * @return string html representation of the NodeSettings object */ private function getHtmlFromNodeSettings(NodeSettings $nodeSettings) { $inheritedSettings = $nodeSettings->getInheritedNodeSettings(); if ($inheritedSettings) { $arrayInheritedSettings = $inheritedSettings->getArray(true, true); } else { $arrayInheritedSettings = array(); } $arraySettings = $nodeSettings->getArray(); $settings = Structure::merge($arrayInheritedSettings, $arraySettings); ksort($settings); $html = ''; foreach ($settings as $key => $setting) { $value = $setting->getIniString(true); if ($setting->inherit) { $value = substr($value, 1); } if (isset($arraySettings[$key])) { $html .= '<strong>' . $value . '</strong>'; } else { $html .= $value; } $html .= "<br />\n"; } return $html; }
/** * Gets the parent node of this node * @return Node * @throws zibo\ZiboException when the NodeSettings are not set to this node */ public function getParentNode() { $this->checkSettings(); $inheritedNodeSettings = $this->settings->getInheritedNodeSettings(); if (!$inheritedNodeSettings) { return null; } return $inheritedNodeSettings->getNode(); }
/** * Get the authentication options * @param zibo\library\i18n\translation\Translator $translator * @return array Array with the authentication status as key and the translation as value */ private function getAuthenticationStatusOptions(Translator $translator) { $options = array(); $inheritedNodeSettings = $this->nodeSettings->getInheritedNodeSettings(); if ($inheritedNodeSettings) { $options[self::INHERIT] = $translator->translate(self::TRANSLATION_INHERIT) . $this->getPermissionInheritSuffix($inheritedNodeSettings, $translator); } $options[NodeSettingModel::AUTHENTICATION_STATUS_EVERYBODY] = $translator->translate(self::TRANSLATION_EVERYBODY); $options[NodeSettingModel::AUTHENTICATION_STATUS_ANONYMOUS] = $translator->translate(self::TRANSLATION_ANONYMOUS); $options[NodeSettingModel::AUTHENTICATION_STATUS_AUTHENTICATED] = $translator->translate(self::TRANSLATION_AUTHENTICATED); return $options; }
/** * Get the value for the authentication status field from the permission configuration value * @param string $permissions permission configuration value * @param joppa\model\NodeSettings $nodeSettings the NodeSettings where the permission configuration value came from * @return string value for the authentication status field */ private function getFormAuthenticationStatus($permissions, NodeSettings $nodeSettings) { if ($permissions == null) { if (!$nodeSettings->getInheritedNodeSettings()) { return NodeSettingModel::AUTHENTICATION_STATUS_EVERYBODY; } else { return self::INHERIT; } } if ($permissions == NodeSettingModel::AUTHENTICATION_STATUS_EVERYBODY || $permissions == NodeSettingModel::AUTHENTICATION_STATUS_ANONYMOUS) { return $permissions; } return NodeSettingModel::AUTHENTICATION_STATUS_AUTHENTICATED; }