Database Reference
In-Depth Information
The
getContent
method in
Content
class, shown in Listing 8-30, will first determine whom the user is following
and then match that set of user with the status updates starting with the
CURRENTPOST
. The
CURRENTPOST
is then
matched on the next three status updates via the
[:NEXTPOST*0..3]
section of the query. Finally, the method uses
a loop to add a readable date and time string property—based on the timestamp—on the results returned to the
controller and view.
Listing 8-30.
The
getContent
Method in the
Content
Class
public static function getContent($username, $s) {
// we're doing LIMIT 4. at present were' only displaying 3. the extra item
// is to ensure there's more to view, so the next skip will be 3, then 6, then 12
$queryString = " MATCH (u:User {username: {u} })-[:FOLLOWS*0..1]->f " .
" WITH DISTINCT f,u " .
" MATCH f-[:CURRENTPOST]-lp-[:NEXTPOST*0..3]-p " .
" RETURN p, f.username as username, f=u as owner " .
" ORDER BY p.timestamp desc SKIP {s} LIMIT 4 ";
$query = new Everyman\Neo4j\Cypher\Query(Neo4Client::client(), $queryString, array(
'u' => $username,
's' => $s
));
$result = $query->getResultSet();
return self::returnMappedContent($result);
}
Adding a Status Update
Figure
8-10
shows the form to add a status update for the current user, which is displayed when clicking on the “Add
Content” link just under the “Graph Story - Social Feed” header. The HTML for the form can be found in
{PROJECTROOT}/
app/templates/graphs/social/posts.mustache
. The form uses the
add_content
function in
graphstory.js
to
POST
a
new status update as well as return the response and add it to the top of the status update stream.