Changeset 10756
- Timestamp:
- Feb 13, 2009, 6:02:04 PM (13 years ago)
- Location:
- OpenPNE3/plugins/opOpenSocialPlugin/trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE3/plugins/opOpenSocialPlugin/trunk/config/schema.yml
r10308 r10756 45 45 application_persistent_data: 46 46 id: ~ 47 member_application_id: { type: integer, foreignTable: member_application, foreignReference: id, onDelete: cascade } 48 key: { type: varchar(128), required: true } 47 application_id: { type: integer, foreignTable: application, foreignReference: id, onDelete: cascade } 48 member_id: { type: integer, foreignTable: member, foreignReference: id, onDelete: cascade } 49 name: { type: varchar(128), required: true } 49 50 value: { type : longvarchar, required: true } 50 51 -
OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/model/ApplicationPersistentDataPeer.php
r10014 r10756 9 9 */ 10 10 11 /** 12 * ApplicationPersistentDataPeer 13 * 14 * @author Shogo Kawahara <kawahara@tejimaya.net> 15 */ 11 16 class ApplicationPersistentDataPeer extends BaseApplicationPersistentDataPeer 12 17 { 18 public static function retrieveByApplicationIdAndMemberIdAndName($applicationId, $memberId, $name) 19 { 20 $criteria = new Criteria(); 21 $criteria->add(self::APPLICATION_ID, $applicationId); 22 $criteria->add(self::MEMBER_ID, $memberId); 23 $criteria->add(self::NAME, $name); 24 return self::doSelectOne($criteria); 25 } 26 27 public static function retrievesByApplicationIdAndMemberId($applicationId, $memberId, $fields = array()) 28 { 29 $criteria = new Criteria(); 30 $criteria->add(self::APPLICATION_ID, $applicationId); 31 $criteria->add(self::MEMBER_ID, $memberId); 32 if (count($fields)) 33 { 34 $criteria->add(self::NAME, $fields, Criteria::IN); 35 } 36 return self::doSelect($criteria); 37 } 38 39 public static function getMemberFriendPersistentDatas($applicationId, $memberId, $fields = array()) 40 { 41 $friendIds = MemberRelationshipPeer::getFriendMemberIds($memberId); 42 $criteria = new Criteria(); 43 $criteria->add(self::APPLICATION_ID, $applicationId); 44 $criteria->add(self::MEMBER_ID, $friendIds, Criteria::IN); 45 if (count($fields)) 46 { 47 $criteria->add(self::NAME, $fields, Criteria::IN); 48 } 49 return self::doSelect($criteria); 50 } 13 51 } -
OpenPNE3/plugins/opOpenSocialPlugin/trunk/lib/user/opJsonDbOpensocialService.class.php
r10546 r10756 1 1 <?php 2 3 /** 4 * This file is part of the OpenPNE package. 5 * (c) OpenPNE Project (http://www.openpne.jp/) 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file and the NOTICE file that were distributed with this source code. 9 */ 2 10 3 11 /** … … 35 43 $max = $options->getCount(); 36 44 $ret = array(); 45 37 46 $criteria = new Criteria(); 38 47 $criteria->add(MemberPeer::ID, $ids, Criteria::IN); 39 48 $totalSize = MemberPeer::doCount($criteria); 49 40 50 $criteria->addAscendingOrderByColumn(MemberPeer::ID); 41 51 if ($first !== false && $max !== false && is_numeric($first) && is_numeric($max) && $first >= 0 && $max > 0) … … 45 55 } 46 56 $members = MemberPeer::doSelect($criteria); 57 47 58 $people = array(); 48 59 foreach ($members as $member) 49 60 { 61 //FIXME 50 62 $p = array(); 51 63 $p['isOwner'] = (!$token->isAnonymous() && $member->getId() == $token->getOwnerId()) ? true : false; … … 79 91 $people[] = $p; 80 92 } 93 81 94 $collection = new RestfulCollection($people, $options->getStartIndex(), $totalSize); 82 95 $collection->setItemsPerPage($options->getCount()); … … 89 102 } 90 103 91 public function getActivity($userId, $groupId, $app dId, $fields, $activityId, SecurityToken $token)104 public function getActivity($userId, $groupId, $appId, $fields, $activityId, SecurityToken $token) 92 105 { 93 106 throw new SocialSpiException("Not implemented", ResponseError::$NOT_IMPLEMENTED); … … 106 119 public function getPersonData($userId, GroupId $groupId, $appId, $fields, SecurityToken $token) 107 120 { 108 $ids = $this->getIdSet($userId, $groupId, $token); 109 $criteria = new Criteria(); 110 $criteria->addJoin(ApplicationPersistentDataPeer::MEMBER_APPLICATION_ID, MemberApplicationPeer::ID); 111 $criteria->add(MemberApplicationPeer::APPLICATION_ID, $appId); 112 $criteria->add(MemberApplicationPeer::MEMBER_ID, $ids, Criteria::IN); 113 if (count($fields)) 114 { 115 $criteria->add(ApplicationPersistentDataPeer::KEY, $fields, Criteria::IN); 116 } 117 $persistentDatas = ApplicationPersistentDataPeer::doSelect($criteria); 118 if (!count($persistentDatas)) 119 { 120 throw new SocialSpiException("UnKnown person app data key(s): ".implode(', ', $fields)); 121 if (!($userId instanceof UserId)) 122 { 123 throw new SocialSpiException("Not support request", ResponseError::$NOT_IMPLEMENTED); 124 } 125 $targetUserId = (int)$userId->getUserId($token); 126 $viewerId = (int)$token->getViewerId(); 127 if ($targetUserId != $viewerId) 128 { 129 $memberRelationship = MemberRelationshipPeer::retrieveByFromAndTo($targetUserId, $viewerId); 130 if (!($memberRelationship && $memberRelationship->isFriend())) 131 { 132 throw new SocialSpiException("Unauthorized", ResponseError::$UNAUTHORIZED); 133 } 134 } 135 if ($groupId->getType() == 'self') 136 { 137 $appPersistentDatas = ApplicationPersistentDataPeer::retrievesByApplicationIdAndMemberId($appId, $targetUserId, $fields); 138 } 139 else if($groupId->getType() == 'friends') 140 { 141 $appPersistentDatas = ApplicationPersistentDataPeer::getMemberFriendPersistentDatas($appId, $targetUserId, $fields); 142 } 143 else 144 { 145 throw new SocialSpiException("We support getting data only when GROUP_ID is SELF or FRIENDS ", ResponseError::$NOT_IMPLEMENTED); 121 146 } 122 147 $data = array(); 123 foreach ($persistentDatas as $persistentData)124 { 125 $data[$ persistentData->getMemberApplication()->getMemberId()][$persistentData->getKey()] = $persistentData->getValue();148 foreach ($appPersistentDatas as $appPersistentData) 149 { 150 $data[$appPersistentData->getMemberId()][$appPersistentData->getName()] = $appPersistentData->getValue(); 126 151 } 127 152 return new DataCollection($data); … … 130 155 public function deletePersonData($userId, GroupId $groupId, $appId, $fields, SecurityToken $token) 131 156 { 157 if (!($userId instanceof UserId) || $userId->getUserId($token) == null ) 158 { 159 throw new SocialSpiException("Unknown person id", ResponseError::$NOT_FOUND); 160 } 161 162 $targetUserId = $userId->getUserId($token); 163 164 if ($targetUserId != $token->getViewerId()) 165 { 166 throw new SocialSpiException("Unauthorized", ResponseError::$UNAUTHORIZED); 167 } 168 132 169 foreach ($fields as $key) 133 170 { … … 137 174 } 138 175 } 139 $ids = $this->getIdSet($userId, $groupId, $token); 140 if (count($ids) < 1) 141 { 142 throw new InvalidArgumentException("No userId specified"); 143 } 144 else if (count($ids) > 1) 145 { 146 throw new InvalidArgumentException("Multiple userIds not supported"); 147 } 148 $userId = $ids[0]; 149 $appId = $token->getAppId(); 176 177 $appPersistentDatas = ApplicationPersistentDataPeer::retrievesByApplicationIdAndMemberId($appId, $targetUserId, $fields); 178 179 foreach ($appPersistentDatas as $appPersistentData) 180 { 181 $appPersistentData->delete(); 182 } 183 } 184 185 public function updatePersonData(UserId $userId, GroupId $groupId, $appId, $fields, $values, SecurityToken $token) 186 { 187 if ($userId->getUserId($token) == null) 188 { 189 throw new SocialSpiException("Unknown person id", ResponseError::$NOT_FOUND); 190 } 191 150 192 foreach ($fields as $key) 151 193 { 152 $criteria = new Criteria();153 $criteria->addJoin(ApplicationPersistentDataPeer::MEMBER_APPLICATION_ID, MemberApplicationPeer::ID);154 $criteria->add(MemberApplicationPeer::APPLICATION_ID, $appId);155 $criteria->add(MemberApplicationPeer::MEMBER_ID, $userId);156 $criteria->add(ApplicationPersistentDataPeer::KEY, $key);157 $persistentData = ApplicationPersistentDataPeer::doSelectOne($criteria);158 if (!$persistentData)159 {160 throw new SocialSpiException("Internal server error", ResponseError::$INTERNAL_ERROR);161 }162 $persistentData->delete();163 }164 }165 166 public function updatePersonData(UserId $userId, GroupId $groupId, $appId, $fields, $values, SecurityToken $token)167 {168 if ($userId->getUserId($token) == null)169 {170 throw new SocialSpiException("Unknown person id.", ResponseError::$NOT_FOUND);171 }172 173 foreach ($fields as $key)174 {175 194 if (!preg_match('/[\w\-\.]+/',$key)) 176 195 { … … 178 197 } 179 198 } 180 switch ($groupId->getType()) 181 { 182 case 'self': 183 foreach ($fields as $key) 199 200 if ($groupId->getType() != 'self') 201 { 202 throw new SocialSpiException("We don't support updating data in batches yet", ResponseError::$NOT_IMPLEMENTED); 203 } 204 205 $targetUserId = $userId->getUserId($token); 206 if ($token->getOwnerId() == $targetUserId || $token->getViewerId() == $targetUserId) 207 { 208 $memberApplication = MemberApplicationPeer::retrieveByApplicationIdAndMemberId($appId, $targetUserId); 209 if (!$memberApplication) 210 { 211 throw new SocialSpiException("Unauthorized", ResponseError::$UNAUTHORIZED); 212 } 213 214 foreach($fields as $name) 215 { 216 $value = isset($values[$name]) ? $values[$name] : null; 217 $appPersistentData = ApplicationPersistentDataPeer::retrieveByApplicationIdAndMemberIdAndName($appId, $targetUserId, $name); 218 if (!$appPersistentData) 184 219 { 185 $value = isset($values[$key]) ? $values[$key] : null; 186 $criteria = new Criteria(); 187 188 $criteria->add(ApplicationPersistentDataPeer::MEMBER_APPLICATION_ID, $token->getModuleId()); 189 $criteria->add(ApplicationPersistentDataPeer::KEY, $key); 190 $persistentData = ApplicationPersistentDataPeer::doSelectOne($criteria); 191 if (!$persistentData) 192 { 193 $persistentData = new ApplicationPersistentData(); 194 $persistentData->setMemberApplicationId($token->getModuleId()); 195 $persistentData->setKey($key); 196 } 197 $persistentData->setValue($value); 198 $persistentData->save(); 220 $appPersistentData = new ApplicationPersistentData(); 221 $appPersistentData->setApplicationId($appId); 222 $appPersistentData->setMemberId($targetUserId); 223 $appPersistentData->setName($name); 199 224 } 200 break; 201 default: 202 throw new SocialSpiException("We don't support updating data in batches yet", ResponseError::$NOT_IMPLEMENTED); 225 $appPersistentData->setValue($value); 226 $appPersistentData->save(); 227 } 228 } 229 else 230 { 231 throw new SocialSpiException("Unauthorized", ResponseError::$UNAUTHORIZED); 203 232 } 204 233 } … … 209 238 } 210 239 211 pr ivatefunction getIdSet($user, GroupId $group, SecurityToken $token)240 protected function getIdSet($user, GroupId $group, SecurityToken $token) 212 241 { 213 242 $ids = array(); … … 224 253 case 'friends': 225 254 case 'groupId': 226 227 $criteria = new Criteria(); 228 $criteria->add(MemberRelationshipPeer::MEMBER_ID_FROM,$userId); 229 $criteria->add(MemberRelationshipPeer::IS_FRIEND, true); 230 $friends = MemberRelationshipPeer::doSelect($criteria); 231 232 $friendIds = array(); 233 foreach ($friends as $friend) 234 { 235 $friendIds[] = $friend->getMemberIdTo(); 236 } 237 if (count($friendIds)) 238 { 239 $ids = $friendIds; 240 } 255 $ids = MemberRelationshipPeer::getFriendMemberIds($userId); 241 256 break; 242 257 case 'self':
Note: See TracChangeset
for help on using the changeset viewer.