Exemplo n.º 1
0
 /**
  * @param \Illuminate\Http\Request $request
  * @param Question                 $question
  *
  * @return \Illuminate\Http\Response
  */
 public function answer(Request $request, Question $question)
 {
     // TODO: If question has been answered can't answer again
     // TODO: Validate
     // TODO: AI. Global Badges
     // Obtain how many points has its answer obtained
     $points = 0;
     $success = false;
     foreach ($request->choices as $answer) {
         $choice = $question->choices()->find($answer);
         $points += $choice->points;
         $success = $success || $choice->correct;
     }
     // minimun points for answer is '1'
     if ($points < 1) {
         $points = 1;
     }
     // Create relation between User and Question
     Auth::user()->answeredQuestions()->attach($question, ['points' => $points, 'answers' => implode(',', $request->choices)]);
     // Add XP to user
     Game::addExperience(Auth::user(), $points, 'has earned ' . $points . ' points.');
     // Deal with Question specific Badges
     if ($success) {
         $answerStatus = 'correct';
     } else {
         $answerStatus = 'incorrect';
     }
     $badges = $question->actions()->whereIn('when', ['always', $answerStatus]);
     // AI. Increment actions
     foreach ($badges as $badge) {
         Game::incrementBadge(Auth::user(), $badge);
     }
     // AI. Add notifications and return view
     return redirect()->route('questions.show', $question->shortname);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $data = [];
     $data['badges'] = Badge::all()->count();
     $data['questions'] = Question::published()->count();
     $data['answers'] = User::Member()->with('answeredQuestions')->count();
     $data['members'] = User::Member()->count();
     return view('admin.dashboard.index', compact('data'));
 }
 /**
  * Show a list of all the questions formatted for Datatables.
  *
  * @param Request    $request
  * @param Datatables $dataTable
  *
  * @return JsonResponse
  */
 public function data(Request $request, Datatables $dataTable)
 {
     // Disable this query if isn't AJAX
     if (!$request->ajax()) {
         abort(400);
     }
     $question = Question::select(['id', 'shortname', 'name', 'status'])->orderBy('name', 'ASC');
     $statusLabel = ['draft' => '<span class="label label-default">' . trans('admin/question/model.status_list.draft') . '</span>', 'publish' => '<span class="label label-success">' . trans('admin/question/model.status_list.publish') . '</span>', 'unpublish' => '<span class="label label-warning">' . trans('admin/question/model.status_list.unpublish') . '</span>'];
     return $dataTable->of($question)->editColumn('status', function (Question $question) use($statusLabel) {
         return $statusLabel[$question->status];
     })->addColumn('actions', function (Question $question) {
         return view('admin/partials.actions_dd', ['model' => 'questions', 'id' => $question->id])->render();
     })->removeColumn('id')->make(true);
 }
Exemplo n.º 4
0
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
/** ------------------------------------------
 *  Route model binding
 *  ------------------------------------------.
 */
Route::bind('username', function ($value) {
    return \Gamify\User::where('username', $value)->first();
});
Route::bind('question', function ($value) {
    return \Gamify\Question::where('shortname', $value)->first();
});
Route::model('users', '\\Gamify\\User');
Route::model('badges', '\\Gamify\\Badge');
Route::model('levels', '\\Gamify\\Level');
Route::model('questions', '\\Gamify\\Question');
Route::model('actions', '\\Gamify\\QuestionAction');
// Authentication routes...
Route::get('auth/login', 'Auth\\AuthController@getLogin');
Route::post('auth/login', 'Auth\\AuthController@postLogin');
Route::get('auth/logout', 'Auth\\AuthController@getLogout');
// Registration routes...
//Route::get('auth/register', 'Auth\AuthController@getRegister');
//Route::post('auth/register', 'Auth\AuthController@postRegister');
/* ------------------------------------------
 * Authenticated routes
Exemplo n.º 5
0
 public function getPendingQuestions()
 {
     // TODO: Add an scope to only index questions (published and not answered and not hidden)
     $answeredQuestions = $this->answeredQuestions()->lists('question_id')->toArray();
     return Question::PublishedAndVisible()->whereNotIn('id', $answeredQuestions)->get();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param Question                    $question
  * @param QuestionActionCreateRequest $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Question $question, QuestionActionCreateRequest $request)
 {
     $question->actions()->create($request->all());
     return redirect()->route('admin.questions.edit', $question)->with('success', trans('admin/action/messages.create.success'));
 }