| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
class InsertEntryBase { |
| 5 |
public $FormId; |
| 6 |
public $FormEntryData; |
| 7 |
public $FormOptions; |
| 8 |
public $ElementOptions; |
| 9 |
public $AdditionalData; |
| 10 |
protected $_StringBuilder; |
| 11 |
/** |
| 12 |
* @var InsertEntryActionBase[] array |
| 13 |
*/ |
| 14 |
private $_actions=array(); |
| 15 |
|
| 16 |
public function __construct(&$formId,&$formEntryData,&$formOptions,&$elementOptions,&$additionalData) |
| 17 |
{ |
| 18 |
$this->FormId = $formId; |
| 19 |
$this->FormEntryData=$formEntryData; |
| 20 |
$this->FormOptions=$formOptions; |
| 21 |
$this->ElementOptions=$elementOptions; |
| 22 |
$this->AdditionalData=$additionalData; |
| 23 |
$this->_StringBuilder=null; |
| 24 |
} |
| 25 |
|
| 26 |
public function GetSerializedActions() |
| 27 |
{ |
| 28 |
$actionData=array(); |
| 29 |
foreach($this->_actions as $action) |
| 30 |
{ |
| 31 |
array_push($actionData,$action->GetSerializedData()); |
| 32 |
} |
| 33 |
return $actionData; |
| 34 |
} |
| 35 |
|
| 36 |
public function GetExtensionInfo($extensionId) |
| 37 |
{ |
| 38 |
if(isset($this->FormOptions["Extensions"][$extensionId])) |
| 39 |
return $this->FormOptions["Extensions"][$extensionId]; |
| 40 |
else |
| 41 |
return null; |
| 42 |
} |
| 43 |
|
| 44 |
public function GetField($fieldId) |
| 45 |
{ |
| 46 |
foreach($this->ElementOptions as $field) |
| 47 |
if($field["Id"]==$fieldId) |
| 48 |
return $field; |
| 49 |
|
| 50 |
throw new Exception("Invalid field ".$fieldId); |
| 51 |
} |
| 52 |
|
| 53 |
public function GetFieldEntryData($fieldId) |
| 54 |
{ |
| 55 |
foreach($this->FormEntryData as $key=>$value) |
| 56 |
if($key==$fieldId) |
| 57 |
return $value; |
| 58 |
|
| 59 |
throw new Exception("Invalid field ".$fieldId); |
| 60 |
} |
| 61 |
|
| 62 |
public function AddAction($action) |
| 63 |
{ |
| 64 |
array_push($this->_actions,$action); |
| 65 |
} |
| 66 |
|
| 67 |
protected function GetStringBuilder() |
| 68 |
{ |
| 69 |
if($this->_StringBuilder==null) |
| 70 |
{ |
| 71 |
include_once(SMART_FORMS_DIR.'string_renderer/rednao_string_builder.php'); |
| 72 |
$this->_StringBuilder=new rednao_string_builder(); |
| 73 |
} |
| 74 |
|
| 75 |
return $this->_StringBuilder; |
| 76 |
} |
| 77 |
|
| 78 |
public function GetFieldValue($fieldId,$serializationType=0) |
| 79 |
{ |
| 80 |
if($serializationType==SFSerializationType::TEXT) |
| 81 |
return $this->GetStringBuilder()->GetStringFromColumn($this->GetField($fieldId),$this->GetFieldEntryData($fieldId)); |
| 82 |
if($serializationType==SFSerializationType::DATE) |
| 83 |
return $this->GetStringBuilder()->GetDateValue($this->GetField($fieldId),$this->GetFieldEntryData($fieldId)); |
| 84 |
if($serializationType==SFSerializationType::ARRAYLIST) |
| 85 |
return $this->GetStringBuilder()->GetListValue($this->GetField($fieldId),$this->GetFieldEntryData($fieldId)); |
| 86 |
|
| 87 |
throw new Exception('Invalid Serialization Type'); |
| 88 |
} |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
abstract class SFSerializationType{ |
| 93 |
const TEXT=0; |
| 94 |
const DATE=1; |
| 95 |
const ARRAYLIST=2; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
class InsertEntryActionBase |
| 100 |
{ |
| 101 |
public $Action=""; |
| 102 |
public $Value=Array(); |
| 103 |
|
| 104 |
public function GetSerializedData() |
| 105 |
{ |
| 106 |
return Array( |
| 107 |
"Action"=>$this->Action, |
| 108 |
"Value"=>$this->Value |
| 109 |
); |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
class ShowMessageInsertEntryAction extends InsertEntryActionBase{ |
| 115 |
public $_message; |
| 116 |
/** |
| 117 |
* @var |
| 118 |
*/ |
| 119 |
|
| 120 |
public function __construct($message) |
| 121 |
{ |
| 122 |
$this->_message = $message; |
| 123 |
$this->Action="ShowMessage"; |
| 124 |
$this->Value["Message"]=$message; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
class RedirectToInsertEntryAction extends InsertEntryActionBase{ |
| 131 |
/** |
| 132 |
* @var |
| 133 |
*/ |
| 134 |
|
| 135 |
public function __construct($url) |
| 136 |
{ |
| 137 |
$this->Action="RedirectTo"; |
| 138 |
$this->Value=$url; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
class CustomActionEntryAction extends InsertEntryActionBase{ |
| 145 |
public function __construct($action,$value) |
| 146 |
{ |
| 147 |
$this->Action=$action; |
| 148 |
$this->Value=$value; |
| 149 |
} |
| 150 |
|
| 151 |
} |