Updated clipboard API to properly handle show order
authorAlexander Ebert <ebert@woltlab.com>
Fri, 3 May 2013 23:33:47 +0000 (01:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 3 May 2013 23:33:47 +0000 (01:33 +0200)
wcfsetup/install/files/lib/action/ClipboardAction.class.php
wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php
wcfsetup/install/files/lib/system/clipboard/action/AbstractClipboardAction.class.php
wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php
wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php

index 328c345cb997becd17ae9e3c6dc058fd33044f7a..d8dd4eb89fa674742b4e7e6c5aabbd4c2f61e349 100644 (file)
@@ -125,8 +125,8 @@ class ClipboardAction extends AJAXInvokeAction {
                                'items' => array()
                        );
                        
-                       foreach ($itemData['items'] as $item) {
-                               $items['items'][] = array(
+                       foreach ($itemData['items'] as $showOrder => $item) {
+                               $items['items'][$showOrder] = array(
                                        'actionName' => $item->getName(),
                                        'internalData' => $item->getInternalData(),
                                        'parameters' => $item->getParameters(),
index 18b38bb7c00b040d70e9f68236d2e9a32fa04470..9a9c6415c9c71472a75ab8bd9a9a06a11a5d55ee 100644 (file)
@@ -306,8 +306,8 @@ class ClipboardHandler extends SingletonFactory {
                // load actions
                $actions = array();
                foreach ($actionIDs as $actionID) {
-                       $actionClassName = $this->actionCache[$actionID]->actionClassName;
-                       $actionName = $this->actionCache[$actionID]->actionName;
+                       $actionObject = $this->actionCache[$actionID];
+                       $actionClassName = $actionObject->actionClassName;
                        if (!isset($actions[$actionClassName])) {
                                // validate class
                                if (!ClassUtil::isInstanceOf($actionClassName, 'wcf\system\clipboard\action\IClipboardAction')) {
@@ -320,7 +320,7 @@ class ClipboardHandler extends SingletonFactory {
                                );
                        }
                        
-                       $actions[$actionClassName]['actions'][] = $actionName;
+                       $actions[$actionClassName]['actions'][] = $actionObject;
                }
                
                // execute actions
@@ -346,13 +346,13 @@ class ClipboardHandler extends SingletonFactory {
                                );
                        }
                        
-                       foreach ($actionData['actions'] as $action) {
-                               $data = $actionData['object']->execute($objects, $action);
+                       foreach ($actionData['actions'] as $actionObject) {
+                               $data = $actionData['object']->execute($objects, $actionObject);
                                if ($data === null) {
                                        continue;
                                }
                                
-                               $editorData[$typeName]['items'][$action] = $data;
+                               $editorData[$typeName]['items'][$actionObject->showOrder] = $data;
                        }
                }
                
index ab8765f0d4aadde30ea134b544f776ad756e0bf4..d7eaa84c22642a56c22e232f23b2e5f7dd93318f 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\clipboard\action;
+use wcf\data\clipboard\action\ClipboardAction;
 use wcf\system\clipboard\ClipboardEditorItem;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
@@ -8,7 +9,7 @@ use wcf\system\WCF;
  * Abstract implementation of a clipboard action handler.
  * 
  * @author     Matthias Schmidt
- * @copyright  2001-2012 WoltLab GmbH
+ * @copyright  2001-2013 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.clipboard.action
@@ -36,24 +37,24 @@ abstract class AbstractClipboardAction implements IClipboardAction {
        /**
         * @see wcf\system\clipboard\action\IClipboardAction::execute()
         */
-       public function execute(array $objects, $actionName) {
-               if (!in_array($actionName, $this->supportedActions)) {
-                       throw new SystemException("Unknown clipboard action '".$actionName."'");
+       public function execute(array $objects, ClipboardAction $action) {
+               if (!in_array($action->actionName, $this->supportedActions)) {
+                       throw new SystemException("Unknown clipboard action '".$action->actionName."'");
                }
                
                $this->objects = $objects;
                
                $item = new ClipboardEditorItem();
-               $item->setName($this->getTypeName().'.'.$actionName);
+               $item->setName($this->getTypeName().'.'.$action->actionName);
                
                // set action class-related data
-               if (in_array($actionName, $this->actionClassActions)) {
-                       $item->addParameter('actionName', $actionName);
+               if (in_array($action->actionName, $this->actionClassActions)) {
+                       $item->addParameter('actionName', $action->actionName);
                        $item->addParameter('className', $this->getClassName());
                }
                
                // validate objects if relevant method exists and set valid object ids
-               $methodName = 'validate'.ucfirst($actionName);
+               $methodName = 'validate'.ucfirst($action->actionName);
                if (method_exists($this, $methodName)) {
                        $objectIDs = $this->$methodName();
                        if (empty($objectIDs)) {
index a431b1029681d5c7fc7dd7db2b9855ed6fff38c1..d6e52c826da2229c0eedb69cfe7c078c501f2454 100644 (file)
@@ -1,11 +1,12 @@
 <?php
 namespace wcf\system\clipboard\action;
+use wcf\data\clipboard\action\ClipboardAction;
 
 /**
  * Basic interface for all clipboard editor actions.
  * 
  * @author     Alexander Ebert
- * @copyright  2001-2012 WoltLab GmbH
+ * @copyright  2001-2013 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.clipboard.action
@@ -23,11 +24,11 @@ interface IClipboardAction {
         * Returns editor item for the clipboard action with the given name or null
         * if the action is not applicable to the given objects.
         * 
-        * @param       array           $objects
-        * @param       string          $actionName
+        * @param       array<wcf\data\DatabaseObject>                  $objects
+        * @param       wcf\data\clipboard\action\ClipboardAction       $action
         * @return      wcf\system\clipboard\ClipboardEditorItem
         */
-       public function execute(array $objects, $actionName);
+       public function execute(array $objects, ClipboardAction $action);
        
        /**
         * Filters the given objects by the given type data and returns the filtered
index e3acc404441e10a0d73c7ca67c84a2660e537cf6..61e0f3532f710f46dfe02e53a57e8fd20614553e 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\clipboard\action;
+use wcf\data\clipboard\action\ClipboardAction;
 use wcf\data\user\group\UserGroup;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\request\LinkHandler;
@@ -9,7 +10,7 @@ use wcf\system\WCF;
  * Prepares clipboard editor items for user objects.
  * 
  * @author     Alexander Ebert
- * @copyright  2001-2012 WoltLab GmbH
+ * @copyright  2001-2013 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.clipboard.action
@@ -29,15 +30,15 @@ class UserClipboardAction extends AbstractClipboardAction {
        /**
         * @see wcf\system\clipboard\action\IClipboardAction::execute()
         */
-       public function execute(array $objects, $actionName) {
-               $item = parent::execute($objects, $actionName);
+       public function execute(array $objects, ClipboardAction $action) {
+               $item = parent::execute($objects, $action);
                
                if ($item === null) {
                        return null;
                }
                
                // handle actions
-               switch ($actionName) {
+               switch ($action->actionName) {
                        case 'assignToGroup':
                                $item->setURL(LinkHandler::getInstance()->getLink('UserAssignToGroup'));
                        break;