6 Steps on How to Write a New Module in Orange HRM
Updated: May 13
It is not easy to write a new module in Orange HRM since it is divided in many layers. I will guide you step by step on how to create new module in Orange HRM.
Step 1 – Download Orange HRM
First download latest version of Orange HRM. Then extract it, and place it to root directory. Now install the Orange HRM. After the installation is complete, your file folder should look like.
Create a folder named orangehrmTestPlugin in plugins folder. Test is name of the plugin, you can change its name. This folder contains the code of the module.
Step 3 – Enable the Plugin
Now you have to enable the plugin. Go to Symfony/apps/orangehrm/config/setting.yml. Symfony folder contains the code of OrangeHRM.
Step 4 – Configure Plugin
Now add plugin to admin configure list. This allows admin to easily enable or disable plugin at any time. To do this you need to include your plugin in the database. Open up ‘ohrm_module’ and ‘hs_hr_module’ tables in database and make these changes.
Status ‘1’ in ‘ohrm_module’ shows that this module is enabled.
Now the plugin needs to be included in the database. To add module in code go to ‘symfony\plugins\orangehrmAdminPlugin\lib\form\ModuleForm.php’ and make changes in there.
The admin should make changes in the check box class. Simply add these lines in ‘symfony\plugins\orangehrmAdminPlugin\modules\admin\templates\viewModulesSuccess.php’.
Now delete cache and refresh your browser. Click on Admin ->Configuration ->Modules. Your plugin will be shown there.
Create these folders inside your plugin. Lib folder contains dao, form, and service. Dao (Database Access Object) contains all the database operation (fetch, update, insert and delete). Form contains forms to get data from user. Service allows user to call dao operations. Modules contain your plugin with 2 folders inside (actions and templates). Actions consist of different classes that will perform actions when user interacts with system.
Default action must have a template file. An action class may have 1 or more template file. Action file ends with Action.class.php. Templates consist of HTML code for GUI.
Step 6 – Final Step
Now include your plugin on main menu. To do this you need to create screen in your database. Open up ‘`ohrm_screen’ Table and insert line no 105 as shown in figure below.
ViewTestMessage is the file inside actions and templates folder. This is the default class. Whenever user clicks on Test Message execute function inside ViewTestMessageAction.class.php executes. Inside Actions folder, template against this file is viewTestMessageSuccess.php which is executed. You can create 1 or more screens in a plugin, but every screen name must be different from other. Every screen must have a user which means that specific user can access this screen. Simply add screen id (105) and any user roleid (user role id from ‘ohrm_user_role’ Table) in‘ohrm_user_role_screen’ Table. Also specify what operation can perform this user role. Now time to show TestMessage in main Menu. Open up ‘ohrm_menu_item’ Table. Insert menu_title as Test Message, screen_id as 105 (created in ‘ohrm_screen’ Table), parent_id as Null (if it is parent itself), level as 1 (2 for sub menu and 3 for 3rd level), order_hint as 800 (100 for most left side, 200 for second place from left, 300 for 3rd place and so on), url_extras as Null, and states as 1 (0 mean don’t show).
Now logout delete cache and login back. You will see Test Message in your main menu bar.