Mage_Adminhtml_Model_Customer_Renderer_Region Class Reference

Inheritance diagram for Mage_Adminhtml_Model_Customer_Renderer_Region:

Varien_Data_Form_Element_Renderer_Interface

List of all members.

Public Member Functions

 render (Varien_Data_Form_Element_Abstract $element)

Static Protected Attributes

static $_regionCollections


Detailed Description

Definition at line 34 of file Region.php.


Member Function Documentation

render ( Varien_Data_Form_Element_Abstract element  ) 

Implements Varien_Data_Form_Element_Renderer_Interface.

Definition at line 47 of file Region.php.

00048     {
00049         $html = '<tr>'."\n";
00050 
00051         $countryId = false;
00052         if ($country = $element->getForm()->getElement('country_id')) {
00053             $countryId = $country->getValue();
00054         }
00055 
00056         $regionCollection = false;
00057         if ($countryId) {
00058             if (!isset(self::$_regionCollections[$countryId])) {
00059                 self::$_regionCollections[$countryId] = Mage::getModel('directory/country')
00060                     ->setId($countryId)
00061                     ->getLoadedRegionCollection();
00062             }
00063             $regionCollection = self::$_regionCollections[$countryId];
00064         }
00065 
00066         $regionId = $element->getForm()->getElement('region_id')->getValue();
00067 
00068         $htmlAttributes = $element->getHtmlAttributes();
00069         foreach ($htmlAttributes as $key => $attribute) {
00070             if ('type' === $attribute) {
00071                 unset($htmlAttributes[$key]);
00072                 break;
00073             }
00074         }
00075         if ($regionCollection && $regionCollection->getSize()) {
00076             $elementClass = $element->getClass();
00077             $element->setClass(str_replace('input-text', '', $elementClass));
00078             $html.= '<td class="label">'.$element->getLabelHtml().'</td>';
00079             $html.= '<td class="value"><select id="'.$element->getHtmlId().'" name="'.$element->getName().'" '
00080                  .$element->serialize($htmlAttributes).'>'."\n";
00081             foreach ($regionCollection as $region) {
00082                 $selected = ($regionId==$region->getId()) ? ' selected="selected"' : '';
00083                 $html.= '<option value="'.$region->getId().'"'.$selected.'>'.$region->getName().'</option>';
00084             }
00085             $html.= '</select></td>';
00086             $element->setClass($elementClass);
00087         }
00088         else {
00089             $element->setClass('input-text');
00090             $html.= '<td class="label"><label for="'.$element->getHtmlId().'">'
00091                 . $element->getLabel()
00092                 . ' <span class="required" style="display:none">*</span></label></td>';
00093 
00094             $element->setRequired(false);
00095             $html.= '<td class="value"><input id="'.$element->getHtmlId().'" name="'.$element->getName()
00096                  .'" value="'.$element->getEscapedValue().'"'.$element->serialize($htmlAttributes).'/></td>'."\n";
00097         }
00098         $html.= '</tr>'."\n";
00099         return $html;
00100     }


Member Data Documentation

$_regionCollections [static, protected]

Definition at line 45 of file Region.php.


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

Generated on Sat Jul 4 17:23:12 2009 for Magento by  doxygen 1.5.8