3 * Table Definition for profile_tag
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Profile_tag extends Memcached_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'profile_tag'; // table name
13 public $tagger; // int(4) primary_key not_null
14 public $tagged; // int(4) primary_key not_null
15 public $tag; // varchar(64) primary_key not_null
16 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
19 function staticGet($k,$v=null)
20 { return Memcached_DataObject::staticGet('Profile_tag',$k,$v); }
22 /* the code above is auto generated do not remove the tag below */
25 static function getTags($tagger, $tagged) {
28 # XXX: store this in memcached
30 $profile_tag = new Profile_tag();
31 $profile_tag->tagger = $tagger;
32 $profile_tag->tagged = $tagged;
36 while ($profile_tag->fetch()) {
37 $tags[] = $profile_tag->tag;
45 static function setTags($tagger, $tagged, $newtags) {
46 $newtags = array_unique($newtags);
47 $oldtags = Profile_tag::getTags($tagger, $tagged);
49 # Delete stuff that's old that not in new
51 $to_delete = array_diff($oldtags, $newtags);
53 # Insert stuff that's in new and not in old
55 $to_insert = array_diff($newtags, $oldtags);
57 $profile_tag = new Profile_tag();
59 $profile_tag->tagger = $tagger;
60 $profile_tag->tagged = $tagged;
62 $profile_tag->query('BEGIN');
64 foreach ($to_delete as $deltag) {
65 $profile_tag->tag = $deltag;
66 $result = $profile_tag->delete();
68 common_log_db_error($profile_tag, 'DELETE', __FILE__);
73 foreach ($to_insert as $instag) {
74 $profile_tag->tag = $instag;
75 $result = $profile_tag->insert();
77 common_log_db_error($profile_tag, 'INSERT', __FILE__);
82 $profile_tag->query('COMMIT');
87 # Return profiles with a given tag
88 static function getTagged($tagger, $tag) {
89 $profile = new Profile();
90 $profile->query('SELECT profile.* ' .
91 'FROM profile JOIN profile_tag ' .
92 'ON profile.id = profile_tag.tagged ' .
93 'WHERE profile_tag.tagger = ' . $tagger . ' ' .
94 'AND profile_tag.tag = "' . $tag . '" ');
96 while ($profile->fetch()) {
97 $tagged[] = clone($profile);