Mage_Directory_Model_Country Class Reference

Inheritance diagram for Mage_Directory_Model_Country:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 loadByCode ($code)
 getRegions ()
 getLoadedRegionCollection ()
 getRegionCollection ()
 formatAddress (Varien_Object $address, $html=false)
 getFormats ()
 getFormat ($type)
 getName ()

Static Public Attributes

static $_format = array()

Protected Member Functions

 _construct ()


Detailed Description

Country model

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 32 of file Country.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 36 of file Country.php.

00037     {
00038         $this->_init('directory/country');
00039     }

formatAddress ( Varien_Object address,
html = false 
)

Definition at line 66 of file Country.php.

00067     {
00068         //TODO: is it still used?
00069         $address->getRegion();
00070         $address->getCountry();
00071 
00072 
00073 
00074         $template = $this->getData('address_template_'.($html ? 'html' : 'plain'));
00075         if (empty($template)) {
00076             if (!$this->getId()) {
00077                 $template = '{{firstname}} {{lastname}}';
00078             } elseif (!$html) {
00079                 $template = "{{firstname}} {{lastname}}
00080 {{company}}
00081 {{street1}}
00082 {{street2}}
00083 {{city}}, {{region}} {{postcode}}";
00084             } else {
00085                 $template = "{{firstname}} {{lastname}}<br/>
00086 {{street}}<br/>
00087 {{city}}, {{region}} {{postcode}}<br/>
00088 T: {{telephone}}";
00089             }
00090         }
00091 
00092         $filter = new Varien_Filter_Template_Simple();
00093         $addressText = $filter->setData($address->getData())->filter($template);
00094 
00095         if ($html) {
00096             $addressText = preg_replace('#(<br\s*/?>\s*){2,}#im', '<br/>', $addressText);
00097         } else {
00098             $addressText = preg_replace('#(\n\s*){2,}#m', "\n", $addressText);
00099         }
00100 
00101         return $addressText;
00102     }

getFormat ( type  ) 

Retrive format

Parameters:
string $type
Returns:
Mage_Directory_Model_Country_Format

Definition at line 131 of file Country.php.

00132     {
00133         if ($this->getFormats()) {
00134             foreach ($this->getFormats() as $format) {
00135                 if ($format->getType()==$type) {
00136                     return $format;
00137                 }
00138             }
00139         }
00140         return null;
00141     }

getFormats (  ) 

Retrive formats for

Returns:
Mage_Directory_Model_Mysql4_Country_Format_Collection

Definition at line 109 of file Country.php.

00110     {
00111         if (!isset(self::$_format[$this->getId()]) && $this->getId()) {
00112             self::$_format[$this->getId()] = Mage::getModel('directory/country_format')
00113                                                 ->getCollection()
00114                                                 ->setCountryFilter($this)
00115                                                 ->load();
00116         }
00117 
00118         if (isset(self::$_format[$this->getId()])) {
00119             return self::$_format[$this->getId()];
00120         }
00121 
00122         return null;
00123     }

getLoadedRegionCollection (  ) 

Definition at line 52 of file Country.php.

00053     {
00054         $collection = $this->getRegionCollection();
00055         $collection->load();
00056         return $collection;
00057     }

getName (  ) 

Definition at line 143 of file Country.php.

00144     {
00145         if(!$this->getData('name')) {
00146             $this->setData(
00147                 'name',
00148                 Mage::app()->getLocale()->getCountryTranslation($this->getId())
00149             );
00150         }
00151         return $this->getData('name');
00152     }

getRegionCollection (  ) 

Definition at line 59 of file Country.php.

00060     {
00061         $collection = Mage::getResourceModel('directory/region_collection');
00062         $collection->addCountryFilter($this->getId());
00063         return $collection;
00064     }

getRegions (  ) 

Definition at line 47 of file Country.php.

00048     {
00049         return $this->getLoadedRegionCollection();
00050     }

loadByCode ( code  ) 

Definition at line 41 of file Country.php.

00042     {
00043         $this->_getResource()->loadByCode($this, $code);
00044         return $this;
00045     }


Member Data Documentation

$_format = array() [static]

Definition at line 34 of file Country.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