Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Catalog_Model_Entity_Product_Attribute_Design_Options_Container
  • Mage_Catalog_Model_Product_Attribute_Source_Inputtype
  • Mage_Eav_Block_Adminhtml_Attribute_Edit_Js
  • Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract
  • Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract
  • Mage_Eav_Helper_Data
  • Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype
  • Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype_Validator
  • Mage_Eav_Model_Attribute
  • Mage_Eav_Model_Attribute_Data
  • Mage_Eav_Model_Attribute_Data_Abstract
  • Mage_Eav_Model_Attribute_Data_Boolean
  • Mage_Eav_Model_Attribute_Data_Date
  • Mage_Eav_Model_Attribute_Data_File
  • Mage_Eav_Model_Attribute_Data_Hidden
  • Mage_Eav_Model_Attribute_Data_Image
  • Mage_Eav_Model_Attribute_Data_Multiline
  • Mage_Eav_Model_Attribute_Data_Multiselect
  • Mage_Eav_Model_Attribute_Data_Select
  • Mage_Eav_Model_Attribute_Data_Text
  • Mage_Eav_Model_Attribute_Data_Textarea
  • Mage_Eav_Model_Config
  • Mage_Eav_Model_Convert_Adapter_Entity
  • Mage_Eav_Model_Convert_Adapter_Grid
  • Mage_Eav_Model_Convert_Parser_Abstract
  • Mage_Eav_Model_Entity
  • Mage_Eav_Model_Entity_Abstract
  • Mage_Eav_Model_Entity_Attribute
  • Mage_Eav_Model_Entity_Attribute_Abstract
  • Mage_Eav_Model_Entity_Attribute_Backend_Abstract
  • Mage_Eav_Model_Entity_Attribute_Backend_Array
  • Mage_Eav_Model_Entity_Attribute_Backend_Datetime
  • Mage_Eav_Model_Entity_Attribute_Backend_Default
  • Mage_Eav_Model_Entity_Attribute_Backend_Increment
  • Mage_Eav_Model_Entity_Attribute_Backend_Serialized
  • Mage_Eav_Model_Entity_Attribute_Backend_Store
  • Mage_Eav_Model_Entity_Attribute_Backend_Time_Created
  • Mage_Eav_Model_Entity_Attribute_Backend_Time_Updated
  • Mage_Eav_Model_Entity_Attribute_Frontend_Abstract
  • Mage_Eav_Model_Entity_Attribute_Frontend_Datetime
  • Mage_Eav_Model_Entity_Attribute_Frontend_Default
  • Mage_Eav_Model_Entity_Attribute_Group
  • Mage_Eav_Model_Entity_Attribute_Option
  • Mage_Eav_Model_Entity_Attribute_Set
  • Mage_Eav_Model_Entity_Attribute_Source_Abstract
  • Mage_Eav_Model_Entity_Attribute_Source_Boolean
  • Mage_Eav_Model_Entity_Attribute_Source_Config
  • Mage_Eav_Model_Entity_Attribute_Source_Store
  • Mage_Eav_Model_Entity_Attribute_Source_Table
  • Mage_Eav_Model_Entity_Collection
  • Mage_Eav_Model_Entity_Collection_Abstract
  • Mage_Eav_Model_Entity_Increment_Abstract
  • Mage_Eav_Model_Entity_Increment_Alphanum
  • Mage_Eav_Model_Entity_Increment_Numeric
  • Mage_Eav_Model_Entity_Setup
  • Mage_Eav_Model_Entity_Store
  • Mage_Eav_Model_Entity_Type
  • Mage_Eav_Model_Form
  • Mage_Eav_Model_Form_Element
  • Mage_Eav_Model_Form_Fieldset
  • Mage_Eav_Model_Form_Type
  • Mage_Eav_Model_Mysql4_Config
  • Mage_Eav_Model_Mysql4_Entity_Attribute
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Collection
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Group
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Option
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Option_Collection
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Set
  • Mage_Eav_Model_Mysql4_Entity_Attribute_Set_Collection
  • Mage_Eav_Model_Mysql4_Entity_Store
  • Mage_Eav_Model_Mysql4_Entity_Type
  • Mage_Eav_Model_Mysql4_Entity_Type_Collection
  • Mage_Eav_Model_Mysql4_Form_Element
  • Mage_Eav_Model_Mysql4_Form_Element_Collection
  • Mage_Eav_Model_Mysql4_Form_Fieldset
  • Mage_Eav_Model_Mysql4_Form_Fieldset_Collection
  • Mage_Eav_Model_Mysql4_Form_Type
  • Mage_Eav_Model_Mysql4_Form_Type_Collection
  • Mage_Eav_Model_Resource_Attribute
  • Mage_Eav_Model_Resource_Attribute_Collection
  • Mage_Eav_Model_Resource_Config
  • Mage_Eav_Model_Resource_Entity_Attribute
  • Mage_Eav_Model_Resource_Entity_Attribute_Collection
  • Mage_Eav_Model_Resource_Entity_Attribute_Group
  • Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection
  • Mage_Eav_Model_Resource_Entity_Attribute_Option
  • Mage_Eav_Model_Resource_Entity_Attribute_Option_Collection
  • Mage_Eav_Model_Resource_Entity_Attribute_Set
  • Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection
  • Mage_Eav_Model_Resource_Entity_Store
  • Mage_Eav_Model_Resource_Entity_Type
  • Mage_Eav_Model_Resource_Entity_Type_Collection
  • Mage_Eav_Model_Resource_Form_Attribute
  • Mage_Eav_Model_Resource_Form_Attribute_Collection
  • Mage_Eav_Model_Resource_Form_Element
  • Mage_Eav_Model_Resource_Form_Element_Collection
  • Mage_Eav_Model_Resource_Form_Fieldset
  • Mage_Eav_Model_Resource_Form_Fieldset_Collection
  • Mage_Eav_Model_Resource_Form_Type
  • Mage_Eav_Model_Resource_Form_Type_Collection
  • Mage_Eav_Model_Resource_Helper_Mysql4

Interfaces

  • Mage_Eav_Model_Entity_Attribute_Backend_Interface
  • Mage_Eav_Model_Entity_Attribute_Frontend_Interface
  • Mage_Eav_Model_Entity_Attribute_Interface
  • Mage_Eav_Model_Entity_Attribute_Source_Interface
  • Mage_Eav_Model_Entity_Increment_Interface
  • Mage_Eav_Model_Entity_Interface

Exceptions

  • Mage_Eav_Exception
  • Mage_Eav_Model_Entity_Attribute_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Eav
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: class Mage_Eav_Model_Convert_Adapter_Entity
 29:     extends Mage_Dataflow_Model_Convert_Adapter_Abstract
 30: {
 31:     /**
 32:      * Current store model
 33:      *
 34:      * @var Mage_Core_Model_Store
 35:      */
 36:     protected $_store;
 37: 
 38:     protected $_filter = array();
 39:     protected $_joinFilter = array();
 40:     protected $_joinAttr = array();
 41:     protected $_attrToDb;
 42:     protected $_joinField = array();
 43: 
 44:     /**
 45:      * Retrieve store Id
 46:      *
 47:      * @return int
 48:      */
 49:     public function getStoreId()
 50:     {
 51:         if (is_null($this->_store)) {
 52:             try {
 53:                 $this->_store = Mage::app()->getStore($this->getVar('store'));
 54:             }
 55:             catch (Exception $e) {
 56:                 $message = Mage::helper('eav')->__('Invalid store specified');
 57:                 $this->addException($message, Varien_Convert_Exception::FATAL);
 58:                 throw $e;
 59:             }
 60:         }
 61:         return $this->_store->getId();
 62:     }
 63: 
 64:     /**
 65:      * @param $attrFilter - $attrArray['attrDB']   = ['like','eq','fromTo','dateFromTo]
 66:      * @param $attrToDb    - attribute name to DB field
 67:      * @return Mage_Eav_Model_Convert_Adapter_Entity
 68:     */
 69:     protected function _parseVars()
 70:     {
 71:         $varFilters = $this->getVars();
 72:         $filters = array();
 73:         foreach ($varFilters as $key => $val) {
 74:             if (substr($key,0,6) === 'filter') {
 75:                 $keys = explode('/', $key, 2);
 76:                 $filters[$keys[1]] = $val;
 77:             }
 78:         }
 79:         return $filters;
 80:     }
 81: 
 82:     public function setFilter($attrFilterArray, $attrToDb = null, $bind = null, $joinType = null)
 83:     {
 84:         if (is_null($bind)) {
 85:             $defBind = 'entity_id';
 86:         }
 87:         if (is_null($joinType)) {
 88:             $joinType = 'LEFT';
 89:         }
 90: 
 91:         $this->_attrToDb=$attrToDb;
 92:         $filters = $this->_parseVars();
 93: 
 94:         foreach ($attrFilterArray as $key => $type) {
 95:             if (is_array($type)) {
 96:                 if (isset($type['bind'])) {
 97:                    $bind = $type['bind'];
 98:                 } else {
 99:                    $bind = $defBind;
100:                 }
101:                 $type = $type['type'];
102:             }
103: 
104:             if ($type == 'dateFromTo' || $type == 'datetimeFromTo') {
105:                 foreach ($filters as $k => $v) {
106:                     if (strpos($k, $key . '/') === 0) {
107:                         $split = explode('/', $k);
108:                         $filters[$key][$split[1]] = $v;
109:                     }
110:                 }
111:             }
112: 
113:             $keyDB = (isset($this->_attrToDb[$key])) ? $this->_attrToDb[$key] : $key;
114: 
115:             $exp = explode('/',$key);
116: 
117:             if(isset($exp[1])){
118:                 if(isset($filters[$exp[1]])){
119:                    $val = $filters[$exp[1]];
120:                    $this->setJoinAttr(array(
121:                        'attribute' => $keyDB,
122:                        'bind' => $bind,
123:                        'joinType' => $joinType
124:                     ));
125:                 } else {
126:                     $val = null;
127:                 }
128:                 $keyDB = str_replace('/','_',$keyDB);
129:             } else {
130:                 $val = isset($filters[$key]) ? $filters[$key] : null;
131:             }
132:             if (is_null($val)) {
133:                 continue;
134:             }
135:             $attr = array();
136:             switch ($type){
137:                 case 'eq':
138:                     $attr = array(
139:                         'attribute' => $keyDB,
140:                         'eq'        => $val
141:                     );
142:                     break;
143:                 case 'like':
144:                     $attr = array(
145:                         'attribute' => $keyDB,
146:                         'like'      => '%'.$val.'%'
147:                     );
148:                     break;
149:                 case 'startsWith':
150:                      $attr = array(
151:                          'attribute' => $keyDB,
152:                          'like'      => $val.'%'
153:                      );
154:                      break;
155:                 case 'fromTo':
156:                     $attr = array(
157:                         'attribute' => $keyDB,
158:                         'from'      => $val['from'],
159:                         'to'        => $val['to']
160:                     );
161:                     break;
162:                 case 'dateFromTo':
163:                     $attr = array(
164:                         'attribute' => $keyDB,
165:                         'from'      => $val['from'],
166:                         'to'        => $val['to'],
167:                         'date'      => true
168:                     );
169:                     break;
170:                 case 'datetimeFromTo':
171:                     $attr = array(
172:                         'attribute' => $keyDB,
173:                         'from'      => isset($val['from']) ? $val['from'] : null,
174:                         'to'        => isset($val['to']) ? $val['to'] : null,
175:                         'datetime'  => true
176:                     );
177:                     break;
178:                 default:
179:                 break;
180:             }
181:             $this->_filter[] = $attr;
182:         }
183: 
184:         return $this;
185:     }
186: 
187:     public function getFilter()
188:     {
189:         return $this->_filter;
190:     }
191: 
192:     protected function getFieldValue($fields = array(), $name)
193:     {
194:         $result = array();
195:         if ($fields && $name) {
196:             foreach($fields as $index => $value) {
197:                 $exp = explode('/', $index);
198:                 if (isset($exp[1]) && $exp[0] == $name) {
199:                     $result[$exp[1]] = $value;
200:                 }
201:             }
202:             if ($result) return $result;
203:         }
204:         return false;
205:     }
206: 
207:     public function setJoinAttr($joinAttr)
208:     {
209:         if(is_array($joinAttr)){
210:             $joinArrAttr = array();
211:             $joinArrAttr['attribute'] = isset($joinAttr['attribute']) ? $joinAttr['attribute'] : null;
212:             $joinArrAttr['alias'] = isset($joinAttr['attribute']) ? str_replace('/','_',$joinAttr['attribute']):null;
213:             $joinArrAttr['bind'] = isset($joinAttr['bind']) ? $joinAttr['bind'] : null;
214:             $joinArrAttr['joinType'] = isset($joinAttr['joinType']) ? $joinAttr['joinType'] : null;
215:             $joinArrAttr['storeId'] = isset($joinAttr['storeId']) ? $joinAttr['storeId'] : $this->getStoreId();
216:             $this->_joinAttr[] = $joinArrAttr;
217:         }
218: 
219:     }
220: 
221:     /**
222:      * Add join field
223:      *
224:      * @param array $joinField   Variable should be have view:
225:      *     Example:
226:      *         array(
227:      *            'alias'     => 'alias_table',
228:      *            'attribute' => 'table_name', //table name, must be used path of table like 'module/table_name'
229:      *            'field'     => 'field_name', //selected field name (optional)
230:      *            //bind main condition
231:      *            //left field use for joined table
232:      *            //and right field use for main table of collection
233:      *            //NOTE: around '=' cannot be used ' ' (space) because on the exploding not use space trimming
234:      *            'bind'      => 'self_item_id=other_id',
235:      *            'cond'      => 'alias_table.entity_id = e.entity_id', //additional condition (optional)
236:      *            'joinType'  => 'LEFT'
237:      *         )
238:      *     NOTE: Optional key must be have NULL at least
239:      * @return void
240:      */
241:     public function setJoinField($joinField)
242:     {
243:         if (is_array($joinField)) {
244:             $this->_joinField[] = $joinField;
245:         }
246:     }
247: 
248:     public function load()
249:     {
250:         if (!($entityType = $this->getVar('entity_type'))
251:             || !(Mage::getResourceSingleton($entityType) instanceof Mage_Eav_Model_Entity_Interface)) {
252:             $this->addException(Mage::helper('eav')->__('Invalid entity specified'), Varien_Convert_Exception::FATAL);
253:         }
254:         try {
255:             $collection = $this->_getCollectionForLoad($entityType);
256: 
257:             if (isset($this->_joinAttr) && is_array($this->_joinAttr)) {
258:                 foreach ($this->_joinAttr as $val) {
259: //                    print_r($val);
260:                     $collection->joinAttribute(
261:                         $val['alias'],
262:                         $val['attribute'],
263:                         $val['bind'],
264:                         null,
265:                         strtolower($val['joinType']),
266:                         $val['storeId']
267:                     );
268:                 }
269:             }
270: 
271:             $filterQuery = $this->getFilter();
272:             if (is_array($filterQuery)) {
273:                 foreach ($filterQuery as $val) {
274:                     $collection->addFieldToFilter(array($val));
275:                 }
276:             }
277: 
278:             $joinFields = $this->_joinField;
279:             if (isset($joinFields) && is_array($joinFields)) {
280:                 foreach ($joinFields as $field) {
281: //                  print_r($field);
282:                     $collection->joinField(
283:                         $field['alias'],
284:                         $field['attribute'],
285:                         $field['field'],
286:                         $field['bind'],
287:                         $field['cond'],
288:                         $field['joinType']);
289:                }
290:            }
291: 
292:            /**
293:             * Load collection ids
294:             */
295:            $entityIds = $collection->getAllIds();
296: 
297:            $message = Mage::helper('eav')->__("Loaded %d records", count($entityIds));
298:            $this->addException($message);
299:         }
300:         catch (Varien_Convert_Exception $e) {
301:             throw $e;
302:         }
303:         catch (Exception $e) {
304:             $message = Mage::helper('eav')->__('Problem loading the collection, aborting. Error: %s', $e->getMessage());
305:             $this->addException($message, Varien_Convert_Exception::FATAL);
306:         }
307: 
308:         /**
309:          * Set collection ids
310:          */
311:         $this->setData($entityIds);
312:         return $this;
313:     }
314: 
315:     /**
316:      * Retrieve collection for load
317:      *
318:      * @return Mage_Eav_Model_Entity_Collection
319:      */
320:     protected function _getCollectionForLoad($entityType)
321:     {
322:         return Mage::getResourceModel($entityType.'_collection');
323:     }
324: 
325:     public function save()
326:     {
327:         $collection = $this->getData();
328:         if ($collection instanceof Mage_Eav_Model_Entity_Collection_Abstract) {
329:             $this->addException(Mage::helper('eav')->__('Entity collections expected.'), Varien_Convert_Exception::FATAL);
330:         }
331: 
332:         $this->addException($collection->getSize().' records found.');
333: 
334:         if (!$collection instanceof Mage_Eav_Model_Entity_Collection_Abstract) {
335:             $this->addException(Mage::helper('eav')->__('Entity collection expected.'), Varien_Convert_Exception::FATAL);
336:         }
337:         try {
338:             $i = 0;
339:             foreach ($collection->getIterator() as $model) {
340:                 $model->save();
341:                 $i++;
342:             }
343:             $this->addException(Mage::helper('eav')->__("Saved %d record(s).", $i));
344:         }
345:         catch (Varien_Convert_Exception $e) {
346:             throw $e;
347:         }
348:         catch (Exception $e) {
349:             $this->addException(Mage::helper('eav')->__('Problem saving the collection, aborting. Error: %s', $e->getMessage()),
350:                 Varien_Convert_Exception::FATAL);
351:         }
352:         return $this;
353:     }
354: }
355: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0