2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ class AddressReq
24 class AddressReq
extends ProfileValidate
28 // Address primary field that are not in its formatted array.
34 // We need the text given by the user, and the toy version to try to improve
38 public $toy_text = '';
39 public $modified = false
;
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.';
46 public function __construct(User
$_user, Profile
$_profile, $_text, $_pid, $_jobid, $_groupid, $_type, $_stamp = 0)
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));
56 $this->address
= $address->toFormArray();
60 // {{{ function formu()
62 public function formu()
64 return 'include/form.valid.address.tpl';
68 // {{{ function editor()
70 public function editor()
72 return 'include/form.valid.edit-address.tpl';
76 // {{{ function handle_editor()
78 protected function handle_editor()
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
));
85 $this->address
= $address->toFormArray();
87 $this->modified
= isset($data['modified']);
93 // {{{ function _mail_subj
95 protected function _mail_subj()
97 return '[Polytechnique.org/Adresse] Demande d\'amélioration de la localisation d\'une adresse';
101 // {{{ function _mail_body
103 protected function _mail_body($isok)
106 return " Nous avons réussit à mieux localiser l'adresse.";
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.";
113 // {{{ function commit()
115 public function commit()
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
123 $this->address
['text'] = ($this->modified ?
$this->toy_text
: $this->given_text
);;
124 $this->address
['changed'] = 0;
125 $address = new Address($this->address
);
127 $address->updateGeocoding($this->given_text
);
133 // {{{ function get_request()
135 static public function get_request($pid, $jobid, $groupid, $type, $address)
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) {
148 // {{{ function purge_requests()
150 // Purges address localization requests based on deleted addresses.
151 static public function purge_requests($pid, $jobid, $groupid, $type)
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']);
173 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: