Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:entwickler:changelog_implementation [2025/02/16 11:10] – [Part C: Steps to Extend the Admidio Core with a New Module / Plugin] kainhofer | en:entwickler:changelog_implementation [2025/03/21 08:55] (current) – kainhofer | ||
---|---|---|---|
Line 5: | Line 5: | ||
Starting with Admidio 5.0, all changes to objects (Users, Events, Groups/ | Starting with Admidio 5.0, all changes to objects (Users, Events, Groups/ | ||
- | }{{: | + | {{: |
Line 179: | Line 179: | ||
* The raw database table name is translated into a nice label by the '' | * The raw database table name is translated into a nice label by the '' | ||
* Object name: The display name is already stored in the adm_log_changes table. The changelog page first tries to translate it using '' | * Object name: The display name is already stored in the adm_log_changes table. The changelog page first tries to translate it using '' | ||
- | * If a record has a related record stored in the changelog, the same is done for the related record. By default, the related record uses the same object type. If this is not desired (e.g. a File has its parent folder as its related object), then one has to change the '' | + | * If a record has a related record stored in the changelog, the same is done for the related record. By default, the related record uses the same object type. If this is not desired (e.g. a File has its parent folder as its related object), then one has to change the '' |
* To translate the raw database column names (or field names in general) into nice labels, and define data types for it values, the '' | * To translate the raw database column names (or field names in general) into nice labels, and define data types for it values, the '' | ||
<code php> | <code php> | ||
Line 219: | Line 219: | ||
===== Links to Related Objects of a Different Type ===== | ===== Links to Related Objects of a Different Type ===== | ||
- | By default, if a record has a related object, it will be formatted and linked with the same object type. E.g. if a folder has a parent folder (set as related record in the changelog table), the parent folder will also be formatted as a folder and a link to the folder page created. In many cases this is not desired, e.g. a File is related to its parent folder, which cannot be formatted as File, but rather as folder. This needs to be added to the file '' | + | By default, if a record has a related object, it will be formatted and linked with the same object type. E.g. if a folder has a parent folder (set as related record in the changelog table), the parent folder will also be formatted as a folder and a link to the folder page created. In many cases this is not desired, e.g. a File is related to its parent folder, which cannot be formatted as File, but rather as folder. This needs to be added to the method '' |
<code php> | <code php> | ||
- | if ($row[' | + | case ' |
- | | + | |
- | } | + | |
</ | </ | ||
Line 271: | Line 270: | ||
====== Part C: Steps to Extend the Admidio Core with a New Module / Plugin ====== | ====== Part C: Steps to Extend the Admidio Core with a New Module / Plugin ====== | ||
- | At the example of the Forum module' | + | At the example of the Forum module' |
+ | |||
+ | The example of the forum module is taken directly from the admidio code tree ([[https:// | ||
- **A: Preparation / General setup for forum logging** | - **A: Preparation / General setup for forum logging** | ||
Line 367: | Line 368: | ||
</ | </ | ||
- **Format links to related objects (in the " | - **Format links to related objects (in the " | ||
- | - In the change history view (file '' | + | - In method |
- | if ($row[' | + | case ' |
- | | + | |
- | } | + | case ' |
- | if ($row[' | + | |
- | | + | |
- | } | + | |
</ | </ | ||
- **Object name in changelog headline**: Create empty Topic and Post objects for given tables name ' | - **Object name in changelog headline**: Create empty Topic and Post objects for given tables name ' | ||
Line 395: | Line 394: | ||
====== Part D: Additional Steps for Third-Party Extensions ====== | ====== Part D: Additional Steps for Third-Party Extensions ====== | ||
+ | Adding support for changelogs in third-party extensions, where modifying the core Admidio code is not possible, works similar to the above steps. Modifying the changelog entry creation is implemented inside the extension' | ||
- | ======= TODO ======= | ||
- | * How to add new tables/objects | + | However, the ChanglogService class additionally provides a way to register mapping |
- | | + | * Register a callback function or value for the changelog functionality. If the callback is a value (string, array, etc.), it will |
- | | + | * be returned. If the callback is a function, it will be executed and if the return value is not empty, it will be returned. If the |
- | | + | * function returns a null or empty value, the next callback or the default processing of the ChangelogService method will proceed. |
- | * adding data types to DB columns | + | * @param string $function The method of the ChangelogService class that should be customized. One of |
- | | + | |
- | | + | |
- | | + | * @param string $moduleOrKey The module or type that should be customized. If empty, the callback will be |
- | * | + | |
- | + | * @param mixed $callback The callback function or value. A value will be returned unchanged, a function will | |
+ | be executed (arguments are identical | ||
+ | */ | ||
+ | static ChangelogService:: | ||
+ | |||
+ | Using these callback mechanisms, the forum changelog described above could also be implemented with the following code. It should be executed somewhere during php startup when the third-party module is loaded, and before either a changelog page can be displayed | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | ## Translation of database tables | ||
+ | ChangelogService:: | ||
+ | ChangelogService:: | ||
+ | |||
+ | ## Translations and type definitions of database columns | ||
+ | ChangelogService:: | ||
+ | | ||
+ | | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ]); | ||
+ | |||
+ | ## Formatting of new database column types (in many cases not needed) | ||
+ | ChangelogService:: | ||
+ | | ||
+ | if (empty($value)) return ''; | ||
+ | $obj = new Topic($gDb, $value?? | ||
+ | return ChangelogService:: | ||
+ | $obj-> | ||
+ | }); | ||
+ | ChangelogService:: | ||
+ | global $gDb; | ||
+ | if (empty($value)) return ''; | ||
+ | $obj = new POST($gDb, $value?? | ||
+ | return ChangelogService:: | ||
+ | $obj-> | ||
+ | }); | ||
+ | |||
+ | ## Create HTML links to the object' | ||
+ | ChangelogService:: | ||
+ | | ||
+ | array(' | ||
+ | }); | ||
+ | ChangelogService:: | ||
+ | | ||
+ | array(' | ||
+ | }); | ||
+ | |||
+ | ## Object types of related objects (if object relations are used at all!) | ||
+ | ChangelogService:: | ||
+ | ChangelogService:: | ||
+ | |||
+ | |||
+ | ## Create Entity-derived objects to create headlines with proper object names | ||
+ | ChangelogService:: | ||
+ | ChangelogService:: | ||
+ | |||
+ | ## Enable per-user detection | ||
+ | ChangelogService:: | ||
+ | | ||
+ | | ||
+ | }); | ||
+ | </ |