Mage_Directory_Model_Mysql4_Region_Collection Class Reference

Inheritance diagram for Mage_Directory_Model_Mysql4_Region_Collection:

Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 __construct ()
 addCountryFilter ($countryId)
 addCountryCodeFilter ($countryCode)
 addRegionCodeFilter ($regionCode)
 addRegionNameFilter ($regionName)
 toOptionArray ()

Protected Attributes

 $_regionTable
 $_regionNameTable
 $_countryTable


Detailed Description

Definition at line 34 of file Collection.php.


Constructor & Destructor Documentation

__construct (  ) 

Reimplemented from Varien_Data_Collection.

Definition at line 40 of file Collection.php.

00041     {
00042         parent::__construct(Mage::getSingleton('core/resource')->getConnection('directory_read'));
00043 
00044         $this->_countryTable    = Mage::getSingleton('core/resource')->getTableName('directory/country');
00045         $this->_regionTable     = Mage::getSingleton('core/resource')->getTableName('directory/country_region');
00046         $this->_regionNameTable = Mage::getSingleton('core/resource')->getTableName('directory/country_region_name');
00047 
00048         $locale = Mage::app()->getLocale()->getLocaleCode();
00049 
00050         $this->_select->from(array('region'=>$this->_regionTable),
00051             array('region_id'=>'region_id', 'country_id'=>'country_id', 'code'=>'code', 'default_name'=>'default_name')
00052         );
00053         $this->_select->joinLeft(array('rname'=>$this->_regionNameTable),
00054             "region.region_id=rname.region_id AND rname.locale='$locale'", array('name'));
00055 
00056         $this->setItemObjectClass(Mage::getConfig()->getModelClassName('directory/region'));
00057     }


Member Function Documentation

addCountryCodeFilter ( countryCode  ) 

Definition at line 71 of file Collection.php.

00072     {
00073         $this->_select->joinLeft(array('country'=>$this->_countryTable), 'region.country_id=country.country_id');
00074         $this->_select->where("country.iso3_code = '{$countryCode}'");
00075         return $this;
00076     }

addCountryFilter ( countryId  ) 

Definition at line 59 of file Collection.php.

00060     {
00061         if (!empty($countryId)) {
00062             if (is_array($countryId)) {
00063                 $this->addFieldToFilter('region.country_id', array('in'=>$countryId));
00064             } else {
00065                 $this->addFieldToFilter('region.country_id', $countryId);
00066             }
00067         }
00068         return $this;
00069     }

addRegionCodeFilter ( regionCode  ) 

Definition at line 78 of file Collection.php.

00079     {
00080         if (!empty($regionCode)) {
00081             if (is_array($regionCode)) {
00082                 $this->_select->where("region.code IN ('".implode("','", $regionCode)."')");
00083             } else {
00084                 $this->_select->where("region.code = '{$regionCode}'");
00085             }
00086         }
00087         return $this;
00088     }

addRegionNameFilter ( regionName  ) 

Definition at line 90 of file Collection.php.

00091     {
00092         if (!empty($regionName)) {
00093             if (is_array($regionName)) {
00094                 $this->_select->where("region.default_name in ('".implode("','", $regionName)."')");
00095             } else {
00096                 $this->_select->where("region.default_name = '{$regionName}'");
00097             }
00098         }
00099         return $this;
00100     }

toOptionArray (  ) 

Reimplemented from Varien_Data_Collection.

Definition at line 102 of file Collection.php.

00103     {
00104         $options = array();
00105         foreach ($this as $item) {
00106             $options[] = array(
00107                'value' => $item->getId(),
00108                'label' => $item->getName()
00109             );
00110         }
00111         if (count($options)>0) {
00112             array_unshift($options, array('title'=>null, 'value'=>'0', 'label'=>Mage::helper('directory')->__('-- Please select --')));
00113         }
00114         return $options;
00115     }


Member Data Documentation

$_countryTable [protected]

Definition at line 38 of file Collection.php.

$_regionNameTable [protected]

Definition at line 37 of file Collection.php.

$_regionTable [protected]

Definition at line 36 of file Collection.php.


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

Generated on Sat Jul 4 17:24:07 2009 for Magento by  doxygen 1.5.8