b31bc9bdb72b7ab149b99dd3ea826f5f0ac722cd
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.
35 // We need the text given by the user, and the toy version to try to improve
39 public $toy_text = '';
40 public $modified = false
;
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.';
47 public function __construct(User
$_user, array $_address, $_pid, $_jobid, $_groupid, $_type, $_id, $_stamp = 0)
49 $_profile = Profile
::get($_pid);
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;
56 $this->given_text
= $_address['text'];
57 $this->address
= $_address;
61 // {{{ function formu()
63 public function formu()
65 return 'include/form.valid.address.tpl';
69 // {{{ function editor()
71 public function editor()
73 return 'include/form.valid.edit-address.tpl';
77 // {{{ function handle_editor()
79 protected function handle_editor()
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
));
86 $this->address
= $address->toFormArray();
88 $this->modified
= isset($data['modified']);
94 // {{{ function _mail_subj
96 protected function _mail_subj()
98 return '[Polytechnique.org/Adresse] Demande d\'amélioration de la localisation d\'une adresse';
102 // {{{ function _mail_body
104 protected function _mail_body($isok)
107 return " Nous avons réussit à mieux localiser l'adresse.";
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.";
114 // {{{ function commit()
116 public function commit()
118 $this->address
= array_merge($this->address
, array(
119 'pid' => $this->key_pid
,
120 'jobid' => $this->key_jobid
,
121 'groupid' => $this->key_groupid
,
122 'type' => $this->key_type
,
123 'id' => $this->key_id
125 $this->address
['text'] = ($this->modified ?
$this->toy_text
: $this->given_text
);;
126 $this->address
['changed'] = 0;
127 $address = new Address($this->address
);
129 $address->updateGeocoding($this->given_text
);
135 // {{{ function get_request()
137 static public function get_request($pid, $jobid, $groupid, $type, $id)
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
142 && $req->key_type
== $type && $req->key_id
== $id) {
150 // {{{ function purge_requests()
152 // Purges address localization requests based on deleted addresses.
153 static public function purge_requests($pid, $jobid, $groupid, $type)
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) {
168 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: