00001 <?php
00002 Load::models('continents', 'countriesgroups', 'countries2countriesgroups');
00003
00004
00005
00006
00007
00008
00009 class Countries {
00010 const GROUP_TYPE_NONE = 'NONE';
00011 const GROUP_TYPE_POLITICAL = 'POLITICAL';
00012 const GROUP_TYPE_GEOGRAPHICAL = 'GEOGRAPHICAL';
00013 const GROUP_TYPE_CULTURAL = 'CULTURAL';
00014
00015 const GROUP_ID_EU = 1;
00016
00017
00018
00019
00020
00021
00022 public static function get_group_types() {
00023 return array(
00024 self::GROUP_TYPE_NONE => tr(self::GROUP_TYPE_NONE, 'countries'),
00025 self::GROUP_TYPE_POLITICAL => tr(self::GROUP_TYPE_POLITICAL, 'countries'),
00026 self::GROUP_TYPE_GEOGRAPHICAL => tr(self::GROUP_TYPE_GEOGRAPHICAL, 'countries'),
00027 self::GROUP_TYPE_CULTURAL => tr(self::GROUP_TYPE_CULTURAL, 'countries')
00028 );
00029 }
00030
00031
00032
00033
00034
00035
00036 public static function get($country_code) {
00037 return DB::get_item('countries', 'id', $country_code);
00038 }
00039
00040
00041
00042
00043
00044
00045 public static function create_adapter() {
00046 return new DAOCountries();
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 public static function create_continent_adapter($id_continent) {
00056 $dao = self::create_adapter();
00057 $dao->id_continent = $id_continent;
00058 return $dao;
00059 }
00060
00061
00062
00063
00064
00065
00066 public static function create_localized_sort_adapter($lang = false) {
00067 $dao = new DAOCountries();
00068 self::localize_adapter($dao, $lang);
00069 return $dao;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078 public static function localize_adapter(DAOCountries $adapter, $lang = false) {
00079 if (empty($lang)) {
00080 $lang = GyroLocale::get_language();
00081 }
00082 $trans = new DAOCountriestranslations();
00083 $adapter->join(
00084 $trans,
00085 array(
00086 new DBJoinCondition($trans, 'id_country', $adapter, 'id'),
00087 new DBWhere($trans, 'lang', '=', $lang)
00088 ),
00089 DBQueryJoined::LEFT
00090 );
00091 $adapter->sort('countriestranslations.name');
00092 }
00093
00094
00095
00096
00097
00098
00099 public static function get_all() {
00100 $ret = array();
00101 $dao = self::create_localized_sort_adapter(GyroLocale::get_language());
00102 $dao->sort('name');
00103 $dao->find();
00104 while($dao->fetch()) {
00105 $ret[$dao->id] = $dao->get_title();
00106 }
00107 return $ret;
00108 }
00109
00110
00111
00112
00113
00114
00115 public static function get_continents() {
00116 $ret = array();
00117 $dao = new DAOContinents();
00118 $dao->find();
00119 while($dao->fetch()) {
00120 $ret[$dao->id] = $dao->get_title();
00121 }
00122 return $ret;
00123 }
00124
00125
00126
00127
00128
00129
00130 public static function get_continent($id) {
00131 return DB::get_item('continents', 'id', $id);
00132 }
00133
00134 }