source: branches/1.2/workflow/inc/local/classes/class.wf_location.php @ 1349

Revision 1349, 3.6 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * Class for getting city/state information
4 * @license http://www.gnu.org/copyleft/gpl.html GPL
5 * @package Workflow
6 * @subpackage local
7 */
8
9class wf_location
10{  /**
11        * @var object $db banco de dados
12        * @access private
13        */
14        var $db;
15   /**
16        * @var array $cityInfo Armazena informações sobre a cidade
17        * @access public
18        */
19        var $cityInfo;
20   /**
21        * @var array $stateInfo Armazena as informações sobre o Estado
22        * @access public
23        */
24        var $stateInfo;
25   /**
26        * @var array $citiesFromState Armazena as cidades de um estado
27        * @access public
28        */
29        var $citiesFromState;
30
31        /**
32         * Inicializa os arrays da classe
33         * return void
34         * @access private
35         */
36        function initialize()
37        {
38                $this->db = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso()->Link_ID;
39                $this->db->setFetchMode(ADODB_FETCH_ASSOC);
40                $this->cityInfo = array();
41                $this->stateInfo = array();
42                $this->citiesFromState = array();
43        }
44
45        /**
46         * Construtor da classe
47         * return object
48         * @access public
49         */
50        function wf_location()
51        {
52                $this->initialize();
53        }
54
55        /**
56         * Busca as informações da cidade pelo numero id passado
57         * @param int $city_id Numero ID da cidade
58         * @return mixed (array ou boolean)
59         * @access public
60         */
61        function getCityById($city_id)
62        {
63                if (!is_numeric($city_id))
64                        return false;
65
66                $city_id = (int) $city_id;
67                if (isset($this->cityInfo[$city_id]))
68                        return $this->cityInfo[$city_id];
69
70                $sql =
71                "SELECT
72                        c.id_city AS id_city,
73                        c.city_name AS city_name,
74                        s.id_state AS id_state,
75                        s.state_name AS state_name,
76                        s.state_symbol AS state_symbol
77                FROM
78                        phpgw_cc_state s,
79                        phpgw_cc_city c
80                WHERE
81                        c.id_state = s.id_state AND
82                        s.id_country = 'BR' AND
83                        c.id_city = ?";
84
85                $result = $this->db->query($sql, array($city_id));
86                $output = $result->fetchRow();
87
88                $this->cityInfo[$city_id] = $output;
89                return $output;
90        }
91
92   /**
93        * Busca as informações do estado pelo id passado
94        * @param int $state_id Numero ID do estado
95        * @return mixed (array ou boolean)
96        * @access public
97        */
98        function getStateById($state_id)
99        {
100                if (!is_numeric($state_id))
101                        return false;
102
103                $state_id = (int) $state_id;
104                if (isset($this->stateInfo[$state_id]))
105                        return $this->stateInfo[$state_id];
106
107                $sql =
108                "SELECT
109                        id_state,
110                        state_name,
111                        state_symbol
112                FROM
113                        phpgw_cc_state
114                WHERE
115                        id_country = 'BR' AND
116                        id_state = ?";
117
118                $result = $this->db->query($sql, array($state_id));
119                $output = $result->fetchRow();
120
121                $this->stateInfo[$city_id] = $output;
122                return $output;
123        }
124    /**
125         * Busca as cidades de um estado
126         * @param int $state_id Numero ID do estado
127         * @return mixed (array ou boolean)
128         * @access public
129         */
130        function getCitiesFromState($state_id)
131        {
132                if (!is_numeric($state_id))
133                        return false;
134
135                $state_id = (int) $state_id;
136                if (isset($this->citiesFromState[$state_id]))
137                        return $this->citiesFromState[$state_id];
138
139                $sql =
140                "SELECT
141                        c.id_city AS id_city,
142                        c.city_name AS city_name
143                FROM
144                        phpgw_cc_state s,
145                        phpgw_cc_city c
146                WHERE
147                        c.id_state = s.id_state AND
148                        s.id_country = 'BR' AND
149                        c.id_state = ?
150                ORDER BY
151                        city_name";
152
153                $result = $this->db->query($sql, array($state_id));
154                $output = array();
155                while ($row = $result->fetchRow())
156                        $output[] = $row;
157
158                $this->citiesFromState[$state_id] = $output;
159                return $output;
160        }
161    /**
162         * Busca os estados brasileiros
163         * @return mixed (array ou boolean)
164         * @access public
165         */
166        function getStates()
167        {
168                $sql =
169                "SELECT
170                        id_state,
171                        state_name
172                FROM
173                        phpgw_cc_state
174                WHERE
175                        id_country = 'BR'
176                ORDER BY
177                        state_name";
178
179                $result = $this->db->query($sql);
180                $output = array();
181                while ($row = $result->fetchRow())
182                        $output[] = $row;
183
184                return $output;
185        }
186}
187?>
Note: See TracBrowser for help on using the repository browser.