00001 <?php
00002
00009 class TKSWATAction extends TKPostAction {
00018 public function __construct($target, $actionId, $vars = array(), $action = "") {
00019 if(!isset($GLOBALS['SWAT'])) {
00020 self::setError("You must have a global \$SWAT object in this project to use the SWAT action!");
00021 return;
00022 }
00023 global $SWAT;
00024 $trans = $SWAT->getTransaction();
00025 if(is_object($target))
00026 $targetId = $target->getId();
00027 else
00028 $targetId = $target;
00029 $swat = array(
00030 'action' => $actionId,
00031 'transaction' => $trans,
00032 'target' => $targetId
00033 );
00034 if($vars instanceof TKForm || $vars instanceof TKFormTable) {
00035 foreach($swat as $name => $value)
00036 $vars->addFormInput('hidden', $name, "$value");
00037 parent::__construct($vars, $action);
00038 }
00039 else {
00040 parent::__construct(array_merge($vars, $swat), $action);
00041 }
00042 }
00043
00045 public static function createFromXML($attrs, $children) {
00046 $targetId = (string)$attrs['target'];
00047 $actionId = (string)$attrs['actionId'];
00048 $varStr = isset($attrs['vars']) ? (string)$attrs['vars'] : "";
00049 $action = isset($attrs['faction']) ? (string)$attrs['faction'] : "";
00050 $vars = array();
00051 $tmp = split(";", $varStr);
00052 foreach($tmp as $t) {
00053 if($t == '')
00054 continue;
00055 $tmp2 = split("::", $t);
00056 $vars[$tmp2[0]] = $tmp2[1];
00057 }
00058 $target = Toolkit::getComponent($targetId);
00059 $obj = new TKSWATAction($target, $actionId, $vars, $action);
00060 return $obj;
00061 }
00062 }
00063
00064 ?>