Add TReasonedBulkProcessingAction
authorMatthias Schmidt <gravatronics@live.com>
Fri, 26 Jun 2015 16:38:20 +0000 (18:38 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 26 Jun 2015 16:38:20 +0000 (18:38 +0200)
wcfsetup/install/files/acp/templates/reasonedBulkProcessingAction.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/system/bulk/processing/TReasonedBulkProcessingAction.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/acp/templates/reasonedBulkProcessingAction.tpl b/wcfsetup/install/files/acp/templates/reasonedBulkProcessingAction.tpl
new file mode 100644 (file)
index 0000000..7f17e46
--- /dev/null
@@ -0,0 +1,10 @@
+<dl{if $errorField == $reasonFieldName} class="formError"{/if}>
+       <dt><label for="{$reasonFieldName}">{lang}wcf.global.reason{/lang}</label></dt>
+       <dd>
+               <textarea name="{$reasonFieldName}" id="{$reasonFieldName}" cols="40" rows="3">{$reason}</textarea>
+               
+               {if $errorField == $reasonFieldName}
+                       <small class="innerError">{lang}wcf.global.form.error.{$errorType}{/lang}</small>
+               {/if}
+       </dd>
+</dl>
diff --git a/wcfsetup/install/files/lib/system/bulk/processing/TReasonedBulkProcessingAction.class.php b/wcfsetup/install/files/lib/system/bulk/processing/TReasonedBulkProcessingAction.class.php
new file mode 100644 (file)
index 0000000..2df21eb
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+namespace wcf\system\bulk\processing;
+use wcf\util\StringUtil;
+use wcf\system\WCF;
+
+/**
+ * Trait for bulk processing actions allowing given a reason for executing the action.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.bulk.processing
+ * @category   Community Framework
+ */
+trait TReasonedBulkProcessingAction {
+       /**
+        * reason
+        * @var string
+        */
+       protected $reason = '';
+       
+       /**
+        * @see \wcf\system\bulk\processing\IBulkProcessingAction::getHTML()
+        */
+       public function getHTML() {
+               return WCF::getTPL()->fetch('reasonedBulkProcessingAction', 'wcf', [
+                       'reason' => $this->reason,
+                       'reasonFieldName' => $this->getReasonFieldName()
+               ]);
+       }
+       
+       /**
+        * Returns the name of the reason field.
+        * 
+        * @return      string
+        */
+       abstract protected function getReasonFieldName();
+       
+       /**
+        * @see \wcf\system\bulk\processing\IBulkProcessingAction::readFormParameters()
+        */
+       public function readFormParameters() {
+               if (isset($_POST[$this->getReasonFieldName()])) $this->reason = StringUtil::trim($_POST[$this->getReasonFieldName()]);
+       }
+       
+       /**
+        * @see \wcf\system\bulk\processing\IBulkProcessingAction::reset()
+        */
+       public function reset() {
+               $this->reason = '';
+       }
+}