172 lines
4.7 KiB
PHP
172 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* SOTESHOP/stCountriesPlugin
|
|
*
|
|
* Ten plik należy do aplikacji stCountriesPlugin opartej na licencji (Professional License SOTE).
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stCountriesPlugin
|
|
* @subpackage helpers
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/sote (Professional License SOTE)
|
|
* @version $Id: CountriesHelper.php 4 2009-08-24 08:52:56Z marcin $
|
|
* @author Marcin Olejniczak <marcin.olejniczak@sote.pl>
|
|
*/
|
|
|
|
/**
|
|
* Pobieranie nazwy kraju
|
|
*
|
|
* @param integer $country numer kraju
|
|
* @return string nazwa kraju
|
|
*/
|
|
function getName($country)
|
|
{
|
|
$country = CountriesPeer::retrieveByPK($country);
|
|
return $country->getName();
|
|
}
|
|
|
|
/**
|
|
* Pobieranie strefy kraju
|
|
*
|
|
* @param integer $country numer kraju
|
|
* @return integer strefa kraju
|
|
*/
|
|
function getArea($country)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(CountriesAreaHasCountriesPeer::COUNTRIES_ID , $country);
|
|
$country_area = CountriesAreaHasCountriesPeer::doSelectOne($c);
|
|
|
|
return $country_area->getCountriesAreaId();
|
|
}
|
|
|
|
function st_countries_select_tag($name, $value, array $params = array())
|
|
{
|
|
$iso = false;
|
|
$countryName = false;
|
|
|
|
$optionsParams = array();
|
|
|
|
if (isset($params['include_custom']))
|
|
{
|
|
$optionsParams['include_custom'] = $params['include_custom'];
|
|
unset($params['include_custom']);
|
|
}
|
|
|
|
if (isset($params['include_custom']))
|
|
{
|
|
$optionsParams['include_custom'] = $params['include_custom'];
|
|
}
|
|
|
|
if (isset($params['iso']))
|
|
{
|
|
$iso = $params['iso'];
|
|
unset($params['iso']);
|
|
}
|
|
|
|
if (isset($params['country_name']))
|
|
{
|
|
$countryName = $params['country_name'];
|
|
unset($params['country_name']);
|
|
}
|
|
|
|
if (!isset($params['all']))
|
|
{
|
|
$countries = CountriesPeer::doSelectActiveCached();
|
|
|
|
$eu = array();
|
|
$outsideEu = array();
|
|
|
|
foreach ($countries as $country)
|
|
{
|
|
if ($countryName)
|
|
{
|
|
$id = $country->getOptName();
|
|
}
|
|
elseif ($iso)
|
|
{
|
|
$id = $country->getIsoA2();
|
|
}
|
|
else
|
|
{
|
|
$id = $country->getId();
|
|
}
|
|
|
|
if ($country->isEU())
|
|
{
|
|
$eu[$id] = $country->getName();
|
|
}
|
|
else
|
|
{
|
|
$outsideEu[$id] = $country->getName();
|
|
}
|
|
}
|
|
|
|
$options = array("Unia Europejska" => $eu, "Państwa spoza Unii Europejskiej" => $outsideEu);
|
|
}
|
|
else
|
|
{
|
|
unset($params['all']);
|
|
|
|
CountriesPeer::setHydrateMethod(function(ResultSet $rs) use ($iso, $countryName) {
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
$eu = array();
|
|
$outsideEu = array();
|
|
|
|
while($rs->next())
|
|
{
|
|
$row = $rs->getRow();
|
|
|
|
$name = $row['NAME'] ? $row['NAME'] : $row['OPT_NAME'];
|
|
$code = $row['ISO_A2'];
|
|
|
|
if ($countryName)
|
|
{
|
|
$id = $name;
|
|
}
|
|
elseif ($iso)
|
|
{
|
|
$id = $code;
|
|
}
|
|
else
|
|
{
|
|
$id = $row['ID'];
|
|
}
|
|
|
|
if (CountriesPeer::isEuCountryCode($code))
|
|
{
|
|
$eu[$id] = $name;
|
|
}
|
|
else
|
|
{
|
|
$outsideEu[$id] = $name;
|
|
}
|
|
}
|
|
|
|
return array($eu, $outsideEu);
|
|
});
|
|
|
|
$c = new Criteria();
|
|
$c->addSelectColumn(CountriesPeer::ID);
|
|
$c->addSelectColumn(CountriesPeer::ISO_A2);
|
|
$c->addSelectColumn(CountriesPeer::OPT_NAME);
|
|
$c->addSelectColumn(CountriesI18nPeer::NAME);
|
|
$c->addAscendingOrderByColumn(CountriesI18nPeer::NAME);
|
|
list($eu, $outsideEu) = CountriesPeer::doSelectWithI18n($c);
|
|
|
|
$options = array("Unia Europejska" => $eu, "Państwa spoza Unii Europejskiej" => $outsideEu);
|
|
}
|
|
|
|
|
|
|
|
return select_tag($name, options_for_select($options, $value, $optionsParams), $params);
|
|
}
|
|
|
|
function object_st_countries_select_tag($object, $method, array $params = array())
|
|
{
|
|
$value = _get_object_value($object, $method);
|
|
return st_countries_select_tag(_convert_method_to_name($method, $params), $value, $params);
|
|
} |