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 file 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 for your module */ return $return; } protected function _getFile($id, $moduleName, $crmid) { if(!$this->isModuleActive()) { return false; } $adb = \PearDatabase::getInstance(); $parts = explode('#', $id); $tmpFilename = $this->_getTmpFilename(); if($parts[0] == 'pdf') { } $sql = 'SELECT * FROM vtiger_sqlreports WHERE sqlreportsid = '.$parts[1]; $result = $adb->query($sql); $row = $adb->fetchByAssoc($result); switch($parts[0]) { case 'pdf': $file_name = "Report_".preg_replace('/[^A-Za-z0-9-_]/', '_', $row['reportname']).".pdf"; $this->_createPDF($tmpFilename, $parts[1]); $type = 'application/pdf'; break; case 'xls': $file_name = "Report_".preg_replace('/[^A-Za-z0-9-_]/', '_', $row['reportname']).".xls"; $this->_createXLS($tmpFilename, $parts[1]); $type = 'application/x-msexcel'; break; case 'csv': $file_name = "Report_".preg_replace('/[^A-Za-z0-9-_]/', '_', $row['reportname']).".csv"; $this->_createCSV($tmpFilename, $parts[1]); $type = 'application/csv'; break; } return array( 'path' => $tmpFilename, 'type' => $type, 'name' => $file_name ); } private function _createPDF($tmpFile, $reportId) { $reportModel = \SQLReports_Record_Model::getInstanceById($reportId); $pdf = $reportModel->getReportPDF(); $pdf->Output($tmpFile, 'F'); } private function _createCSV($tmpFile, $reportId) { vimport('~~/modules/SQLReports/ReportRunSQL.php'); $reportRun = \ReportRunSQL::getInstance($reportId); $reportRun->writeReportToCSVFile($tmpFile, false); } private function _createXLS($tmpFile, $reportId) { vimport('~~/modules/SQLReports/ReportRunSQL.php'); /** * @var $reportRun \ReportRunSQL */ $reportRun = \ReportRunSQL::getInstance($reportId); $reportRun->writeReportToExcelFile($tmpFile, false); } public function isModuleActive() { return getTabid('SQLReports') && vtlib_isModuleActive('SQLReports'); } } \Workflow\InterfaceFiles::register('sqlreport', '\Workflow\Plugins\InterfaceFiles\SQLReports');