Database Reference
In-Depth Information
Figure 8-10.
Adding a status update
The post content route and
addContent
method are shown in Listing 8-31. When a new status update is created, in
addition to its graph id, the
addContent
method also generates a contentId, which performs using the
uniqid
method.
The
addContent
method also makes the status the
CURRENTPOST
. Determine whether a previous
CURRENTPOST
exists and, if one does, change its relationship type to
NEXTPOST
. In addition, the tags connected to the status update
will be merged into the graph and connected to the status update via the
HAS
relationship type.
Listing 8-31.
addContent
Route and
addContent
Method for a Status Update
// add a status update - route
$app->post('/posts/add', function() use ($app){
$request = $app->request();
$contentParams = json_decode($request->getBody());
$content = new Content();
$content->title=$contentParams->title;
$content->url=$contentParams->url;
// are tags set?
if(isset($contentParams->tagstr)){
$content->tagstr=$contentParams->tagstr;
}
$content = Content::addContent($_SESSION['username'], $content);