PubKit uses PHP classes to keep specific features of item types together and simplify the core creating/updating loop.There are two base classes, Resource and Record.
Resource is the default class, and uses the existing Document class by ur001 to create, retrieve, update and delete MODX resources (documents).
The Record class contains general functions for these operations using database tables. PubKit does not include any means to create the custom tables. You need to use a MODx module, phpMyAdmin or equivalent facilities to do that.
Both base classes provide shared initialization and data verification functions for the various item types.
The item types, such as Post, Event and the sample Player class, extend the base classes. In addition to the properties and methods of the base classes, they can declare their own properties and methods as required, including specialized initialization and save operations, either replacing or adding to the parent class's properties and methods.
All of the PubKit snippet call's parameters are supplied to the class as an array called params within the fields array. (See Record class for example of this)
Standard tasks for a class are:
- CRUD: Create, Retrieve, Update and Delete an item and its data
- List template variables used by the item type, and copy data between them and the fields array, with transformations where necessary
- (Record) list database columns the Save function must handle
- (Resource) list extra document fields used by the item type
- Specify a chunk to use for confirming deletions, initalize the deletion message
- List the fields to be validated, their status (required, optional) and the error message to be picked from the language file if needed.