Database Reference
In-Depth Information
The unfollow feature for the FOLLOWS relationships uses a nearly identical application flow as follows feature.
In the unfollow method, shown in Listing 8-29, the controller passes in two arguments—the current username and
username to be unfollowed. As with the follows method, once the operation is completed, the next part of the query
then runs a MATCH on the users being followed to return the full list of followers ordered by the username.
Listing 8-29. The unfollow Route and unfollow Service Method
// takes current user session and will unfollow :username
$app->get('/unfollow/:username', function ($username) use ($app) {
$following = User::unfollow($_SESSION['username'], $username);
echo '{"following": ' . json_encode($following) . '}';
});
// the unfollow method in the User class
public static function unfollow($username, $userToUnfollow)
{
$queryString = "MATCH (user1:User {username:{cu}} )-[f:FOLLOWS]->".
" (user2:User {username:{u}} ) " .
" DELETE f " .
" WITH user1" .
" MATCH (user1)-[f:FOLLOWS]->(users)" .
" RETURN users " .
" ORDER BY users.username";
$query = new Everyman\Neo4j\Cypher\Query(Neo4Client::client(), $queryString, array(
'cu' => $username,
'u' => $userToUnfollow
));
$result = $query->getResultSet();
return self::returnAsUsers($result);
}
User-Generated Content
Another important feature in social media applications is being able to have users view, add, edit, and remove
content—sometimes referred to as user-generated content . In the case of this content, we will not be creating
connections between the content and its owner, but creating a linked list of status updates. In other words, you are
connecting a User to their most recent status update and then connecting each subsequent status to the next update
through the CURRENTPOST and NEXTPOST directed relationship types, respectively.
This approach is used for two reasons. First, the sample application displays a given number of posts at a time,
and using a limited linked list is more efficient than getting all status updates connected directly to a user and then
sorting and limiting the number of items to return. Second, it helps to limit the number of relationships that are
placed on the User and Content entities. Therefore, the overall graph operations should be more efficient using the
linked list approach.
Getting the Status Updates
To display the first set of status updates, start with the social route of the social section of the sample PHP application.
This method accesses the get_content method within Content service class, which takes an argument of the current
user's username and the page being requested. The page refers to set number of objects within a collection. In this
instance the paging is zero-based, so will request page 0 and limit the page size to 4 in order to return the first page.
 
Search WWH ::




Custom Search