Mage_Directory_Model_Mysql4_Country_Collection Class Reference

Inheritance diagram for Mage_Directory_Model_Mysql4_Country_Collection:

Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 __construct ()
 loadByStore ()
 getItemById ($countryId)
 addCountryCodeFilter ($countryCode, $iso=array(0=> 'iso3', 'iso2'))
 addCountryIdFilter ($countryId)
 toOptionArray ($emptyLabel= ' ')

Protected Attributes

 $_countryTable


Detailed Description

Definition at line 34 of file Collection.php.


Constructor & Destructor Documentation

__construct (  ) 

Reimplemented from Varien_Data_Collection.

Definition at line 38 of file Collection.php.

00039     {
00040         parent::__construct(Mage::getSingleton('core/resource')->getConnection('directory_read'));
00041 
00042         $this->_countryTable = Mage::getSingleton('core/resource')->getTableName('directory/country');
00043 
00044         $this->_select->from(array('country'=>$this->_countryTable));
00045         $this->setItemObjectClass(Mage::getConfig()->getModelClassName('directory/country'));
00046     }


Member Function Documentation

addCountryCodeFilter ( countryCode,
iso = array(0 => 'iso3', 'iso2') 
)

Definition at line 70 of file Collection.php.

00071     {
00072         if (!empty($countryCode)) {
00073             $where_expr = '';
00074             if (is_array($countryCode)) {
00075                 if (is_array($iso)) {
00076                     $i = 0;
00077                     foreach ($iso as $iso_curr) {
00078                         $where_expr .= ($i++ > 0 ? ' OR ' : '');
00079                         $where_expr .= "country.{$iso_curr}_code IN ('".implode("','", $countryCode)."')";
00080                     }
00081                 } else {
00082                     $where_expr = "country.{$iso}_code IN ('".implode("','", $countryCode)."')";
00083                 }
00084             } else {
00085                 if (is_array($iso)) {
00086                     $i = 0;
00087                     foreach ($iso as $iso_curr) {
00088                         $where_expr .= ($i++ > 0 ? ' OR ' : '');
00089                         $where_expr = "country.{$iso_curr}_code = '{$countryCode}'";
00090                     }
00091                 } else {
00092                     $where_expr = "country.{$iso}_code = '{$countryCode}'";
00093                 }
00094             }
00095             $this->_select->where($where_expr);
00096         }
00097         return $this;
00098     }

addCountryIdFilter ( countryId  ) 

Definition at line 100 of file Collection.php.

00101     {
00102         if (!empty($countryId)) {
00103             if (is_array($countryId)) {
00104                 $this->_select->where("country.country_id IN ('".implode("','", $countryId)."')");
00105             } else {
00106                 $this->_select->where("country.country_id = '{$countryId}'");
00107             }
00108         }
00109         return $this;
00110     }

getItemById ( idValue  ) 

Retrieve item by id

Parameters:
mixed $idValue
Returns:
Varien_Object

Reimplemented from Varien_Data_Collection.

Definition at line 60 of file Collection.php.

00061     {
00062         foreach ($this->_items as $country) {
00063             if ($country->getCountryId() == $countryId) {
00064                 return $country;
00065             }
00066         }
00067         return Mage::getResourceModel('directory/country');
00068     }

loadByStore (  ) 

Definition at line 48 of file Collection.php.

00049     {
00050         $allowCountries = explode(',', (string)Mage::getStoreConfig('general/country/allow'));
00051         if (!empty($allowCountries)) {
00052             $this->addFieldToFilter("country.country_id", array('in'=>$allowCountries));
00053         }
00054 
00055         $this->load();
00056 
00057         return $this;
00058     }

toOptionArray ( emptyLabel = ' '  ) 

Definition at line 112 of file Collection.php.

00113     {
00114         $options = $this->_toOptionArray('country_id', 'name', array('title'=>'iso2_code'));
00115 
00116         $sort = array();
00117         foreach ($options as $index=>$data) {
00118             $name = Mage::app()->getLocale()->getCountryTranslation($data['value']);
00119             if (!empty($name)) {
00120                 $sort[$name] = $data['value'];
00121             }
00122         }
00123 
00124         ksort($sort);
00125         $options = array();
00126         foreach ($sort as $label=>$value) {
00127             $options[] = array(
00128                'value' => $value,
00129                'label' => $label
00130             );
00131         }
00132 
00133         if (count($options)>0 && $emptyLabel !== false) {
00134             array_unshift($options, array('value'=>'', 'label'=>$emptyLabel));
00135         }
00136         return $options;
00137     }


Member Data Documentation

$_countryTable [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