00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 abstract class Mage_Dataflow_Model_Convert_Container_Abstract
00036 implements Mage_Dataflow_Model_Convert_Container_Interface
00037 {
00038 protected $_batchParams = array();
00039
00040 protected $_vars;
00041
00042 protected $_profile;
00043
00044 protected $_action;
00045
00046 protected $_data;
00047
00048 protected $_position;
00049
00050 public function getVar($key, $default=null)
00051 {
00052 if (!isset($this->_vars[$key]) || (!is_array($this->_vars[$key]) && strlen($this->_vars[$key]) == 0)) {
00053 return $default;
00054 }
00055 return $this->_vars[$key];
00056 }
00057
00058 public function getVars()
00059 {
00060 return $this->_vars;
00061 }
00062
00063 public function setVar($key, $value=null)
00064 {
00065 if (is_array($key) && is_null($value)) {
00066 $this->_vars = $key;
00067 } else {
00068 $this->_vars[$key] = $value;
00069 }
00070 return $this;
00071 }
00072
00073 public function getAction()
00074 {
00075 return $this->_action;
00076 }
00077
00078 public function setAction(Mage_Dataflow_Model_Convert_Action_Interface $action)
00079 {
00080 $this->_action = $action;
00081 return $this;
00082 }
00083
00084 public function getProfile()
00085 {
00086 return $this->_profile;
00087 }
00088
00089 public function setProfile(Mage_Dataflow_Model_Convert_Profile_Interface $profile)
00090 {
00091 $this->_profile = $profile;
00092 return $this;
00093 }
00094
00095 public function getData()
00096 {
00097 if (is_null($this->_data) && $this->getProfile()) {
00098 $this->_data = $this->getProfile()->getContainer()->getData();
00099 }
00100 return $this->_data;
00101 }
00102
00103 public function setData($data)
00104 {
00105 if ($this->getProfile()) {
00106 $this->getProfile()->getContainer()->setData($data);
00107 }
00108 $this->_data = $data;
00109 return $this;
00110 }
00111
00112 public function validateDataString($data=null)
00113 {
00114 if (is_null($data)) {
00115 $data = $this->getData();
00116 }
00117 if (!is_string($data)) {
00118 $this->addException("Invalid data type, expecting string.", Mage_Dataflow_Model_Convert_Exception::FATAL);
00119 }
00120 return true;
00121 }
00122
00123 public function validateDataArray($data=null)
00124 {
00125 if (is_null($data)) {
00126 $data = $this->getData();
00127 }
00128 if (!is_array($data)) {
00129 $this->addException("Invalid data type, expecting array.", Mage_Dataflow_Model_Convert_Exception::FATAL);
00130 }
00131 return true;
00132 }
00133
00134 public function validateDataGrid($data=null)
00135 {
00136 if (is_null($data)) {
00137 $data = $this->getData();
00138 }
00139 if (!is_array($data) || !is_array(current($data))) {
00140 if (count($data)==0) {
00141 return true;
00142 }
00143 $this->addException("Invalid data type, expecting 2D grid array.", Mage_Dataflow_Model_Convert_Exception::FATAL);
00144 }
00145 return true;
00146 }
00147
00148 public function getGridFields($grid)
00149 {
00150 $fields = array();
00151 foreach ($grid as $i=>$row) {
00152 foreach ($row as $fieldName=>$data) {
00153 if (!in_array($fieldName, $fields)) {
00154 $fields[] = $fieldName;
00155 }
00156 }
00157 }
00158 return $fields;
00159 }
00160
00161 public function addException($error, $level=null)
00162 {
00163 $e = new Mage_Dataflow_Model_Convert_Exception($error);
00164 $e->setLevel(!is_null($level) ? $level : Mage_Dataflow_Model_Convert_Exception::NOTICE);
00165 $e->setContainer($this);
00166 $e->setPosition($this->getPosition());
00167
00168 if ($this->getProfile()) {
00169 $this->getProfile()->addException($e);
00170 }
00171
00172 return $e;
00173 }
00174
00175 public function getPosition()
00176 {
00177 return $this->_position;
00178 }
00179
00180 public function setPosition($position)
00181 {
00182 $this->_position = $position;
00183 return $this;
00184 }
00185
00186 public function setBatchParams($data)
00187 {
00188 if (is_array($data)) {
00189 $this->_batchParams = $data;
00190 }
00191 return $this;
00192 }
00193
00194 public function getBatchParams($key = null)
00195 {
00196 if (!empty($key)) {
00197 return isset($this->_batchParams[$key]) ? $this->_batchParams[$key] : null;
00198 }
00199 return $this->_batchParams;
00200 }
00201 }