From 589e650403ea064332f8b4e4c3b7c9215bce78f8 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 8 Jul 2021 14:52:50 +0200 Subject: [PATCH] Fix code for several codeboxes --- docs/php/api/sitemaps.md | 6 ++--- docs/php/api/user_notifications.md | 30 ++++++++++++------------- docs/php/code-style.md | 6 ++--- docs/php/database-objects.md | 36 +++++++++++++++--------------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/docs/php/api/sitemaps.md b/docs/php/api/sitemaps.md index 9ad079e5..68fce681 100644 --- a/docs/php/api/sitemaps.md +++ b/docs/php/api/sitemaps.md @@ -27,9 +27,9 @@ Other optional methods are: As an example, the implementation for users looks like this: {jinja{ codebox( - "php", - "php/api/sitemaps/UserSitemapObject.class.php", - "files/lib/system/sitemap/object/UserSitemapObject.class.php" + title="files/lib/system/sitemap/object/UserSitemapObject.class.php", + language="php", + filepath="php/api/sitemaps/UserSitemapObject.class.php" ) }} Next, the sitemap object must be registered as an object type: diff --git a/docs/php/api/user_notifications.md b/docs/php/api/user_notifications.md index 52330202..e063f3a8 100644 --- a/docs/php/api/user_notifications.md +++ b/docs/php/api/user_notifications.md @@ -8,26 +8,26 @@ WoltLab Suite includes a powerful user notification system that supports notific For any type of object related to events, you have to define an object type for the object type definition `com.woltlab.wcf.notification.objectType`: {jinja{ codebox( - "xml", - "php/api/user_notifications/objectType.xml", - "objectType.xml" + title="objectType.xml", + language="xml", + filepath="php/api/user_notifications/objectType.xml" ) }} The referenced class `FooUserNotificationObjectType` has to implement the [IUserNotificationObjectType](https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/system/user/notification/object/type/IUserNotificationObjectType.class.php) interface, which should be done by extending [AbstractUserNotificationObjectType](https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/system/user/notification/object/type/AbstractUserNotificationObjectType.class.php). {jinja{ codebox( - "php", - "php/api/user_notifications/FooUserNotificationObjectType.class.php", - "files/lib/system/user/notification/object/type/FooUserNotificationObjectType.class.php" + title="files/lib/system/user/notification/object/type/FooUserNotificationObjectType.class.php", + language="php", + filepath="php/api/user_notifications/FooUserNotificationObjectType.class.php" ) }} You have to set the class names of the database object (`$objectClassName`) and the related list (`$objectListClassName`). Additionally, you have to create a class that implements the [IUserNotificationObject](https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/system/user/notification/object/IUserNotificationObject.class.php) whose name you have to set as the value of the `$decoratorClassName` property. {jinja{ codebox( - "php", - "php/api/user_notifications/FooUserNotificationObject.class.php", - "files/lib/system/user/notification/object/FooUserNotificationObject.class.php" + title="files/lib/system/user/notification/object/FooUserNotificationObject.class.php", + language="php", + filepath="php/api/user_notifications/FooUserNotificationObject.class.php" ) }} - The `getTitle()` method returns the title of the object. @@ -44,9 +44,9 @@ Each event that you fire in your package needs to be registered using the [user An example file might look like this: {jinja{ codebox( - "xml", - "php/api/user_notifications/userNotificationEvent.xml", - "userNotificationEvent.xml" + title="userNotificationEvent.xml", + language="xml", + filepath="php/api/user_notifications/userNotificationEvent.xml" ) }} Here, you reference the user notification object type created via `objectType.xml`. @@ -54,9 +54,9 @@ The referenced class in the `` element has to implement the [IUserNot In `AbstractSharedUserNotificationEvent::prepare()`, you can, for example, tell runtime caches to prepare to load certain objects which then are loaded all at once when the objects are needed. {jinja{ codebox( - "php", - "php/api/user_notifications/FooUserNotificationEvent.class.php", - "files/lib/system/user/notification/event/FooUserNotificationEvent.class.php" + title="files/lib/system/user/notification/event/FooUserNotificationEvent.class.php", + language="php", + filepath="php/api/user_notifications/FooUserNotificationEvent.class.php" ) }} - The `$stackable` property is `false` by default and has to be explicitly set to `true` if stacking of notifications should be enabled. diff --git a/docs/php/code-style.md b/docs/php/code-style.md index cdbe9ea1..f10ae015 100644 --- a/docs/php/code-style.md +++ b/docs/php/code-style.md @@ -146,9 +146,9 @@ $className = Example::class; Some database objects provide static getters, either if they are decorators or for a unique combination of database table columns, like `wcf\data\box\Box::getBoxByIdentifier()`: {jinja{ codebox( - "php", - "php/code-style/Box.class.php", - "files/lib/data/box/Box.class.php" + title="files/lib/data/box/Box.class.php", + language="php", + filepath="php/code-style/Box.class.php" ) }} Such methods should always either return the desired object or `null` if the object does not exist. diff --git a/docs/php/database-objects.md b/docs/php/database-objects.md index de6e178c..2fb99e08 100644 --- a/docs/php/database-objects.md +++ b/docs/php/database-objects.md @@ -10,9 +10,9 @@ Developers are required to provide the proper DatabaseObject implementations the The basic model derives from `wcf\data\DatabaseObject` and provides a convenient constructor to fetch a single row or construct an instance using pre-loaded rows. {jinja{ codebox( - "php", - "php/database-objects/Example.class.php", - "files/lib/data/example/Example.class.php" + title="files/lib/data/example/Example.class.php", + language="php", + filepath="php/database-objects/Example.class.php" ) }} The class is intended to be empty by default and there only needs to be code if you want to add additional logic to your model. Both the class name and primary key are determined by `DatabaseObject` using the namespace and class name of the derived class. The example above uses the namespace `wcf\…` which is used as table prefix and the class name `Example` is converted into `exampleID`, resulting in the database table name `wcfN_example` with the primary key `exampleID`. @@ -25,9 +25,9 @@ You can prevent this automatic guessing by setting the class properties `$databa If you already have a `DatabaseObject` class and would like to extend it with additional data or methods, for example by providing a class `ViewableExample` which features view-related changes without polluting the original object, you can use `DatabaseObjectDecorator` which a default implementation of a decorator for database objects. {jinja{ codebox( - "php", - "php/database-objects/ViewableExample.class.php", - "files/lib/data/example/ViewableExample.class.php" + title="files/lib/data/example/ViewableExample.class.php", + language="php", + filepath="php/database-objects/ViewableExample.class.php" ) }} It is mandatory to set the static `$baseClass` property to the name of the decorated class. @@ -43,9 +43,9 @@ You can access the decorated objects directly via `DatabaseObjectDecorator::getD Adding, editing and deleting models is done using the `DatabaseObjectEditor` class that decorates a `DatabaseObject` and uses its data to perform the actions. {jinja{ codebox( - "php", - "php/database-objects/ExampleEditor.class.php", - "files/lib/data/example/ExampleEditor.class.php" + title="files/lib/data/example/ExampleEditor.class.php", + language="php", + filepath="php/database-objects/ExampleEditor.class.php" ) }} The editor class requires you to provide the fully qualified name of the model, that is the class name including the complete namespace. Database table name and index key will be pulled directly from the model. @@ -103,9 +103,9 @@ $exampleEditor->delete(); Every row is represented as a single instance of the model, but the instance creation deals with single rows only. Retrieving larger sets of rows would be quite inefficient due to the large amount of queries that will be dispatched. This is solved with the `DatabaseObjectList` object that exposes an interface to query the database table using arbitrary conditions for data selection. All rows will be fetched using a single query and the resulting rows are automatically loaded into separate models. {jinja{ codebox( - "php", - "php/database-objects/ExampleList.class.php", - "files/lib/data/example/ExampleList.class.php" + title="files/lib/data/example/ExampleList.class.php", + language="php", + filepath="php/database-objects/ExampleList.class.php" ) }} The following code listing illustrates loading a large set of examples and iterating over the list to retrieve the objects. @@ -163,9 +163,9 @@ $exampleList->decoratorClassName = \wcf\data\example\ViewableExample::class; Of course, you do not have to set the property after creating the list object, you can also set it by creating a dedicated class: {jinja{ codebox( - "php", - "php/database-objects/ViewableExampleList.class.php", - "files/lib/data/example/ViewableExampleList.class.php" + title="files/lib/data/example/ViewableExampleList.class.php", + language="php", + filepath="php/database-objects/ViewableExampleList.class.php" ) }} @@ -179,9 +179,9 @@ Row creation and manipulation can be performed using the aforementioned `Databas The `AbstractDatabaseObjectAction` solves both problems by wrapping around the editor class and thus provide an additional layer between the action that should be taken and the actual process. The first problem is solved by a fixed set of events being fired, the second issue is addressed by having a single entry point for all data editing. {jinja{ codebox( - "php", - "php/database-objects/ExampleAction.class.php", - "files/lib/data/example/ExampleAction.class.php" + title="files/lib/data/example/ExampleAction.class.php", + language="php", + filepath="php/database-objects/ExampleAction.class.php" ) }} ### Executing an Action -- 2.20.1