Mage_Eav_Model_Convert_Adapter_Entity Class Reference

Inheritance diagram for Mage_Eav_Model_Convert_Adapter_Entity:

Mage_Dataflow_Model_Convert_Adapter_Abstract Mage_Dataflow_Model_Convert_Container_Abstract Mage_Dataflow_Model_Convert_Adapter_Interface Mage_Dataflow_Model_Convert_Container_Interface Mage_Catalog_Model_Convert_Adapter_Product Mage_Customer_Model_Convert_Adapter_Customer

List of all members.

Public Member Functions

 getStoreId ()
 setFilter ($attrFilterArray, $attrToDb=null, $bind=null, $joinType=null)
 getFilter ()
 setJoinAttr ($joinAttr)
 setJoinField ($joinField)
 load ()
 save ()

Protected Member Functions

 _parseVars ()
 getFieldValue ($fields=array(), $name)
 _getCollectionForLoad ($entityType)

Protected Attributes

 $_store
 $_filter = array()
 $_joinFilter = array()
 $_joinAttr = array()
 $_attrToDb
 $_joinField = array()


Detailed Description

Definition at line 28 of file Entity.php.


Member Function Documentation

_getCollectionForLoad ( entityType  )  [protected]

Retrieve collection for load

Returns:
Mage_Eav_Model_Entity_Collection

Reimplemented in Mage_Catalog_Model_Convert_Adapter_Product.

Definition at line 293 of file Entity.php.

00294     {
00295         return Mage::getResourceModel($entityType.'_collection');
00296     }

_parseVars (  )  [protected]

Parameters:
$attrFilter - $attrArray['attrDB'] = ['like','eq','fromTo','dateFromTo]
$attrToDb - attribute name to DB field
Returns:
Mage_Eav_Model_Convert_Adapter_Entity

Definition at line 69 of file Entity.php.

00070     {
00071         $varFilters = $this->getVars();
00072         $filters = array();
00073         foreach ($varFilters as $key => $val) {
00074             if (substr($key,0,6) === 'filter') {
00075                 $keys = explode('/', $key, 2);
00076                 $filters[$keys[1]] = $val;
00077             }
00078         }
00079         return $filters;
00080     }

getFieldValue ( fields = array(),
name 
) [protected]

Definition at line 186 of file Entity.php.

00187     {
00188         $result = array();
00189         if ($fields && $name) {
00190             foreach($fields as $index => $value) {
00191                 $exp = explode('/', $index);
00192                 if (isset($exp[1]) && $exp[0] == $name) {
00193                     $result[$exp[1]] = $value;
00194                 }
00195             }
00196             if ($result) return $result;
00197         }
00198         return false;
00199     }

getFilter (  ) 

Definition at line 181 of file Entity.php.

00182     {
00183         return $this->_filter;
00184     }

getStoreId (  ) 

Retrieve store Id

Returns:
int

Definition at line 49 of file Entity.php.

00050     {
00051         if (is_null($this->_store)) {
00052             try {
00053                 $this->_store = Mage::app()->getStore($this->getVar('store'));
00054             }
00055             catch (Exception $e) {
00056                 $message = Mage::helper('eav')->__('Invalid store specified');
00057                 $this->addException($message, Varien_Convert_Exception::FATAL);
00058                 throw $e;
00059             }
00060         }
00061         return $this->_store->getId();
00062     }

load (  ) 

Load collection ids

Set collection ids

Implements Mage_Dataflow_Model_Convert_Adapter_Interface.

Reimplemented in Mage_Catalog_Model_Convert_Adapter_Product, and Mage_Customer_Model_Convert_Adapter_Customer.

Definition at line 221 of file Entity.php.

00222     {
00223         if (!($entityType = $this->getVar('entity_type'))
00224             || !(Mage::getResourceSingleton($entityType) instanceof Mage_Eav_Model_Entity_Interface)) {
00225             $this->addException(Mage::helper('eav')->__('Invalid entity specified'), Varien_Convert_Exception::FATAL);
00226         }
00227         try {
00228             $collection = $this->_getCollectionForLoad($entityType);
00229 
00230             if (isset($this->_joinAttr) && is_array($this->_joinAttr)) {
00231                 foreach ($this->_joinAttr as $val) {
00232 //                    print_r($val);
00233                     $collection->joinAttribute(
00234                         $val['alias'],
00235                         $val['attribute'],
00236                         $val['bind'],
00237                         null,
00238                         strtolower($val['joinType']),
00239                         $val['storeId']
00240                     );
00241                 }
00242             }
00243 
00244             $filterQuery = $this->getFilter();
00245             if (is_array($filterQuery)) {
00246                 foreach ($filterQuery as $val) {
00247                     $collection->addFieldToFilter(array($val));
00248                 }
00249             }
00250 
00251             $joinFields = $this->_joinField;
00252             if (isset($joinFields) && is_array($joinFields)) {
00253                 foreach ($joinFields as $field) {
00254 //                  print_r($field);
00255                     $collection->joinField(
00256                         $field['alias'],
00257                         $field['attribute'],
00258                         $field['field'],
00259                         $field['bind'],
00260                         $field['cond'],
00261                         $field['joinType']);
00262                }
00263            }
00264 
00265            /**
00266             * Load collection ids
00267             */
00268            $entityIds = $collection->getAllIds();
00269 
00270            $message = Mage::helper('eav')->__("Loaded %d records", count($entityIds));
00271            $this->addException($message);
00272         }
00273         catch (Varien_Convert_Exception $e) {
00274             throw $e;
00275         }
00276         catch (Exception $e) {
00277             $message = Mage::helper('eav')->__('Problem loading the collection, aborting. Error: %s', $e->getMessage());
00278             $this->addException($message, Varien_Convert_Exception::FATAL);
00279         }
00280 
00281         /**
00282          * Set collection ids
00283          */
00284         $this->setData($entityIds);
00285         return $this;
00286     }

save (  ) 

Implements Mage_Dataflow_Model_Convert_Adapter_Interface.

Reimplemented in Mage_Catalog_Model_Convert_Adapter_Product, and Mage_Customer_Model_Convert_Adapter_Customer.

Definition at line 298 of file Entity.php.

00299     {
00300         $collection = $this->getData();
00301         if ($collection instanceof Mage_Eav_Model_Entity_Collection_Abstract) {
00302             $this->addException(Mage::helper('eav')->__('Entity collections expected'), Varien_Convert_Exception::FATAL);
00303         }
00304 
00305         $this->addException($collection->getSize().' records found.');
00306 
00307         if (!$collection instanceof Mage_Eav_Model_Entity_Collection_Abstract) {
00308             $this->addException(Mage::helper('eav')->__('Entity collection expected'), Varien_Convert_Exception::FATAL);
00309         }
00310         try {
00311             $i = 0;
00312             foreach ($collection->getIterator() as $model) {
00313                 $model->save();
00314                 $i++;
00315             }
00316             $this->addException(Mage::helper('eav')->__("Saved ".$i." record(s)"));
00317         }
00318         catch (Varien_Convert_Exception $e) {
00319             throw $e;
00320         }
00321         catch (Exception $e) {
00322             $this->addException(Mage::helper('eav')->__('Problem saving the collection, aborting. Error: %s', $e->getMessage()),
00323                 Varien_Convert_Exception::FATAL);
00324         }
00325         return $this;
00326     }

setFilter ( attrFilterArray,
attrToDb = null,
bind = null,
joinType = null 
)

Definition at line 82 of file Entity.php.

00083     {
00084         if (is_null($bind)) {
00085             $defBind = 'entity_id';
00086         }
00087         if (is_null($joinType)) {
00088             $joinType = 'LEFT';
00089         }
00090 
00091         $this->_attrToDb=$attrToDb;
00092         $filters = $this->_parseVars();
00093 
00094         foreach ($attrFilterArray as $key => $type) {
00095             if (is_array($type)) {
00096                 if (isset($type['bind'])) {
00097                    $bind = $type['bind'];
00098                 } else {
00099                    $bind = $defBind;
00100                 }
00101                 $type = $type['type'];
00102             }
00103 
00104             if ($type == 'dateFromTo' || $type == 'datetimeFromTo') {
00105                 foreach ($filters as $k => $v) {
00106                     if (strpos($k, $key . '/') === 0) {
00107                         $split = split('/', $k);
00108                         $filters[$key][$split[1]] = $v;
00109                     }
00110                 }
00111             }
00112 
00113             $keyDB = (isset($this->_attrToDb[$key])) ? $this->_attrToDb[$key] : $key;
00114 
00115             $exp = explode('/',$key);
00116 
00117             if(isset($exp[1])){
00118                 if(isset($filters[$exp[1]])){
00119                    $val = $filters[$exp[1]];
00120                    $this->setJoinAttr(array(
00121                        'attribute' => $keyDB,
00122                        'bind' => $bind,
00123                        'joinType' => $joinType
00124                     ));
00125                 } else {
00126                     $val = null;
00127                 }
00128                 $keyDB = str_replace('/','_',$keyDB);
00129             } else {
00130                 $val = isset($filters[$key]) ? $filters[$key] : null;
00131             }
00132             if (is_null($val)) {
00133                 continue;
00134             }
00135             $attr = array();
00136             switch ($type){
00137                 case 'eq':
00138                     $attr = array(
00139                         'attribute' => $keyDB,
00140                         'eq'        => $val
00141                     );
00142                     break;
00143                 case 'like':
00144                     $attr = array(
00145                         'attribute' => $keyDB,
00146                         'like'      => '%'.$val.'%'
00147                     );
00148                     break;
00149                 case 'fromTo':
00150                     $attr = array(
00151                         'attribute' => $keyDB,
00152                         'from'      => $val['from'],
00153                         'to'        => $val['to']
00154                     );
00155                     break;
00156                 case 'dateFromTo':
00157                     $attr = array(
00158                         'attribute' => $keyDB,
00159                         'from'      => $val['from'],
00160                         'to'        => $val['to'],
00161                         'date'      => true
00162                     );
00163                     break;
00164                 case 'datetimeFromTo':
00165                     $attr = array(
00166                         'attribute' => $keyDB,
00167                         'from'      => $val['from'],
00168                         'to'        => $val['to'],
00169                         'datetime'  => true
00170                     );
00171                     break;
00172                 default:
00173                 break;
00174             }
00175             $this->_filter[] = $attr;
00176         }
00177 
00178         return $this;
00179     }

setJoinAttr ( joinAttr  ) 

Definition at line 201 of file Entity.php.

00202     {
00203         if(is_array($joinAttr)){
00204             $joinArrAttr = array();
00205             $joinArrAttr['attribute'] = isset($joinAttr['attribute']) ? $joinAttr['attribute'] : null;
00206             $joinArrAttr['alias'] = isset($joinAttr['attribute']) ? str_replace('/','_',$joinAttr['attribute']):null;
00207             $joinArrAttr['bind'] = isset($joinAttr['bind']) ? $joinAttr['bind'] : null;
00208             $joinArrAttr['joinType'] = isset($joinAttr['joinType']) ? $joinAttr['joinType'] : null;
00209             $joinArrAttr['storeId'] = isset($joinAttr['storeId']) ? $joinAttr['storeId'] : $this->getStoreId();
00210             $this->_joinAttr[] = $joinArrAttr;
00211         }
00212 
00213     }

setJoinField ( joinField  ) 

Definition at line 215 of file Entity.php.

00216     {
00217         if (is_array($joinField)) {
00218             $this->_joinField[] = $joinField;
00219         }
00220     }


Member Data Documentation

$_attrToDb [protected]

Definition at line 41 of file Entity.php.

$_filter = array() [protected]

Definition at line 38 of file Entity.php.

$_joinAttr = array() [protected]

Definition at line 40 of file Entity.php.

$_joinField = array() [protected]

Definition at line 42 of file Entity.php.

$_joinFilter = array() [protected]

Definition at line 39 of file Entity.php.

$_store [protected]

Definition at line 36 of file Entity.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:09 2009 for Magento by  doxygen 1.5.8