From: Matthias Schmidt Date: Tue, 20 Apr 2021 10:59:15 +0000 (+0200) Subject: Update code pf tutorial series part 2 X-Git-Tag: 5.6.final~259^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=182e8fa9a36fa50b2760ce92dc4361f661e8a639;p=GitHub%2FWoltLab%2Fwoltlab.github.io.git Update code pf tutorial series part 2 --- diff --git a/snippets/tutorial/tutorial-series/part-2/acptemplates/__personAddBirthday.tpl b/snippets/tutorial/tutorial-series/part-2/acptemplates/__personAddBirthday.tpl deleted file mode 100644 index 451466a1..00000000 --- a/snippets/tutorial/tutorial-series/part-2/acptemplates/__personAddBirthday.tpl +++ /dev/null @@ -1,15 +0,0 @@ - -
-
- - {if $errorField == 'birthday'} - - {if $errorType == 'noValidSelection'} - {lang}wcf.global.form.error.noValidSelection{/lang} - {else} - {lang}wcf.acp.person.birthday.error.{$errorType}{/lang} - {/if} - - {/if} -
- diff --git a/snippets/tutorial/tutorial-series/part-2/eventListener.xml b/snippets/tutorial/tutorial-series/part-2/eventListener.xml index fb8631de..54d0c62f 100644 --- a/snippets/tutorial/tutorial-series/part-2/eventListener.xml +++ b/snippets/tutorial/tutorial-series/part-2/eventListener.xml @@ -1,36 +1,24 @@ - + - + admin wcf\acp\page\PersonListPage validateSortField wcf\system\event\listener\BirthdaySortFieldPersonListPageListener - + admin wcf\acp\form\PersonAddForm - saved - wcf\system\event\listener\BirthdayPersonAddFormListener - - - admin - wcf\acp\form\PersonAddForm - assignVariables,readFormParameters,save,validate + createForm wcf\system\event\listener\BirthdayPersonAddFormListener 1 - - admin - wcf\acp\form\PersonEditForm - readData - wcf\system\event\listener\BirthdayPersonAddFormListener - - + user wcf\page\PersonListPage validateSortField diff --git a/snippets/tutorial/tutorial-series/part-2/files/acp/database/install_com.woltlab.wcf.people.birthday.php b/snippets/tutorial/tutorial-series/part-2/files/acp/database/install_com.woltlab.wcf.people.birthday.php new file mode 100644 index 00000000..ad4be9ad --- /dev/null +++ b/snippets/tutorial/tutorial-series/part-2/files/acp/database/install_com.woltlab.wcf.people.birthday.php @@ -0,0 +1,11 @@ +columns([ + DateDatabaseTableColumn::create('birthday'), + ]), +]; diff --git a/snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdayPersonAddFormListener.class.php b/snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdayPersonAddFormListener.class.php index df26e491..29b44ecd 100644 --- a/snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdayPersonAddFormListener.class.php +++ b/snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdayPersonAddFormListener.class.php @@ -1,90 +1,34 @@ - * @package WoltLabSuite\Core\System\Event\Listener + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @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() + ); + } } diff --git a/snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdaySortFieldPersonListPageListener.class.php b/snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdaySortFieldPersonListPageListener.class.php index c704048e..f61d1ca8 100644 --- a/snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdaySortFieldPersonListPageListener.class.php +++ b/snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdaySortFieldPersonListPageListener.class.php @@ -1,22 +1,24 @@ - * @package WoltLabSuite\Core\System\Event\Listener + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @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'; + } } diff --git a/snippets/tutorial/tutorial-series/part-2/install.sql b/snippets/tutorial/tutorial-series/part-2/install.sql deleted file mode 100644 index 5e121fcf..00000000 --- a/snippets/tutorial/tutorial-series/part-2/install.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE wcf1_person ADD birthday DATE NOT NULL; diff --git a/snippets/tutorial/tutorial-series/part-2/language/de.xml b/snippets/tutorial/tutorial-series/part-2/language/de.xml index 4e49b140..c92aec13 100644 --- a/snippets/tutorial/tutorial-series/part-2/language/de.xml +++ b/snippets/tutorial/tutorial-series/part-2/language/de.xml @@ -1,5 +1,5 @@ - + diff --git a/snippets/tutorial/tutorial-series/part-2/language/en.xml b/snippets/tutorial/tutorial-series/part-2/language/en.xml index 133e822c..a3b32cc0 100644 --- a/snippets/tutorial/tutorial-series/part-2/language/en.xml +++ b/snippets/tutorial/tutorial-series/part-2/language/en.xml @@ -1,5 +1,5 @@ - + diff --git a/snippets/tutorial/tutorial-series/part-2/package.xml b/snippets/tutorial/tutorial-series/part-2/package.xml index 463253cb..2db4f66d 100644 --- a/snippets/tutorial/tutorial-series/part-2/package.xml +++ b/snippets/tutorial/tutorial-series/part-2/package.xml @@ -1,10 +1,10 @@ - + WoltLab Suite Core Tutorial: People (Birthday) Adds a birthday field to the people management system as part of a tutorial to create packages. - 3.1.0 - 2018-03-30 + 5.4.0 + 2021-04-16 @@ -13,22 +13,17 @@ - com.woltlab.wcf - com.woltlab.wcf.people + com.woltlab.wcf + com.woltlab.wcf.people - com.woltlab.wcf + com.woltlab.wcf - - - - - - + acp/database/install_com.woltlab.wcf.people.birthday.php diff --git a/snippets/tutorial/tutorial-series/part-2/templateListener.xml b/snippets/tutorial/tutorial-series/part-2/templateListener.xml index 565310eb..fbe8f05e 100644 --- a/snippets/tutorial/tutorial-series/part-2/templateListener.xml +++ b/snippets/tutorial/tutorial-series/part-2/templateListener.xml @@ -1,5 +1,5 @@ - + @@ -11,15 +11,9 @@ columns admin - {if $person->birthday !== '0000-00-00'}{@$person->birthday|strtotime|date}{/if}]]> + {if $person->birthday}{@$person->birthday|strtotime|date}{/if}]]> personList - - dataFields - admin - - personAdd - diff --git a/snippets/tutorial/tutorial-series/part-2/templates/__personListBirthday.tpl b/snippets/tutorial/tutorial-series/part-2/templates/__personListBirthday.tpl index cb393bb9..5cdf561e 100644 --- a/snippets/tutorial/tutorial-series/part-2/templates/__personListBirthday.tpl +++ b/snippets/tutorial/tutorial-series/part-2/templates/__personListBirthday.tpl @@ -1,4 +1,4 @@ -{if $person->birthday !== '0000-00-00'} +{if $person->birthday}
{lang}wcf.person.birthday{/lang}
{@$person->birthday|strtotime|date}
{/if}