2 declare(strict_types=1);
3 namespace wcf\system\bulk\processing\user;
4 use wcf\data\user\UserList;
5 use wcf\data\DatabaseObjectList;
7 use wcf\util\StringUtil;
10 * Bulk processing action implementation for exporting mail addresses of users.
12 * @author Matthias Schmidt
13 * @copyright 2001-2018 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Bulk\Processing\User
18 class ExportMailAddressUserBulkProcessingAction extends AbstractUserBulkProcessingAction {
20 * type of the file the email addresses will be saved in (csv or xml)
23 public $fileType = 'csv';
26 * separates the exported email addresses
29 public $separator = ',';
32 * encloses the exported email addresses
35 public $textSeparator = '"';
40 public function executeAction(DatabaseObjectList $objectList) {
41 if (!($objectList instanceof UserList)) {
42 throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
46 header('Content-Type: text/'.$this->fileType.'; charset=UTF-8');
47 header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"');
49 if ($this->fileType == 'xml') {
50 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
53 $userCount = count($objectList);
55 foreach ($objectList as $user) {
56 if ($this->fileType == 'xml') {
57 echo "<address><![CDATA[".StringUtil::escapeCDATA($user->email)."]]></address>\n";
60 echo $this->textSeparator.$user->email.$this->textSeparator.($i < $userCount ? $this->separator : '');
66 if ($this->fileType == 'xml') {
74 public function getHTML() {
75 return WCF::getTPL()->fetch('exportMailAddressUserBulkProcessing', 'wcf', [
76 'fileType' => $this->fileType,
77 'separator' => $this->separator,
78 'textSeparator' => $this->textSeparator
85 public function getObjectList() {
86 $userList = parent::getObjectList();
88 $userList->sqlOrderBy = 'user_table.email';
96 public function readFormParameters() {
97 if (isset($_POST['fileType']) && $_POST['fileType'] == 'xml') $this->fileType = $_POST['fileType'];
98 if (isset($_POST['separator'])) $this->separator = $_POST['separator'];
99 if (isset($_POST['textSeparator'])) $this->textSeparator = $_POST['textSeparator'];
105 public function reset() {