Update code pf tutorial series part 2
authorMatthias Schmidt <gravatronics@live.com>
Tue, 20 Apr 2021 10:59:15 +0000 (12:59 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 20 Apr 2021 11:05:47 +0000 (13:05 +0200)
snippets/tutorial/tutorial-series/part-2/acptemplates/__personAddBirthday.tpl [deleted file]
snippets/tutorial/tutorial-series/part-2/eventListener.xml
snippets/tutorial/tutorial-series/part-2/files/acp/database/install_com.woltlab.wcf.people.birthday.php [new file with mode: 0644]
snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdayPersonAddFormListener.class.php
snippets/tutorial/tutorial-series/part-2/files/lib/system/event/listener/BirthdaySortFieldPersonListPageListener.class.php
snippets/tutorial/tutorial-series/part-2/install.sql [deleted file]
snippets/tutorial/tutorial-series/part-2/language/de.xml
snippets/tutorial/tutorial-series/part-2/language/en.xml
snippets/tutorial/tutorial-series/part-2/package.xml
snippets/tutorial/tutorial-series/part-2/templateListener.xml
snippets/tutorial/tutorial-series/part-2/templates/__personListBirthday.tpl

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 (file)
index 451466a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<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>
index fb8631de990eb4c646656564b21e5f9a12e724a4..54d0c62f7a4c9793378591ed9fa80c46862db024 100644 (file)
@@ -1,36 +1,24 @@
 <?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>
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 (file)
index 0000000..ad4be9a
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+use wcf\system\database\table\column\DateDatabaseTableColumn;
+use wcf\system\database\table\PartialDatabaseTable;
+
+return [
+    PartialDatabaseTable::create('wcf1_person')
+        ->columns([
+            DateDatabaseTableColumn::create('birthday'),
+        ]),
+];
index df26e4914e69549daaa9987a2f93478e92025815..29b44ecd73c3dc864cb2f114bdb156c1bc8d1225 100644 (file)
@@ -1,90 +1,34 @@
 <?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()
+        );
+    }
 }
index c704048e549cc79ca2d175dca3ef25957d744efc..f61d1ca863730078d8fd579494b8e5922722d629 100644 (file)
@@ -1,22 +1,24 @@
 <?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';
+    }
 }
diff --git a/snippets/tutorial/tutorial-series/part-2/install.sql b/snippets/tutorial/tutorial-series/part-2/install.sql
deleted file mode 100644 (file)
index 5e121fc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE wcf1_person ADD birthday DATE NOT NULL;
index 4e49b140b60a4dfa17af6497a67a99cfe0f80062..c92aec13f04ec48b349f814b643aa1848f9ff172 100644 (file)
@@ -1,5 +1,5 @@
 <?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>
index 133e822ca4decc363494de934bdcdb627344c75b..a3b32cc0d3dc1e56b9f990cd98a5e669dff1890f 100644 (file)
@@ -1,5 +1,5 @@
 <?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>
index 463253cb7265adefb94df09a5aa44ff480692257..2db4f66d9986119e5ba9a17b3d3a3d2696af3a55 100644 (file)
@@ -1,10 +1,10 @@
 <?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" />
                
index 565310eb5032ef800f4e4b308f0e735825ae4481..fbe8f05ecd42c774549cd6d059ddd17bd73a297b 100644 (file)
@@ -1,5 +1,5 @@
 <?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 -->
index cb393bb940298f970813f2ddda5d43bd36910b04..5cdf561eb0a0c2c56be56480933dd8b94a6297d8 100644 (file)
@@ -1,4 +1,4 @@
-{if $person->birthday !== '0000-00-00'}
+{if $person->birthday}
        <dt>{lang}wcf.person.birthday{/lang}</dt>
        <dd>{@$person->birthday|strtotime|date}</dd>
 {/if}