From fac06d55786123f1edbe05ecea4915a12e0c65bd Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 20 Apr 2021 13:20:35 +0200 Subject: [PATCH] Update code of third part of tutorial series --- .../tutorial-series/part-3/acpMenu.xml | 2 +- .../part-3/acptemplates/personAdd.tpl | 55 +----- .../part-3/acptemplates/personList.tpl | 14 +- .../install_com.woltlab.wcf.people.php | 21 ++ .../lib/acp/form/PersonAddForm.class.php | 182 +++++++----------- .../lib/acp/form/PersonEditForm.class.php | 118 ++++-------- .../lib/acp/page/PersonListPage.class.php | 53 ++--- .../files/lib/data/person/Person.class.php | 82 ++++---- .../lib/data/person/PersonAction.class.php | 39 ++-- .../lib/data/person/PersonEditor.class.php | 31 +-- .../lib/data/person/PersonList.class.php | 26 +-- .../files/lib/page/PersonListPage.class.php | 43 +++-- .../files/lib/page/PersonPage.class.php | 170 ++++++++-------- .../runtime/PersonRuntimeCache.class.php | 28 +-- .../manager/PersonCommentManager.class.php | 149 +++++++------- .../page/handler/PersonPageHandler.class.php | 174 +++++++++-------- .../tutorial-series/part-3/install.sql | 8 - .../tutorial-series/part-3/language/de.xml | 10 +- .../tutorial-series/part-3/language/en.xml | 14 +- .../tutorial-series/part-3/menuItem.xml | 2 +- .../tutorial-series/part-3/objectType.xml | 2 +- .../tutorial-series/part-3/package.xml | 17 +- .../tutorial/tutorial-series/part-3/page.xml | 2 +- .../part-3/templates/person.tpl | 19 +- .../part-3/userGroupOption.xml | 11 +- 25 files changed, 579 insertions(+), 693 deletions(-) create mode 100644 snippets/tutorial/tutorial-series/part-3/files/acp/database/install_com.woltlab.wcf.people.php delete mode 100644 snippets/tutorial/tutorial-series/part-3/install.sql diff --git a/snippets/tutorial/tutorial-series/part-3/acpMenu.xml b/snippets/tutorial/tutorial-series/part-3/acpMenu.xml index 8ad2af2c..6ccf64fd 100644 --- a/snippets/tutorial/tutorial-series/part-3/acpMenu.xml +++ b/snippets/tutorial/tutorial-series/part-3/acpMenu.xml @@ -1,5 +1,5 @@ - + wcf.acp.menu.link.content diff --git a/snippets/tutorial/tutorial-series/part-3/acptemplates/personAdd.tpl b/snippets/tutorial/tutorial-series/part-3/acptemplates/personAdd.tpl index 0e369071..4cf2ec4a 100644 --- a/snippets/tutorial/tutorial-series/part-3/acptemplates/personAdd.tpl +++ b/snippets/tutorial/tutorial-series/part-3/acptemplates/personAdd.tpl @@ -14,59 +14,6 @@ -{include file='formNotice'} - -
-
- -
-
- - {if $errorField == 'firstName'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {else} - {lang}wcf.acp.person.firstName.error.{$errorType}{/lang} - {/if} - - {/if} -
- - - -
-
- - {if $errorField == 'lastName'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {else} - {lang}wcf.acp.person.lastName.error.{$errorType}{/lang} - {/if} - - {/if} -
- - -
-
-
- - {lang}wcf.person.enableComments.description{/lang} -
-
- - {event name='dataFields'} -
- - {event name='sections'} - -
- - {csrfToken} -
-
+{@$form->getHtml()} {include file='footer'} diff --git a/snippets/tutorial/tutorial-series/part-3/acptemplates/personList.tpl b/snippets/tutorial/tutorial-series/part-3/acptemplates/personList.tpl index fc7dc36e..71766eff 100644 --- a/snippets/tutorial/tutorial-series/part-3/acptemplates/personList.tpl +++ b/snippets/tutorial/tutorial-series/part-3/acptemplates/personList.tpl @@ -21,8 +21,8 @@ {/hascontent} {if $objects|count} -
- +
+
@@ -35,10 +35,10 @@ {foreach from=$objects item=person} - + @@ -72,10 +72,4 @@

{lang}wcf.global.noItems{/lang}

{/if} - - {include file='footer'} diff --git a/snippets/tutorial/tutorial-series/part-3/files/acp/database/install_com.woltlab.wcf.people.php b/snippets/tutorial/tutorial-series/part-3/files/acp/database/install_com.woltlab.wcf.people.php new file mode 100644 index 00000000..895cbe52 --- /dev/null +++ b/snippets/tutorial/tutorial-series/part-3/files/acp/database/install_com.woltlab.wcf.people.php @@ -0,0 +1,21 @@ +columns([ + ObjectIdDatabaseTableColumn::create('personID'), + NotNullVarchar255DatabaseTableColumn::create('firstName'), + NotNullVarchar255DatabaseTableColumn::create('lastName'), + SmallintDatabaseTableColumn::create('comments') + ->length(5) + ->notNull() + ->defaultValue(0), + DefaultTrueBooleanDatabaseTableColumn::create('enableComments'), + ]), +]; diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/acp/form/PersonAddForm.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/acp/form/PersonAddForm.class.php index 7e6de521..565274d1 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/acp/form/PersonAddForm.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/acp/form/PersonAddForm.class.php @@ -1,123 +1,75 @@ - * @package WoltLabSuite\Core\Acp\Form + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Acp\Form */ -class PersonAddForm extends AbstractForm { - /** - * @inheritDoc - */ - public $activeMenuItem = 'wcf.acp.menu.link.person.add'; - - /** - * is `1` if comments are enabled for the person, otherwise `0` - * @var integer - */ - public $enableComments = 1; - - /** - * first name of the person - * @var string - */ - public $firstName = ''; - - /** - * last name of the person - * @var string - */ - public $lastName = ''; - - /** - * @inheritDoc - */ - public $neededPermissions = ['admin.content.canManagePeople']; - - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign([ - 'action' => 'add', - 'enableComments' => $this->enableComments, - 'firstName' => $this->firstName, - 'lastName' => $this->lastName - ]); - } - - /** - * @inheritDoc - */ - public function readFormParameters() { - parent::readFormParameters(); - - $this->enableComments = isset($_POST['enableComments']) ? 1 : 0; - if (isset($_POST['firstName'])) $this->firstName = StringUtil::trim($_POST['firstName']); - if (isset($_POST['lastName'])) $this->lastName = StringUtil::trim($_POST['lastName']); - } - - /** - * @inheritDoc - */ - public function save() { - parent::save(); - - $this->objectAction = new PersonAction([], 'create', [ - 'data' => array_merge($this->additionalFields, [ - 'enableComments' => $this->enableComments, - 'firstName' => $this->firstName, - 'lastName' => $this->lastName - ]) - ]); - $returnValues = $this->objectAction->executeAction(); - - $this->saved(); - - // reset values - $this->enableComments = 1; - $this->firstName = ''; - $this->lastName = ''; - - // show success message - WCF::getTPL()->assign([ - 'success' => true, - 'objectEditLink' => LinkHandler::getInstance()->getControllerLink(PersonEditForm::class, ['id' => $returnValues['returnValues']->personID]), - ]); - } - - /** - * @inheritDoc - */ - public function validate() { - parent::validate(); - - // validate first name - if (empty($this->firstName)) { - throw new UserInputException('firstName'); - } - if (mb_strlen($this->firstName) > 255) { - throw new UserInputException('firstName', 'tooLong'); - } - - // validate last name - if (empty($this->lastName)) { - throw new UserInputException('lastName'); - } - if (mb_strlen($this->lastName) > 255) { - throw new UserInputException('lastName', 'tooLong'); - } - } +class PersonAddForm extends AbstractFormBuilderForm +{ + /** + * @inheritDoc + */ + public $activeMenuItem = 'wcf.acp.menu.link.person.add'; + + /** + * @inheritDoc + */ + public $formAction = 'create'; + + /** + * @inheritDoc + */ + public $neededPermissions = ['admin.content.canManagePeople']; + + /** + * @inheritDoc + */ + public $objectActionClass = PersonAction::class; + + /** + * @inheritDoc + */ + public $objectEditLinkController = PersonEditForm::class; + + /** + * @inheritDoc + */ + public function createForm() + { + parent::createForm(); + + $this->form->appendChild( + FormContainer::create('data') + ->label('wcf.global.form.data') + ->appendChildren([ + TextFormField::create('firstName') + ->label('wcf.person.firstName') + ->required() + ->autoFocus() + ->maximumLength(255), + + TextFormField::create('lastName') + ->label('wcf.person.lastName') + ->required() + ->maximumLength(255), + + BooleanFormField::create('enableComments') + ->label('wcf.person.enableComments') + ->description('wcf.person.enableComments.description') + ->value(true), + ]) + ); + } } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/acp/form/PersonEditForm.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/acp/form/PersonEditForm.class.php index 1cb63335..47c2b765 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/acp/form/PersonEditForm.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/acp/form/PersonEditForm.class.php @@ -1,93 +1,43 @@ - * @package WoltLabSuite\Core\Acp\Form + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Acp\Form */ -class PersonEditForm extends PersonAddForm { - /** - * @inheritDoc - */ - public $activeMenuItem = 'wcf.acp.menu.link.person'; - - /** - * edited person object - * @var Person - */ - public $person = null; - - /** - * id of the edited person - * @var integer - */ - public $personID = 0; - - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign([ - 'action' => 'edit', - 'person' => $this->person - ]); - } - - /** - * @inheritDoc - */ - public function readData() { - parent::readData(); - - if (empty($_POST)) { - $this->enableComments = $this->person->enableComments; - $this->firstName = $this->person->firstName; - $this->lastName = $this->person->lastName; - } - } - - /** - * @inheritDoc - */ - public function readParameters() { - parent::readParameters(); - - if (isset($_REQUEST['id'])) $this->personID = intval($_REQUEST['id']); - $this->person = new Person($this->personID); - if (!$this->person->personID) { - throw new IllegalLinkException(); - } - } - - /** - * @inheritDoc - */ - public function save() { - AbstractForm::save(); - - $this->objectAction = new PersonAction([$this->person], 'update', [ - 'data' => array_merge($this->additionalFields, [ - 'enableComments' => $this->enableComments, - 'firstName' => $this->firstName, - 'lastName' => $this->lastName - ]) - ]); - $this->objectAction->executeAction(); - - $this->saved(); - - // show success message - WCF::getTPL()->assign('success', true); - } +class PersonEditForm extends PersonAddForm +{ + /** + * @inheritDoc + */ + public $activeMenuItem = 'wcf.acp.menu.link.person'; + + /** + * @inheritDoc + */ + public $formAction = 'update'; + + /** + * @inheritDoc + */ + public function readParameters() + { + parent::readParameters(); + + if (isset($_REQUEST['id'])) { + $this->formObject = new Person($_REQUEST['id']); + + if (!$this->formObject->getObjectID()) { + throw new IllegalLinkException(); + } + } + } } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/acp/page/PersonListPage.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/acp/page/PersonListPage.class.php index a16f28dd..9d57855b 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/acp/page/PersonListPage.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/acp/page/PersonListPage.class.php @@ -1,34 +1,37 @@ - * @package WoltLabSuite\Core\Acp\Page + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Acp\Page */ -class PersonListPage extends SortablePage { - /** - * @inheritDoc - */ - public $activeMenuItem = 'wcf.acp.menu.link.person.list'; - - /** - * @inheritDoc - */ - public $neededPermissions = ['admin.content.canManagePeople']; - - /** - * @inheritDoc - */ - public $objectListClassName = PersonList::class; - - /** - * @inheritDoc - */ - public $validSortFields = ['personID', 'firstName', 'lastName']; +class PersonListPage extends SortablePage +{ + /** + * @inheritDoc + */ + public $activeMenuItem = 'wcf.acp.menu.link.person.list'; + + /** + * @inheritDoc + */ + public $neededPermissions = ['admin.content.canManagePeople']; + + /** + * @inheritDoc + */ + public $objectListClassName = PersonList::class; + + /** + * @inheritDoc + */ + public $validSortFields = ['personID', 'firstName', 'lastName']; } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/Person.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/Person.class.php index eaeb1085..d5c6d166 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/Person.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/Person.class.php @@ -1,48 +1,52 @@ - * @package WoltLabSuite\Core\Data\Person - * - * @property-read integer $personID unique id of the person - * @property-read string $firstName first name of the person - * @property-read string $lastName last name of the person - * @property-read integer $comments number of comments on the person - * @property-read integer $enableComments is `1` if comments are enabled for the person, otherwise `0` + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Data\Person + * + * @property-read integer $personID unique id of the person + * @property-read string $firstName first name of the person + * @property-read string $lastName last name of the person + * @property-read int $enableComments is `1` if comments are enabled for the person, otherwise `0` */ -class Person extends DatabaseObject implements ILinkableObject, IRouteController { - /** - * Returns the first and last name of the person if a person object is treated as a string. - * - * @return string - */ - public function __toString() { - return $this->getTitle(); - } - - /** - * @inheritDoc - */ - public function getLink() { - return LinkHandler::getInstance()->getLink('Person', [ - 'forceFrontend' => true, - 'object' => $this - ]); - } - - /** - * @inheritDoc - */ - public function getTitle() { - return $this->firstName . ' ' . $this->lastName; - } +class Person extends DatabaseObject implements ITitledLinkObject +{ + /** + * Returns the first and last name of the person if a person object is treated as a string. + * + * @return string + */ + public function __toString() + { + return $this->getTitle(); + } + + /** + * @inheritDoc + */ + public function getLink() + { + return LinkHandler::getInstance()->getControllerLink(PersonPage::class, [ + 'object' => $this, + ]); + } + + /** + * @inheritDoc + */ + public function getTitle() + { + return $this->firstName . ' ' . $this->lastName; + } } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonAction.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonAction.class.php index d76b9267..3f346556 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonAction.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonAction.class.php @@ -1,27 +1,30 @@ - * @package WoltLabSuite\Core\Data\Person * - * @method Person create() - * @method PersonEditor[] getObjects() - * @method PersonEditor getSingleObject() + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Data\Person + * + * @method Person create() + * @method PersonEditor[] getObjects() + * @method PersonEditor getSingleObject() */ -class PersonAction extends AbstractDatabaseObjectAction { - /** - * @inheritDoc - */ - protected $permissionsDelete = ['admin.content.canManagePeople']; - - /** - * @inheritDoc - */ - protected $requireACP = ['delete']; +class PersonAction extends AbstractDatabaseObjectAction +{ + /** + * @inheritDoc + */ + protected $permissionsDelete = ['admin.content.canManagePeople']; + + /** + * @inheritDoc + */ + protected $requireACP = ['delete']; } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonEditor.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonEditor.class.php index 3890bc10..b8d5a3ce 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonEditor.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonEditor.class.php @@ -1,22 +1,25 @@ - * @package WoltLabSuite\Core\Data\Person - * - * @method static Person create(array $parameters = []) - * @method Person getDecoratedObject() - * @mixin Person + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Data\Person + * + * @method static Person create(array $parameters = []) + * @method Person getDecoratedObject() + * @mixin Person */ -class PersonEditor extends DatabaseObjectEditor { - /** - * @inheritDoc - */ - protected static $baseClass = Person::class; +class PersonEditor extends DatabaseObjectEditor +{ + /** + * @inheritDoc + */ + protected static $baseClass = Person::class; } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonList.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonList.class.php index bedf543c..4e16a0d0 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonList.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/data/person/PersonList.class.php @@ -1,18 +1,22 @@ - * @package WoltLabSuite\Core\Data\Person - * - * @method Person current() - * @method Person[] getObjects() - * @method Person|null search($objectID) - * @property Person[] $objects + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Data\Person + * + * @method Person current() + * @method Person[] getObjects() + * @method Person|null search($objectID) + * @property Person[] $objects */ -class PersonList extends DatabaseObjectList {} +class PersonList extends DatabaseObjectList +{ +} diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonListPage.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonListPage.class.php index 839b3e2a..5fbacd44 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonListPage.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonListPage.class.php @@ -1,28 +1,31 @@ - * @package WoltLabSuite\Core\Page + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Page */ -class PersonListPage extends SortablePage { - /** - * @inheritDoc - */ - public $defaultSortField = 'lastName'; - - /** - * @inheritDoc - */ - public $objectListClassName = PersonList::class; - - /** - * @inheritDoc - */ - public $validSortFields = ['personID', 'firstName', 'lastName']; +class PersonListPage extends SortablePage +{ + /** + * @inheritDoc + */ + public $defaultSortField = 'lastName'; + + /** + * @inheritDoc + */ + public $objectListClassName = PersonList::class; + + /** + * @inheritDoc + */ + public $validSortFields = ['personID', 'firstName', 'lastName']; } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonPage.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonPage.class.php index d68c0d73..24be70a8 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonPage.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/page/PersonPage.class.php @@ -1,5 +1,7 @@ - * @package WoltLabSuite\Core\Page + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\Page */ -class PersonPage extends AbstractPage { - /** - * list of comments - * @var StructuredCommentList - */ - public $commentList; - - /** - * person comment manager object - * @var PersonCommentManager - */ - public $commentManager; - - /** - * id of the person comment object type - * @var integer - */ - public $commentObjectTypeID = 0; - - /** - * shown person - * @var Person - */ - public $person; - - /** - * id of the shown person - * @var integer - */ - public $personID = 0; - - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign([ - 'commentCanAdd' => WCF::getSession()->getPermission('user.person.canAddComment'), - 'commentList' => $this->commentList, - 'commentObjectTypeID' => $this->commentObjectTypeID, - 'lastCommentTime' => $this->commentList ? $this->commentList->getMinCommentTime() : 0, - 'likeData' => (MODULE_LIKE && $this->commentList) ? $this->commentList->getLikeData() : [], - 'person' => $this->person - ]); - } - - /** - * @inheritDoc - */ - public function readData() { - parent::readData(); - - if ($this->person->enableComments) { - $this->commentObjectTypeID = CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.person.personComment'); - $this->commentManager = CommentHandler::getInstance()->getObjectType($this->commentObjectTypeID)->getProcessor(); - $this->commentList = CommentHandler::getInstance()->getCommentList($this->commentManager, $this->commentObjectTypeID, $this->person->personID); - } - } - - /** - * @inheritDoc - */ - public function readParameters() { - parent::readParameters(); - - if (isset($_REQUEST['id'])) $this->personID = intval($_REQUEST['id']); - $this->person = new Person($this->personID); - if (!$this->person->personID) { - throw new IllegalLinkException(); - } - } +class PersonPage extends AbstractPage +{ + /** + * list of comments + * @var StructuredCommentList + */ + public $commentList; + + /** + * person comment manager object + * @var PersonCommentManager + */ + public $commentManager; + + /** + * id of the person comment object type + * @var integer + */ + public $commentObjectTypeID = 0; + + /** + * shown person + * @var Person + */ + public $person; + + /** + * id of the shown person + * @var integer + */ + public $personID = 0; + + /** + * @inheritDoc + */ + public function assignVariables() + { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'commentCanAdd' => WCF::getSession()->getPermission('user.person.canAddComment'), + 'commentList' => $this->commentList, + 'commentObjectTypeID' => $this->commentObjectTypeID, + 'lastCommentTime' => $this->commentList ? $this->commentList->getMinCommentTime() : 0, + 'likeData' => MODULE_LIKE && $this->commentList ? $this->commentList->getLikeData() : [], + 'person' => $this->person, + ]); + } + + /** + * @inheritDoc + */ + public function readData() + { + parent::readData(); + + if ($this->person->enableComments) { + $this->commentObjectTypeID = CommentHandler::getInstance()->getObjectTypeID( + 'com.woltlab.wcf.person.personComment' + ); + $this->commentManager = CommentHandler::getInstance()->getObjectType( + $this->commentObjectTypeID + )->getProcessor(); + $this->commentList = CommentHandler::getInstance()->getCommentList( + $this->commentManager, + $this->commentObjectTypeID, + $this->person->personID + ); + } + } + + /** + * @inheritDoc + */ + public function readParameters() + { + parent::readParameters(); + + if (isset($_REQUEST['id'])) { + $this->personID = \intval($_REQUEST['id']); + } + $this->person = new Person($this->personID); + if (!$this->person->personID) { + throw new IllegalLinkException(); + } + } } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/system/cache/runtime/PersonRuntimeCache.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/system/cache/runtime/PersonRuntimeCache.class.php index db63fdee..1f9a67f8 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/system/cache/runtime/PersonRuntimeCache.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/system/cache/runtime/PersonRuntimeCache.class.php @@ -1,24 +1,26 @@ - * @package WoltLabSuite\Core\System\Cache\Runtime - * @since 3.0 + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Cache\Runtime * - * @method Person[] getCachedObjects() - * @method Person getObject($objectID) - * @method Person[] getObjects(array $objectIDs) + * @method Person[] getCachedObjects() + * @method Person getObject($objectID) + * @method Person[] getObjects(array $objectIDs) */ -class PersonRuntimeCache extends AbstractRuntimeCache { - /** - * @inheritDoc - */ - protected $listClassName = PersonList::class; +class PersonRuntimeCache extends AbstractRuntimeCache +{ + /** + * @inheritDoc + */ + protected $listClassName = PersonList::class; } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/system/comment/manager/PersonCommentManager.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/system/comment/manager/PersonCommentManager.class.php index 0b35af23..6cbad9d9 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/system/comment/manager/PersonCommentManager.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/system/comment/manager/PersonCommentManager.class.php @@ -1,5 +1,7 @@ - * @package WoltLabSuite\Core\System\Comment\Manager + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Comment\Manager */ -class PersonCommentManager extends AbstractCommentManager { - /** - * @inheritDoc - */ - protected $permissionAdd = 'user.person.canAddComment'; - - /** - * @inheritDoc - */ - protected $permissionAddWithoutModeration = 'user.person.canAddCommentWithoutModeration'; - - /** - * @inheritDoc - */ - protected $permissionCanModerate = 'mod.person.canModerateComment'; - - /** - * @inheritDoc - */ - protected $permissionDelete = 'user.person.canDeleteComment'; - - /** - * @inheritDoc - */ - protected $permissionEdit = 'user.person.canEditComment'; - - /** - * @inheritDoc - */ - protected $permissionModDelete = 'mod.person.canDeleteComment'; - - /** - * @inheritDoc - */ - protected $permissionModEdit = 'mod.person.canEditComment'; - - /** - * @inheritDoc - */ - public function getLink($objectTypeID, $objectID) { - return PersonRuntimeCache::getInstance()->getObject($objectID)->getLink(); - } - - /** - * @inheritDoc - */ - public function isAccessible($objectID, $validateWritePermission = false) { - return PersonRuntimeCache::getInstance()->getObject($objectID) !== null; - } - - /** - * @inheritDoc - */ - public function getTitle($objectTypeID, $objectID, $isResponse = false) { - if ($isResponse) { - return WCF::getLanguage()->get('wcf.person.commentResponse'); - } - - return WCF::getLanguage()->getDynamicVariable('wcf.person.comment'); - } - - /** - * @inheritDoc - */ - public function updateCounter($objectID, $value) { - (new PersonEditor(new Person($objectID)))->updateCounters(['comments' => $value]); - } +class PersonCommentManager extends AbstractCommentManager +{ + /** + * @inheritDoc + */ + protected $permissionAdd = 'user.person.canAddComment'; + + /** + * @inheritDoc + */ + protected $permissionAddWithoutModeration = 'user.person.canAddCommentWithoutModeration'; + + /** + * @inheritDoc + */ + protected $permissionCanModerate = 'mod.person.canModerateComment'; + + /** + * @inheritDoc + */ + protected $permissionDelete = 'user.person.canDeleteComment'; + + /** + * @inheritDoc + */ + protected $permissionEdit = 'user.person.canEditComment'; + + /** + * @inheritDoc + */ + protected $permissionModDelete = 'mod.person.canDeleteComment'; + + /** + * @inheritDoc + */ + protected $permissionModEdit = 'mod.person.canEditComment'; + + /** + * @inheritDoc + */ + public function getLink($objectTypeID, $objectID) + { + return PersonRuntimeCache::getInstance()->getObject($objectID)->getLink(); + } + + /** + * @inheritDoc + */ + public function isAccessible($objectID, $validateWritePermission = false) + { + return PersonRuntimeCache::getInstance()->getObject($objectID) !== null; + } + + /** + * @inheritDoc + */ + public function getTitle($objectTypeID, $objectID, $isResponse = false) + { + if ($isResponse) { + return WCF::getLanguage()->get('wcf.person.commentResponse'); + } + + return WCF::getLanguage()->getDynamicVariable('wcf.person.comment'); + } + + /** + * @inheritDoc + */ + public function updateCounter($objectID, $value) + { + (new PersonEditor(new Person($objectID)))->updateCounters(['comments' => $value]); + } } diff --git a/snippets/tutorial/tutorial-series/part-3/files/lib/system/page/handler/PersonPageHandler.class.php b/snippets/tutorial/tutorial-series/part-3/files/lib/system/page/handler/PersonPageHandler.class.php index 58819b63..353900bb 100644 --- a/snippets/tutorial/tutorial-series/part-3/files/lib/system/page/handler/PersonPageHandler.class.php +++ b/snippets/tutorial/tutorial-series/part-3/files/lib/system/page/handler/PersonPageHandler.class.php @@ -1,5 +1,7 @@ - * @package WoltLabSuite\Core\System\Page\Handler + * + * @author Matthias Schmidt + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Page\Handler */ -class PersonPageHandler extends AbstractLookupPageHandler implements IOnlineLocationPageHandler { - use TOnlineLocationPageHandler; - - /** - * @inheritDoc - */ - public function getLink($objectID) { - return PersonRuntimeCache::getInstance()->getObject($objectID)->getLink(); - } - - /** - * Returns the textual description if a user is currently online viewing this page. - * - * @see IOnlineLocationPageHandler::getOnlineLocation() - * - * @param Page $page visited page - * @param UserOnline $user user online object with request data - * @return string - */ - public function getOnlineLocation(Page $page, UserOnline $user) { - if ($user->pageObjectID === null) { - return ''; - } - - $person = PersonRuntimeCache::getInstance()->getObject($user->pageObjectID); - if ($person === null) { - return ''; - } - - return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, ['person' => $person]); - } - - /** - * @inheritDoc - */ - public function isValid($objectID = null) { - return PersonRuntimeCache::getInstance()->getObject($objectID) !== null; - } - - /** - * @inheritDoc - */ - public function lookup($searchString) { - $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR'); - $conditionBuilder->add('person.firstName LIKE ?', ['%' . $searchString . '%']); - $conditionBuilder->add('person.lastName LIKE ?', ['%' . $searchString . '%']); - - $personList = new PersonList(); - $personList->getConditionBuilder()->add($conditionBuilder, $conditionBuilder->getParameters()); - $personList->readObjects(); - - $results = []; - foreach ($personList as $person) { - $results[] = [ - 'image' => 'fa-user', - 'link' => $person->getLink(), - 'objectID' => $person->personID, - 'title' => $person->getTitle() - ]; - } - - return $results; - } - - /** - * Prepares fetching all necessary data for the textual description if a user is currently online - * viewing this page. - * - * @see IOnlineLocationPageHandler::prepareOnlineLocation() - * - * @param Page $page visited page - * @param UserOnline $user user online object with request data - */ - public function prepareOnlineLocation(/** @noinspection PhpUnusedParameterInspection */Page $page, UserOnline $user) { - if ($user->pageObjectID !== null) { - PersonRuntimeCache::getInstance()->cacheObjectID($user->pageObjectID); - } - } +class PersonPageHandler extends AbstractLookupPageHandler implements IOnlineLocationPageHandler +{ + use TOnlineLocationPageHandler; + + /** + * @inheritDoc + */ + public function getLink($objectID) + { + return PersonRuntimeCache::getInstance()->getObject($objectID)->getLink(); + } + + /** + * Returns the textual description if a user is currently online viewing this page. + * + * @see IOnlineLocationPageHandler::getOnlineLocation() + * + * @param Page $page visited page + * @param UserOnline $user user online object with request data + * @return string + */ + public function getOnlineLocation(Page $page, UserOnline $user) + { + if ($user->pageObjectID === null) { + return ''; + } + + $person = PersonRuntimeCache::getInstance()->getObject($user->pageObjectID); + if ($person === null) { + return ''; + } + + return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.' . $page->identifier, ['person' => $person]); + } + + /** + * @inheritDoc + */ + public function isValid($objectID = null) + { + return PersonRuntimeCache::getInstance()->getObject($objectID) !== null; + } + + /** + * @inheritDoc + */ + public function lookup($searchString) + { + $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR'); + $conditionBuilder->add('person.firstName LIKE ?', ['%' . $searchString . '%']); + $conditionBuilder->add('person.lastName LIKE ?', ['%' . $searchString . '%']); + + $personList = new PersonList(); + $personList->getConditionBuilder()->add($conditionBuilder, $conditionBuilder->getParameters()); + $personList->readObjects(); + + $results = []; + foreach ($personList as $person) { + $results[] = [ + 'image' => 'fa-user', + 'link' => $person->getLink(), + 'objectID' => $person->personID, + 'title' => $person->getTitle(), + ]; + } + + return $results; + } + + /** + * Prepares fetching all necessary data for the textual description if a user is currently online + * viewing this page. + * + * @see IOnlineLocationPageHandler::prepareOnlineLocation() + * + * @param Page $page visited page + * @param UserOnline $user user online object with request data + */ + public function prepareOnlineLocation(Page $page, UserOnline $user) + { + if ($user->pageObjectID !== null) { + PersonRuntimeCache::getInstance()->cacheObjectID($user->pageObjectID); + } + } } diff --git a/snippets/tutorial/tutorial-series/part-3/install.sql b/snippets/tutorial/tutorial-series/part-3/install.sql deleted file mode 100644 index af5dfcb4..00000000 --- a/snippets/tutorial/tutorial-series/part-3/install.sql +++ /dev/null @@ -1,8 +0,0 @@ -DROP TABLE IF EXISTS wcf1_person; -CREATE TABLE wcf1_person ( - personID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, - firstName VARCHAR(255) NOT NULL, - lastName VARCHAR(255) NOT NULL, - comments SMALLINT(5) NOT NULL DEFAULT 0, - enableComments TINYINT(1) NOT NULL DEFAULT 1 -); diff --git a/snippets/tutorial/tutorial-series/part-3/language/de.xml b/snippets/tutorial/tutorial-series/part-3/language/de.xml index 1cf1af38..506326d4 100644 --- a/snippets/tutorial/tutorial-series/part-3/language/de.xml +++ b/snippets/tutorial/tutorial-series/part-3/language/de.xml @@ -1,15 +1,12 @@ - + - - - @@ -23,15 +20,12 @@ - {$person} wirklich löschen?]]> - - - getLink()}">{$person}]]> + diff --git a/snippets/tutorial/tutorial-series/part-3/language/en.xml b/snippets/tutorial/tutorial-series/part-3/language/en.xml index a7155b5f..e9f5dd6f 100644 --- a/snippets/tutorial/tutorial-series/part-3/language/en.xml +++ b/snippets/tutorial/tutorial-series/part-3/language/en.xml @@ -1,20 +1,17 @@ - + - - - - + @@ -23,15 +20,12 @@ - {$person}?]]> - - - + - getLink()}">{$person}]]> + diff --git a/snippets/tutorial/tutorial-series/part-3/menuItem.xml b/snippets/tutorial/tutorial-series/part-3/menuItem.xml index 378a2973..bcf3e04d 100644 --- a/snippets/tutorial/tutorial-series/part-3/menuItem.xml +++ b/snippets/tutorial/tutorial-series/part-3/menuItem.xml @@ -1,5 +1,5 @@ - + com.woltlab.wcf.MainMenu diff --git a/snippets/tutorial/tutorial-series/part-3/objectType.xml b/snippets/tutorial/tutorial-series/part-3/objectType.xml index acce4314..d8c50e0a 100644 --- a/snippets/tutorial/tutorial-series/part-3/objectType.xml +++ b/snippets/tutorial/tutorial-series/part-3/objectType.xml @@ -1,5 +1,5 @@ - + com.woltlab.wcf.person.personComment diff --git a/snippets/tutorial/tutorial-series/part-3/package.xml b/snippets/tutorial/tutorial-series/part-3/package.xml index 65191154..ecc46fd1 100644 --- a/snippets/tutorial/tutorial-series/part-3/package.xml +++ b/snippets/tutorial/tutorial-series/part-3/package.xml @@ -1,10 +1,10 @@ - + WoltLab Suite Core Tutorial: People Adds a simple management system for people as part of a tutorial to create packages. - 3.1.0 - 2018-03-30 + 5.4.0 + 2021-04-16 @@ -13,24 +13,19 @@ - com.woltlab.wcf + com.woltlab.wcf - com.woltlab.wcf + com.woltlab.wcf - - - - - + acp/database/install_com.woltlab.wcf.people.php - diff --git a/snippets/tutorial/tutorial-series/part-3/page.xml b/snippets/tutorial/tutorial-series/part-3/page.xml index 0e1ea88c..8270c57f 100644 --- a/snippets/tutorial/tutorial-series/part-3/page.xml +++ b/snippets/tutorial/tutorial-series/part-3/page.xml @@ -1,5 +1,5 @@ - + system diff --git a/snippets/tutorial/tutorial-series/part-3/templates/person.tpl b/snippets/tutorial/tutorial-series/part-3/templates/person.tpl index 8ccd8f90..4f6bebd2 100644 --- a/snippets/tutorial/tutorial-series/part-3/templates/person.tpl +++ b/snippets/tutorial/tutorial-series/part-3/templates/person.tpl @@ -8,19 +8,22 @@ {if $commentList|count || $commentCanAdd}
-

{lang}wcf.person.comments{/lang}{if $person->comments} {#$person->comments}{/if}

+

+ {lang}wcf.person.comments{/lang} + {if $person->comments}{#$person->comments}{/if} +

{include file='__commentJavaScript' commentContainerID='personCommentList'}
-
    +
      {include file='commentListAddComment' wysiwygSelector='personCommentListAddComment'} {include file='commentList'}
    diff --git a/snippets/tutorial/tutorial-series/part-3/userGroupOption.xml b/snippets/tutorial/tutorial-series/part-3/userGroupOption.xml index 044394af..bb2e311e 100644 --- a/snippets/tutorial/tutorial-series/part-3/userGroupOption.xml +++ b/snippets/tutorial/tutorial-series/part-3/userGroupOption.xml @@ -1,18 +1,16 @@ - + mod - user - - - - - - - - -- 2.20.1
{lang}wcf.global.objectID{/lang}
- + {objectAction action="delete" objectTitle=$person->getTitle()} {event name='rowButtons'}