return $groups;
}
+ function isTagged($peopletag)
+ {
+ $tag = Profile_tag::pkeyGet(array('tagger' => $peopletag->tagger,
+ 'tagged' => $this->id,
+ 'tag' => $peopletag->tag));
+ return !empty($tag);
+ }
+
+ function canTag($tagged)
+ {
+ if (empty($tagged)) {
+ return false;
+ }
+
+ if ($tagged->id == $this->id) {
+ return true;
+ }
+
+ $all = common_config('peopletag', 'allow_tagging', 'all');
+ $local = common_config('peopletag', 'allow_tagging', 'local');
+ $remote = common_config('peopletag', 'allow_tagging', 'remote');
+ $subs = common_config('peopletag', 'allow_tagging', 'subs');
+
+ if ($all) {
+ return true;
+ }
+
+ $tagged_user = $tagged->getUser();
+ if (!empty($tagged_user)) {
+ if ($local) {
+ return true;
+ }
+ } else if ($subs) {
+ return (Subscription::exists($this, $tagged) ||
+ Subscription::exists($tagged, $this));
+ } else if ($remote) {
+ return true;
+ }
+ return false;
+ }
+
+ function getOwnedTags($auth_user, $offset=0, $limit=null, $since_id=0, $max_id=0)
+ {
+ $tags = new Profile_list();
+ $tags->tagger = $this->id;
+
+ if (($auth_user instanceof User || $auth_user instanceof Profile) &&
+ $auth_user->id === $this->id) {
+ // no condition, get both private and public tags
+ } else {
+ $tags->private = false;
+ }
+
+ $tags->selectAdd('id as "cursor"');
+
+ 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 getOtherTags($auth_user=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
+ {
+ $lists = new Profile_list();
+
+ $tags = new Profile_tag();
+ $tags->tagged = $this->id;
+
+ $lists->joinAdd($tags);
+ #@fixme: postgres (round(date_part('epoch', my_date)))
+ $lists->selectAdd('unix_timestamp(profile_tag.modified) as "cursor"');
+
+ if ($auth_user instanceof User || $auth_user instanceof Profile) {
+ $lists->whereAdd('( ( profile_list.private = false ) ' .
+ 'OR ( profile_list.tagger = ' . $auth_user->id . ' AND ' .
+ 'profile_list.private = true ) )');
+ } else {
+ $lists->private = false;
+ }
+
+ 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('profile_tag.modified DESC');
+ $lists->find();
+
+ return $lists;
+ }
+
+ 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($subs);
+ #@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;
+ }
+
+ /**
+ * Request to join the given group.
+ * May throw exceptions on failure.
+ *
+ * @param User_group $group
+ * @return mixed: Group_member on success, Group_join_queue if pending approval, null on some cancels?
+ */
+ function joinGroup(User_group $group)
+ {
+ $ok = null;
+ if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
+ $ok = Group_join_queue::saveNew($this, $group);
+ } else {
+ if (Event::handle('StartJoinGroup', array($group, $this))) {
+ $ok = Group_member::join($group->id, $this->id);
+ Event::handle('EndJoinGroup', array($group, $this));
+ }
+ }
+ return $ok;
+ }
+
+ /**
+ * Cancel a pending group join...
+ *
+ * @param User_group $group
+ */
+ function cancelJoinGroup(User_group $group)
+ {
+ $request = Group_join_queue::pkeyGet(array('profile_id' => $this->id,
+ 'group_id' => $group->id));
+ if ($request) {
+ if (Event::handle('StartCancelJoinGroup', array($group, $this))) {
+ $request->delete();
+ Event::handle('EndCancelJoinGroup', array($group, $this));
+ }
+ }
+ }
+
+ /**
+ * Complete a pending group join on our end...
+ *
+ * @param User_group $group
+ */
+ function completeJoinGroup(User_group $group)
+ {
+ $ok = null;
+ $request = Group_join_queue::pkeyGet(array('profile_id' => $this->id,
+ 'group_id' => $group->id));
+ if ($request) {
+ if (Event::handle('StartJoinGroup', array($group, $this))) {
+ $ok = Group_member::join($group->id, $this->id);
+ $request->delete();
+ Event::handle('EndJoinGroup', array($group, $this));
+ }
+ } else {
+ throw new Exception(_m('Invalid group join approval: not pending.'));
+ }
+ return $ok;
+ }
+
+ /**
+ * Leave a group that this profile is a member of.
+ *
+ * @param User_group $group
+ */
+ function leaveGroup(User_group $group)
+ {
+ if (Event::handle('StartLeaveGroup', array($group, $this))) {
+ Group_member::leave($group->id, $this->id);
+ Event::handle('EndLeaveGroup', array($group, $this));
+ }
+ }
+
function avatarUrl($size=AVATAR_PROFILE_SIZE)
{
$avatar = $this->getAvatar($size);