Permalink
Browse files

Allow objects to specify a subset of fields when exported by having a…

… toFilteredMap instead of just Map and SS3 updates
  • Loading branch information...
1 parent ea9ed1c commit 80e7b1b1ce3e0577e7a7247b74eaeced7fe67d0d Marcus Nyeholt committed Jun 29, 2012
@@ -66,7 +66,7 @@ public function init() {
}
}
- public function handleRequest(SS_HTTPRequest $request) {
+ public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
try {
$this->pushCurrent();
if ((!Member::currentUserID() && !self::$allow_public_access) || $request->requestVar('token')) {
@@ -88,7 +88,7 @@ public function handleRequest(SS_HTTPRequest $request) {
} else if (!self::$allow_public_access) {
throw new WebServiceException(403, "Invalid request");
}
- $response = parent::handleRequest($request);
+ $response = parent::handleRequest($request, $model);
if (self::has_curr()) {
$this->popCurrent();
@@ -9,6 +9,9 @@
class DataObjectJsonConverter {
public function convert(DataObject $object) {
+ if ($object->hasMethod('toFilteredMap')) {
+ return Convert::raw2json($object->toFilteredMap());
+ }
return Convert::raw2json($object->toMap());
}
}
@@ -12,7 +12,9 @@ public function convert($set) {
$ret = new stdClass();
$ret->items = array();
foreach ($set as $item) {
- if (method_exists($item, 'toMap')) {
+ if ($item instanceof Object && $item->hasMethod('toFilteredMap')) {
+ $ret->items[] = $item->toFilteredMap();
+ } else if (method_exists($item, 'toMap')) {
$ret->items[] = $item->toMap();
} else {
$ret->items[] = $item;
@@ -24,7 +24,6 @@ public function webEnabledMethods() {
}
public function myMethod($param) {
-
return array(
'SomeParam' => 'Goes here',
'Boolean' => true,

0 comments on commit 80e7b1b

Please sign in to comment.