summaryrefslogtreecommitdiff
path: root/_darcs/pristine/classes/Profile_tag.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-05-06 11:17:29 -0400
committerEvan Prodromou <evan@prodromou.name>2008-05-06 11:17:29 -0400
commit1d4f1f6bf6bd8313cbb51dbf61d675408171d1b8 (patch)
tree8c622e1c4c1cbfc78abe335c1a153e354f29eee4 /_darcs/pristine/classes/Profile_tag.php
parentd4fd1c505e14bdef4945e51d4f46a949d3abfb98 (diff)
add standard directories
Added some of the standard directories darcs-hash:20080506151729-84dde-563da8505e06a7302041c93ab157ced31165876c.gz
Diffstat (limited to '_darcs/pristine/classes/Profile_tag.php')
-rw-r--r--_darcs/pristine/classes/Profile_tag.php101
1 files changed, 101 insertions, 0 deletions
diff --git a/_darcs/pristine/classes/Profile_tag.php b/_darcs/pristine/classes/Profile_tag.php
new file mode 100644
index 000000000..dde19aea2
--- /dev/null
+++ b/_darcs/pristine/classes/Profile_tag.php
@@ -0,0 +1,101 @@
+<?php
+/**
+ * Table Definition for profile_tag
+ */
+require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
+
+class Profile_tag extends Memcached_DataObject
+{
+ ###START_AUTOCODE
+ /* the code below is auto generated do not remove the above tag */
+
+ public $__table = 'profile_tag'; // table name
+ public $tagger; // int(4) primary_key not_null
+ public $tagged; // int(4) primary_key not_null
+ public $tag; // varchar(64) primary_key not_null
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile_tag',$k,$v); }
+
+ /* 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, $newtags) {
+
+ $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;
+ }
+
+ # 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 $tagged;
+ }
+}