Views: 13416
Last Modified: 18.06.2019

Description

Each module must be properly described in the system. That way, the system will “know” how to work with such a module. Improperly described modules can cause the complete or partial unserviceability of the system (e.g., the update system might fail).

The main file used by the system in order to manipulate the module is /bitrix/modules/module ID/install/index.php. (in this case, module ID - full code of partner module that is set in the following format: partner_code.module_code.) The main purpose of this file is the placement of a class in it with a name that coincides with the module ID. (module ID is used here in the format partner_code.module_code, Because, period sign is unavailable for the class name.)

Example:

01	<?
02	Class mymodule extends CModule
03	{
04	    var $MODULE_ID = "mymodule";
05	    var $MODULE_NAME;
06	 
07	    function DoInstall()
08	    {
09	        global $DB, $APPLICATION, $step;
10	        $APPLICATION->IncludeAdminFile(GetMessage("FORM_INSTALL_TITLE"), $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/mymodule/install/step1.php");
11	    }
12	 
13	    function DoUninstall()
14	    {
15	        global $DB, $APPLICATION, $step;
16	        $APPLICATION->IncludeAdminFile(GetMessage("FORM_INSTALL_TITLE"), $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/mymodule/install/unstep1.php");
17	 
18	    }
19	}
20	?>

Mandatory methods of this class:

  • DoInstall - launches upon clicking the button Install on the page Module Management of the administrative section and installs the module.
  • DoUninstall - aunches upon clicking the button Remove on the page Module Management of the administrative section and uninstalls the module.

Optional method for this class:

Mandatory properties of an object of this class:

  • MODULE_ID - stores module ID;
  • MODULE_VERSION - current version of the module in the format XX.XX.XX;
  • MODULE_VERSION_DATE - the line containing the date of the module version; the date must be set in the format YYYY-MM-DD HH:MI:SS;
  • MODULE_NAME - module name;
  • MODULE_DESCRIPTION - module description;
  • MODULE_GROUP_RIGHTS - if the method GetModuleRightList is set, this property must contain Y.

Examples

Example of the file with the description of the module Web Forms:

<?
global $MESS;
$PathInstall = str_replace("\\", "/", __FILE__);
$PathInstall = substr($PathInstall, 0, strlen($PathInstall)-strlen("/index.php"));
IncludeModuleLangFile($PathInstall."/install.php");
include($PathInstall."/version.php");
if(class_exists("form")) return;
Class form extends CModule
{
    var $MODULE_ID = "form";
    var $MODULE_VERSION;
    var $MODULE_VERSION_DATE;
    var $MODULE_NAME;
    var $MODULE_DESCRIPTION;
    var $MODULE_GROUP_RIGHTS = "Y";

    function form()
    {
        $this->MODULE_VERSION = FORM_VERSION;
        $this->MODULE_VERSION_DATE = FORM_VERSION_DATE;
        $this->MODULE_NAME = GetMessage("FORM_MODULE_NAME");
        $this->MODULE_DESCRIPTION = GetMessage("FORM_MODULE_DESCRIPTION");
    }

    function DoInstall()
    {
        global $DB, $APPLICATION, $step;
        $FORM_RIGHT = $APPLICATION->GetGroupRight("form");
        if ($FORM_RIGHT=="W")
        {
            $step = IntVal($step);
            if($step<2)
                $APPLICATION->IncludeAdminFile(GetMessage("FORM_INSTALL_TITLE"),
                $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/install/step1.php");
            elseif($step==2)
                $APPLICATION->IncludeAdminFile(GetMessage("FORM_INSTALL_TITLE"),
                $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/install/step2.php");
        }
    }

    function DoUninstall()
    {
        global $DB, $APPLICATION, $step;
        $FORM_RIGHT = $APPLICATION->GetGroupRight("form");
        if ($FORM_RIGHT=="W")
        {
            $step = IntVal($step);
            if($step<2)
                $APPLICATION->IncludeAdminFile(GetMessage("FORM_UNINSTALL_TITLE"),
                $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/install/unstep1.php");
            elseif($step==2)
                $APPLICATION->IncludeAdminFile(GetMessage("FORM_UNINSTALL_TITLE"),
                $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/install/unstep2.php");
        }
    }

    function GetModuleRightList()
    {
        global $MESS;
        $arr = array(
            "reference_id" => array("D","R","W"),
            "reference" => array(
                GetMessage("FORM_DENIED"),
                GetMessage("FORM_OPENED"),
                GetMessage("FORM_FULL"))
            );
        return $arr;
    }
}
?>

Example of the file indicating module version

<?
$arModuleVersion = array(
    "VERSION" => "11.0.4",
    "VERSION_DATE" => "2011-11-17 14:00:00"
);
?>

Parameters

Module parameters are available for change in the administrative interface on the page Module Settings (Settings > System settings > Module settings). When choosing a module on this page, the system connects the file /bitrix/modules/module ID/options.php intended for controlling module parameters, setting up rights to the module, etc.

Module parameters are stored in the database.

When receiving module parameters, a default value can be used that is set in the file /bitrix/modules/module ID/default_option.php. In this file, the array $ID module_default_option is defined which stores the default values.

Example of the file /bitrix/modules/module ID/default_option.php:

<?
$support_default_option = array(
    "SUPPORT_DIR"                => "#SITE_DIR#support/",
    "SUPPORT_MAX_FILESIZE"       => "100",
    "ONLINE_INTERVAL"            => "900",
    "DEFAULT_VALUE_HIDDEN"       => "N",
    "NOT_IMAGE_EXTENSION_SUFFIX" => "_",
    "NOT_IMAGE_UPLOAD_DIR"       => "support/not_image",
    "DEFAULT_AUTO_CLOSE_DAYS"    => "7"
    );
?>

Example of use:

<?
// We set up a string parameter
COption::SetOptionString("my_module_id", "MY_PARAMETER_ID", "VALUE");

// We will obtain a string parameter
$value = COption::GetOptionString("my_module_id", "MY_PARAMETER_ID", "DEFAULT_VALUE");
?>

The class COption is intended for work with module parameters.




Courses developed by Bitrix24