summaryrefslogtreecommitdiff
path: root/classes/Profile_tag.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-11-20 16:48:21 -0500
committerEvan Prodromou <evan@prodromou.name>2008-11-20 16:48:21 -0500
commit6f31f25105f59bee5d6a8eccf43952e1396846b3 (patch)
treeca3fe49756d05e81b5b2fed39bd3f0953fbb3fb8 /classes/Profile_tag.php
parent8a0c438aedebaa0282e4f23c83dbe0d7d2635f33 (diff)
let users set their own profile tags from profilesettings
darcs-hash:20081120214821-84dde-c8569ef645b389de545f78bf01a270f28b871f02.gz
Diffstat (limited to 'classes/Profile_tag.php')
-rw-r--r--classes/Profile_tag.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/classes/Profile_tag.php b/classes/Profile_tag.php
index f2d6ec6cf..464a817fc 100644
--- a/classes/Profile_tag.php
+++ b/classes/Profile_tag.php
@@ -20,4 +20,67 @@ class Profile_tag extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
+ static function getTags($tagger, $tagged) {
+
+ $tags = array();
+
+ # XXX: store this in memcached
+
+ $profile_tag = new Profile_tag();
+ $profile_tag->tagger = $tagger;
+ $profile_tag->tagged = $tagged;
+
+ $profile_tag->find();
+
+ while ($profile_tag->fetch()) {
+ $tags[] = $profile_tag->tag;
+ }
+
+ $profile_tag->free();
+
+ return $tags;
+ }
+
+ static function setTags($tagger, $tagged, $tags) {
+
+ $oldtags = Profile_tag::getTags($tagger, $tagged);
+
+ # Delete stuff that's old that not in new
+
+ $to_delete = array_diff($oldtags, $newtags);
+
+ # Insert stuff that's in new and not in old
+
+ $to_insert = array_diff($newtags, $oldtags);
+
+ $profile_tag = new Profile_tag();
+
+ $profile_tag->tagger = $tagger;
+ $profile_tag->tagged = $tagged;
+
+ $profile_tag->query('BEGIN');
+
+ foreach ($to_delete as $deltag) {
+ $profile_tag->tag = $deltag;
+ $result = $profile_tag->delete();
+ if (!$result) {
+ common_log_db_error($profile_tag, 'DELETE', __FILE__);
+ return false;
+ }
+ }
+
+ foreach ($to_insert as $instag) {
+ $profile_tag->tag = $instag;
+ $result = $profile_tag->insert();
+ if (!$result) {
+ common_log_db_error($profile_tag, 'INSERT', __FILE__);
+ return false;
+ }
+ }
+
+ $profile_tag->query('COMMIT');
+
+ return true;
+ }
}