IceHrm
  • Introduction
  • Getting Started
    • Introduction
    • Installation
    • Manual Installation
    • Securing icehrm installation
    • Basic Settings
    • Mobile App
    • AWS S3 File Storage
  • Employees
    • Employee Management
    • Employee Data Import
    • User permissions
  • Time and Attendance
    • Attendance Module
    • Timesheets
  • Documents
    • HR Form Management
    • Document Management
  • Leave Management
    • Vacation and Leave Management
    • Company Leave Policy
    • Leave Requests and Approval
  • Recruitment
    • Recruitment Management
  • Training and Reviews
    • Training Module
    • Performance Reviews
  • Travel Module
  • Payroll
    • Salary
    • Payroll Management
    • Import - Export Payrolls
    • Building Payroll For India
  • Expenses
    • Expense Management
  • Insights
    • Charts
    • Reporting
  • Other Modules
    • Company Assets
    • Reporting
    • Data Import
  • Api and Single Sign-on
    • Rest Api
    • Using LDAP
    • Sign-In with SAML (Okta)
  • Mobile Application
    • Attendance Tracking
    • My Leave
  • FAQ
    • Upgrade IceHrmPro
    • FAQ
    • Close Cloud Account
    • Blog
  • Developer Guide
    • Setup Development Environment
    • Creating First Extension
    • Adding a DB Migration
    • Adding Entries to DB
  • Release Notes
    • Release Notes IceHrmPro
    • Release Notes IceHrm Open Source
Powered by GitBook
On this page
  • Introduction
  • Add meta.json file
  • Add Extension Manager Class
  • Adding Extension Include File
  • Adding the View file
  • web/index.php
  • Load the Extension in IceHrm

Was this helpful?

  1. Developer Guide

Creating First Extension

Here we introduce IceHrm extensions and covers the steps needed to create a basic extension

PreviousSetup Development EnvironmentNextAdding a DB Migration

Last updated 4 years ago

Was this helpful?

Introduction

IceHrm extensions allow developers to extend the features offered by IceHrm without making changes to the IceHrm core. Here we will start building an extension to list some tasks for employees

  • Create the directory icehrm/extensions if it doesn't exist

  • Create a directory named tasks inside icehrm/extensions

Code for this extension is here:

Add meta.json file

icehrm
    |--extnsions
          |--tasks
               |--meta.json

The meta.json file for this extension should look like:

{
    "label": "My Tasks",
    "menu": ["Tasks", "fa-list"],
    "icon": "fa-tasks",
    "user_levels": [
        "Admin",
        "Manager",
        "User"
    ],
    "model_namespace": "\\Tasks\\Model",
    "manager": "\\Tasks\\Extension",
    "headless": false
}
  • menu: the name of the main menu and the icon for the main menu

  • label: the name of the menu item that will be created by this extension

  • icon: the icon for the menu that will hold the extension

  • user_levels: which types of users will be able to see and use the extension (in this case Admins / Managers and Employees)

  • headless: if true this extension will not have any UI visibility. It'll just function as a background module

  • manager: the main class which will control the extension

  • model_namespace: the namespace which will hold all the database model classes

Add Extension Manager Class

icehrm
    |--extnsions
          |--tasks
               |--src
                  |--Tasks
                       |--Extension.php
               |--meta.json

Extension.php

<?php
namespace Tasks;

use Classes\IceExtension;

class Extension extends IceExtension
{

    public function install() {

    }

    public function uninstall() {

    }

    public function setupModuleClassDefinitions()
    {

    }

    public function setupRestEndPoints()
    {

    }
}

Adding Extension Include File

Every extension should have an include file with the same name as the extension. In our example, it will be tasks.php

icehrm
    |--extnsions
          |--tasks
               |--src
                  |--Tasks
                       |--Extension.php
               |--meta.json
               |--tasks.php

tasks.php

<?php

require_once __DIR__.'/src/Tasks/Extension.php';

Adding the View file

Every extension must have a view file if it's not running on headless mode. File should always be <extension_dir>/web/index.php

icehrm
    |--extnsions
          |--tasks
               |--src
                  |--Tasks
                       |--Extension.php
               |--web
                   |--index.php
               |--meta.json
               |--tasks.php

web/index.php

<?php
$user = \Classes\BaseService::getInstance()->getCurrentUser();
echo "Welcome ".$user->username;

Here we use a core class from Icehrm to get the currently logged in user

Load the Extension in IceHrm

Visit http://icehrm.os and you should see the My Tasks menu

https://github.com/gamonoid/icehrm/tree/feature/custom-extentions-example/extensions/tasks