]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
move role functions to Profile class
authorEvan Prodromou <evan@status.net>
Mon, 16 Nov 2009 14:52:33 +0000 (15:52 +0100)
committerEvan Prodromou <evan@status.net>
Mon, 16 Nov 2009 14:52:33 +0000 (15:52 +0100)
classes/Profile.php
classes/User.php

index 7c1e9db332cb420b970b866e2efa62e3fc54c56b..2668efcc70cd4bd3f524eeb7048f018815c0a37d 100644 (file)
@@ -587,4 +587,78 @@ class Profile extends Memcached_DataObject
 
         return $location;
     }
+
+    function hasRole($name)
+    {
+        $role = User_role::pkeyGet(array('user_id' => $this->id,
+                                         'role' => $name));
+        return (!empty($role));
+    }
+
+    function grantRole($name)
+    {
+        $role = new User_role();
+
+        $role->user_id = $this->id;
+        $role->role    = $name;
+        $role->created = common_sql_now();
+
+        $result = $role->insert();
+
+        if (!$result) {
+            common_log_db_error($role, 'INSERT', __FILE__);
+            return false;
+        }
+
+        return true;
+    }
+
+    function revokeRole($name)
+    {
+        $role = User_role::pkeyGet(array('user_id' => $this->id,
+                                         'role' => $name));
+
+        if (empty($role)) {
+            throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; does not exist.');
+        }
+
+        $result = $role->delete();
+
+        if (!$result) {
+            common_log_db_error($role, 'DELETE', __FILE__);
+            throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; database error.');
+        }
+
+        return true;
+    }
+
+    function isSandboxed()
+    {
+        return $this->hasRole(User_role::SANDBOXED);
+    }
+
+    function isSilenced()
+    {
+        return $this->hasRole(User_role::SILENCED);
+    }
+
+    function sandbox()
+    {
+        $this->grantRole(User_role::SANDBOXED);
+    }
+
+    function unsandbox()
+    {
+        $this->revokeRole(User_role::SANDBOXED);
+    }
+
+    function silence()
+    {
+        $this->grantRole(User_role::SILENCED);
+    }
+
+    function unsilence()
+    {
+        $this->revokeRole(User_role::SILENCED);
+    }
 }
index 0e84043771b6fd665eff6ad6bc343d98b174079d..1dca59f2376ab35549894038e3b794b7e95175ff 100644 (file)
@@ -657,50 +657,6 @@ class User extends Memcached_DataObject
         return Design::staticGet('id', $this->design_id);
     }
 
-    function hasRole($name)
-    {
-        $role = User_role::pkeyGet(array('user_id' => $this->id,
-                                         'role' => $name));
-        return (!empty($role));
-    }
-
-    function grantRole($name)
-    {
-        $role = new User_role();
-
-        $role->user_id = $this->id;
-        $role->role    = $name;
-        $role->created = common_sql_now();
-
-        $result = $role->insert();
-
-        if (!$result) {
-            common_log_db_error($role, 'INSERT', __FILE__);
-            return false;
-        }
-
-        return true;
-    }
-
-    function revokeRole($name)
-    {
-        $role = User_role::pkeyGet(array('user_id' => $this->id,
-                                         'role' => $name));
-
-        if (empty($role)) {
-            throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; does not exist.');
-        }
-
-        $result = $role->delete();
-
-        if (!$result) {
-            common_log_db_error($role, 'DELETE', __FILE__);
-            throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; database error.');
-        }
-
-        return true;
-    }
-
     /**
      * Does this user have the right to do X?
      *
@@ -779,13 +735,33 @@ class User extends Memcached_DataObject
         // XXX delete group block? Reset blocker?
     }
 
+    function hasRole($name)
+    {
+        $profile = $this->getProfile();
+        return $profile->hasRole($name);
+    }
+
+    function grantRole($name)
+    {
+        $profile = $this->getProfile();
+        return $profile->grantRole($name);
+    }
+
+    function revokeRole($name)
+    {
+        $profile = $this->getProfile();
+        return $profile->revokeRole($name);
+    }
+
     function isSandboxed()
     {
-        return $this->hasRole(User_role::SANDBOXED);
+        $profile = $this->getProfile();
+        return $profile->isSandboxed();
     }
 
     function isSilenced()
     {
-        return $this->hasRole(User_role::SILENCED);
+        $profile = $this->getProfile();
+        return $profile->isSilenced();
     }
 }