Artaengine provides two ways for storing and retrieving data. One is the conventional way of using an abstract database object and working directly on a relational database. The other way is by an object oriented approach where the data entities are declared by classes. Data attributes are defined as class properties and methods. The default basic actions for storing and getting data are inherited from an Artaengine library class and other actions can be defined within each data model class. Artaengine will use a relational database for storing and querying model data.
Benefits of data modeling over conventional:
Data entities are only defined inside the application by model classes and Artaengine will take care of building the database relations needed for the data models to work. There is no need to manually do anything on the database. Even when a model is changed Artaengine takes care of synchronizing the database with the models (unless changes violate the data integrity).
Data is accessed and manipulated by creating objects of models. Project codes will be very clean and encapsulated. Anything outside data models will not be involved with the data definitions.
Everything about a data entity is defined within the model. Application codes will be clean and readable and easy to maintenance. Small or dramatic changes to data structures can be done by only changing the model definitions without the need to touch and adopt other parts of the application.
Model objects can be used in foreach statements and templates for retrieving data. Things can be very easy for example methods for formatting data can be defined within a model class and used instead of the original data properties to get formatted data inside a template.
Models inherit from Artaengine Model class which provides high level functionalities such as:
Data manipulating methods take care of basic things such as data integrity and preventing SQL injections.
Property data can be defined as multi lingual.
Trigger methods and mid-ware methods can be defined to format or change data before storing or getting the data.
Data can be queries in pages and paging HTML links will be provided.
Methods understand transactions.
Models create a standard data platform. There is no need to manually create forms, tables, sort, do validation... Models contain all the required descriptions of a data entity. Artaengine provides classes that perform automated actions on the models for example:
Creating and submiting data entry forms (add/update).
Creating search forms and querying model data based on the submitted data.
Model data properties define themselves so well that things like labels, widgets and relations with other models are all taken care of.
Import or export data.
Batch different model objects, to do activities on more models in a single transaction.
Get all relations between models. A sample usage is to show a tree of affected data after deleting a model data entry.
Beside the model libraries provided by Artaengine, you can create generic plugins and tools for the models.
Artaengine provides a lot of data about models (application data entities) such as relations and dependencies between models. This high level data can help to create documents, charts and graphs for the projects.
Where to start
Note that Artaengine project administrator can be used to make the config files and create the model classes and files instead of the steps shown below.
Buildout. Each time one or more models are changed (usually only if the data properties are changed) rebuild the application to synchronize the changes with the database.
You can have any number of model groups in an application. Each group can only use one database as repo.
There is no force to use models, only use models if it makes sense for you. Whenever you feel its more easy or efficient use the database abstract object to access the database instead of the models. You can even have methods in a model which access the database by the abstract object. Outside a model $modelObj->___dbo___; and inside a model $this->___dbo___; gives a reference to the database abstract instance which the model is using.
Under the hood
Below is a class diagram of Artaengine classes and an example application that uses models:
Classes inside the brown box build the application. Class Models is responsible for working on model classes and creating/synchronizing models with database. This class is able to create/edit model PHP files, create data files about models and anything about managing models from above. Artaengine uses this part of the library for model works. Models can also be used inside the application for manipulating model files, for example you can create forms for dynamically adding/editing/removing data properties of models. Using Models on the back-end edit model PHP files and then synchronize the database with the new layout.
The dark pink box contains the main classes which models are derived from. Model is the parent class for every model. The other classes in this section are helper classes which do things on more than one model or model object.
The light pink box contains classes which get a model object and do things such as rendering forms and tables.
Classes inside the blue box are database abstract/advanced layers and database object factory. This part of Artaengine is used by models as repo and by the builder classes for model/database compare and synchronizing.
The light blue box contains cache abstract classes and cache object factory. Some classes associated with models are able to cache data and rendered HTML to gain performance using this classes.
Artaengine models create and use relations on databases. Tables and views created by Artaengine are very simple with the same names used in the models. When needed developers can use this tables in the conventional ways. Also Artaengine can not analyze the database and enhance it, analyzing database and creating indexes must be done manually. Models can use any of the DBMS supported by Artaengine. MySQL and PostgreSQL are have been supported from the early versions, other DBMS support will be added later.