function deleteQuestion(Request $request, Question $question)
 {
     // Double check to make sure the current user is authorized to do this...
     $this->authorize('delete-question');
     $question->delete();
     $request->session()->flash('success', 'The question has been deleted.');
     return redirect('/questions');
 }
Exemple #2
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $subject = Subject::findOne(['id' => $this->subject_id]);
         $this->section = $subject->section;
         $question = new Question();
         $this->questions_ids = $question->getSubjectQuestionsIds($this->subject_id);
         return true;
     }
     return false;
 }
 public function quiz()
 {
     if (Session::has('id') && (Session::get('type') === 'Student' || Session::get('type') === 'SuperAdmin')) {
         //$questions = Question::all();
         //$ansAr = array(
         //);
         $random_question = Question::orderBY(DB::raw('Rand()', 'Unique()'))->take(2)->get(array('id', 'q_description', 'q_opt_1', 'q_opt_2', 'q_opt_3', 'q_opt_4', 'q_ans'));
         //print_r($random_question);
         $cnt = 0;
         foreach ($random_question as $tmp) {
             //			    print_r($tmp);
             //			    print("---------------\n-----------------");
             $cnt++;
         }
         $totNoOfQus = $cnt;
         //echo $cnt;
         $correct_answer = array_pluck($random_question, 'q_ans');
         $qIds = array_pluck($random_question, 'id');
         $combined = array_combine($qIds, $correct_answer);
         //		    echo '<pre>';
         //		    print_r($combined);
         //		    die;
         Session::put('correct_answer', $combined);
         Session::put('total_qus', $totNoOfQus);
         //		    return $correct_answer;
         return view::make('quiz')->with('title', 'QUIZ')->with('quiz', $random_question);
     } else {
         echo 'You are not authorised';
     }
 }
 function createFeedback(FeedbackRequest $request)
 {
     // Double check to make sure the current user is authorized to do this...
     $this->authorize('create-feedback');
     $input = $request->all();
     // Check application ID
     $application = Application::find($input['application_id']);
     // Check regarding ID / type, Note, nothing to be done for 'general' feedback
     if ($input['regarding_type'] == 'question') {
         $regarding = Question::find($input['regarding_id']);
     } elseif ($input['regarding_type'] == 'document') {
         // todo
     }
     // Create new feedback
     $feedback = new Feedback();
     $feedback->application_id = $application->id;
     $feedback->regarding_type = $input['regarding_type'];
     if (isset($regarding) && $regarding->exists) {
         $feedback->regarding_id = $regarding->id;
     }
     // Set the current judge ID for a record of who requested this feedback
     $feedback->user_id = Auth::user()->id;
     $feedback->save();
     $feedback->update($input);
     // Notify applicant of new feedback requested
     event(new FeedbackChanged($feedback, ['status' => 'created']));
     $request->session()->flash('success', 'Your feedback has been requested.');
     return redirect('/applications/' . $application->id . '/review');
 }
Exemple #5
0
 public function editItem(AcceptanceTester $I)
 {
     $q = Question::get()->random();
     $I->wantTo('show edit page');
     $I->amOnRoute('admin.q.edit', ['id' => $q->id]);
     $I->seeInField('title', $q->title);
 }
Exemple #6
0
 public function index()
 {
     $entities = Quizz::all();
     $entitiesQuestion = Question::all();
     $entitiesTheme = Theme::all();
     return view('admin.quizz.index', ['entities' => $entities, 'entitiesQuestion' => $entitiesQuestion, 'entitiesTheme' => $entitiesTheme]);
 }
 public function run()
 {
     DB::table("questions")->delete();
     Question::create(['quiz_id' => 1, 'question' => 'A program that can copy itself and infect a computer without the permission or knowledge of the owner is called what?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which of these is a correct format of IP address?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which was the first web browser?']);
     Question::create(['quiz_id' => 1, 'question' => 'It is a small piece of text stored on a user\'s computer by a web browser for maintaining the state. What we are talking about?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which of these is a correct format of Email address?']);
     Question::create(['quiz_id' => 1, 'question' => 'What does HTTP stands for?']);
     Question::create(['quiz_id' => 1, 'question' => 'In computers, what is the smallest and basic unit of information storage?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which company is nicknamed "Big Blue"?']);
     Question::create(['quiz_id' => 1, 'question' => 'What is JVM?']);
     Question::create(['quiz_id' => 1, 'question' => 'What is Windows XP?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which of the following is responsible for the management and coordination of activities and the sharing of the resources of the computer?']);
     Question::create(['quiz_id' => 1, 'question' => 'WAV file format is associated with what type of files?']);
     Question::create(['quiz_id' => 1, 'question' => 'What is a Compiler?']);
     Question::create(['quiz_id' => 1, 'question' => 'Machine language is also known as']);
     Question::create(['quiz_id' => 1, 'question' => 'What does FTP stand for?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which company acquired Sun Microsystems on January 27, 2010?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which was the first ever web server software?']);
     Question::create(['quiz_id' => 1, 'question' => 'What does BCC means in EMail?']);
     Question::create(['quiz_id' => 1, 'question' => 'MS-Word is an example of']);
     Question::create(['quiz_id' => 1, 'question' => 'Who is known as the father of the Java programming language?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which software application is used for accessing sites or information on a network (as the World Wide Web)?']);
     Question::create(['quiz_id' => 1, 'question' => 'What are the two broad categories of software?']);
     Question::create(['quiz_id' => 1, 'question' => 'One kilobyte contains how many bytes?']);
     Question::create(['quiz_id' => 1, 'question' => 'In computers, a collection of row data is known as what?']);
     Question::create(['quiz_id' => 1, 'question' => 'Who Owns the Internet?']);
     Question::create(['quiz_id' => 1, 'question' => 'What is the shortcut key of printing a document for computer having windows?']);
     Question::create(['quiz_id' => 1, 'question' => 'It is defined as the period of time that a unique user interacts with a Web application. What we are talking about?']);
     Question::create(['quiz_id' => 1, 'question' => 'Java is a']);
     Question::create(['quiz_id' => 1, 'question' => 'In computers, \'.TMP\' extension refers usually to what kind of file?']);
     Question::create(['quiz_id' => 1, 'question' => 'The way of manipulating data into information is called']);
     Question::create(['quiz_id' => 1, 'question' => 'What Does BIOS Stand For?']);
     Question::create(['quiz_id' => 1, 'question' => 'Abbreviate \'LAN\' in computer networks']);
     Question::create(['quiz_id' => 1, 'question' => 'Which of the following performs modulation and demodulation?']);
     Question::create(['quiz_id' => 1, 'question' => 'In windows computers, MPEG extension refers to what kind of file?']);
     Question::create(['quiz_id' => 1, 'question' => 'Memory management is a feature of']);
     Question::create(['quiz_id' => 1, 'question' => 'Which of the following is not a storage device?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which of these is the first web-based e-mail service?']);
     Question::create(['quiz_id' => 1, 'question' => 'The Specially designed computers to perform very complex calculations extremely rapidly are called as']);
     Question::create(['quiz_id' => 1, 'question' => 'A bus is a / an']);
     Question::create(['quiz_id' => 1, 'question' => 'How many layers are described in networking?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which of the following is not a web server?']);
     Question::create(['quiz_id' => 1, 'question' => 'What was the first general-purpose electronic computer?']);
     Question::create(['quiz_id' => 1, 'question' => 'What is CGI?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which of the following is not a database?']);
     Question::create(['quiz_id' => 1, 'question' => 'The term \'Pentium\' is related to what?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which supercomputer is developed by the Indian Scientists?']);
     Question::create(['quiz_id' => 1, 'question' => 'Check the odd term out']);
     Question::create(['quiz_id' => 1, 'question' => 'What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?']);
     Question::create(['quiz_id' => 1, 'question' => 'When does the code block following while(x<100) execute?']);
     Question::create(['quiz_id' => 1, 'question' => 'Which is not a loop structure?']);
     Question::create(['question' => 'A for?', 'quiz_id' => 2]);
     Question::create(['question' => 'B for?', 'quiz_id' => 4]);
     Question::create(['question' => 'C for?', 'quiz_id' => 2]);
     Question::create(['question' => 'D for?', 'quiz_id' => 3]);
     Question::create(['question' => 'E for?', 'quiz_id' => 3]);
     Question::create(['question' => 'F for?', 'quiz_id' => 4]);
 }
 public function createAnswer(AnswerRequest $request)
 {
     // Check if current user created this application
     $input = $request->all();
     $application = Application::find($input['application_id']);
     $question = Question::find($input['question_id']);
     if ($application->user->id != Auth::user()->id) {
         $request->session()->flash('error', 'Only the person who created an application may answer questions for it.');
         return redirect('/login');
     }
     if ($application->status != 'new') {
         $request->session()->flash('error', 'Your application has been submitted, you may no longer make changes.');
         return redirect('/applications/' . $application->id . '/review');
     }
     // Check if an answer already exists for this question
     $answer = Answer::firstOrNew(['application_id' => $application->id, 'question_id' => $question->id]);
     // Add submitted information
     $answer->application_id = $application->id;
     $answer->question_id = $question->id;
     $answer->answer = $input['answer'];
     $answer->save();
     // Check if a file needs to be uploaded
     if ($question->type == 'file') {
         // Save uploaded file
         $upload = Document::handleUpload($request);
         // Save new document
         Document::createDocument($application, $upload, $answer);
     }
     $request->session()->flash('success', 'Your answer has been saved.');
     return redirect('/applications/' . $application->id);
 }
 public function actionIndex()
 {
     $model = Question::find()->with('answers')->where(['active' => 1]);
     $searchModel = new QuestionSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 /**
  * Finds the Question model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Question the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Question::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 protected function create($values)
 {
     $data = [];
     foreach ($this->structure as $i => $key) {
         $data[$key] = $values[$i];
     }
     Question::create($data);
 }
Exemple #12
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $cur_subject = Subject::findOne(['id' => $this->subject_id]);
         $this->section = $cur_subject->section;
         $question = new Question();
         $subjects = Subject::find()->where(['section' => $cur_subject->section, 'type' => 1])->all();
         $q_ids = '';
         foreach ($subjects as $subject) {
             $q_ids .= $question->getSubjectQuestionsIds($subject->id) . ',';
         }
         $q_ids .= $question->getSubjectQuestionsIds($cur_subject->id);
         $this->questions_ids = $q_ids;
         return true;
     }
     return false;
 }
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     //create base question for each question
     // TODO this should actually be an event
     $fact_id = $this->fact->id;
     $questions = [['fact_id' => $fact_id, 'question_title' => 'Can you create a question from this fact?', 'question_type' => 1], ['fact_id' => $fact_id, 'question_title' => 'Can you Write this idea in your own words?', 'question_type' => 2], ['fact_id' => $fact_id, 'question_title' => 'Can you write a paragraph about this idea and its related implications? Remember to save it!', 'question_type' => 3], ['fact_id' => $fact_id, 'question_title' => 'How can this idea be used in your life?', 'question_type' => 4], ['fact_id' => $fact_id, 'question_title' => 'Can you find a related idea to this fact?', 'question_type' => 5], ['fact_id' => $fact_id, 'question_title' => 'Can you give an example in recent new or history related to this idea?', 'question_type' => 6], ['fact_id' => $fact_id, 'question_title' => 'What is one key term or phrase that you can later define', 'question_type' => 7], ['fact_id' => $fact_id, 'question_title' => 'How can you take action on this idea right this moment?', 'question_type' => 8], ['fact_id' => $fact_id, 'question_title' => 'What would be the potential significance of this idea in the future', 'question_type' => 9], ['fact_id' => $fact_id, 'question_title' => 'What is the significance of this idea in other places of the world', 'question_type' => 10], ['fact_id' => $fact_id, 'question_title' => 'How would you think of this idea if you were not you? If you were a women, white, etc.', 'question_type' => 11], ['fact_id' => $fact_id, 'question_title' => 'Name one person you idolize. How would they interpret and use this idea', 'question_type' => 12], ['fact_id' => $fact_id, 'question_title' => 'What are some ideas that build up this idea ', 'question_type' => 13], ['fact_id' => $fact_id, 'question_title' => 'Name one field you have interest in? How would they take advantage of this idea', 'question_type' => 14], ['fact_id' => $fact_id, 'question_title' => 'How can you use this idea in relation to your strengths?', 'question_type' => 15], ['fact_id' => $fact_id, 'question_title' => 'Can you prove this idea false?', 'question_type' => 16], ['fact_id' => $fact_id, 'question_title' => 'Is there an opposite to this idea?', 'question_type' => 17], ['fact_id' => $fact_id, 'question_title' => 'What if this idea was in a vacuum and had no constraints? What would be the effect?', 'question_type' => 19], ['fact_id' => $fact_id, 'question_title' => 'What would this idea be link if it exaggerated?', 'question_type' => 20], ['fact_id' => $fact_id, 'question_title' => 'What would this idea be like if it was minimized', 'question_type' => 21], ['fact_id' => $fact_id, 'question_title' => 'How can this idea relate to your goals in life', 'question_type' => 22], ['fact_id' => $fact_id, 'question_title' => 'Is this an idea that would be accepted or rejected by society', 'question_type' => 23], ['fact_id' => $fact_id, 'question_title' => 'What would be the effects if everybody accepted this idea as universal truth', 'question_type' => 24], ['fact_id' => $fact_id, 'question_title' => 'If you discovered this idea for yourself, what would it be worth to everybody else?', 'question_type' => 25], ['fact_id' => $fact_id, 'question_title' => 'How can this idea be used to prepare for future?', 'question_type' => 26], ['fact_id' => $fact_id, 'question_title' => 'How can this idea be used to provide a better world?', 'question_type' => 27], ['fact_id' => $fact_id, 'question_title' => 'How can this idea set you apart from most people', 'question_type' => 28], ['fact_id' => $fact_id, 'question_title' => 'How can remember this idea for future?', 'question_type' => 29], ['fact_id' => $fact_id, 'question_title' => 'Slowly re-read this idea', 'question_type' => 30], ['fact_id' => $fact_id, 'question_title' => 'Defend the merit of this idea.', 'question_type' => 31], ['fact_id' => $fact_id, 'question_title' => 'Can you provide an alternative interpretation of this idea', 'question_type' => 32]];
     Question::insert($questions);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $question = Question::find($id);
     if (!$question) {
         return $this->respondNotFound('Item Not Found');
     }
     return $this->respond(['data' => [$this->questionTransformer->transform($question)]]);
 }
Exemple #15
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(QuestionRequest $request, $id)
 {
     // dd($request->only('tag_id'));
     $q = Question::findOrFail($id);
     $q->update($request->only('title', 'body'));
     $q->tags()->sync($request->only('tag_id')['tag_id']);
     \Session::flash('alerts', ['success' => 'Вопрос успешно обновлен']);
     return redirect()->back();
 }
 public function run()
 {
     Question::truncate();
     $faker = Faker\Factory::create();
     $authorIds = User::lists('id');
     for ($i = 0; $i < 10; $i++) {
         Question::create(['desc' => $faker->sentence, 'type' => $faker->word, 'status' => $faker->randomElement(array(0, 1)), 'author_id' => $faker->randomElement($authorIds)]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Question::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['fr_id' => $this->fr_id]);
     $query->andFilterWhere(['like', 'frage', $this->frage])->andFilterWhere(['like', 'display', $this->display])->andFilterWhere(['like', 'antworten', $this->antworten])->andFilterWhere(['like', 'suche', $this->suche]);
     return $dataProvider;
 }
Exemple #18
0
 public function edit($id)
 {
     $question = Question::findOrFail($id);
     $items = Quizz::all();
     $quizzSelectedArray = [];
     foreach ($question->quizzs as $quizz) {
         $quizzSelectedArray[] = $quizz->id;
     }
     $quizzSelected = json_encode($quizzSelectedArray);
     return view('admin.question.edit', ['question' => $question, 'items' => $items, 'quizzSelected' => $quizzSelected]);
 }
 public function testIf_fact_and_question_returned()
 {
     //arrange
     $fact_id = Fact::create(['user_id' => 1, 'fact' => 'I hope you learn to make it on your own'])->id;
     $questions = $this->getSampleQuestions($fact_id);
     Question::insert($questions);
     //act
     $questionRandomizer = new QuestionSelector();
     $fact_with_question = $questionRandomizer->getRandomQuestion($fact_id);
     //assert
     $this->assertArrayHasKeys(['fact_id', 'user_id', 'question_title', 'question_type', 'fact'], $fact_with_question);
 }
 public function actionIndex()
 {
     $file = file_get_contents(__DIR__ . '/QuestionImport.txt');
     $line = explode("\n", $file);
     $array = [];
     foreach ($line as $k => $v) {
         $el = explode("\t", $v);
         $count_el = count($el);
         $array[$k]['title'] = $el[0];
         $array[$k]['occured_number'] = $el[1];
         $array[$k]['correct_answer_key'] = $el[2];
         for ($i = 3; $i < $count_el; $i++) {
             $array[$k]['answer'][$i] = $el[$i];
         }
         $array[$k]['number_of_elements'] = $count_el;
     }
     $user = User::findByUsername('admin');
     foreach ($array as $v) {
         $model_question = new Question();
         $model_question->title = $v['title'];
         $model_question->occured_number = $v['occured_number'];
         $model_question->correct_answer_id = '0';
         $model_question->author_id = $user->id;
         $model_question->save();
         $correct_answer_id = 0;
         foreach ($v['answer'] as $k2 => $v2) {
             $model_answer = new Answer();
             $model_answer->question_id = $model_question->id;
             $model_answer->title = $v2;
             $model_answer->author_id = $user->id;
             $model_answer->save();
             if ($k2 - 3 == $v['correct_answer_key']) {
                 $correct_answer_id = $model_answer->id;
             }
         }
         $model_question->correct_answer_id = $correct_answer_id;
         $model_question->save();
     }
 }
Exemple #21
0
 /**
  * ask user a question through ajax
  * @return string
  */
 public function actionAsk()
 {
     if (\Yii::$app->request->isAjax) {
         $request = \Yii::$app->request;
         $question = new Question();
         if (!is_numeric($request->post('id_user'))) {
             return 0;
         }
         $question->id_user = $request->post('id_user');
         $question->id_from = \Yii::$app->user->id;
         $question->question = $request->post('question');
         $question->date = date('Y-m-d H:i');
         $question->status = 0;
         $question->save();
         return 1;
     } else {
         $model = (new User())->findById(\Yii::$app->user->id);
         $this->view->params['user'] = $model;
         $this->view->params['isProfile'] = false;
         return $this->render('ask');
     }
 }
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     $id = Yii::$app->request->get('id');
     $this->question = Question::findOne($id);
     if (!$this->question) {
         throw new HttpException(404, "Question not found");
     }
     return true;
     // or false to not run the action
 }
 public function allDo($params)
 {
     $query = Question::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['npp' => SORT_DESC]], 'pagination' => ['pageSize' => 50]]);
     $this->load($params);
     $query->where('npp!=0');
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('link=""');
         return $dataProvider;
     }
     $query->andFilterWhere(['user_created' => $this->user_created]);
     return $dataProvider;
 }
Exemple #24
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Question::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'description' => $this->description, 'answer_number' => $this->answer_number, 'section' => $this->section, 'cost' => $this->cost, 'level' => $this->level, 'subject_id' => $this->subject_id]);
     $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'var1', $this->var1])->andFilterWhere(['like', 'var2', $this->var2])->andFilterWhere(['like', 'var3', $this->var3])->andFilterWhere(['like', 'var4', $this->var4])->andFilterWhere(['like', 'var5', $this->var5])->andFilterWhere(['like', 'answer', $this->answer]);
     return $dataProvider;
 }
Exemple #25
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Question::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Question::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSizeParam' => 'perpage', 'pageSizeLimit' => [30, 500]], 'sort' => ['defaultOrder' => ['occured_number' => SORT_ASC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'occured_number' => $this->occured_number, 'correct_answer_id' => $this->correct_answer_id, 'author_id' => $this->author_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Exemple #27
0
 public function comment(Request $request)
 {
     if ($request->has('answer_id')) {
         $answer = Answer::find($request->input('answer_id'));
         $comment = $answer->comments()->create(['body' => $request->input('body')]);
         $comment->user()->associate(\Auth::user())->save();
     } else {
         if ($request->has('question_id')) {
             $question = Question::find($request->input('question_id'));
             $comment = $question->comments()->create(['body' => $request->input('body')]);
             $comment->user()->associate(\Auth::user())->save();
         }
     }
     return back();
 }
Exemple #28
0
 public function index()
 {
     $quizzs = Quizz::all();
     $questions = Question::all();
     $themes = Theme::all();
     $users = User::all();
     $actifQuizz = Quizz::where('actif', 1)->first();
     if (!$actifQuizz) {
         $goodAnswerNbr = 0;
         $badAnswerNbr = 0;
     } else {
         $goodAnswerNbr = Score::where('quizz_id', $actifQuizz->id)->where('correct', true)->count();
         $badAnswerNbr = Score::where('quizz_id', $actifQuizz->id)->where('correct', false)->count();
     }
     return view('admin.dashboard.index', ['quizzs' => $quizzs, 'questions' => $questions, 'themes' => $themes, 'users' => $users, 'actifQuizz' => $actifQuizz, 'goodAnswerNbr' => $goodAnswerNbr, 'badAnswerNbr' => $badAnswerNbr]);
 }
Exemple #29
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $id = '')
 {
     if ($id == '') {
         $query = Question::find();
     } else {
         $query = Question::find()->where(['e_id' => $id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => '10']]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', '_id', $this->_id])->andFilterWhere(['like', 'q_title', $this->q_title])->andFilterWhere(['like', 'knowledge', $this->knowledge])->andFilterWhere(['like', 'q_type', $this->q_type])->andFilterWhere(['like', 'q_choose', $this->q_choose])->andFilterWhere(['like', 'addtime', $this->addtime]);
     return $dataProvider;
 }
Exemple #30
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $Role1 = \App\Models\Role::create(['title' => 'Пользователь', 'default' => true]);
     $Role2 = \App\Models\Role::create(['title' => 'Администратор', 'admin' => true]);
     \App\Models\Group::create(['title' => 'КИТ-10']);
     $Group1 = \App\Models\Group::create(['title' => 'КИТ-10']);
     \App\Models\Group::create(['title' => 'КИТ-20']);
     $Group2 = \App\Models\Group::create(['title' => 'КИТ-30']);
     \App\Models\Group::create(['title' => 'КИТ-40']);
     \App\User::create(['first_name' => 'Admin', 'last_name' => 'Admin', 'second_name' => 'Admin', 'email' => '*****@*****.**', 'password' => bcrypt('admin'), 'group_id' => $Group2->id, 'role_id' => $Role2->id]);
     \App\User::create(['first_name' => 'Test first name', 'last_name' => 'Test last name', 'second_name' => 'Test second name', 'email' => '*****@*****.**', 'password' => bcrypt('123456'), 'group_id' => $Group1->id, 'role_id' => $Role1->id]);
     \Illuminate\Support\Facades\DB::table('type_question')->insert([['title' => 'radio'], ['title' => 'checkbox']]);
     $Prototype = \App\Models\Prototype::create(['title' => 'Тест по биологии', 'time' => 40, 'count_questions' => 5]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Сколько лап у ежа?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => '4', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '6', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Много', 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какая длина хобота у слона?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => 'У слона нет хобота', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '2 метра', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Зависит от возраста', 'right' => true, 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Сколько рёбер у человека?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => '12 пар', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Кто такой человек?', 'right' => true, 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какие типы данных из перечисленных есть в PHP?', 'type' => 'checkbox']);
     $Answer = \App\Models\Answer::create(['text' => 'Integer', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Float', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'String', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Char', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Array', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => 'Callbacks / Callables', 'right' => true, 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какой оператор выполняет строгое сравнение?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => '==', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '===', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '&', 'question_id' => $Question->id]);
     $Question = \App\Models\Question::create(['prototype_id' => $Prototype->id, 'text' => 'Какой оператор не правильный?', 'type' => 'radio']);
     $Answer = \App\Models\Answer::create(['text' => '$a and $b', 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '$a or $b', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '! $a', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '$a => $b', 'right' => true, 'question_id' => $Question->id]);
     $Answer = \App\Models\Answer::create(['text' => '$a <= $b', 'right' => true, 'question_id' => $Question->id]);
     // $this->call('UserTableSeeder');
 }