2 namespace wcf\system\bulk\processing\user;
3 use wcf\data\user\UserList;
4 use wcf\data\DatabaseObjectList;
6 use wcf\util\StringUtil;
9 * Bulk processing action implementation for exporting mail addresses of users.
11 * @author Matthias Schmidt
12 * @copyright 2001-2016 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\Bulk\Processing\User
17 class ExportMailAddressUserBulkProcessingAction extends AbstractUserBulkProcessingAction {
19 * type of the file the email addresses will be saved in (csv or xml)
22 public $fileType = 'csv';
25 * separates the exported email addresses
28 public $separator = ',';
31 * encloses the exported email addresses
34 public $textSeparator = '"';
39 public function executeAction(DatabaseObjectList $objectList) {
40 if (!($objectList instanceof UserList)) {
41 throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
45 header('Content-Type: text/'.$this->fileType.'; charset=UTF-8');
46 header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"');
48 if ($this->fileType == 'xml') {
49 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
52 $userCount = count($objectList);
54 foreach ($objectList as $user) {
55 if ($this->fileType == 'xml') {
56 echo "<address><![CDATA[".StringUtil::escapeCDATA($user->email)."]]></address>\n";
59 echo $this->textSeparator.$user->email.$this->textSeparator.($i < $userCount ? $this->separator : '');
65 if ($this->fileType == 'xml') {
73 public function getHTML() {
74 return WCF::getTPL()->fetch('exportMailAddressUserBulkProcessing', 'wcf', [
75 'fileType' => $this->fileType,
76 'separator' => $this->separator,
77 'textSeparator' => $this->textSeparator
84 public function getObjectList() {
85 $userList = parent::getObjectList();
87 $userList->sqlOrderBy = 'user_table.email';
95 public function readFormParameters() {
96 if (isset($_POST['fileType']) && $_POST['fileType'] == 'xml') $this->fileType = $_POST['fileType'];
97 if (isset($_POST['separator'])) $this->separator = $_POST['separator'];
98 if (isset($_POST['textSeparator'])) $this->textSeparator = $_POST['textSeparator'];
104 public function reset() {