コード例 #1
0
ファイル: user.php プロジェクト: urukalo/chpoll
        if ($activationRepository->completed($user)) {
            echo 'User is already activated. Try to log in.';
            return;
        }
        //ops, cant activate!
        echo "Activation error!";
        return;
    }
    //activated, do login
    echo 'Your account has been activated.';
    $app->container->auth->login($user);
    $app->redirect('/');
    return;
});
$app->get('/user/poll(/:id)', function ($id = null) use($app) {
    $pollData = urukalo\CH\Poll::where('active', 1)->with('answers')->with('user_polls');
    $user = $this->app->container->auth->check();
    if (!is_null($id)) {
        $pollDataVote = clone $pollData;
        //check is voted
        if ($pollDataVote->whereHas('user_polls', function ($query) use($user) {
            $query->where('user_polls.idUser', $user->id);
        })->find((int) $id)) {
            echo "You can vote only one time";
            //voted! show results if is public
            $pollData->where('public', 1)->find((int) $id);
            $app->twig->display('poll.html.twig', array("poll" => $pollData));
        } else {
            //have premision to vote?
            if (!$user->hasAccess('poll.vote')) {
                echo "You don't have the permission to vote.";
コード例 #2
0
ファイル: admin.php プロジェクト: urukalo/chpoll
        $poll = urukalo\CH\Poll::where('active', 1)->with('answers')->find((int) $id);
    } else {
        $poll = new urukalo\CH\Poll();
    }
    $poll->name = $data['name'];
    $poll->question = $data['question'];
    $poll->public = isset($data['public']) && $data['public'] == 'on' ? 1 : 0;
    $poll->active = isset($data['active']) && $data['active'] == 'on' ? 1 : 0;
    $poll->archived = isset($data['archived']) && $data['archived'] == 'on' ? 1 : 0;
    $poll->save();
    //save all answers too
    $answer = array();
    foreach ($data['answer'] as $answerData) {
        $answer[] = new urukalo\CH\Answers($answerData);
    }
    $poll->answers()->saveMany($answer);
    $app->redirect('/admin/poll');
});
//delete poll
$app->delete('/admin/poll(/:id)', function ($id = null) use($app) {
    $loggedUser = $app->container->auth->check();
    if (!$loggedUser->hasAccess('poll.delete')) {
        echo "You don't have the permission to access this page.";
        return;
    }
    if ($poll = urukalo\CH\Poll::find((int) $id)->has('user_polls', '=', 0)) {
        $poll->delete();
    } else {
        echo "no poll to delete";
    }
});