Adds default implementation AbstractClipboardAction::execute()
authorMatthias Schmidt <gravatronics@live.com>
Wed, 9 Jan 2013 10:31:05 +0000 (11:31 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 9 Jan 2013 10:31:05 +0000 (11:31 +0100)
wcfsetup/install/files/lib/system/clipboard/action/AbstractClipboardAction.class.php
wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 1a2725d927188f6140e697850c7a3b298b9b18fe..85b35bcf0fc940ae8ee24a1dddf0117a7d097a94 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\system\clipboard\action;
+use wcf\system\clipboard\ClipboardEditorItem;
+use wcf\system\exception\SystemException;
 
 /**
  * Abstract implementation of a clipboard action handler.
@@ -12,6 +14,54 @@ namespace wcf\system\clipboard\action;
  * @category   Community Framework
  */
 abstract class AbstractClipboardAction implements IClipboardAction {
+       /**
+        * list of the clipboard actions which are executed by the action class
+        * @var array<string>
+        */
+       protected $actionClassActions = array();
+       
+       /**
+        * relevant database objects
+        * @var array<wcf\data\DatabaseObject>
+        */
+       protected $objects = array();
+       
+       /**
+        * list of the supported clipboard actions
+        * @var array<string>
+        */
+       protected $supportedActions = array();
+       
+       /**
+        * @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."'");
+               }
+               
+               $this->objects = $objects;
+               
+               $item = new ClipboardEditorItem();
+               $item->setName($this->getTypeName().'.'.$actionName);
+               if (in_array($actionName, $this->actionClassActions)) {
+                       $item->addParameter('actionName', $actionName);
+                       $item->addParameter('className', $this->getClassName());
+               }
+               
+               $methodName = 'validate'.ucfirst($actionName);
+               if (method_exists($this, $methodName)) {
+                       $objectIDs = $this->$methodName();
+                       if (empty($objectIDs)) {
+                               return null;
+                       }
+                       
+                       $item->addParameter('objectIDs', $objectIDs);
+               }
+               
+               return $item;
+       }
+       
        /**
         * @see wcf\system\clipboard\action\IClipboardAction::filterObjects()
         */
index c1636a7f4425d7d20b34e52c742759f633fc6860..36f19ac564dcfd3a591b6566fa3b24b15b6d161d 100644 (file)
@@ -1,9 +1,7 @@
 <?php
 namespace wcf\system\clipboard\action;
 use wcf\data\user\group\UserGroup;
-use wcf\system\clipboard\ClipboardEditorItem;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\exception\SystemException;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
 
@@ -19,51 +17,44 @@ use wcf\system\WCF;
  */
 class UserClipboardAction extends AbstractClipboardAction {
        /**
-        * @see wcf\system\clipboard\action\IClipboardAction::getTypeName()
+        * @see wcf\system\clipboard\action\AbstractClipboardAction::$actionClassActions
         */
-       public function getTypeName() {
-               return 'com.woltlab.wcf.user';
-       }
+       protected $actionClassActions = array('delete');
+       
+       /**
+        * @see wcf\system\clipboard\action\AbstractClipboardAction::$supportedActions
+        */
+       protected $supportedActions = array('assignToGroup', 'delete', 'exportMailAddress', 'sendMail');
        
        /**
         * @see wcf\system\clipboard\action\IClipboardAction::execute()
         */
        public function execute(array $objects, $actionName) {
-               $item = new ClipboardEditorItem();
+               $item = parent::execute($objects, $actionName);
+               
+               if ($item === null) {
+                       return null;
+               }
                
                // handle actions
                switch ($actionName) {
                        case 'assignToGroup':
-                               $item->setName('user.assignToGroup');
                                $item->setURL(LinkHandler::getInstance()->getLink('UserAssignToGroup'));
                        break;
                        
                        case 'delete':
-                               $userIDs = $this->validateDelete($objects);
-                               if (empty($userIDs)) {
-                                       return null;
-                               }
-                               
-                               $item->addInternalData('confirmMessage', WCF::getLanguage()->getDynamicVariable('wcf.clipboard.item.user.delete.confirmMessage', array('count' => count($userIDs))));
-                               $item->addParameter('actionName', 'delete');
-                               $item->addParameter('className', 'wcf\data\user\UserAction');
-                               $item->addParameter('objectIDs', $userIDs);
-                               $item->setName('user.delete');
+                               $item->addInternalData('confirmMessage', WCF::getLanguage()->getDynamicVariable('wcf.clipboard.item.com.woltlab.wcf.user.delete.confirmMessage', array(
+                                       'count' => $item->getCount()
+                               )));
                        break;
                        
                        case 'exportMailAddress':
-                               $item->setName('user.exportMailAddress');
                                $item->setURL(LinkHandler::getInstance()->getLink('UserEmailAddressExport'));
                        break;
                        
                        case 'sendMail':
-                               $item->setName('user.sendMail');
                                $item->setURL(LinkHandler::getInstance()->getLink('UserMail'));
                        break;
-                       
-                       default:
-                               throw new SystemException("action '".$actionName."' is invalid");
-                       break;
                }
                
                return $item;
@@ -76,23 +67,28 @@ class UserClipboardAction extends AbstractClipboardAction {
                return 'wcf\data\user\UserAction';
        }
        
+       /**
+        * @see wcf\system\clipboard\action\IClipboardAction::getTypeName()
+        */
+       public function getTypeName() {
+               return 'com.woltlab.wcf.user';
+       }
+       
        /**
         * Returns the ids of the users which can be deleted.
         * 
-        * @param       array<wcf\data\user\User>       $objects
-        * @return      integer
+        * @return      array<integer>
         */
-       protected function validateDelete(array $objects) {
+       protected function validateDelete() {
                // check permissions
                if (!WCF::getSession()->getPermission('admin.user.canDeleteUser')) {
                        return 0;
                }
                
                // user cannot delete itself
-               $userIDs = array_keys($objects);
+               $userIDs = array_keys($this->objects);
                foreach ($userIDs as $index => $userID) {
                        if ($userID == WCF::getUser()->userID) {
-                               unset($objects[$userID]);
                                unset($userIDs[$index]);
                        }
                }
@@ -133,6 +129,8 @@ class UserClipboardAction extends AbstractClipboardAction {
         * @see wcf\system\clipboard\action\IClipboardAction::getEditorLabel()
         */
        public function getEditorLabel(array $objects) {
-               return WCF::getLanguage()->getDynamicVariable('wcf.clipboard.label.user.marked', array('count' => count($objects)));
+               return WCF::getLanguage()->getDynamicVariable('wcf.clipboard.label.com.woltlab.wcf.user.marked', array(
+                       'count' => count($objects)
+               ));
        }
 }
index cf30ee1279c6ee0556d1e4435652d7876fbe8b00..1f8dae9a6567703ce7dec91f2579efc301db8b0a 100644 (file)
        
        <category name="wcf.clipboard">
                <item name="wcf.clipboard.item.unmarkAll"><![CDATA[Demarkieren]]></item>
-               <item name="wcf.clipboard.item.user.assignToGroup"><![CDATA[Benutzergruppe zuweisen]]></item>
-               <item name="wcf.clipboard.item.user.delete"><![CDATA[Benutzer löschen]]></item>
-               <item name="wcf.clipboard.item.user.delete.confirmMessage"><![CDATA[{if $count == 1}Einen{else}{#$count}{/if} Benutzer löschen?]]></item>
-               <item name="wcf.clipboard.item.user.exportMailAddress"><![CDATA[E-Mail-Adressen exportieren]]></item>
-               <item name="wcf.clipboard.item.user.sendMail"><![CDATA[E-Mail senden]]></item>
-               <item name="wcf.clipboard.label.user.marked"><![CDATA[{if $count == 1}Ein{else}{#$count}{/if} Benutzer markiert]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.assignToGroup"><![CDATA[Benutzergruppe zuweisen]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.delete"><![CDATA[Benutzer löschen]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.delete.confirmMessage"><![CDATA[{if $count == 1}Einen{else}{#$count}{/if} Benutzer löschen?]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.exportMailAddress"><![CDATA[E-Mail-Adressen exportieren]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.sendMail"><![CDATA[E-Mail senden]]></item>
+               <item name="wcf.clipboard.label.com.woltlab.wcf.user.marked"><![CDATA[{if $count == 1}Ein{else}{#$count}{/if} Benutzer markiert]]></item>
        </category>
        
        <category name="wcf.date">
index befea72c40c1375d0ea65934d2a0fa2cbd48c06f..400f9a6983876481f9ba4c97534d50e38de41e64 100644 (file)
        
        <category name="wcf.clipboard">
                <item name="wcf.clipboard.item.user.assignToGroup"><![CDATA[Assign to user group]]></item>
-               <item name="wcf.clipboard.item.user.delete"><![CDATA[Delete users]]></item>
-               <item name="wcf.clipboard.item.user.delete.confirmMessage"><![CDATA[Delete {if $count == 1}one{else}{#$count}{/if} user{if $count > 1}s{/if}?]]></item>
-               <item name="wcf.clipboard.item.user.exportMailAddress"><![CDATA[Export e-mail addresses]]></item>
-               <item name="wcf.clipboard.item.user.sendMail"><![CDATA[Send an e-mail]]></item>
-               <item name="wcf.clipboard.label.user.marked"><![CDATA[{if $count == 1}One{else}{#$count}{/if} user{if $count > 1}s{/if} marked]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.delete"><![CDATA[Delete users]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.delete.confirmMessage"><![CDATA[Delete {if $count == 1}one{else}{#$count}{/if} user{if $count > 1}s{/if}?]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.exportMailAddress"><![CDATA[Export e-mail addresses]]></item>
+               <item name="wcf.clipboard.item.com.woltlab.wcf.user.sendMail"><![CDATA[Send an e-mail]]></item>
+               <item name="wcf.clipboard.label.com.woltlab.wcf.user.marked"><![CDATA[{if $count == 1}One{else}{#$count}{/if} user{if $count > 1}s{/if} marked]]></item>
        </category>
        
        <category name="wcf.date">