private function createUser($randomized = false)
 {
     $user = $this->standardUser;
     if ($randomized) {
         $user = new User();
         $id = mt_rand(101, 200);
         $user->id = $id;
         $user->username = $this->standardUser->username . $id;
         $user->firstname = $this->standardUser->firstname;
         $user->lastname = $this->standardUser->lastname;
     }
     $userService = new UserService();
     $userService->save($user);
     return $user;
 }
Example #2
0
})->name('social-follow');
// takes current user session and will unfollow :username
$app->delete('/unfollow/:userToUnfollow', function ($userToUnfollow) use($app) {
    UserService::unfollowUser($_SESSION['username'], $userToUnfollow);
    $following = UserService::following($_SESSION['username']);
    $unfollowUrl = $app->urlFor('social-unfollow', array('userToUnfollow' => null));
    $return = array();
    foreach ($following as $friend) {
        $content = array_merge(array('unfollowUrl' => $unfollowUrl), $friend->toArray());
        $return[] = $app->view->getInstance()->render('graphs/social/friends-partial', $content);
    }
    $app->jsonResponse->build(array('following' => $return));
})->name('social-unfollow');
//search users by name
$app->get('/searchbyusername/:search', function ($search) use($app) {
    $users = UserService::searchByUsername($search, $_SESSION['username']);
    $app->jsonResponse->build(array('users' => $users));
})->name('user-search');
// social - show posts
$app->get('/posts', $isLoggedIn, function () use($app) {
    $content = ContentService::getContent($_SESSION['username'], 0);
    $socialContent = array_slice($content, 0, 3);
    $moreContent = count($content) >= 4;
    $app->render('graphs/social/posts.mustache', array('username' => $_SESSION['username'], 'socialContent' => $socialContent, 'moreContent' => $moreContent, 'moreContentUrl' => $app->urlFor('social-feed', array('skip' => null)), 'addContentUrl' => $app->urlFor('social-post-add'), 'friendsUrl' => $app->urlFor('social-friends'), 'postUrl' => $app->urlFor('social-post', array('postId' => null))));
})->name('social-graph');
// social - return posts as JSON
$app->get('/feed/:skip', $isLoggedIn, function ($skip) use($app) {
    $result = ContentService::getContent($_SESSION['username'], (int) $skip);
    $postUrl = $app->urlFor('social-post', array('postId' => null));
    $return = array();
    foreach ($result as $content) {