+++ /dev/null
-<dl{if $errorField == 'birthday'} class="formError"{/if}>
- <dt><label for="birthday">{lang}wcf.person.birthday{/lang}</label></dt>
- <dd>
- <input type="date" id="birthday" name="birthday" value="{$birthday}">
- {if $errorField == 'birthday'}
- <small class="innerError">
- {if $errorType == 'noValidSelection'}
- {lang}wcf.global.form.error.noValidSelection{/lang}
- {else}
- {lang}wcf.acp.person.birthday.error.{$errorType}{/lang}
- {/if}
- </small>
- {/if}
- </dd>
-</dl>
<?xml version="1.0" encoding="UTF-8"?>
-<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/tornado/eventListener.xsd">
+<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/5.4/eventListener.xsd">
<import>
<!-- admin -->
- <eventlistener name="birthdaySortFieldAdminPersonList">
+ <eventlistener name="validateSortField@wcf\acp\page\PersonListPage">
<environment>admin</environment>
<eventclassname>wcf\acp\page\PersonListPage</eventclassname>
<eventname>validateSortField</eventname>
<listenerclassname>wcf\system\event\listener\BirthdaySortFieldPersonListPageListener</listenerclassname>
</eventlistener>
- <eventlistener name="birthdayPersonAddForm">
+ <eventlistener name="createForm@wcf\acp\form\PersonAddForm">
<environment>admin</environment>
<eventclassname>wcf\acp\form\PersonAddForm</eventclassname>
- <eventname>saved</eventname>
- <listenerclassname>wcf\system\event\listener\BirthdayPersonAddFormListener</listenerclassname>
- </eventlistener>
- <eventlistener name="birthdayPersonAddFormInherited">
- <environment>admin</environment>
- <eventclassname>wcf\acp\form\PersonAddForm</eventclassname>
- <eventname>assignVariables,readFormParameters,save,validate</eventname>
+ <eventname>createForm</eventname>
<listenerclassname>wcf\system\event\listener\BirthdayPersonAddFormListener</listenerclassname>
<inherit>1</inherit>
</eventlistener>
- <eventlistener name="birthdayPersonEditForm">
- <environment>admin</environment>
- <eventclassname>wcf\acp\form\PersonEditForm</eventclassname>
- <eventname>readData</eventname>
- <listenerclassname>wcf\system\event\listener\BirthdayPersonAddFormListener</listenerclassname>
- </eventlistener>
<!-- /admin -->
<!-- user -->
- <eventlistener name="birthdaySortFieldPersonList">
+ <eventlistener name="validateSortField@wcf\page\PersonListPage">
<environment>user</environment>
<eventclassname>wcf\page\PersonListPage</eventclassname>
<eventname>validateSortField</eventname>
--- /dev/null
+<?php
+
+use wcf\system\database\table\column\DateDatabaseTableColumn;
+use wcf\system\database\table\PartialDatabaseTable;
+
+return [
+ PartialDatabaseTable::create('wcf1_person')
+ ->columns([
+ DateDatabaseTableColumn::create('birthday'),
+ ]),
+];
<?php
+
namespace wcf\system\event\listener;
+
use wcf\acp\form\PersonAddForm;
-use wcf\acp\form\PersonEditForm;
-use wcf\form\IForm;
-use wcf\page\IPage;
-use wcf\system\exception\UserInputException;
-use wcf\system\WCF;
-use wcf\util\StringUtil;
+use wcf\form\AbstractFormBuilderForm;
+use wcf\system\form\builder\container\FormContainer;
+use wcf\system\form\builder\field\DateFormField;
/**
* Handles setting the birthday when adding and editing people.
*
- * @author Matthias Schmidt
- * @copyright 2001-2020 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\System\Event\Listener
+ * @author Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Event\Listener
*/
-class BirthdayPersonAddFormListener extends AbstractEventListener {
- /**
- * birthday of the created or edited person
- * @var string
- */
- protected $birthday = '';
-
- /**
- * @see IPage::assignVariables()
- */
- protected function onAssignVariables() {
- WCF::getTPL()->assign('birthday', $this->birthday);
- }
-
- /**
- * @see IPage::readData()
- */
- protected function onReadData(PersonEditForm $form) {
- if (empty($_POST)) {
- $this->birthday = $form->person->birthday;
-
- if ($this->birthday === '0000-00-00') {
- $this->birthday = '';
- }
- }
- }
-
- /**
- * @see IForm::readFormParameters()
- */
- protected function onReadFormParameters() {
- if (isset($_POST['birthday'])) {
- $this->birthday = StringUtil::trim($_POST['birthday']);
- }
- }
-
- /**
- * @see IForm::save()
- */
- protected function onSave(PersonAddForm $form) {
- if ($this->birthday) {
- $form->additionalFields['birthday'] = $this->birthday;
- }
- else {
- $form->additionalFields['birthday'] = '0000-00-00';
- }
- }
-
- /**
- * @see IForm::saved()
- */
- protected function onSaved() {
- $this->birthday = '';
- }
-
- /**
- * @see IForm::validate()
- */
- protected function onValidate() {
- if (empty($this->birthday)) {
- return;
- }
-
- if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $this->birthday, $match)) {
- throw new UserInputException('birthday', 'noValidSelection');
- }
-
- if (!checkdate(intval($match[2]), intval($match[3]), intval($match[1]))) {
- throw new UserInputException('birthday', 'noValidSelection');
- }
- }
+class BirthdayPersonAddFormListener extends AbstractEventListener
+{
+ /**
+ * @see AbstractFormBuilderForm::createForm()
+ */
+ protected function onCreateForm(PersonAddForm $form): void
+ {
+ /** @var FormContainer $dataContainer */
+ $dataContainer = $form->form->getNodeById('data');
+ $dataContainer->appendChild(
+ DateFormField::create('birthday')
+ ->label('wcf.person.birthday')
+ ->saveValueFormat('Y-m-d')
+ ->nullable()
+ );
+ }
}
<?php
+
namespace wcf\system\event\listener;
+
use wcf\page\SortablePage;
/**
* Makes people's birthday a valid sort field in the ACP and the front end.
- *
- * @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\System\Event\Listener
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Event\Listener
*/
-class BirthdaySortFieldPersonListPageListener implements IParameterizedEventListener {
- /**
- * @inheritDoc
- */
- public function execute($eventObj, $className, $eventName, array &$parameters) {
- /** @var SortablePage $eventObj */
-
- $eventObj->validSortFields[] = 'birthday';
- }
+class BirthdaySortFieldPersonListPageListener extends AbstractEventListener
+{
+ /**
+ * @see SortablePage::validateSortField()
+ */
+ public function onValidateSortField(SortablePage $page): void
+ {
+ $page->validSortFields[] = 'birthday';
+ }
}
+++ /dev/null
-ALTER TABLE wcf1_person ADD birthday DATE NOT NULL;
<?xml version="1.0" encoding="UTF-8"?>
-<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/tornado/language.xsd" languagecode="de">
+<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/5.4/language.xsd" languagecode="de">
<category name="wcf.person">
<item name="wcf.person.birthday"><![CDATA[Geburtstag]]></item>
</category>
<?xml version="1.0" encoding="UTF-8"?>
-<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/tornado/language.xsd" languagecode="en">
+<language xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/5.4/language.xsd" languagecode="en">
<category name="wcf.person">
<item name="wcf.person.birthday"><![CDATA[Birthday]]></item>
</category>
<?xml version="1.0" encoding="UTF-8"?>
-<package name="com.woltlab.wcf.people.birthday" xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/tornado/package.xsd">
+<package name="com.woltlab.wcf.people.birthday" xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/5.4/package.xsd">
<packageinformation>
<packagename>WoltLab Suite Core Tutorial: People (Birthday)</packagename>
<packagedescription>Adds a birthday field to the people management system as part of a tutorial to create packages.</packagedescription>
- <version>3.1.0</version>
- <date>2018-03-30</date>
+ <version>5.4.0</version>
+ <date>2021-04-16</date>
</packageinformation>
<authorinformation>
</authorinformation>
<requiredpackages>
- <requiredpackage minversion="3.1.0">com.woltlab.wcf</requiredpackage>
- <requiredpackage minversion="3.1.0">com.woltlab.wcf.people</requiredpackage>
+ <requiredpackage minversion="5.4.0 Alpha 1">com.woltlab.wcf</requiredpackage>
+ <requiredpackage minversion="5.4.0">com.woltlab.wcf.people</requiredpackage>
</requiredpackages>
<excludedpackages>
- <excludedpackage version="3.2.0 Alpha 1">com.woltlab.wcf</excludedpackage>
+ <excludedpackage version="6.0.0 Alpha 1">com.woltlab.wcf</excludedpackage>
</excludedpackages>
- <compatibility>
- <api version="2018" />
- </compatibility>
-
<instructions type="install">
- <instruction type="acpTemplate" />
<instruction type="file" />
- <instruction type="sql" />
+ <instruction type="database">acp/database/install_com.woltlab.wcf.people.birthday.php</instruction>
<instruction type="template" />
<instruction type="language" />
<?xml version="1.0" encoding="UTF-8"?>
-<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/tornado/XSD/templateListener.xsd">
+<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/tornado/5.4/templateListener.xsd">
<import>
<!-- admin -->
<templatelistener name="personListBirthdayColumnHead">
<templatelistener name="personListBirthdayColumn">
<eventname>columns</eventname>
<environment>admin</environment>
- <templatecode><![CDATA[<td class="columnDate columnBirthday">{if $person->birthday !== '0000-00-00'}{@$person->birthday|strtotime|date}{/if}</td>]]></templatecode>
+ <templatecode><![CDATA[<td class="columnDate columnBirthday">{if $person->birthday}{@$person->birthday|strtotime|date}{/if}</td>]]></templatecode>
<templatename>personList</templatename>
</templatelistener>
- <templatelistener name="personAddBirthday">
- <eventname>dataFields</eventname>
- <environment>admin</environment>
- <templatecode><![CDATA[{include file='__personAddBirthday'}]]></templatecode>
- <templatename>personAdd</templatename>
- </templatelistener>
<!-- /admin -->
<!-- user -->
-{if $person->birthday !== '0000-00-00'}
+{if $person->birthday}
<dt>{lang}wcf.person.birthday{/lang}</dt>
<dd>{@$person->birthday|strtotime|date}</dd>
{/if}