00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Model_Customer_Renderer_Region implements Varien_Data_Form_Element_Renderer_Interface
00035 {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 static protected $_regionCollections;
00046
00047 public function render(Varien_Data_Form_Element_Abstract $element)
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 }
00101 }