Projekt

Obecné

Profil

<?php

defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/

/**
* @author Ondrej Fibich
* @package Model
*
* @property integer $id
* @property string $country_name
* @property string $country_iso
* @property string $country_code
* @property ORM $contacts
* @property ORM $address_points
*/
class Country_Model extends ORM
{
protected $has_many = array('address_points');
protected $has_and_belongs_to_many = array('contacts');

/**
* Gets list of countries for combo box
*
* @return array
*/
public function select_country_list()
{
$countries = $this->db->query("
SELECT c.id, CONCAT(c.country_code, '\t', c.country_name) AS val
FROM countries c
WHERE c.country_code IS NOT NULL AND c.country_code != ''
ORDER BY c.country_code
");

$list = array();

foreach ($countries as $country)
{
$list[$country->id] = $country->val;
}

return $list;
}

/**
* Finds country by area (in VoIP)
*
* @author Michal Kliment
* @param string $area
* @return MySQL_Result object
*/
public function find_country_by_area($area)
{
$result = $this->db->query("
SELECT * FROM countries
WHERE ? LIKE CONCAT( country_name, '%' )
LIMIT 0,1
", array($area));
return ($result && $result->count()) ? $result->current() : NULL;
}

}
(22-22/82)