Skip to content

Commit

Permalink
Added some basic relation functions for settings/removing/checking. #37
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnClake committed Mar 8, 2017
1 parent a3c8c5d commit f528bd1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
18 changes: 12 additions & 6 deletions classes/FriendsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
*/
class FriendsManager
{
const UE_FRIEND_REQUESTED = 1;
const UE_FRIENDS = 2;
const UE_FOLLOWING = 4;
const UE_SUBSCRIBED = 8;
const UE_BLOCKED = 16;
const UE_DELETED = 32;
const UE_FRIEND_REQUESTED = 1; // 0 digit
const UE_FOLLOWING = 2; // 1 digit
const UE_SUBSCRIBED = 4; // 2 digit
const UE_FRIENDS = 8; // 3 digit

// Additional Relation States should be given here. States 0-9 are reserved for UE official
// States 10-19 can be used by other modules

const UE_BLOCKED = 1048576; // 20 digit
const UE_DELETED = 2097152; // 21 digit

// States above 21 will override UE_BLOCKED and UE_DELETED. Be extremely careful with this!!!

/**
* Returns a list of friend requests received.
Expand Down
66 changes: 63 additions & 3 deletions models/Friend.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static function isRelationExists($userIdA, $userIdB = null)

/**
* Determines whether or not two users are friends. Run count on the result. If >0 then they are.
* Can find sender and accepter by examining the returned object using ->get() on the result
* Can find sender and acceptor by examining the returned object using ->get() on the result
* @param $query
* @param $userIdA
* @param $userIdB
Expand All @@ -177,7 +177,7 @@ public function scopeFriend($query, $userIdA, $userIdB = null)

/**
* Checks whether or not a friend request between two users exists
* Can find sender and accepter by examining the returned object using ->get() on the result
* Can find sender and acceptor by examining the returned object using ->get() on the result
* @param $query
* @param $userIdA
* @param null $userIdB
Expand All @@ -204,7 +204,7 @@ public function scopeRequest($query, $userIdA, $userIdB = null)

/**
* Checks whether or not a friend request between users was declined. Run count on result, if >0 then they are.
* Can find sender and accepter by examining the returned object using ->get() on the result
* Can find sender and acceptor by examining the returned object using ->get() on the result
* @param $query
* @param $userIdA
* @param null $userIdB
Expand Down Expand Up @@ -480,4 +480,64 @@ public function otherUser($userId = null)

}

/**
* ALL CODE BELOW THIS POINT IS FOR 2.2.00
*/

/**
* @param $relation_states
*/
public function setRelation($relation_states)
{
if(!is_array($relation_states))
$relation_states = [$relation_states];

foreach($relation_states as $state)
{
$this->relation = (int)($this->relation) | (int)($state);
}
}

/**
* @param $relation_state
* @return bool
*/
public function hasRelation($relation_state)
{
if(!!((int)($this->relation) & (int)($relation_state)))
return true;
return false;
}

/**
* @param $relation_states
*/
public function removeRelation($relation_states)
{
if(!is_array($relation_states))
$relation_states = [$relation_states];

foreach($relation_states as $state)
{
$this->relation = (int)($this->relation) & ~((int)($state));
}
}

/**
*
*/
public function flushRelations()
{
$this->relation = 0;
}

/**
* @param $relation_states
*/
public function setExclusiveRelation($relation_states)
{
$this->flushRelations();
$this->setRelation($relation_states);
}

}

0 comments on commit f528bd1

Please sign in to comment.