You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

 

Required Methods

The following methods are required to be implemented for each module.

getName()

The getName() method simply returns the name of the method. It's always best to define any language in your module using language files (see Translating Blesta for more information).

class MyModule extends Module {
...
	public function getName() {
		return Language::_("MyModule.name", true);
	}
...
}

getVersion()

This method must return the current version number of the module. Upon installation or upgrade, Blesta records the current code version so that it can tell when an upgrade/downgrade is available. The version number should be compatible with PHP's version_compare() function.

class MyModule extends Module {
	const VERSION = "1.0.0";	
...
	public function getVersion() {
		return self::VERSION;
	}
...

}

getAuthors()

This method returns an array containing information about the authors of the module.

class MyModule extends Module {
    private static $authors = array(array('name' => "Phillips Data, Inc.", 'url' =>"http://www.blesta.com"));
...
	public function getAuthors() {
		return self::$authors;
	}
...
}

getServiceName($service)

Given a particular service, this method should return the label used to identify the service. For example, if the module were representing VOIP services, the value returned by this method might be the phone number associated with the VOIP service.

class MyModule extends Module {
...
	public function getServiceName($service) {
		$key = "phone_number";
        foreach ($service->fields as $field) {
            if ($field->key == $key)
                return $field->value;
        }
        return null;
	}
...
}

moduleRowName()

The moduleRowName() method returns the value used to represent a module row. For example, if the module were representing shared hosting services and each module row were a physical server the value returned by this method might be "Server".

class MyModule extends Module {
...
	public function moduleRowName() {
		return Language::_("MyModule.module_row", true);
	}
...
}

moduleRowNamePlural()

A plural representation of the moduleRowName() method (e.g. "Servers").

class MyModule extends Module {
...
	public function moduleRowNamePlural() {
		return Language::_("MyModule.module_row_plural", true);
	}
...
}

moduleGroupName()

The moduleGroupName() method returns the value used to represent a module group.

class MyModule extends Module {
...
	public function moduleGroupName() {
		return Language::_("MyModule.module_group", true);
	}
...
}

moduleRowMetaKey()

This method returns a string identifying the module meta key value that is used to identify module rows. This is used to identify module rows from one another.  For example, servers may be identified by their host name.

class MyModule extends Module {
...
	public function moduleRowMetaKey() {
		return "host_name";
	}
...
}

 

Optional Methods

The methods below are optional, but may be required to implement a module of any utility.

install/upgrade/uninstall()

The methods are invoked when the module is installed, upgraded, or uninstalled respectively.

class MyModule extends Module {
...
	public function install() {
		// Perform install logic
	}

    public function upgrade($current_version) {
		// Perform upgrade logic       
    }

	public function uninstall($module_id, $last_instance) {
		// Perform uninstall logic

		if ($last_instance) {
			// Delete all trace of this module
		}
	}
...
}

getLogo()

The getLogo() method returns the relative path (within the module's directory) to the logo used to represent the module. The default value is views/default/images/logo.png. This translates to /install_dir/components/modules/my_module/views/default/images/logo.png

class MyModule extends Module {
...
	public function getLogo() {
		return "some/path/to/my/logo.png";
	}
...
}

validateService($package, array $vars=null)

 

addService($package, array $vars=null, $parent_package=null, $parent_service=null, $status="pending")

 

editService($package, $service, array $vars=array(), $parent_package=null, $parent_service=null)

 

cancelService($package, $service, $parent_package=null, $parent_service=null)

 

suspendService($package, $service, $parent_package=null, $parent_service=null)

 

unsuspendService($package, $service, $parent_package=null, $parent_service=null)

 

renewService($package, $service, $parent_package=null, $parent_service=null)

 

changeServicePackage($package_from, $package_to, $service, $parent_package=null, $parent_service=null)

 

addPackage(array $vars=null)

 

editPackage($package, array $vars=null)

 

deletePackage($package)

 

manageModule($module, array &$vars)

 

manageAddRow(array &$vars)

 

manageEditRow($module_row, array &$vars)

 

addModuleRow(array &$vars)

 

editModuleRow($module_row, array &$vars)

 

deleteModuleRow($module_row)

 

getGroupOrderOptions()

 

selectModuleRow($module_group_id)

 

getPackageFields($vars=null)

 

getEmailTags()

 

getAdminAddFields($package, $vars=null)

 

getClientAddFields($package, $vars=null)

 

getAdminEditFields($package, $vars=null)

 

getAdminServiceInfo($service, $package)

 

getClientServiceInfo($service, $package)

 

getAdminTabs($package)

 

getClientTabs($package)

 

  • No labels