+ return new ArrayWrapper($lists);
+ }
+
+ /**
+ * Get tags that other people put on this profile, in reverse-chron order
+ *
+ * @param (Profile|User) $auth_user Authorized user (used for privacy)
+ * @param int $offset Offset from latest
+ * @param int $limit Max number to get
+ * @param datetime $since_id max date
+ * @param datetime $max_id min date
+ *
+ * @return Profile_list resulting lists
+ */
+
+ function getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
+ {
+ $list = new Profile_list();
+
+ $qry = sprintf('select profile_list.*, unix_timestamp(profile_tag.modified) as "cursor" ' .
+ 'from profile_tag join profile_list '.
+ 'on (profile_tag.tagger = profile_list.tagger ' .
+ ' and profile_tag.tag = profile_list.tag) ' .
+ 'where profile_tag.tagged = %d ',
+ $this->id);
+
+
+ if ($auth_user instanceof User || $auth_user instanceof Profile) {
+ $qry .= sprintf('AND ( ( profile_list.private = false ) ' .
+ 'OR ( profile_list.tagger = %d AND ' .
+ 'profile_list.private = true ) )',
+ $auth_user->id);
+ } else {
+ $qry .= 'AND profile_list.private = 0 ';
+ }
+
+ if ($since_id > 0) {
+ $qry .= sprintf('AND (cursor > %d) ', $since_id);
+ }
+
+ if ($max_id > 0) {
+ $qry .= sprintf('AND (cursor < %d) ', $max_id);
+ }
+
+ $qry .= 'ORDER BY profile_tag.modified DESC ';
+
+ if ($offset >= 0 && !is_null($limit)) {
+ $qry .= sprintf('LIMIT %d OFFSET %d ', $limit, $offset);
+ }
+
+ $list->query($qry);
+ return $list;
+ }
+
+ function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0)
+ {
+ $tags = new Profile_list();
+ $tags->private = true;
+ $tags->tagger = $this->id;
+
+ if ($since_id>0) {
+ $tags->whereAdd('id > '.$since_id);
+ }
+
+ if ($max_id>0) {
+ $tags->whereAdd('id <= '.$max_id);
+ }
+
+ if($offset>=0 && !is_null($limit)) {
+ $tags->limit($offset, $limit);
+ }
+
+ $tags->orderBy('id DESC');
+ $tags->find();
+
+ return $tags;
+ }
+
+ function hasLocalTags()
+ {
+ $tags = new Profile_tag();
+
+ $tags->joinAdd(array('tagger', 'user:id'));
+ $tags->whereAdd('tagged = '.$this->id);
+ $tags->whereAdd('tagger != '.$this->id);
+
+ $tags->limit(0, 1);
+ $tags->fetch();
+
+ return ($tags->N == 0) ? false : true;
+ }
+
+ function getTagSubscriptions($offset=0, $limit=null, $since_id=0, $max_id=0)
+ {
+ $lists = new Profile_list();
+ $subs = new Profile_tag_subscription();
+
+ $lists->joinAdd(array('id', 'profile_tag_subscription:profile_tag_id'));
+
+ #@fixme: postgres (round(date_part('epoch', my_date)))
+ $lists->selectAdd('unix_timestamp(profile_tag_subscription.created) as "cursor"');
+
+ $lists->whereAdd('profile_tag_subscription.profile_id = '.$this->id);
+
+ if ($since_id>0) {
+ $lists->whereAdd('cursor > '.$since_id);
+ }
+
+ if ($max_id>0) {
+ $lists->whereAdd('cursor <= '.$max_id);
+ }
+
+ if($offset>=0 && !is_null($limit)) {
+ $lists->limit($offset, $limit);
+ }
+
+ $lists->orderBy('"cursor" DESC');
+ $lists->find();
+
+ return $lists;