summaryrefslogtreecommitdiff
path: root/demos/address-book/protected/pages/AddressProvider.php
diff options
context:
space:
mode:
Diffstat (limited to 'demos/address-book/protected/pages/AddressProvider.php')
-rw-r--r--demos/address-book/protected/pages/AddressProvider.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/demos/address-book/protected/pages/AddressProvider.php b/demos/address-book/protected/pages/AddressProvider.php
new file mode 100644
index 00000000..bbfedd1b
--- /dev/null
+++ b/demos/address-book/protected/pages/AddressProvider.php
@@ -0,0 +1,52 @@
+<?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);
+ }
+}
+
+?> \ No newline at end of file