2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
15 class ATutorAppDataService extends ATutorService implements AppDataService {
16 public function deletePersonData($userId, GroupId $groupId, $appId, $fields, SecurityToken $token) {
17 $ids = $this->getIdSet($userId, $groupId, $token);
18 if (count($ids) < 1) {
19 throw new InvalidArgumentException("No userId specified");
20 } elseif (count($ids) > 1) {
21 throw new InvalidArgumentException("Multiple userIds not supported");
24 $appId = $token->getAppId();
25 if ($fields == null) {
26 if (! ATutorDbFetcher::get()->deleteAppData($userId, '*', $appId)) {
27 throw new SocialSpiException("Internal server error", ResponseError::$INTERNAL_ERROR);
30 foreach ($fields as $key) {
31 if (! self::isValidKey($key) && $key != '*') {
32 throw new SocialSpiException("The person app data key had invalid characters", ResponseError::$BAD_REQUEST);
35 foreach ($fields as $key) {
36 if (! ATutorDbFetcher::get()->deleteAppData($userId, $key, $appId)) {
37 throw new SocialSpiException("Internal server error", ResponseError::$INTERNAL_ERROR);
43 public function getPersonData($userId, GroupId $groupId, $appId, $fields, SecurityToken $token) {
44 $ids = $this->getIdSet($userId, $groupId, $token);
45 $data = ATutorDbFetcher::get()->getAppData($ids, $fields, $appId);
46 // If the data array is empty, return empty DataCollection.
47 return new DataCollection($data);
50 public function updatePersonData(UserId $userId, GroupId $groupId, $appId, $fields, $values, SecurityToken $token) {
51 if ($userId->getUserId($token) == null) {
52 throw new SocialSpiException("Unknown person id.", ResponseError::$NOT_FOUND);
54 foreach ($fields as $key) {
55 if (! self::isValidKey($key)) {
56 throw new SocialSpiException("The person app data key had invalid characters", ResponseError::$BAD_REQUEST);
59 switch ($groupId->getType()) {
61 foreach ($fields as $key) {
62 $value = isset($values[$key]) ? $values[$key] : null;
63 if (! ATutorDbFetcher::get()->setAppData($userId->getUserId($token), $key, $value, $token->getAppId())) {
64 throw new SocialSpiException("Internal server error", ResponseError::$INTERNAL_ERROR);
69 throw new SocialSpiException("We don't support updating data in batches yet", ResponseError::$NOT_IMPLEMENTED);