Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options Class Reference

Inheritance diagram for Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options:

Mage_Adminhtml_Block_Widget Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ()
 getDeleteButtonHtml ()
 getAddNewButtonHtml ()
 getStores ()
 getOptionValues ()
 getLabelValues ()
 getStoreOptionValues ($storeId)
 getAttributeObject ()

Protected Member Functions

 _prepareLayout ()


Detailed Description

Definition at line 34 of file Options.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

By default is looking for first argument as array and assignes it as object attributes This behaviour may change in child classes

Reimplemented from Varien_Object.

Definition at line 37 of file Options.php.

00038     {
00039         parent::__construct();
00040         $this->setTemplate('catalog/product/attribute/options.phtml');
00041     }


Member Function Documentation

_prepareLayout (  )  [protected]

Preparing global layout

You can redefine this method in child classes for changin layout

Returns:
Mage_Core_Block_Abstract

Reimplemented from Mage_Core_Block_Abstract.

Definition at line 43 of file Options.php.

00044     {
00045         $this->setChild('delete_button',
00046             $this->getLayout()->createBlock('adminhtml/widget_button')
00047                 ->setData(array(
00048                     'label' => Mage::helper('catalog')->__('Delete'),
00049                     'class' => 'delete delete-option'
00050                 )));
00051 
00052         $this->setChild('add_button',
00053             $this->getLayout()->createBlock('adminhtml/widget_button')
00054                 ->setData(array(
00055                     'label' => Mage::helper('catalog')->__('Add Option'),
00056                     'class' => 'add',
00057                     'id'    => 'add_new_option_button'
00058                 )));
00059         return parent::_prepareLayout();
00060     }

getAddNewButtonHtml (  ) 

Definition at line 67 of file Options.php.

00068     {
00069         return $this->getChildHtml('add_button');
00070     }

getAttributeObject (  ) 

Definition at line 180 of file Options.php.

00181     {
00182         return Mage::registry('entity_attribute');
00183     }

getDeleteButtonHtml (  ) 

Definition at line 62 of file Options.php.

00063     {
00064         return $this->getChildHtml('delete_button');
00065     }

getLabelValues (  ) 

Definition at line 143 of file Options.php.

00144     {
00145         $values = array();
00146         $values[0] = $this->getAttributeObject()->getFrontend()->getLabel();
00147         // it can be array and cause bug
00148         $frontendLabel = $this->getAttributeObject()->getFrontend()->getLabel();
00149         if (is_array($frontendLabel)) {
00150             $frontendLabel = array_shift($frontendLabel);
00151         }
00152         $translations = Mage::getModel('core/translate_string')
00153            ->load(Mage_Catalog_Model_Entity_Attribute::MODULE_NAME.Mage_Core_Model_Translate::SCOPE_SEPARATOR.$frontendLabel)
00154            ->getStoreTranslations();
00155         foreach ($this->getStores() as $store) {
00156             if ($store->getId() != 0) {
00157                 $values[$store->getId()] = isset($translations[$store->getId()]) ? $translations[$store->getId()] : '';
00158             }
00159         }
00160         return $values;
00161     }

getOptionValues (  ) 

Definition at line 85 of file Options.php.

00086     {
00087         $attributeType = $this->getAttributeObject()->getFrontendInput();
00088         $defaultValues = $this->getAttributeObject()->getDefaultValue();
00089         if ($attributeType == 'select' || $attributeType == 'multiselect') {
00090             $defaultValues = explode(',', $defaultValues);
00091         } else {
00092             $defaultValues = array();
00093         }
00094 
00095         switch ($attributeType) {
00096             case 'select':
00097                 $inputType = 'radio';
00098                 break;
00099             case 'multiselect':
00100                 $inputType = 'checkbox';
00101                 break;
00102             default:
00103                 $inputType = '';
00104                 break;
00105         }
00106 
00107         $values = $this->getData('option_values');
00108         if (is_null($values)) {
00109             $values = array();
00110             $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
00111                 ->setAttributeFilter($this->getAttributeObject()->getId())
00112                 ->setPositionOrder('desc', true)
00113                 ->load();
00114 
00115             foreach ($optionCollection as $option) {
00116                 $value = array();
00117                 if (in_array($option->getId(), $defaultValues)) {
00118                     $value['checked'] = 'checked="checked"';
00119                 } else {
00120                     $value['checked'] = '';
00121                 }
00122 
00123                 $value['intype'] = $inputType;
00124                 $value['id'] = $option->getId();
00125                 $value['sort_order'] = $option->getSortOrder();
00126                 foreach ($this->getStores() as $store) {
00127                     $storeValues = $this->getStoreOptionValues($store->getId());
00128                     if (isset($storeValues[$option->getId()])) {
00129                         $value['store'.$store->getId()] = htmlspecialchars($storeValues[$option->getId()]);
00130                     }
00131                     else {
00132                         $value['store'.$store->getId()] = '';
00133                     }
00134                 }
00135                 $values[] = new Varien_Object($value);
00136             }
00137             $this->setData('option_values', $values);
00138         }
00139 
00140         return $values;
00141     }

getStoreOptionValues ( storeId  ) 

Definition at line 163 of file Options.php.

00164     {
00165         $values = $this->getData('store_option_values_'.$storeId);
00166         if (is_null($values)) {
00167             $values = array();
00168             $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
00169                 ->setAttributeFilter($this->getAttributeObject()->getId())
00170                 ->setStoreFilter($storeId, false)
00171                 ->load();
00172             foreach ($valuesCollection as $item) {
00173                 $values[$item->getId()] = $item->getValue();
00174             }
00175             $this->setData('store_option_values_'.$storeId, $values);
00176         }
00177         return $values;
00178     }

getStores (  ) 

Definition at line 72 of file Options.php.

00073     {
00074         $stores = $this->getData('stores');
00075         if (is_null($stores)) {
00076             $stores = Mage::getModel('core/store')
00077                 ->getResourceCollection()
00078                 ->setLoadDefault(true)
00079                 ->load();
00080             $this->setData('stores', $stores);
00081         }
00082         return $stores;
00083     }


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

Generated on Sat Jul 4 17:22:43 2009 for Magento by  doxygen 1.5.8