summaryrefslogtreecommitdiff
path: root/demos/address-book/protected/pages/AddressProvider.php
blob: 94b71e114dada6e3ecbd656c2cec336665e29084 (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
<?php
Prado::using('Application.pages.AddressRecord');
/**
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
 * @version $Id$
 * @since 3.1
 */
class AddressProvider
{
	/**
	 * @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);
	}
}

?>