Added methods to enable/disable styles
authorAlexander Ebert <ebert@woltlab.com>
Fri, 12 Oct 2012 02:41:59 +0000 (04:41 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 12 Oct 2012 02:41:59 +0000 (04:41 +0200)
wcfsetup/install/files/lib/data/style/StyleAction.class.php

index 48f9d75c27422a9f614f533946aac2ffc0afb62a..90555c5c5e4ecb5b9b1f4c5b773ef441725740b4 100644 (file)
@@ -35,6 +35,11 @@ class StyleAction extends AbstractDatabaseObjectAction {
         */
        protected $permissionsDelete = array('admin.style.canDeleteStyle');
        
+       /**
+        * @see wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate
+        */
+       protected $permissionsUpdate = array('admin.style.canEditStyle');
+       
        /**
         * @see wcf\data\AbstractDatabaseObjectAction::create()
         */
@@ -423,4 +428,27 @@ class StyleAction extends AbstractDatabaseObjectAction {
                        'redirectURL' => LinkHandler::getInstance()->getLink('StyleEdit', array('id' => $newStyle->styleID))
                );
        }
+       
+       /**
+        * Validates parameters to enable/disable styles.
+        */
+       public function validateToggle() {
+               parent::validateUpdate();
+               
+               foreach ($this->objects as $style) {
+                       if ($style->isDefault) {
+                               throw new UserInputException('objectIDs');
+                       } 
+               }
+       }
+       
+       /**
+        * Enables/disables styles.
+        */
+       public function toggle() {
+               foreach ($this->objects as $style) {
+                       $disabled = ($style->disabled) ? 0 : 1;
+                       $style->update(array('disabled' => $disabled));
+               }
+       }
 }