+ public static function schemaDef()
+ {
+ return array(
+
+ 'fields' => array(
+ 'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag'),
+ 'tagged' => array('type' => 'int', 'not null' => true, 'description' => 'profile tagged'),
+ 'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
+ 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date the tag was added'),
+ ),
+ 'primary key' => array('tagger', 'tagged', 'tag'),
+ 'foreign keys' => array(
+ 'profile_tag_tagger_fkey' => array('profile', array('tagger' => 'id')),
+ 'profile_tag_tagged_fkey' => array('profile', array('tagged' => 'id')),
+ 'profile_tag_tag_fkey' => array('profile_list', array('tag' => 'tag')),
+ ),
+ 'indexes' => array(
+ 'profile_tag_modified_idx' => array('modified'),
+ 'profile_tag_tagger_tag_idx' => array('tagger', 'tag'),
+ 'profile_tag_tagged_idx' => array('tagged'),
+ ),
+ );
+ }
+
+ function links()
+ {
+ return array('tagger,tag' => 'profile_list:tagger,tag');
+ }
+
+ function getMeta()
+ {
+ return Profile_list::pkeyGet(array('tagger' => $this->tagger, 'tag' => $this->tag));
+ }
+
+ static function getSelfTagsArray(Profile $target)
+ {
+ return self::getTagsArray($target->getID(), $target->getID(), $target);
+ }
+
+ static function setSelfTags(Profile $target, array $newtags, array $privacy=array())
+ {
+ return self::setTags($target->getID(), $target->getID(), $newtags, $privacy);
+ }
+
+ static function getTags($tagger, $tagged, $auth_user=null) {
+
+ $profile_list = new Profile_list();
+ $include_priv = 1;
+
+ if (!($auth_user instanceof User ||
+ $auth_user instanceof Profile) ||
+ ($auth_user->id !== $tagger)) {
+
+ $profile_list->private = false;
+ $include_priv = 0;
+ }
+
+ $key = sprintf('profile_tag:tagger_tagged_privacy:%d-%d-%d', $tagger, $tagged, $include_priv);
+ $tags = Profile_list::getCached($key);
+ if ($tags !== false) {
+ return $tags;
+ }
+
+ $qry = 'select profile_list.* from profile_list left join '.
+ 'profile_tag on (profile_list.tag = profile_tag.tag and '.
+ 'profile_list.tagger = profile_tag.tagger) where '.
+ 'profile_tag.tagger = %d and profile_tag.tagged = %d ';
+ $qry = sprintf($qry, $tagger, $tagged);
+
+ if (!$include_priv) {
+ $qry .= ' and profile_list.private = 0';
+ }
+
+ $profile_list->query($qry);
+
+ Profile_list::setCache($key, $profile_list);
+
+ return $profile_list;
+ }
+
+ static function getTagsArray($tagger, $tagged, Profile $scoped=null)
+ {
+ $ptag = new Profile_tag();
+
+ $qry = sprintf('select profile_tag.tag '.
+ 'from profile_tag join profile_list '.
+ ' on (profile_tag.tagger = profile_list.tagger ' .
+ ' and profile_tag.tag = profile_list.tag) ' .
+ 'where profile_tag.tagger = %d ' .
+ 'and profile_tag.tagged = %d ',
+ $tagger, $tagged);