Class Address.
[platal.git] / modules / profile / addresses.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 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 ProfileSettingAddresses implements ProfileSetting
23 {
24 public function value(ProfilePage &$page, $field, $value, &$success)
25 {
26 $success = true;
27 $addresses = array();
28
29 if (is_null($value)) {
30 $it = Address::iterate(array($page->pid()), array(Address::LINK_PROFILE), array(0));
31 while ($address = $it->next()) {
32 $addresses[] = $address->toFormArray();
33 }
34 if (count($addresses) == 0) {
35 $address = new Address();
36 $addresses[] = $address->toFormArray();
37 }
38 return $addresses;
39 }
40
41 return Address::formatFormArray($value, $success);
42 }
43
44 public function save(ProfilePage &$page, $field, $value)
45 {
46 Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS);
47 Address::delete($page->pid(), Address::LINK_PROFILE);
48 Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE);
49 }
50
51 public function getText($value)
52 {
53 return Address::formArrayToString($value);
54 }
55 }
56
57 class ProfileSettingAddresses extends ProfilePage
58 {
59 protected $pg_template = 'profile/adresses.tpl';
60
61 public function __construct(PlWizard &$wiz)
62 {
63 parent::__construct($wiz);
64 $this->settings['addresses'] = new ProfileSettingAddresses();
65 $this->watched['addresses'] = true;
66 }
67 }
68
69 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
70 ?>