*/
protected static $databaseTableIndexName = 'styleID';
+ /**
+ * list of style variables
+ * @var array<string>
+ */
+ protected $variables = array();
+
const PREVIEW_IMAGE_MAX_HEIGHT = 140;
const PREVIEW_IMAGE_MAX_WIDTH = 185;
* @return array<string>
*/
public function getVariables() {
- $variables = array();
+ $this->loadVariables();
+
+ return $this->variables;
+ }
+
+ /**
+ * Returns a specific style variable or null if not found.
+ *
+ * @param string $variableName
+ * @return string
+ */
+ public function getVariable($variableName) {
+ if (isset($this->variables[$variableName])) {
+ return $this->variables[$variableName];
+ }
+
+ return null;
+ }
+
+ /**
+ * Loads style-specific variables.
+ */
+ public function loadVariables() {
+ if (!empty($this->variables)) {
+ return;
+ }
+
$sql = "SELECT variable.variableName, variable.defaultValue, value.variableValue
FROM wcf".WCF_N."_style_variable variable
LEFT JOIN wcf".WCF_N."_style_variable_value value
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->styleID));
while ($row = $statement->fetchArray()) {
- $variables[$row['variableName']] = (isset($row['variableValue'])) ? $row['variableValue'] : $row['defaultValue'];
+ $this->variables[$row['variableName']] = (isset($row['variableValue'])) ? $row['variableValue'] : $row['defaultValue'];
}
-
- return $variables;
}
/**
*/
protected $className = 'wcf\data\style\StyleEditor';
+ /**
+ * @see wcf\data\AbstractDatabaseObjectAction::$permissionsDelete
+ */
+ protected $permissionsDelete = array('admin.style.canDeleteStyle');
+
/**
* @see wcf\data\AbstractDatabaseObjectAction::create()
*/
return array('errorType' => $file->getValidationErrorType());
}
+
+ /**
+ * Validates parameters to assign a new default style.
+ */
+ public function validateSetAsDefault() {
+ if (WCF::getSession()->getPermission('admin.style.canEditStyle')) {
+ throw new PermissionDeniedException();
+ }
+
+ if (empty($this->objects)) {
+ $this->readObjects();
+ if (empty($this->objects)) {
+ throw new UserInputException('objectIDs');
+ }
+ }
+
+ if (count($this->objects) > 1) {
+ throw new UserInputException('objectIDs');
+ }
+ }
+
+ /**
+ * Sets a style as new default style.
+ */
+ public function setAsDefault() {
+ $styleEditor = current($this->objects);
+ $styleEditor->setAsDefault();
+ }
}
$statement->execute();
while ($row = $statement->fetchArray()) {
if ($row['isDefault']) $data['default'] = $row['styleID'];
- $data['styles'][$row['styleID']] = new Style(null, $row);
+ $style = new Style(null, $row);
+ $style->loadVariables();
+
+ $data['styles'][$row['styleID']] = $style;
}
+ // load style-specific variables
+
// get style to packages
$sql = "SELECT *
FROM wcf".WCF_N."_style_to_package