当前位置: 首页>>代码示例>>PHP>>正文


PHP Quiz::findOrFail方法代码示例

本文整理汇总了PHP中Quiz::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Quiz::findOrFail方法的具体用法?PHP Quiz::findOrFail怎么用?PHP Quiz::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Quiz的用法示例。


在下文中一共展示了Quiz::findOrFail方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: delete

 public function delete()
 {
     $quizId = Input::get('quizId', null);
     if (!$quizId) {
         return Response::error("Quiz not found");
     }
     try {
         $quiz = Quiz::findOrFail($quizId ? $quizId : $quizData['id']);
     } catch (ModelNotFoundException $e) {
         return Response::error("Error finding quiz with id " . $quizId);
     }
     if ($quiz->delete()) {
         return Response::json(array('success' => true));
     } else {
         return Response::error("Some error occured while deleting quiz : '" . $quizId->topic . "'");
     }
 }
开发者ID:thunderclap560,项目名称:quizkpop,代码行数:17,代码来源:AdminQuizesController.php

示例2: quizUsers

 public function quizUsers()
 {
     try {
         $sortOptions = self::processSort();
         $activityType = Input::get('activityType');
         $quizId = Input::get('quizId');
         $users = null;
         if ($quizId) {
             $quiz = Quiz::findOrFail($quizId);
             $quizStats = $quiz->stats;
             $quizResultsDistribution = array();
             $quizResultsDistribution = $quiz->resultDistribution();
             if ($activityType) {
                 $activityOptions = array();
                 if ($activityType == 'got-result') {
                     $activityOptions = array('resultId' => Input::get('resultId'));
                 } else {
                     if ($activityType == 'chosen-answer') {
                         $activityOptions = array('questionId' => Input::get('questionId'), 'answerId' => Input::get('answerId'));
                     }
                 }
                 $usersQuery = self::getUsersQueryByActivity($quiz, $activityType, $activityOptions);
                 $usersQuery = $usersQuery->orderBy($sortOptions['sort'], $sortOptions['sortType']);
                 if (Input::get('download')) {
                     return self::downloadEmails($usersQuery);
                 }
                 $users = $usersQuery->paginate(self::$perPage);
                 //dd(DB::getQueryLog());
                 //dd($users->toArray());
                 self::addSerialNumbers($users);
             }
             $results = $quiz->results;
             $questions = $quiz->questions;
             $quizShareRate = $quizLikeRate = 0;
             if ($quizStats && !empty($quizStats->attempts)) {
                 $quizShareRate = number_format($quizStats->shares / $quizStats->attempts * 100, 2);
                 $quizLikeRate = number_format($quizStats->likes / $quizStats->attempts * 100, 2);
             }
             $last30DaysAttempts = AdminController::getLastNDaysActivity(30, 'attempt', $quiz);
             View::share(array('users' => $users, 'quizId' => $quizId, 'quiz' => $quiz, 'quizResults' => $results, 'quizQuestions' => $questions, 'quizStats' => $quizStats, 'quizShareRate' => $quizShareRate, 'quizLikeRate' => $quizLikeRate, 'last30DaysAttempts' => json_encode($last30DaysAttempts), 'quizResultsDistribution' => $quizResultsDistribution));
         } else {
         }
         View::share(array('activityType' => $activityType, 'resultId' => Input::get('resultId'), 'questionId' => Input::get('questionId'), 'answerId' => Input::get('answerId')));
         QuizController::_loadQuizes();
         return View::make('admin/users/quizUsers')->with(array('currentPage' => 'quizUsers'));
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         return Response::notFound('Quiz not found');
     } catch (Exception $e) {
         return Response::make($e->getMessage(), 400);
     }
 }
开发者ID:thunderclap560,项目名称:quizkpop,代码行数:51,代码来源:AdminUsersController.php

示例3: saveUserAnswer

 public function saveUserAnswer($nameString, $quizId = null)
 {
     try {
         $quiz = Quiz::findOrFail($quizId);
         $user = Auth::user();
         $questionId = Input::get('questionId');
         $choiceId = Input::get('choiceId');
         if (!$user) {
             return Response::json(array('error' => 'Not logged in'), 400);
         }
         $quizUserAnswer = QuizUserAnswers::firstOrNew(array('user_id' => $user->id, 'quiz_id' => $quiz->id, 'question_id' => $questionId, 'answer_id' => $choiceId));
         $quizUserAnswer->save();
         return Response::json(array('message' => 'Activity recorded'));
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         return Response::notFound('Quiz not found');
     } catch (Exception $e) {
         return Response::notFound($e->getMessage());
     }
 }
开发者ID:thunderclap560,项目名称:quizkpop,代码行数:19,代码来源:QuizController.php

示例4: show

 public function show($id)
 {
     $quiz = Quiz::findOrFail($id);
     $menu = 'academic';
     return View::make('quizzes.show', compact('quiz', 'menu'));
 }
开发者ID:emanmks,项目名称:oneschool,代码行数:6,代码来源:QuizzesController.php


注:本文中的Quiz::findOrFail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。