Allows users to notify erroneous geocoding.
[platal.git] / include / validations / address.inc.php
CommitLineData
57fa97b3
SJ
1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22// {{{ class AddressReq
23
24class AddressReq extends ProfileValidate
25{
26 // {{{ properties
27
28 // Address primary field that are not in its formatted array.
29 public $pid;
30 public $jobid;
31 public $groupid;
32 public $type;
33
34 // We need the text given by the user, and the toy version to try to improve
35 // the geocoding.
36 public $address;
37 public $given_text;
38 public $toy_text = '';
39 public $modified = false;
40
41 public $rules = 'Si la localisation est bonne, refuser. Sinon, si le texte est faux, le corriger. Si la géolocaliastion ne marche toujours pas, utiliser la version jouet qui ne sera pas stockée, mais dont les données de localisation le seront.';
42
43 // }}}
44 // {{{ constructor
45
46 public function __construct(User $_user, Profile $_profile, $_text, $_pid, $_jobid, $_groupid, $_type, $_stamp = 0)
47 {
48 parent::__construct($_user, $_profile, false, 'address', $_stamp);
49 $this->key_pid = $_pid;
50 $this->key_jobid = $_jobid;
51 $this->key_groupid = $_groupid;
52 $this->key_type = $_type;
53 $this->given_text = $_text;
54 $address = new Address(array('changed' => 1, 'text' => $_text));
55 $address->format();
56 $this->address = $address->toFormArray();
57 }
58
59 // }}}
60 // {{{ function formu()
61
62 public function formu()
63 {
64 return 'include/form.valid.address.tpl';
65 }
66
67 // }}}
68 // {{{ function editor()
69
70 public function editor()
71 {
72 return 'include/form.valid.edit-address.tpl';
73 }
74
75 // }}}
76 // {{{ function handle_editor()
77
78 protected function handle_editor()
79 {
80 $data = Post::v('valid');
81 if (isset($data['text']) && $data['text'] != $this->toy_text && $data['text'] != $this->given_text) {
82 $this->toy_text = $data['text'];
83 $address = new Address(array('changed' => 1, 'text' => $this->toy_text));
84 $address->format();
85 $this->address = $address->toFormArray();
86 }
87 $this->modified = isset($data['modified']);
88
89 return true;
90 }
91
92 // }}}
93 // {{{ function _mail_subj
94
95 protected function _mail_subj()
96 {
97 return '[Polytechnique.org/Adresse] Demande d\'amélioration de la localisation d\'une adresse';
98 }
99
100 // }}}
101 // {{{ function _mail_body
102
103 protected function _mail_body($isok)
104 {
105 if ($isok) {
106 return " Nous avons réussit à mieux localiser l'adresse.";
107 } else {
108 return " L'adresse est suffisemment bien localisée pour les besoins du site (recherche avancée, planisphère), nous avons donc choisi de ne pas la modifier.";
109 }
110 }
111
112 // }}}
113 // {{{ function commit()
114
115 public function commit()
116 {
117 $this->address = array_merge($this->address, array(
118 'pid' => $this->key_pid,
119 'jobid' => $this->key_jobid,
120 'groupid' => $this->key_groupid,
121 'type' => $this->key_type
122 ));
123 $this->address['text'] = ($this->modified ? $this->toy_text : $this->given_text);;
124 $this->address['changed'] = 0;
125 $address = new Address($this->address);
126 $address->format();
127 $address->updateGeocoding($this->given_text);
128
129 return true;
130 }
131
132 // }}}
133 // {{{ function get_request()
134
135 static public function get_request($pid, $jobid, $groupid, $type, $address)
136 {
137 $reqs = parent::get_typed_requests($pid, 'address');
138 foreach ($reqs as &$req) {
139 if ($req->key_pid == $pid && $req->key_jobid == $jobid && $req->key_groupid == $groupid
140 && $req->key_type == $type && $req->address['text'] == $address) {
141 return $req;
142 }
143 }
144 return null;
145 }
146
147 // }}}
148 // {{{ function purge_requests()
149
150 // Purges address localization requests based on deleted addresses.
151 static public function purge_requests($pid, $jobid, $groupid, $type)
152 {
153 $requests = parent::get_all_typed_requests('address');
154 foreach ($requests as &$req) {
155 if ($req->key_pid == $pid && $req->key_jobid == $jobid && $req->key_groupid == $groupid && $req->key_type == $type) {
156 $count = XDB::fetchOneCell('SELECT COUNT(*)
157 FROM profile_addresses
158 WHERE pid = {?} AND jobid = {?} AND groupid = {?}
159 AND type = {?} AND text = {?}',
160 $pid, $jobid, $groupid, $type, $req->address['text']);
161 if ($count == 0) {
162 $req->clean();
163 }
164 }
165 }
166 }
167
168 // }}}
169}
170
171// }}}
172
173// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
174?>