We will now look at the TemplateMerger class. The template merger class is used to display PHP template files. It provides language contants, includes header and footer templates if they are available and makes variables passed from the controller available to the template.
Some controllers use the alternate class FormCreator, which is similar to TemplateMerger, but the FormCreator is deprecated and should not be used for in code.
21
TemplateMerger
Language constants
Makes special variables available to template (eg $stylesheet)
Includes header and footer templates (if available)
Here we look at a code extract from the TemplateMerger's display() method showing how language constants are made available, the header and footer files are included and the stylesheet variable is set.
22
Templates
Located under templates/
Has the following PHP variables available
Variables passed by the controller
Language constants defined in language files
$stylesheet variable pointing to stylesheet directory
Can optionally use any other class in OrangeHRM
header.php and footer.php are included before and after the template file (by the
TemplateMerger class)
Template code should be xhtml 1.0 compatible
We will now look at templates in OrangeHRM.. As mentioned before, template code should be xhtml 1.0 transitional compatible.
The special header.php and footer.php are included before and after the template file by the Template Merger file.
23
Templates
Located under templates/
Template files are located under the templates directory, under subdirectories corresponding to each module as can be seen here. You can also see the header and footer php files.
24
Templates
Templates have access to
Variables passed by the controller
Language constants defined in language files
$stylesheet variable pointing to stylesheet directory
Can optionally use any other class in OrangeHRM
Templates have access to PHP variables passed by the controller, language constants defined in language files, the stylesheet variable which points to the stylesheet directory.
You can also use any other class in OrangeHRM in a template file. But it is recommended to not do this unless necessary, since template files should be kept simple.
25
Model classes
Located under lib/models/
Acts as an ORM (object relational mapping) layer
Stores & retrieves data from the database
Uses SQLQBuilder class to construct SQL queries
Uses DMLFunctions to get access to database connections.
We now look at the Model classes in OrangeHRM. Model classes are used by the module controllers.
26
Model classes
Located under lib/models/
Test class is also located in the same directory
Model classes are located under lib/models in sub directories corresponding to the module. Unit test classes for the Model are also located in the same directory as the model classes.
27
Model classes
Acts as an ORM (object relational mapping) layer Stores retrieves data from the database
Uses SQLQBuilder class to construct SQL queries
Uses DMLFunctions to access database connections.
The code example here shows how model classes:
Act as an Object Relational Mapping (or ORM) layer.
Stores and retrieves data from the database
Uses the SQLQBuilder class to construct SQL Queries.
And
Uses DMLFunctions to access database connections.
28
SQLQBuilder
Located under lib/dao/
Contains different methods which constructs SQL Queries based on passed parameters.
The SQLQBuilder class is used by model classes to construct SQL Queries. It is located under the lib/
dao directory and contain many methods which construct SQL queries based on the passed parameters.
Examples of the kind of methods available in SQLQBuilder are given in the code extract here.
29
Database script files
Located under dbscript/ directory.
Contains SQL to create tables and insert data
dbscript-1.sql: Creates tables and adds constraints. Used by installer
dbscript-2.sql: Inserts data to tables. Used by installer
dbscript.sql: Script used to manually create database without using the installer
constraints.php: All foreign key constraints should be added here. Used to check if constraints are set in a given database.
dbscript-u1.sql: No longer in use.
dbscript-u2.sql: No longer in use.
All these scripts (Except those not in use) should be updated when database changes are done.
OrangeHRM also contains database script files, containing SQL used to create database tables and insert data used by OrangeHRM. These are located under the dbscript directory.
This directory contains 6 files, each of these are described here. All these scripts (except the ones not in use) should be updated when database changes are done.
30
Language files
Located under language/ directory.
Contains different subdirectories for different langages
The lang_xxx_full.php file is the main language file
All new constants should first be added to the langauge/default/lang_default_full.php file
As translations become available, the translated words can be added to other language files.
Benefits module has a separate language file:
lang_xxx_benefits.php
The lang_default_*view.php files are used by the employee list and lists in Admin, reports and recruitment modules.
They reuse language constants defined in other files
Internationalization in OrangeHRM is handled by language files located under the language directory, in sub directories corresponding to the language.
The lang full php file is the main language file.
All new constants should be first added to the lang_default_full.php file.
As translations are available, constants can be added to other language files. The benefits module has a separate language file called lang benefits.php.
The lang view php files are used by the employee list and lists in admin, reports and recruitment modules. They reuse language constants defined in other files.
31
Language files
Sample language file
This slide contains an extract from a language file. Note the convention used in naming language constants.
32
Configuration
lib/confs/Conf.php
lib/confs/sysConf.php
lib/confs/mailConf.php
hs_hr_config database table.
We will now look at how configuration is handled in OrangeHRM. Configuration is stored in conf.php, sysconf.php and mailconf.php. Some configuration is stored in a database table named hs_hr_config and accessed by a class named Config.php located in the lib/common directory.
33
Configuration
lib/confs/Conf.php
Written at install time
This slide contains the usual contents of the Conf.php file which is written at install time.
34
Configuration
lib/confs/sysConf.php
Contains settings like date/time format, items per page in lists and stylesheet
Read only, not modified by code
Here we have an extract from the sysConf.php file which contains settings like date/time format, items per page in lists. This file is read only and is not modified by code.
35
Images and CSS files
Located in subdirectories under theme/
directory.
Theme in use available to templates in
$stylesheet variable
Image and CSS files are located under a subdirectory under the theme directory. The subdirectory name is available to use in templates in the stylesheet variable. Using this, it is possible to have multiple style directories. To change between stylesheets, the stylesheet variable in sysConf.php has to be changed.
36
Javascript
Located under scripts/ directory
In addition to Orangehrm javascript code, The Yahoo User Interface Library (YUI) is used.
Javascript files in OrangeHRM are located under the scripts directory. OrangeHRM uses the Yahoo UI library.
37
Resources
• Subversion trunk:
http://orangehrm.svn.sourceforge.net/svnroot/orangehrm
• Developer wiki:
We have covered most of the code in OrangeHRM very briefly in this presentation. More details can be obtained by going through the OrangeHRM code and the developer wiki.
38