setMainTable('countries'); array_unshift($this->_validOrderingFieldName,'country_name'); $this->_selectedOrdering = 'country_name'; $this->_selectedOrderingDir = 'ASC'; } /** * Retreive a country record given a country code. * * @author RickG, Max Milbers * @param string $code Country code to lookup * @return object Country object from database */ static function getCountryByCode($code) { if(empty($code)) return false; $db = vFactory::getDbo(); $countryCodeLength = strlen($code); switch ($countryCodeLength) { case 2: $fieldname = 'country_2_code'; break; case 3: $fieldname = 'country_3_code'; break; default: $fieldname = 'country_name'; } static $countries = array(); if(!isset($countries[$code])){ $query = 'SELECT *'; $query .= ' FROM `#__virtuemart_countries`'; $query .= ' WHERE `' . $fieldname . '` = "' . $db->escape ($code) . '"'; $db->setQuery($query); $countries[$code] = $db->loadObject(); } return $countries[$code]; } /** * Retrieve a list of countries from the database. * * @author RickG * @author Max Milbers * @param string $onlyPublished True to only retrieve the publish countries, false otherwise * @param string $noLimit True if no record count limit is used, false otherwise * @return object List of country objects */ function getCountries($onlyPublished=true, $noLimit=false, $filterCountry = false) { static $countries = array(); $where = array(); $this->_noLimit = $noLimit; if ($onlyPublished) $where[] = '`published` = 1'; if($filterCountry){ $db = vFactory::getDbo(); $filterCountryS = '"%' . $db->escape( $filterCountry, true ) . '%"' ; $where[] = '`country_name` LIKE '.$filterCountryS.' OR `country_2_code` LIKE '.$filterCountryS.' OR `country_3_code` LIKE '.$filterCountryS; } $whereString = ''; if (count($where) > 0) $whereString = ' WHERE '.implode(' AND ', $where) ; $ordering = $this->_getOrdering(); $hash = $filterCountry.$this->_selectedOrderingDir.(int)$onlyPublished.$this->_selectedOrdering.(int)$noLimit; if(!isset($countries[$hash])){ $countries[$hash] = $this->_data = $this->exeSortSearchListQuery(0,'*',' FROM `#__virtuemart_countries`',$whereString,'',$ordering); } return $countries[$hash]; } function store(&$data){ if(!vmAccess::manager('country')){ vmWarn('Insufficient permissions to store country'); return false; } return parent::store($data); } function remove($ids){ if(!vmAccess::manager('country')){ vmWarn('Insufficient permissions to remove country'); return false; } return parent::remove($ids); } } //no closing tag pure php