<?php
namespace wcf\system\clipboard\action;
+use wcf\system\clipboard\ClipboardEditorItem;
+use wcf\system\exception\SystemException;
/**
* Abstract implementation of a clipboard action handler.
* @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()
*/
<?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;
*/
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;
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]);
}
}
* @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)
+ ));
}
}
<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">
<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">