This is an old revision of the document!


Developers

If you are a PHP developer you could extend the Workflow Designer on lot's of interfaces.
I implement lot's of these interfaces only for the 6.x version. If you are still using 5.4, you probably don't found the directories to create files.

The most important fact for your should be: Don't modify any files created by the core Workflow Designer.
This files will be overwritten with every update and your modifications are lost.

Add functions you could use in custom expressions

This is the only interface existing also in the 5.4.0 version.

Sometimes you want to integrate a function which will too big to integrate in a simple text field.
For this you should create your own PHP functions.

In VtigerCRM 5.4: Create a new file inside modules/Workflow2/functions/ with the filename <individual>.inc.php
In VtigerCRM 6.x: Create a new file inside modules/Workflow2/extends/functions/ with the filename <individual>.inc.php
All functions with the nameprefix wf_ you define in this file, will be available during custom expressions.

Don't modify the core.inc.php File. There are the functions defined, which already come with Workflow Designer.
But you could use this file as example, how your file should be build.

If you break the PHP Syntax and integrate an Error in this file, no Workflow could be executed, because this files are included in most tasks!

Example, which is currently integrated in Core:

if(!function_exists("wf_date")) {
    function wf_date($value, $interval, $format = "Y-m-d") {
        if(empty($interval)) {
            $dateValue = strtotime($value);
        } else {
            $dateValue = strtotime($interval, strtotime($value));
        }
 
        return date($format, $dateValue);
    }
}

You build a module, which create files you want to integrate into Workflows?

Only VtigerCRM 6.x

PDFMaker and SQLReports is implemented in this way!

If you create a similar module you could create a interfacefile to attach this files to Mails, Store as Documents or simple use the file in every task, which could handle files in any way.

Create a files in modules/Workflow2/extends/interfaceFiles/ with the filename <individual>.inc.php.

This file must include a Class, which extends from \Workflow\InterfaceFiles.
You must implement the following structure to be recognized by Workflow Designer:

<?php
namespace Workflow\Plugins\InterfaceFiles;
 
class [ModuleName] extends \Workflow\InterfaceFiles {
    protected $title = '[ModuleName]';
    protected $key = '[SanitizedModuleName]';
 
    public function __construct() {
        if(!$this->isModuleActive()) {
            return;
        }
    }
 
    /**
     * @var String $moduleName The module of the current Workflow
     */
    protected function _getAvailableFiles($moduleName) {
        $return = array();
        if(!$this->isModuleActive()) {
            return $return;
        }
 
        /*
          This function must simple return an array, like this:
             array(
                'filekeyA' => 'File title of this file'
             )
 
           The file title will be shown in the task configurations.
           The filekey will be given to your _getFile and should uniquely identify the file you should generate
        */
 
        return $return;
    }
 
    /**
     * @var String $key - The fileKey you set in the _getAvailableFiles function
     * @var String $moduleName - The module from the given RecordID, which should be used to generate the file
     * @var Int $crmid - The ID of the Record, which should be used to generate the file
     * @return array - An Array with the following Structure
     *                  array(
     *                      'path' => "<temporarily path to the generated file>",
     *                      'type' => "<mime type of the generated file>",
     *                      'name' => "<filename of the generated file>"
     *                  );
     * The filename will probably overwritten by some tasks, but if not, it will be used to give this file to the user.
     */
    protected function _getFile($key, $moduleName, $crmid) {
        if(!$this->isModuleActive()) {
            return false;
        }
 
        return array(
            'path' => "<temporarily path to the generated file>",
            'type' => "<mime type of the generated file>",
            'name' => "<filename of the generated file>"
        );
    }
 
    public function isModuleActive() {
        return getTabid('[moduleName]') && vtlib_isModuleActive('[moduleName]');
    }
}
 
\Workflow\InterfaceFiles::register('[SanitizedModuleName]', '\Workflow\Plugins\InterfaceFiles\[ModuleName]');