Esempio n. 1
0
 * @copyright Ninelabs 2013
 * @author Moses Ngone <*****@*****.**>
 */
use Blueridge\Documents\User;
use Blueridge\Providers\Basecamp;
/**
 * Display projects
 * @param string '/app/projects/'
 * @param type function () use ($app
 * @param type $blueridge
 * @return type
 */
$app->get('/app/projects/', function () use($app, $blueridge) {
    $userQr = $blueridge['documentManager']->getRepository('\\Blueridge\\Documents\\User');
    $user = $userQr->findOneById($blueridge['authenticationService']->getIdentity());
    $basecampClient = new Basecamp($blueridge);
    $basecampProjects = $basecampClient->getProjects($user);
    $user = $userQr->updateProjects($user, $basecampProjects);
    $projects = $user->projects;
    $userDetails = $user->toArray();
    $view = ['user' => $userDetails, 'projects' => $projects, 'route' => 'projects', 'plan' => $userDetails['subscription']['plan'], 'mode' => $app->mode];
    $app->render("app/projects.html", $view);
});
$app->post('/app/projects/', function () use($app, $blueridge) {
    $params = $app->request->post('selected');
    $params = array_map('intval', $params);
    $userQr = $blueridge['documentManager']->getRepository('\\Blueridge\\Documents\\User');
    $user = $userQr->findOneById($blueridge['authenticationService']->getIdentity());
    $userQr->updateProfile($user, 'projects', $params);
    $userQr->setStatus($user, "active");
    Resque::enqueue('sync', 'Blueridge\\Jobs\\FilterBasecampTodosByUser', ['userid' => $user->id]);
Esempio n. 2
0
    }, array_values($todos));
    $collection = ['count' => count($todos), 'projects' => count($user->profile['projects']), 'todos' => $todos];
    echo json_encode($collection);
    $app->response->headers->set('Content-Type', 'application/json');
});
/**
 * $id Todo Id
 * @var String
 */
$app->post('/api/todos/:id/', function ($id) use($app, $blueridge) {
    /**
     * @todo check fot xhr
     */
    $userid = $app->request()->params('user');
    $payload = $app->request()->params('payload');
    $userQr = $blueridge['documentManager']->getRepository('\\Blueridge\\Documents\\User');
    $user = $userQr->findOneById($userid);
    if (empty($user)) {
        $app->response()->status(404);
        return;
    }
    $todoQr = $blueridge['documentManager']->getRepository('\\Blueridge\\Documents\\Todo');
    $todo = $todoQr->findOneById($id);
    $basecampClient = new Basecamp($blueridge);
    $result = $basecampClient->updateTodo($user, $todo, $payload);
    if ($result == 200) {
        $blueridge['documentManager']->remove($todo);
        $blueridge['documentManager']->flush();
    }
    $app->response()->status($result);
});