[795] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare Workflow - Agents Connector - business objects layer * |
---|
| 4 | * ------------------------------------------------------------------------ * |
---|
| 5 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 6 | * under the terms of the GNU General Public License as published * |
---|
| 7 | * by the Free Software Foundation; either version 2 of the License, or * |
---|
| 8 | * any later version. * |
---|
| 9 | \**************************************************************************/ |
---|
| 10 | |
---|
| 11 | /** |
---|
| 12 | * This allows the Workflow Engine to connect to various agents |
---|
| 13 | * Agents are external elements for the workflow. It could be |
---|
| 14 | * email systems, filesystems, calendars, what you want. |
---|
| 15 | * Use this class to make childrens like, for example in the |
---|
| 16 | * class.bo_agent_mail_smtp.inc.php for the mail_smtp susbsytem |
---|
| 17 | * |
---|
| 18 | * @package Workflow |
---|
| 19 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 20 | * @author regis.leroy@glconseil.com |
---|
| 21 | */ |
---|
| 22 | class bo_agent |
---|
| 23 | { |
---|
| 24 | /** |
---|
| 25 | * @var array $error the local error storage |
---|
| 26 | * @access public |
---|
| 27 | */ |
---|
| 28 | var $error = Array(); |
---|
| 29 | /** |
---|
| 30 | * @var object $activity the activity object we are working with at runtime (reference) |
---|
| 31 | * @access public |
---|
| 32 | */ |
---|
| 33 | var $activity = null; |
---|
| 34 | /** |
---|
| 35 | * @var object $instance the instance object we are working with at runtime (reference) |
---|
| 36 | * @access public |
---|
| 37 | */ |
---|
| 38 | var $instance = null; |
---|
| 39 | /** |
---|
| 40 | * @var object $process the process object is used for process level configuration |
---|
| 41 | * @access public |
---|
| 42 | */ |
---|
| 43 | var $process = null; |
---|
| 44 | /** |
---|
| 45 | * @var array $conf |
---|
| 46 | * @access public |
---|
| 47 | */ |
---|
| 48 | var $conf; |
---|
| 49 | // define theses values in your child class ---------------------------------------------- |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * @var string $title Agent title |
---|
| 53 | * @access public |
---|
| 54 | */ |
---|
| 55 | var $title=''; |
---|
| 56 | /** |
---|
| 57 | * @var string $description Agent description |
---|
| 58 | * @access public |
---|
| 59 | */ |
---|
| 60 | var $description=''; |
---|
| 61 | /** |
---|
| 62 | * @var string $help Agent help |
---|
| 63 | * @access public |
---|
| 64 | */ |
---|
| 65 | var $help=''; |
---|
| 66 | /** |
---|
| 67 | * @var object $so_agent derived so object. i.e.: for foo agent it is an so_agent_foo |
---|
| 68 | * @access public |
---|
| 69 | */ |
---|
| 70 | var $so_agent; |
---|
| 71 | /** |
---|
| 72 | * @var integer $agent_id Agent id |
---|
| 73 | * @access public |
---|
| 74 | */ |
---|
| 75 | var $agent_id; |
---|
| 76 | /** |
---|
| 77 | * @var array $fields the fields which are saved at admin time and just changed at runtime (without saving) |
---|
| 78 | * @access public |
---|
| 79 | */ |
---|
| 80 | var $fields = Array(); |
---|
| 81 | /** |
---|
| 82 | * @var array $ProcessConfigurationFieldsdefault the config fields which are at process level , key is the config option and value is the |
---|
| 83 | * default value |
---|
| 84 | * @access public |
---|
| 85 | */ |
---|
| 86 | var $ProcessConfigurationFieldsdefault = Array(); |
---|
| 87 | /** |
---|
| 88 | * @var array $showProcessConfigurationFieldsdefault the config fields which are at process level , key is the config option and value is an |
---|
| 89 | * associative array with keys: |
---|
| 90 | * - 'title' for an helper/title line, not a conf value in fact |
---|
| 91 | * - 'text' for a text input |
---|
| 92 | * - 'yesno' to select between true or false |
---|
| 93 | * - an array for a list of select key => value pairs |
---|
| 94 | * @access public |
---|
| 95 | */ |
---|
| 96 | var $showProcessConfigurationFieldsdefault = Array(); |
---|
| 97 | |
---|
| 98 | /** |
---|
| 99 | * Constructor |
---|
| 100 | * |
---|
| 101 | * @access public |
---|
| 102 | * @return object |
---|
| 103 | */ |
---|
| 104 | function bo_agent() |
---|
| 105 | { |
---|
| 106 | |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * You should always call this function after failed operations on a workflow object to obtain messages |
---|
| 111 | * @param array $as_array if true the result will be send as an array of errors or an empty array. Else, if you do not give any parameter |
---|
| 112 | * or give a false parameter you will obtain a single string which can be empty or will contain error messages with <br /> html tags. |
---|
| 113 | * @return mixed single string,array of errors or an empty array |
---|
| 114 | * @access public |
---|
| 115 | */ |
---|
| 116 | function get_error($as_array=false) |
---|
| 117 | { |
---|
| 118 | if ($as_array) |
---|
| 119 | { |
---|
| 120 | return $this->error; |
---|
| 121 | } |
---|
| 122 | $result_str = implode('<br />',$this->error); |
---|
| 123 | $this->error= Array(); |
---|
| 124 | return $result_str; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | * Get the title |
---|
| 129 | * |
---|
| 130 | * @return string title |
---|
| 131 | * @access public |
---|
| 132 | */ |
---|
| 133 | function getTitle() |
---|
| 134 | { |
---|
| 135 | return $this->title; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | * Get the description |
---|
| 140 | * |
---|
| 141 | * @return string description |
---|
| 142 | * @access public |
---|
| 143 | */ |
---|
| 144 | |
---|
| 145 | function getDescription() |
---|
| 146 | { |
---|
| 147 | return $this->description; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | /** |
---|
| 151 | * Get the help |
---|
| 152 | * |
---|
| 153 | * @return string help |
---|
| 154 | * @access public |
---|
| 155 | */ |
---|
| 156 | function getHelp() |
---|
| 157 | { |
---|
| 158 | return $this->help; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | * Factory: Load the agent values stored somewhere in the agent object and retain the agent id |
---|
| 163 | * |
---|
| 164 | * @param int $agent_id is the agent id |
---|
| 165 | * @param bool $really_load boolean, true by default, if false the data wont be loaded from database and |
---|
| 166 | * the only thing done by this function is storing the agent_id (usefull if you know you wont need actual data) |
---|
| 167 | * @return bool false if the agent cannot be loaded, true else |
---|
| 168 | * @access public |
---|
| 169 | */ |
---|
| 170 | function load($agent_id, $really_load=true) |
---|
| 171 | { |
---|
| 172 | $this->agent_id = $agent_id; |
---|
| 173 | return true; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | * Save the agent datas |
---|
| 178 | * |
---|
| 179 | * @return bool false if the agent cannot be saved, true else |
---|
| 180 | * @access public |
---|
| 181 | */ |
---|
| 182 | function save() |
---|
| 183 | { |
---|
| 184 | return true; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | /** |
---|
| 188 | * Function called at runtime to permit association with the instance and the activity |
---|
| 189 | * we store references to theses objects |
---|
| 190 | * @return void |
---|
| 191 | * @access public |
---|
| 192 | */ |
---|
| 193 | function runtime(&$instance, &$activity) |
---|
| 194 | { |
---|
| 195 | $this->instance =& $instance; |
---|
| 196 | $this->activity =& $activity; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | /** |
---|
| 200 | * Return the agent fields in different forms |
---|
| 201 | * @param int $result_type : |
---|
| 202 | * - 1 the result is an array containing the field names |
---|
| 203 | * - 2 the result is an array containing fields names => value pairs |
---|
| 204 | * - 3 the result is an array containing fields names => field array pairs, the field array is an associative array |
---|
| 205 | * containing all infos about the field with $key => $value pairs. |
---|
| 206 | * @return array an array, the form depends on the parameter $result_type |
---|
| 207 | * @access public |
---|
| 208 | */ |
---|
| 209 | function get($result_type) |
---|
| 210 | { |
---|
| 211 | switch ($result_type) |
---|
| 212 | { |
---|
| 213 | case 1: |
---|
| 214 | return array_keys($this->fields); |
---|
| 215 | break; |
---|
| 216 | case 2: |
---|
| 217 | $res = Array(); |
---|
| 218 | foreach ($this->fields as $key => $value) |
---|
| 219 | { |
---|
| 220 | $res[$key] = html_entity_decode($value['value']); |
---|
| 221 | } |
---|
| 222 | return $res; |
---|
| 223 | break; |
---|
| 224 | default : |
---|
| 225 | return $this->fields; |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | /** |
---|
| 230 | * Affect some values to some of the agent's fields |
---|
| 231 | * @param array $datas is an array containing fields => value pairs |
---|
| 232 | * @return bool false if one or more value cannot be affected, true else |
---|
| 233 | * @access public |
---|
| 234 | */ |
---|
| 235 | function set(&$datas) |
---|
| 236 | { |
---|
| 237 | foreach ($datas as $key => $value) |
---|
| 238 | { |
---|
| 239 | if ( (isset($this->fields[$key])) && (is_array($this->fields[$key])) ) |
---|
| 240 | { |
---|
| 241 | $this->fields[$key]['value'] = htmlentities($value); |
---|
| 242 | } |
---|
| 243 | else |
---|
| 244 | { |
---|
| 245 | return false; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | return true; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | |
---|
| 252 | /** |
---|
| 253 | * this function tell the engine which process level options have to be set |
---|
| 254 | * |
---|
| 255 | * for the agent. Theses options will be initialized for all processes by the engine |
---|
| 256 | * and can be different for each process. |
---|
| 257 | * @return array an array which can be empty |
---|
| 258 | * @access public |
---|
| 259 | */ |
---|
| 260 | function listProcessConfigurationFields() |
---|
| 261 | { |
---|
| 262 | return $this->showProcessConfigurationFields; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | /** |
---|
| 266 | * This function retrieve process level configuration otpions set by the engine |
---|
| 267 | * for the agent. Theses conf values are cached locally for the object life duration |
---|
| 268 | * @param int $wf_p_id is the process id |
---|
| 269 | * @param bool $force is false by default, if true we retrieve theses config values even if the $conf |
---|
| 270 | * local cache is already set |
---|
| 271 | * @return array an associative array which can be empty |
---|
| 272 | * @access public |
---|
| 273 | */ |
---|
| 274 | function getProcessConfigurationFields($wf_p_id, $force=false) |
---|
| 275 | { |
---|
| 276 | if ($force || (!(isset($this->conf))) ) |
---|
| 277 | { |
---|
| 278 | if (!(isset($this->process))) |
---|
| 279 | { |
---|
| 280 | $this->process = CreateObject('workflow.workflow_process'); |
---|
| 281 | $this->process->getProcess($wf_p_id); |
---|
| 282 | } |
---|
| 283 | $this->conf = $this->process->getConfigValues($this->ProcessConfigurationFieldsdefault); |
---|
| 284 | } |
---|
| 285 | return $this->conf; |
---|
| 286 | } |
---|
| 287 | /** |
---|
| 288 | * this function lists activity level options avaible for the agent |
---|
| 289 | * |
---|
| 290 | * @return array an associative array which can be empty |
---|
| 291 | * @access public |
---|
| 292 | */ |
---|
| 293 | function getAdminActivityOptions () |
---|
| 294 | { |
---|
| 295 | return (Array(Array())); |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | ?> |
---|