3 namespace wcf\system\bulk\processing\user;
5 use wcf\data\DatabaseObjectList;
6 use wcf\data\user\UserList;
8 use wcf\util\StringUtil;
11 * Bulk processing action implementation for exporting mail addresses of users.
13 * @author Matthias Schmidt
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Bulk\Processing\User
19 class ExportMailAddressUserBulkProcessingAction extends AbstractUserBulkProcessingAction
22 * type of the file the email addresses will be saved in (csv or xml)
25 public $fileType = 'csv';
28 * separates the exported email addresses
31 public $separator = ',';
34 * encloses the exported email addresses
37 public $textSeparator = '"';
40 * indicates whether output was generated (i.e. executeAction was called)
43 private $executed = false;
48 public function executeAction(DatabaseObjectList $objectList)
50 if (!($objectList instanceof UserList)) {
51 throw new \InvalidArgumentException("Object list is no instance of '" . UserList::class . "', instance of '" . \get_class($objectList) . "' given.");
54 $this->executed = true;
57 \header('Content-Type: text/' . $this->fileType . '; charset=UTF-8');
58 \header('Content-Disposition: attachment; filename="export.' . $this->fileType . '"');
60 if ($this->fileType == 'xml') {
61 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
64 $userCount = \count($objectList);
66 foreach ($objectList as $user) {
67 if ($this->fileType == 'xml') {
68 echo "<address><![CDATA[" . StringUtil::escapeCDATA($user->email) . "]]></address>\n";
70 echo $this->textSeparator . $user->email . $this->textSeparator . ($i < $userCount ? $this->separator : '');
76 if ($this->fileType == 'xml') {
84 public function getHTML()
86 return WCF::getTPL()->fetch('exportMailAddressUserBulkProcessing', 'wcf', [
87 'fileType' => $this->fileType,
88 'separator' => $this->separator,
89 'textSeparator' => $this->textSeparator,
96 public function getObjectList()
98 $userList = parent::getObjectList();
100 $userList->sqlOrderBy = 'user_table.email';
108 public function readFormParameters()
110 if (isset($_POST['fileType']) && $_POST['fileType'] == 'xml') {
111 $this->fileType = $_POST['fileType'];
113 if (isset($_POST['separator'])) {
114 $this->separator = $_POST['separator'];
116 if (isset($_POST['textSeparator'])) {
117 $this->textSeparator = $_POST['textSeparator'];
124 public function reset()
126 if (!$this->executed) {
129 $this->executed = false;