Remove Address::updateGeocoding unused parameter
[platal.git] / include / validations / address.inc.php
CommitLineData
57fa97b3
SJ
1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 Polytechnique.org *
57fa97b3
SJ
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.
a3328b1e
SJ
29 public $key_pid;
30 public $key_jobid;
31 public $key_groupid;
32 public $key_type;
33 public $key_id;
57fa97b3
SJ
34
35 // We need the text given by the user, and the toy version to try to improve
36 // the geocoding.
37 public $address;
38 public $given_text;
39 public $toy_text = '';
40 public $modified = false;
41
42 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.';
43
44 // }}}
45 // {{{ constructor
46
a3328b1e 47 public function __construct(User $_user, array $_address, $_pid, $_jobid, $_groupid, $_type, $_id, $_stamp = 0)
57fa97b3 48 {
a3328b1e 49 $_profile = Profile::get($_pid);
57fa97b3
SJ
50 parent::__construct($_user, $_profile, false, 'address', $_stamp);
51 $this->key_pid = $_pid;
52 $this->key_jobid = $_jobid;
53 $this->key_groupid = $_groupid;
54 $this->key_type = $_type;
a3328b1e
SJ
55 $this->key_id = $_id;
56 $this->given_text = $_address['text'];
57 $this->address = $_address;
57fa97b3
SJ
58 }
59
60 // }}}
61 // {{{ function formu()
62
63 public function formu()
64 {
65 return 'include/form.valid.address.tpl';
66 }
67
68 // }}}
69 // {{{ function editor()
70
71 public function editor()
72 {
73 return 'include/form.valid.edit-address.tpl';
74 }
75
76 // }}}
77 // {{{ function handle_editor()
78
79 protected function handle_editor()
80 {
81 $data = Post::v('valid');
82 if (isset($data['text']) && $data['text'] != $this->toy_text && $data['text'] != $this->given_text) {
83 $this->toy_text = $data['text'];
84 $address = new Address(array('changed' => 1, 'text' => $this->toy_text));
85 $address->format();
86 $this->address = $address->toFormArray();
87 }
88 $this->modified = isset($data['modified']);
89
90 return true;
91 }
92
93 // }}}
94 // {{{ function _mail_subj
95
96 protected function _mail_subj()
97 {
98 return '[Polytechnique.org/Adresse] Demande d\'amélioration de la localisation d\'une adresse';
99 }
100
101 // }}}
102 // {{{ function _mail_body
103
104 protected function _mail_body($isok)
105 {
106 if ($isok) {
7598ba3a 107 return " Nous avons réussi à mieux localiser l'adresse suivante :\n{$this->given_text}.";
57fa97b3
SJ
108 } else {
109 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.";
110 }
111 }
112
113 // }}}
114 // {{{ function commit()
115
116 public function commit()
117 {
118 $this->address = array_merge($this->address, array(
a3328b1e
SJ
119 'pid' => $this->key_pid,
120 'jobid' => $this->key_jobid,
57fa97b3 121 'groupid' => $this->key_groupid,
a3328b1e
SJ
122 'type' => $this->key_type,
123 'id' => $this->key_id
57fa97b3
SJ
124 ));
125 $this->address['text'] = ($this->modified ? $this->toy_text : $this->given_text);;
126 $this->address['changed'] = 0;
127 $address = new Address($this->address);
128 $address->format();
8526cfe0 129 $address->updateGeocoding();
57fa97b3
SJ
130
131 return true;
132 }
133
134 // }}}
135 // {{{ function get_request()
136
a3328b1e 137 static public function get_request($pid, $jobid, $groupid, $type, $id)
57fa97b3
SJ
138 {
139 $reqs = parent::get_typed_requests($pid, 'address');
140 foreach ($reqs as &$req) {
141 if ($req->key_pid == $pid && $req->key_jobid == $jobid && $req->key_groupid == $groupid
a3328b1e 142 && $req->key_type == $type && $req->key_id == $id) {
57fa97b3
SJ
143 return $req;
144 }
145 }
146 return null;
147 }
148
149 // }}}
150 // {{{ function purge_requests()
151
152 // Purges address localization requests based on deleted addresses.
153 static public function purge_requests($pid, $jobid, $groupid, $type)
154 {
155 $requests = parent::get_all_typed_requests('address');
156 foreach ($requests as &$req) {
157 if ($req->key_pid == $pid && $req->key_jobid == $jobid && $req->key_groupid == $groupid && $req->key_type == $type) {
a3328b1e 158 $req->clean();
57fa97b3
SJ
159 }
160 }
161 }
162
163 // }}}
164}
165
166// }}}
167
448c8cdc 168// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
57fa97b3 169?>