]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile_tag.php
better output for registration confirmation
[quix0rs-gnu-social.git] / classes / Profile_tag.php
index 183f79145a136463472eb3dec305131ff22809b0..9e475e83ec16e9db00dc58d02336157e41e61da6 100644 (file)
@@ -106,11 +106,11 @@ class Profile_tag extends Memcached_DataObject
 
         $ptag = new Profile_tag();
 
-        # Delete stuff that's in old and not in new
+        // Delete stuff that's in old and not in new
 
         $to_delete = array_diff($oldtags, $newtags);
 
-        # Insert stuff that's in new and not in old
+        // Insert stuff that's in new and not in old
 
         $to_insert = array_diff($newtags, $oldtags);
 
@@ -143,6 +143,7 @@ class Profile_tag extends Memcached_DataObject
         if (Event::handle('StartTagProfile', array($tagger_profile, $tagged_profile, $tag))) {
 
             if (!$tagger_profile->canTag($tagged_profile)) {
+                // TRANS: Client exception thrown trying to set a tag for a user that cannot be tagged.
                 throw new ClientException(_('You cannot tag this user.'));
                 return false;
             }
@@ -152,6 +153,7 @@ class Profile_tag extends Memcached_DataObject
             $count = (int) $tags->count('distinct tag');
 
             if ($count >= common_config('peopletag', 'maxtags')) {
+                // TRANS: Client exception thrown trying to set more tags than allowed.
                 throw new ClientException(sprintf(_('You already have created %d or more tags ' .
                                                     'which is the maximum allowed number of tags. ' .
                                                     'Try using or deleting some existing tags.'),
@@ -165,9 +167,10 @@ class Profile_tag extends Memcached_DataObject
             $profile_list = Profile_list::ensureTag($tagger, $tag, $desc, $private);
 
             if ($profile_list->taggedCount() >= common_config('peopletag', 'maxpeople')) {
-                throw new ClientException(sprintf(_('You already have %d or more people tagged %s ' .
+                // TRANS: Client exception thrown when trying to add more people than allowed to a list.
+                throw new ClientException(sprintf(_('You already have %1$d or more people in list %2$s, ' .
                                                     'which is the maximum allowed number.' .
-                                                    'Try untagging others with the same tag first.'),
+                                                    'Try unlisting others first.'),
                                                     common_config('peopletag', 'maxpeople'), $tag));
                 return false;
             }
@@ -221,7 +224,9 @@ class Profile_tag extends Memcached_DataObject
             Event::handle('EndUntagProfile', array($orig));
             if ($result) {
                 $profile_list = Profile_list::pkeyGet(array('tag' => $tag, 'tagger' => $tagger));
-                $profile_list->taggedCount(true);
+                if (!empty($profile_list)) {
+                    $profile_list->taggedCount(true);
+                }
                 self::blowCaches($tagger, $tagged);
                 return true;
             }
@@ -271,4 +276,41 @@ class Profile_tag extends Memcached_DataObject
         }
         return true;
     }
+
+    // Return profiles with a given tag
+    static function getTagged($tagger, $tag) {
+        $profile = new Profile();
+        $profile->query('SELECT profile.* ' .
+                        'FROM profile JOIN profile_tag ' .
+                        'ON profile.id = profile_tag.tagged ' .
+                        'WHERE profile_tag.tagger = ' . $tagger . ' ' .
+                        'AND profile_tag.tag = "' . $tag . '" ');
+        $tagged = array();
+        while ($profile->fetch()) {
+            $tagged[] = clone($profile);
+        }
+        return true;
+    }
+
+    function insert()
+    {
+        $result = parent::insert();
+        if ($result) {
+            self::blow('profile_list:tagged_count:%d:%s', 
+                       $this->tagger,
+                       $this->tag);
+        }
+        return $result;
+    }
+
+    function delete()
+    {
+        $result = parent::delete();
+        if ($result) {
+            self::blow('profile_list:tagged_count:%d:%s', 
+                       $this->tagger,
+                       $this->tag);
+        }
+        return $result;
+    }
 }