Fix highlighting external files
[GitHub/WoltLab/woltlab.github.io.git] / snippets / migration / wsc-31 / formBuilder / PersonAddForm_old.class.php
1 <?php
2 namespace wcf\acp\form;
3 use wcf\data\person\PersonAction;
4 use wcf\form\AbstractForm;
5 use wcf\system\exception\UserInputException;
6 use wcf\system\WCF;
7 use wcf\util\StringUtil;
8
9 /**
10 * Shows the form to create a new person.
11 *
12 * @author Matthias Schmidt
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\Acp\Form
16 */
17 class PersonAddForm extends AbstractForm {
18 /**
19 * @inheritDoc
20 */
21 public $activeMenuItem = 'wcf.acp.menu.link.person.add';
22
23 /**
24 * first name of the person
25 * @var string
26 */
27 public $firstName = '';
28
29 /**
30 * last name of the person
31 * @var string
32 */
33 public $lastName = '';
34
35 /**
36 * @inheritDoc
37 */
38 public $neededPermissions = ['admin.content.canManagePeople'];
39
40 /**
41 * @inheritDoc
42 */
43 public function assignVariables() {
44 parent::assignVariables();
45
46 WCF::getTPL()->assign([
47 'action' => 'add',
48 'firstName' => $this->firstName,
49 'lastName' => $this->lastName
50 ]);
51 }
52
53 /**
54 * @inheritDoc
55 */
56 public function readFormParameters() {
57 parent::readFormParameters();
58
59 if (isset($_POST['firstName'])) $this->firstName = StringUtil::trim($_POST['firstName']);
60 if (isset($_POST['lastName'])) $this->lastName = StringUtil::trim($_POST['lastName']);
61 }
62
63 /**
64 * @inheritDoc
65 */
66 public function save() {
67 parent::save();
68
69 $this->objectAction = new PersonAction([], 'create', [
70 'data' => array_merge($this->additionalFields, [
71 'firstName' => $this->firstName,
72 'lastName' => $this->lastName
73 ])
74 ]);
75 $this->objectAction->executeAction();
76
77 $this->saved();
78
79 // reset values
80 $this->firstName = '';
81 $this->lastName = '';
82
83 // show success message
84 WCF::getTPL()->assign('success', true);
85 }
86
87 /**
88 * @inheritDoc
89 */
90 public function validate() {
91 parent::validate();
92
93 // validate first name
94 if (empty($this->firstName)) {
95 throw new UserInputException('firstName');
96 }
97 if (mb_strlen($this->firstName) > 255) {
98 throw new UserInputException('firstName', 'tooLong');
99 }
100
101 // validate last name
102 if (empty($this->lastName)) {
103 throw new UserInputException('lastName');
104 }
105 if (mb_strlen($this->lastName) > 255) {
106 throw new UserInputException('lastName', 'tooLong');
107 }
108 }
109 }