Add response fields
authorJeffrey Reichardt <jeffrey.reichardt@googlemail.com>
Fri, 28 Dec 2012 15:01:19 +0000 (16:01 +0100)
committerJeffrey Reichardt <jeffrey.reichardt@googlemail.com>
Fri, 28 Dec 2012 15:01:19 +0000 (16:01 +0100)
wcfsetup/install/files/lib/data/user/User.class.php

index 52066c27580a274c4c09f7ee81fcab10da066916..8365402952c60ead66df95679dec751e1d8604ba 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\data\user;
 use wcf\data\user\group\UserGroup;
 use wcf\data\user\UserList;
 use wcf\data\DatabaseObject;
+use wcf\system\api\rest\response\IRESTfulResponse;
 use wcf\system\cache\CacheHandler;
 use wcf\system\language\LanguageFactory;
 use wcf\system\request\IRouteController;
@@ -20,7 +21,7 @@ use wcf\util\StringUtil;
  * @subpackage data.user
  * @category   Community Framework
  */
-final class User extends DatabaseObject implements IRouteController {
+final class User extends DatabaseObject implements IRouteController, IRESTfulResponse {
        /**
         * @see wcf\data\DatabaseObject::$databaseTableName
         */
@@ -376,4 +377,23 @@ final class User extends DatabaseObject implements IRouteController {
        public function canEdit() {
                return (WCF::getSession()->getPermission('admin.user.canEditUser') && UserGroup::isAccessibleGroup($this->getGroupIDs()));
        }
+       
+       /**
+        * @see IRESTfulResponse::getResponseFields()
+        */
+       public function getResponseFields() {   
+               $fields = array('userID', 'username', 'signature', 'profileHits', 'userTitle', 'activityPoints', 'likesReceived');
+       
+               if ($this->canViewEmailAddress == 0) {
+                       $fields[] = 'email';
+               }
+       
+               if ($this->canViewProfile == 0) {
+                       return $fields;
+               }
+               else {
+                       // return only userID so we know there is an user but hidden
+                       return array('userID');
+               }
+       }       
 }