示例#1
0
文件: admin.php 项目: urukalo/chpoll
    if (!$loggedUser->hasAccess('poll.*')) {
        echo "You don't have the permission to access this page.";
        return;
    }
    $data = $app->request->post();
    if (isset($data['id'])) {
        $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;
    }