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:  * EAV Entity Attribute File Data Model
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_Eav
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Eav_Model_Attribute_Data_File extends Mage_Eav_Model_Attribute_Data_Abstract
 35: {
 36:     /**
 37:      * Validator for check not protected extensions
 38:      *
 39:      * @var Mage_Core_Model_File_Validator_NotProtectedExtension
 40:      */
 41:     protected $_validatorNotProtectedExtensions;
 42: 
 43:     /**
 44:      * Extract data from request and return value
 45:      *
 46:      * @param Zend_Controller_Request_Http $request
 47:      * @return array|string
 48:      */
 49:     public function extractValue(Zend_Controller_Request_Http $request)
 50:     {
 51:         if ($this->getIsAjaxRequest()) {
 52:             return false;
 53:         }
 54: 
 55:         $extend = $this->_getRequestValue($request);
 56: 
 57:         $attrCode  = $this->getAttribute()->getAttributeCode();
 58:         if ($this->_requestScope) {
 59:             $value  = array();
 60:             if (strpos($this->_requestScope, '/') !== false) {
 61:                 $scopes = explode('/', $this->_requestScope);
 62:                 $mainScope  = array_shift($scopes);
 63:             } else {
 64:                 $mainScope  = $this->_requestScope;
 65:                 $scopes     = array();
 66:             }
 67: 
 68:             if (!empty($_FILES[$mainScope])) {
 69:                 foreach ($_FILES[$mainScope] as $fileKey => $scopeData) {
 70:                     foreach ($scopes as $scopeName) {
 71:                         if (isset($scopeData[$scopeName])) {
 72:                             $scopeData = $scopeData[$scopeName];
 73:                         } else {
 74:                             $scopeData[$scopeName] = array();
 75:                         }
 76:                     }
 77: 
 78:                     if (isset($scopeData[$attrCode])) {
 79:                         $value[$fileKey] = $scopeData[$attrCode];
 80:                     }
 81:                 }
 82:             } else {
 83:                 $value = array();
 84:             }
 85:         } else {
 86:             if (isset($_FILES[$attrCode])) {
 87:                 $value = $_FILES[$attrCode];
 88:             } else {
 89:                 $value = array();
 90:             }
 91:         }
 92: 
 93:         if (!empty($extend['delete'])) {
 94:             $value['delete'] = true;
 95:         }
 96: 
 97:         return $value;
 98:     }
 99: 
100:     /**
101:      * Validate file by attribute validate rules
102:      * Return array of errors
103:      *
104:      * @param array $value
105:      * @return array
106:      */
107:     protected function _validateByRules($value)
108:     {
109:         $label  = $this->getAttribute()->getStoreLabel();
110:         $rules  = $this->getAttribute()->getValidateRules();
111:         $extension  = pathinfo($value['name'], PATHINFO_EXTENSION);
112: 
113:         if (!empty($rules['file_extensions'])) {
114:             $extensions = explode(',', $rules['file_extensions']);
115:             $extensions = array_map('trim', $extensions);
116:             if (!in_array($extension, $extensions)) {
117:                 return array(
118:                     Mage::helper('eav')->__('"%s" is not a valid file extension.', $label)
119:                 );
120:             }
121:         }
122: 
123:         /**
124:          * Check protected file extension
125:          */
126:         /** @var $validator Mage_Core_Model_File_Validator_NotProtectedExtension */
127:         $validator = Mage::getSingleton('core/file_validator_notProtectedExtension');
128:         if (!$validator->isValid($extension)) {
129:             return $validator->getMessages();
130:         }
131: 
132:         if (!is_uploaded_file($value['tmp_name'])) {
133:             return array(
134:                 Mage::helper('eav')->__('"%s" is not a valid file.', $label)
135:             );
136:         }
137: 
138:         if (!empty($rules['max_file_size'])) {
139:             $size = $value['size'];
140:             if ($rules['max_file_size'] < $size) {
141:                 return array(
142:                     Mage::helper('eav')->__('"%s" exceeds the allowed file size.', $label)
143:                 );
144:             };
145:         }
146: 
147:         return array();
148:     }
149: 
150:     /**
151:      * Validate data
152:      *
153:      * @param array|string $value
154:      * @throws Mage_Core_Exception
155:      * @return boolean
156:      */
157:     public function validateValue($value)
158:     {
159:         if ($this->getIsAjaxRequest()) {
160:             return true;
161:         }
162: 
163:         $errors     = array();
164:         $attribute  = $this->getAttribute();
165:         $label      = $attribute->getStoreLabel();
166: 
167:         $toDelete   = !empty($value['delete']) ? true : false;
168:         $toUpload   = !empty($value['tmp_name']) ? true : false;
169: 
170:         if (!$toUpload && !$toDelete && $this->getEntity()->getData($attribute->getAttributeCode())) {
171:             return true;
172:         }
173: 
174:         if (!$attribute->getIsRequired() && !$toUpload) {
175:             return true;
176:         }
177: 
178:         if ($attribute->getIsRequired() && !$toUpload) {
179:             $errors[] = Mage::helper('eav')->__('"%s" is a required value.', $label);
180:         }
181: 
182:         if ($toUpload) {
183:             $errors = array_merge($errors, $this->_validateByRules($value));
184:         }
185: 
186:         if (count($errors) == 0) {
187:             return true;
188:         }
189: 
190:         return $errors;
191:     }
192: 
193:     /**
194:      * Export attribute value to entity model
195:      *
196:      * @param Mage_Core_Model_Abstract $entity
197:      * @param array|string $value
198:      * @return Mage_Eav_Model_Attribute_Data_File
199:      */
200:     public function compactValue($value)
201:     {
202:         if ($this->getIsAjaxRequest()) {
203:             return $this;
204:         }
205: 
206:         $attribute = $this->getAttribute();
207:         $original  = $this->getEntity()->getData($attribute->getAttributeCode());
208:         $toDelete  = false;
209:         if ($original) {
210:             if (!$attribute->getIsRequired() && !empty($value['delete'])) {
211:                 $toDelete  = true;
212:             }
213:             if (!empty($value['tmp_name'])) {
214:                 $toDelete  = true;
215:             }
216:         }
217: 
218:         $path   = Mage::getBaseDir('media') . DS . $attribute->getEntity()->getEntityTypeCode();
219: 
220:         // unlink entity file
221:         if ($toDelete) {
222:             $this->getEntity()->setData($attribute->getAttributeCode(), '');
223:             $file = $path . $original;
224:             $ioFile = new Varien_Io_File();
225:             if ($ioFile->fileExists($file)) {
226:                 $ioFile->rm($file);
227:             }
228:         }
229: 
230:         if (!empty($value['tmp_name'])) {
231:             try {
232:                 $uploader = new Varien_File_Uploader($value);
233:                 $uploader->setFilesDispersion(true);
234:                 $uploader->setFilenamesCaseSensitivity(false);
235:                 $uploader->setAllowRenameFiles(true);
236:                 $uploader->save($path, $value['name']);
237:                 $fileName = $uploader->getUploadedFileName();
238:                 $this->getEntity()->setData($attribute->getAttributeCode(), $fileName);
239:             } catch (Exception $e) {
240:                 Mage::logException($e);
241:             }
242:         }
243: 
244:         return $this;
245:     }
246: 
247:     /**
248:      * Restore attribute value from SESSION to entity model
249:      *
250:      * @param array|string $value
251:      * @return Mage_Eav_Model_Attribute_Data_File
252:      */
253:     public function restoreValue($value)
254:     {
255:         return $this;
256:     }
257: 
258:     /**
259:      * Return formated attribute value from entity model
260:      *
261:      * @return string|array
262:      */
263:     public function outputValue($format = Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_TEXT)
264:     {
265:         $output = '';
266:         $value  = $this->getEntity()->getData($this->getAttribute()->getAttributeCode());
267:         if ($value) {
268:             switch ($format) {
269:                 case Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_JSON:
270:                     $output = array(
271:                         'value'     => $value,
272:                         'url_key'   => Mage::helper('core')->urlEncode($value)
273:                     );
274:                     break;
275:             }
276:         }
277: 
278:         return $output;
279:     }
280: }
281: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0