]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
move flag creation to a method of data object
authorEvan Prodromou <evan@status.net>
Mon, 28 Dec 2009 18:58:49 +0000 (10:58 -0800)
committerEvan Prodromou <evan@status.net>
Mon, 28 Dec 2009 18:58:49 +0000 (10:58 -0800)
plugins/UserFlag/User_flag_profile.php
plugins/UserFlag/flagprofile.php

index b8f3f3fe169a5cb2a331f55864231fb6d3ac924e..658259452436aae780d56956ffe9841c7bf79391 100644 (file)
@@ -118,4 +118,23 @@ class User_flag_profile extends Memcached_DataObject
 
         return !empty($ufp);
     }
+
+    static function create($user_id, $profile_id)
+    {
+        $ufp = new User_flag_profile();
+
+        $ufp->profile_id = $profile_id;
+        $ufp->user_id    = $user_id;
+        $ufp->created    = common_sql_now();
+
+        if (!$ufp->insert()) {
+            $msg = sprintf(_("Couldn't flag profile '%d' for review."),
+                           $profile_id);
+            throw new ServerException($msg);
+        }
+
+        $ufp->free();
+
+        return true;
+    }
 }
index 55753f4e85b11435718254220a5e581d3511a495..2d0f0abb90f80ced2063b2a461e46c6022fdda27 100644 (file)
@@ -105,19 +105,9 @@ class FlagprofileAction extends ProfileFormAction
         assert(!empty($user));
         assert(!empty($this->profile));
 
-        $ufp = new User_flag_profile();
+        // throws an exception on error
 
-        $ufp->profile_id = $this->profile->id;
-        $ufp->user_id    = $user->id;
-        $ufp->created    = common_sql_now();
-
-        if (!$ufp->insert()) {
-            $msg = sprintf(_("Couldn't flag profile '%s' for review."),
-                           $this->profile->nickname);
-            throw new ServerException($msg);
-        }
-
-        $ufp->free();
+        User_flag_profile::create($user->id, $this->profile->id);
 
         if ($this->boolean('ajax')) {
             $this->ajaxResults();