2008-11-20 20:55:06 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Table Definition for profile_tag
|
|
|
|
*/
|
2008-11-20 21:49:45 +00:00
|
|
|
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
2008-11-20 20:55:06 +00:00
|
|
|
|
2009-02-28 23:17:49 +00:00
|
|
|
class Profile_tag extends Memcached_DataObject
|
2008-11-20 20:55:06 +00:00
|
|
|
{
|
|
|
|
###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 */
|
2008-12-23 19:33:23 +00:00
|
|
|
function staticGet($k,$v=null)
|
|
|
|
{ return Memcached_DataObject::staticGet('Profile_tag',$k,$v); }
|
2008-11-20 20:55:06 +00:00
|
|
|
|
|
|
|
/* the code above is auto generated do not remove the tag below */
|
|
|
|
###END_AUTOCODE
|
2008-11-20 21:48:21 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
static function getTags($tagger, $tagged) {
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$tags = array();
|
2008-11-20 21:48:21 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
# XXX: store this in memcached
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$profile_tag = new Profile_tag();
|
|
|
|
$profile_tag->tagger = $tagger;
|
|
|
|
$profile_tag->tagged = $tagged;
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$profile_tag->find();
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
while ($profile_tag->fetch()) {
|
|
|
|
$tags[] = $profile_tag->tag;
|
|
|
|
}
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$profile_tag->free();
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
return $tags;
|
|
|
|
}
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
static function setTags($tagger, $tagged, $newtags) {
|
2009-02-28 23:17:49 +00:00
|
|
|
|
|
|
|
$newtags = array_unique($newtags);
|
2008-12-23 19:19:07 +00:00
|
|
|
$oldtags = Profile_tag::getTags($tagger, $tagged);
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
# Delete stuff that's old that not in new
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$to_delete = array_diff($oldtags, $newtags);
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
# Insert stuff that's in new and not in old
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$to_insert = array_diff($newtags, $oldtags);
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$profile_tag = new Profile_tag();
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$profile_tag->tagger = $tagger;
|
|
|
|
$profile_tag->tagged = $tagged;
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$profile_tag->query('BEGIN');
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$profile_tag->query('COMMIT');
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-02-28 23:17:49 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
# 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;
|
|
|
|
}
|
2008-11-20 20:55:06 +00:00
|
|
|
}
|