[795] | 1 | <?php |
---|
| 2 | require_once (GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Base.php'); |
---|
| 3 | /** |
---|
| 4 | * Represents activities, and must be derived for each activity type supported in the system. |
---|
| 5 | * Derived activities extending this class can be found in the activities subfolder. |
---|
| 6 | * This class is observable. |
---|
| 7 | * |
---|
| 8 | * @package Galaxia |
---|
| 9 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 10 | */ |
---|
| 11 | class BaseActivity extends Base { |
---|
| 12 | /** |
---|
| 13 | * @var string $name Activity's name |
---|
| 14 | * @access public |
---|
| 15 | */ |
---|
| 16 | var $name; |
---|
| 17 | /** |
---|
| 18 | * @var string $normalizedName Activity's normalized (follows a pattern) name |
---|
| 19 | * @access public |
---|
| 20 | */ |
---|
| 21 | var $normalizedName; |
---|
| 22 | /** |
---|
| 23 | * @var string $description Activity's description |
---|
| 24 | * @access public |
---|
| 25 | */ |
---|
| 26 | var $description; |
---|
| 27 | /** |
---|
| 28 | * @var string $menuPath Activity's menu path |
---|
| 29 | * @access public |
---|
| 30 | */ |
---|
| 31 | var $menuPath; |
---|
| 32 | /** |
---|
| 33 | * @var bool $isInteractive |
---|
| 34 | * @access public |
---|
| 35 | */ |
---|
| 36 | var $isInteractive; |
---|
| 37 | /** |
---|
| 38 | * @var bool $isAutoRouted |
---|
| 39 | * @access public |
---|
| 40 | */ |
---|
| 41 | var $isAutoRouted; |
---|
| 42 | /** |
---|
| 43 | * @var array $roles |
---|
| 44 | * @access public |
---|
| 45 | */ |
---|
| 46 | var $roles=Array(); |
---|
| 47 | /** |
---|
| 48 | * @var array $outbound |
---|
| 49 | * @access public |
---|
| 50 | */ |
---|
| 51 | var $outbound=Array(); |
---|
| 52 | /** |
---|
| 53 | * @var array $inbound |
---|
| 54 | * @access public |
---|
| 55 | */ |
---|
| 56 | var $inbound=Array(); |
---|
| 57 | /** |
---|
| 58 | * @var int $pId Process's identification number |
---|
| 59 | * @access public |
---|
| 60 | */ |
---|
| 61 | var $pId; |
---|
| 62 | /** |
---|
| 63 | * @var int $activityId Activity's identification number |
---|
| 64 | * @access public |
---|
| 65 | */ |
---|
| 66 | var $activityId; |
---|
| 67 | /** |
---|
| 68 | * @var string $type Activity's type |
---|
| 69 | * @access public |
---|
| 70 | */ |
---|
| 71 | var $type; |
---|
| 72 | /** |
---|
| 73 | * @var string $defaultUser |
---|
| 74 | * @access public |
---|
| 75 | */ |
---|
| 76 | var $defaultUser='*'; |
---|
| 77 | /** |
---|
| 78 | * @var array $agents |
---|
| 79 | * @access public |
---|
| 80 | */ |
---|
| 81 | var $agents=Array(); |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | * Seems to be the rest of a bad object architecture |
---|
| 85 | * |
---|
[3167] | 86 | * @deprecated 2.2.00.000 |
---|
[795] | 87 | */ |
---|
| 88 | function setDb(&$db) |
---|
| 89 | { |
---|
[3167] | 90 | wf_warn_deprecated_method(); |
---|
[795] | 91 | $this->db =& $db; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * Constructor of the BaseActivity Object |
---|
| 96 | * |
---|
| 97 | * @param object $db ADODB object |
---|
| 98 | * @access public |
---|
| 99 | */ |
---|
[3167] | 100 | function BaseActivity() |
---|
[795] | 101 | { |
---|
| 102 | $this->type='base'; |
---|
| 103 | $this->child_name = 'BaseActivity'; |
---|
[3167] | 104 | parent::Base(); |
---|
[795] | 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * Factory method returning an activity of the desired type, loading the information from the database |
---|
| 109 | * and populating the activity object with datas related to his activity type (being more than a BaseActivity then |
---|
| 110 | * |
---|
| 111 | * @param int $activityId it is the id of the wanted activity |
---|
| 112 | * @param bool $with_roles true by default, gives you the basic roles information in the result |
---|
| 113 | * @param bool $with_agents false by default, gives you the basic agents information in the result |
---|
| 114 | * @param bool $as_array false by default, if true the function will return an array instead of an object |
---|
| 115 | * @return object Activity of the right class (Child class) or an associative array containing the activity |
---|
| 116 | * information if $as_array is set to true |
---|
| 117 | * @access public |
---|
| 118 | */ |
---|
| 119 | function &getActivity($activityId, $with_roles= true,$with_agents=false,$as_array=false) |
---|
| 120 | { |
---|
| 121 | $query = "select * from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?"; |
---|
| 122 | $result = $this->query($query,array($activityId)); |
---|
| 123 | if(!$result || !$result->numRows() ) return false; |
---|
| 124 | $res = $result->fetchRow(); |
---|
[3167] | 125 | |
---|
[795] | 126 | switch($res['wf_type']) { |
---|
| 127 | case 'start': |
---|
[3167] | 128 | $act = &Factory::newInstance('Start'); |
---|
[795] | 129 | break; |
---|
[3167] | 130 | |
---|
[795] | 131 | case 'end': |
---|
[3167] | 132 | $act = &Factory::newInstance('End'); |
---|
[795] | 133 | break; |
---|
[3167] | 134 | |
---|
[795] | 135 | case 'join': |
---|
[3167] | 136 | $act = &Factory::newInstance('Join'); |
---|
[795] | 137 | break; |
---|
[3167] | 138 | |
---|
[795] | 139 | case 'split': |
---|
[3167] | 140 | $act = &Factory::newInstance('Split'); |
---|
[795] | 141 | break; |
---|
[3167] | 142 | |
---|
[795] | 143 | case 'standalone': |
---|
[3167] | 144 | $act = &Factory::newInstance('Standalone'); |
---|
[795] | 145 | break; |
---|
[3167] | 146 | |
---|
[795] | 147 | case 'view': |
---|
[3167] | 148 | $act = &Factory::newInstance('View'); |
---|
[795] | 149 | break; |
---|
[3167] | 150 | |
---|
[795] | 151 | case 'switch': |
---|
[3167] | 152 | $act = &Factory::newInstance('SwitchActivity'); |
---|
[795] | 153 | break; |
---|
[3167] | 154 | |
---|
[795] | 155 | case 'activity': |
---|
[3167] | 156 | $act = &Factory::newInstance('Activity'); |
---|
[795] | 157 | break; |
---|
[3167] | 158 | |
---|
[795] | 159 | default: |
---|
| 160 | trigger_error('Unknown activity type:'.$res['wf_type'],E_USER_WARNING); |
---|
| 161 | } |
---|
[3167] | 162 | |
---|
[795] | 163 | $act->setName($res['wf_name']); |
---|
| 164 | $act->setProcessId($res['wf_p_id']); |
---|
| 165 | $act->setNormalizedName($res['wf_normalized_name']); |
---|
| 166 | $act->setDescription($res['wf_description']); |
---|
| 167 | $act->setMenuPath($res['wf_menu_path']); |
---|
| 168 | $act->setIsInteractive($res['wf_is_interactive']); |
---|
| 169 | $act->setIsAutoRouted($res['wf_is_autorouted']); |
---|
| 170 | $act->setActivityId($res['wf_activity_id']); |
---|
| 171 | $act->setType($res['wf_type']); |
---|
| 172 | $act->setDefaultUser($res['wf_default_user']); |
---|
| 173 | |
---|
| 174 | //Now get forward transitions |
---|
| 175 | |
---|
| 176 | //Now get backward transitions |
---|
| 177 | |
---|
| 178 | //Now get roles |
---|
| 179 | if ($with_roles) |
---|
| 180 | { |
---|
| 181 | $query = "select `wf_role_id` from `".GALAXIA_TABLE_PREFIX."activity_roles` where `wf_activity_id`=?"; |
---|
| 182 | $result=$this->query($query,array($activityId)); |
---|
| 183 | if (!(empty($result))) |
---|
| 184 | { |
---|
| 185 | while($res = $result->fetchRow()) |
---|
| 186 | { |
---|
| 187 | $this->roles[] = $res['wf_role_id']; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | $act->setRoles($this->roles); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | //Now get agents if asked so |
---|
| 194 | if ($with_agents) |
---|
| 195 | { |
---|
| 196 | $query = "select wf_agent_id, wf_agent_type from ".GALAXIA_TABLE_PREFIX."activity_agents where wf_activity_id=?"; |
---|
| 197 | $result=$this->query($query,array($activityId)); |
---|
| 198 | if (!(empty($result))) |
---|
| 199 | { |
---|
| 200 | while($res = $result->fetchRow()) |
---|
| 201 | { |
---|
| 202 | $this->agents[] = array( |
---|
| 203 | 'wf_agent_id' => $res['wf_agent_id'], |
---|
| 204 | 'wf_agent_type' => $res['wf_agent_type'], |
---|
| 205 | ); |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | $act->setAgents($this->agents); |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | if ($as_array) |
---|
| 212 | {//we wont return the object but an associative array instead |
---|
| 213 | $res['wf_name']=$act->getName(); |
---|
| 214 | $res['wf_normalized_name']=$act->getNormalizedName(); |
---|
| 215 | $res['wf_description']=$act->getDescription(); |
---|
| 216 | $res['wf_menu_path']=$act->getMenuPath(); |
---|
| 217 | $res['wf_is_interactive']=$act->isInteractive(); |
---|
| 218 | $res['wf_is_autorouted']=$act->isAutoRouted(); |
---|
| 219 | $res['wf_roles']=$act->getRoles(); |
---|
| 220 | //$res['outbound']=$act->get(); |
---|
| 221 | //$res['inbound']=$act->get(); |
---|
| 222 | $res['wf_p_id']=$act->getProcessId(); |
---|
| 223 | $res['wf_activity_id']=$act->getActivityId(); |
---|
| 224 | $res['wf_type']=$act->getType(); |
---|
| 225 | $res['wf_default_user']=$act->getDefaultUser(); |
---|
| 226 | $res['wf_agents']= $act->getAgents(); |
---|
| 227 | return $res; |
---|
| 228 | } |
---|
| 229 | else |
---|
| 230 | { |
---|
| 231 | return $act; |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | /** |
---|
| 236 | * Gets performed roles for a given user |
---|
| 237 | * |
---|
| 238 | * @param array $user |
---|
| 239 | * @return array RoleIds for the given user |
---|
| 240 | * @access public |
---|
| 241 | */ |
---|
| 242 | function getUserRoles($user) { |
---|
| 243 | |
---|
| 244 | // retrieve user_groups information in an array containing all groups for this user |
---|
| 245 | $user_groups = galaxia_retrieve_user_groups($GLOBALS['phpgw_info']['user']['account_id'] ); |
---|
| 246 | // and append it to query |
---|
| 247 | $query = 'select `wf_role_id` from `'.GALAXIA_TABLE_PREFIX."user_roles` |
---|
| 248 | where ( |
---|
| 249 | (wf_user=? and wf_account_type='u')"; |
---|
| 250 | if (is_array($groups)) |
---|
| 251 | { |
---|
| 252 | foreach ($groups as &$group) |
---|
| 253 | $group = "'{$group}'"; |
---|
| 254 | $mid .= ' or (wf_user in ('.implode(',',$groups).") and wf_account_type='g')"; |
---|
| 255 | } |
---|
| 256 | $mid .= ')'; |
---|
| 257 | |
---|
| 258 | $result=$this->query($query,array($user)); |
---|
| 259 | $ret = Array(); |
---|
| 260 | while($res = $result->fetchRow()) |
---|
| 261 | { |
---|
| 262 | $ret[] = $res['wf_role_id']; |
---|
| 263 | } |
---|
| 264 | return $ret; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | /** |
---|
| 268 | * Gets activity's roleId and name |
---|
| 269 | * |
---|
| 270 | * @return array $ret Array of associative arrays with roleId and name |
---|
| 271 | * @access public |
---|
| 272 | */ |
---|
| 273 | function getActivityRoleNames() { |
---|
| 274 | $aid = $this->activityId; |
---|
| 275 | $query = "select gr.`wf_role_id`, `wf_name` from `".GALAXIA_TABLE_PREFIX."activity_roles` gar, `".GALAXIA_TABLE_PREFIX."roles` gr where gar.`wf_role_id`=gr.`wf_role_id` and gar.`wf_activity_id`=?"; |
---|
| 276 | $result=$this->query($query,array($aid)); |
---|
| 277 | $ret = Array(); |
---|
| 278 | while($res = $result->fetchRow()) { |
---|
| 279 | $ret[] = $res; |
---|
| 280 | } |
---|
| 281 | return $ret; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /** |
---|
| 285 | * Returns the normalized name for the activity |
---|
| 286 | * |
---|
| 287 | * @return string |
---|
| 288 | * @access public |
---|
| 289 | */ |
---|
| 290 | function getNormalizedName() { |
---|
| 291 | return $this->normalizedName; |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | /** |
---|
| 295 | * Sets normalized name for the activity |
---|
| 296 | * |
---|
| 297 | * @return void |
---|
| 298 | * @access public |
---|
| 299 | */ |
---|
| 300 | function setNormalizedName($name) { |
---|
| 301 | $this->normalizedName=$name; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | /** |
---|
| 305 | * Sets the name for the activity |
---|
| 306 | * |
---|
| 307 | * @param string New desired activity's name |
---|
| 308 | * @return void |
---|
| 309 | * @access public |
---|
| 310 | */ |
---|
| 311 | function setName($name) { |
---|
| 312 | $this->name=$name; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | /** |
---|
| 316 | * Gets the activity name |
---|
| 317 | * |
---|
| 318 | * @return void |
---|
| 319 | * @access public |
---|
| 320 | */ |
---|
| 321 | function getName() { |
---|
| 322 | return $this->name; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | /** |
---|
| 326 | * Sets the agents for the activity object (no save) |
---|
| 327 | * |
---|
| 328 | * @param array $agents Has 'wf_agent_id' and 'wf_agent_type' as keys |
---|
| 329 | * @return bool False if any problem is detected |
---|
| 330 | * @access public |
---|
| 331 | */ |
---|
| 332 | function setAgents($agents) |
---|
| 333 | { |
---|
| 334 | if (!(is_array($agents))) |
---|
| 335 | { |
---|
| 336 | $this->error[] = tra('bad parameter for setAgents, the parameter should be an array'); |
---|
| 337 | return false; |
---|
| 338 | } |
---|
| 339 | $this->agents = $agents; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | /** |
---|
| 343 | * Gets the activity agents |
---|
| 344 | * |
---|
| 345 | * @return array Basic agents informations (id an type) or false if no agent is defined for this activity |
---|
| 346 | * @access public |
---|
| 347 | */ |
---|
| 348 | function getAgents() |
---|
| 349 | { |
---|
| 350 | if (empty($this->agents)) return false; |
---|
| 351 | return $this->agents; |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | /** |
---|
| 355 | * Sets the activity description |
---|
| 356 | * |
---|
| 357 | * @param string $desc Activity description |
---|
| 358 | * @return void |
---|
| 359 | * @access public |
---|
| 360 | */ |
---|
| 361 | function setDescription($desc) { |
---|
| 362 | $this->description=$desc; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | /** |
---|
| 366 | * Gets the activity description |
---|
| 367 | * |
---|
| 368 | * @return string |
---|
| 369 | * @access public |
---|
| 370 | */ |
---|
| 371 | function getDescription() { |
---|
| 372 | return $this->description; |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | /** |
---|
| 376 | * Sets the activity menu path |
---|
| 377 | * |
---|
| 378 | * @param string $mp Menu path |
---|
| 379 | * @return void |
---|
| 380 | * @access public |
---|
| 381 | */ |
---|
| 382 | function setMenuPath($mp) { |
---|
| 383 | $this->menuPath=$mp; |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | /** |
---|
| 387 | * Gets the activity menu path |
---|
| 388 | * |
---|
| 389 | * @return string |
---|
| 390 | * @access public |
---|
| 391 | */ |
---|
| 392 | function getMenuPath() { |
---|
| 393 | return $this->menuPath; |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | /** |
---|
| 397 | * Sets the type for the activity although it does NOT allow you to change the current type |
---|
| 398 | * |
---|
| 399 | * @param string $type |
---|
| 400 | * @return void |
---|
| 401 | * @access public |
---|
| 402 | */ |
---|
| 403 | function setType($type) { |
---|
| 404 | $this->type=$type; |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | /** |
---|
| 408 | * Gets the activity type |
---|
| 409 | * |
---|
| 410 | * @return string |
---|
| 411 | * @access public |
---|
| 412 | */ |
---|
| 413 | function getType() { |
---|
| 414 | return $this->type; |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | /** |
---|
| 418 | * Sets if the activity is interactive |
---|
| 419 | * |
---|
| 420 | * @param bool $is |
---|
| 421 | * @return void |
---|
| 422 | * @access public |
---|
| 423 | */ |
---|
| 424 | function setIsInteractive($is) { |
---|
| 425 | $this->isInteractive=$is; |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | /** |
---|
| 429 | * Returns if the activity is interactive |
---|
| 430 | * |
---|
| 431 | * @return string |
---|
| 432 | * @access public |
---|
| 433 | */ |
---|
| 434 | function isInteractive() { |
---|
| 435 | return $this->isInteractive == 'y'; |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | /** |
---|
| 439 | * Sets if the activity is auto-routed |
---|
| 440 | * |
---|
| 441 | * @param boolean $is |
---|
| 442 | * @return void |
---|
| 443 | * @access public |
---|
| 444 | */ |
---|
| 445 | function setIsAutoRouted($is) { |
---|
| 446 | $this->isAutoRouted = $is; |
---|
| 447 | } |
---|
| 448 | |
---|
| 449 | /** |
---|
| 450 | * Gets if the activity is auto routed |
---|
| 451 | * |
---|
| 452 | * @return string |
---|
| 453 | * @access public |
---|
| 454 | */ |
---|
| 455 | function isAutoRouted() { |
---|
| 456 | return $this->isAutoRouted == 'y'; |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | /** |
---|
| 460 | * Sets the processId for this activity |
---|
| 461 | * |
---|
| 462 | * @param int $pid |
---|
| 463 | * @return void |
---|
| 464 | * @access public |
---|
| 465 | */ |
---|
| 466 | function setProcessId($pid) { |
---|
| 467 | $this->pId=$pid; |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | /** |
---|
| 471 | * Gets the processId for this activity |
---|
| 472 | * |
---|
| 473 | * @return int |
---|
| 474 | * @access public |
---|
| 475 | */ |
---|
| 476 | function getProcessId() { |
---|
| 477 | return $this->pId; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | /** |
---|
| 481 | * Gets the activityId |
---|
| 482 | * |
---|
| 483 | * @return int |
---|
| 484 | * @access public |
---|
| 485 | */ |
---|
| 486 | function getActivityId() { |
---|
| 487 | return $this->activityId; |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | /** |
---|
| 491 | * Sets the activityId |
---|
| 492 | * |
---|
| 493 | * @param int $id |
---|
| 494 | * @return void |
---|
| 495 | * @access public |
---|
| 496 | */ |
---|
| 497 | function setActivityId($id) { |
---|
| 498 | $this->activityId=$id; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | /** |
---|
| 502 | * Gets array with roleIds asociated to this activity |
---|
| 503 | * |
---|
| 504 | * @return array |
---|
| 505 | * @access public |
---|
| 506 | */ |
---|
| 507 | function getRoles() { |
---|
| 508 | return $this->roles; |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | /** |
---|
| 512 | * Sets roles for this activities, should receive an array of roleIds |
---|
| 513 | * |
---|
| 514 | * @param array $roles |
---|
| 515 | * @return void |
---|
| 516 | * @access public |
---|
| 517 | */ |
---|
| 518 | function setRoles($roles) { |
---|
| 519 | $this->roles = $roles; |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | /** |
---|
| 523 | * Gets default user id associated with this activity as he's recorded |
---|
| 524 | * there's no check about validity of this user |
---|
| 525 | * |
---|
| 526 | * @return string |
---|
| 527 | * @access protected |
---|
| 528 | */ |
---|
| 529 | function getDefaultUser() { |
---|
| 530 | return $this->defaultUser; |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | /** |
---|
| 534 | * Sets the default user for an activity |
---|
| 535 | * |
---|
| 536 | * @param string $default_user |
---|
| 537 | * @return void |
---|
| 538 | * @access public |
---|
| 539 | */ |
---|
| 540 | function setDefaultUser($default_user) |
---|
| 541 | { |
---|
| 542 | if ((!isset($default_user)) || ($default_user=='') || ($default_user==false)) |
---|
| 543 | { |
---|
| 544 | $default_user='*'; |
---|
| 545 | } |
---|
| 546 | $this->defaultUser = $default_user; |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | /** |
---|
| 550 | * Checks if a user has a certain role (by name) for this activity, |
---|
| 551 | * e.g. $isadmin = $activity->checkUserRole($user,'admin') |
---|
| 552 | * |
---|
[3167] | 553 | * @deprecated 2.2.00.000 - Unused function. Old API, do not use it. Return always false |
---|
[795] | 554 | */ |
---|
| 555 | function checkUserRole($user,$rolename) |
---|
| 556 | { |
---|
[3167] | 557 | wf_warn_deprecated_method(); |
---|
[795] | 558 | $this->error[] = 'use of an old deprecated function checkUserRole, return always false'; |
---|
| 559 | return false; |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | } |
---|
| 563 | ?> |
---|