blob: ae0b369fdbabfc306f2b02886fbb59fc26a26a15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<?php
Prado::using('Application.pages.AddressRecord');
/**
* @author Wei Zhuo <weizho[at]gmail[dot]com>
* @version $Id$
* @since 3.1
*/
class AddressProvider extends TApplicationComponent
{
/**
* @throws exception if not logged in
*/
public function __construct($server)
{
$authMethods = $server->getRequestedMethod()!=='login';
$guestUser = $this->User ? $this->User->IsGuest : true;
if($authMethods && $guestUser)
throw new TException('authentication required');
}
/**
* @param string $username
* @param string $password
* @return boolean
* @soapmethod
*/
public function login($username, $password)
{
return $this->Application->Modules['auth']->login($username, $password);
}
/**
* @return AddressRecord[]
* @soapmethod
*/
public function getAllAddress()
{
return AddressRecord::finder()->findAll();
}
/**
* Update address if $data->id > 0, otherwise add new address.
* @param AddressRecord $data
* @return boolean
* @soapmethod
*/
public function saveAddress($data)
{
$finder = AddressRecord::finder();
if($data->id > 0 && $address=$finder->findByPk($data->id))
{
return $address->copyFrom($data)->save();
}
else
{
$data->id = null; //nullify the id
return $data->save();
}
}
/**
* @param integer $id
* @return integer number of records deleted
* @soapmethod
*/
public function deleteAddress($id)
{
return AddressRecord::finder()->deleteByPk($id);
}
}
?>
|