public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Question::create(['title' => $faker->sentence(25), 'body' => $faker->realText(100), 'user_id' => rand(1, 5)]); } }
function create() { Auth::checkLoggedIn(); $entry = Entry::fromId(Input::get('entryid')); if (!$entry->canView(Auth::getUser())) { throw new Exception('You are not allowed to ask a question in this entry.'); } $question = Question::create(Auth::getUser(), $entry, Input::get('title'), Input::get('text'), Input::getBoolean('private')); View::renderJson($question->getContext(Auth::getUser())); }
public function run() { DB::table('Players')->delete(); DB::table('Questions')->delete(); DB::table('Questionnaires')->delete(); DB::table('Answers')->delete(); DB::table('Level')->delete(); $eingang = Questionnaire::create(array('name' => 'eingang')); $mittel = Questionnaire::create(array('name' => 'mittel')); $end = Questionnaire::create(array('name' => 'end')); $test = Questionnaire::create(array('name' => 'test')); $level = Level::create(array('score' => 1, 'mistakes' => 10, 'hits' => 2, 'info' => 'info')); $test1 = Question::create(array('question' => '1', 'questionnaire_id' => $test->id)); $test2 = Question::create(array('question' => '2', 'questionnaire_id' => $test->id)); $test3 = Question::create(array('question' => '3', 'questionnaire_id' => $test->id)); $test4 = Question::create(array('question' => '4', 'questionnaire_id' => $test->id)); $eingang1 = Question::create(array('question' => 'Ich spiele häufig Computerspiele', 'questionnaire_id' => $eingang->id)); $eingang1 = Question::create(array('question' => 'Ich kenne die Gestaltgesetze', 'questionnaire_id' => $eingang->id)); $frage1 = Question::create(array('question' => 'Das Spiel hat mir Spass gemacht', 'questionnaire_id' => $end->id)); $fam1 = Question::create(array('question' => 'Ich mag solche Rätsel und Knobeleien', 'questionnaire_id' => $end->id)); $fam15 = Question::create(array('question' => 'Ich glaube, der Schwierigkeit dieses Spiels gewachsen zu sein', 'questionnaire_id' => $end->id)); $fam16 = Question::create(array('question' => 'Wahrscheinlich werde ich das Spiel nicht schaffen.', 'questionnaire_id' => $end->id)); $fam1 = Question::create(array('question' => 'Bei dem Spiel mag ich die Rolle des Wissenschaftlers, der Zusammenhänge entdeckt.', 'questionnaire_id' => $end->id)); $fam2 = Question::create(array('question' => 'Das Spiel ist eine richtige Herausforderung für mich.', 'questionnaire_id' => $end->id)); $fam3 = Question::create(array('question' => 'Nach dem Lesen der Instruktion erscheint mir das Spiel sehr interessant.', 'questionnaire_id' => $end->id)); $fam4 = Question::create(array('question' => 'Ich bin sehr gespannt darauf, wie gut ich hier abschneiden werde.', 'questionnaire_id' => $end->id)); $fam5 = Question::create(array('question' => 'Ich fürchte mich ein wenig davor, dass ich mich hier blamieren könnte', 'questionnaire_id' => $end->id)); $fam6 = Question::create(array('question' => 'Ich bin fest entschlossen, mich bei diesem Spiel voll anzustrengen.', 'questionnaire_id' => $end->id)); $fam7 = Question::create(array('question' => 'Bei Spielen wie diesem brauche ich keine Belohnung, sie machen mir auch so viel Spaß. ', 'questionnaire_id' => $end->id)); $fam8 = Question::create(array('question' => 'Es ist mir etwas peinlich, hier zu versagen.', 'questionnaire_id' => $end->id)); $fam9 = Question::create(array('question' => 'Ich glaube, dass kann jeder schaffen', 'questionnaire_id' => $end->id)); $fam10 = Question::create(array('question' => 'Ich glaube, ich schaffe dieses Spiel nicht', 'questionnaire_id' => $end->id)); $fam11 = Question::create(array('question' => 'Wenn ich das Spiel schaffe, werde ich schon ein wenig stolz auf meine Tüchtigkeit sein.', 'questionnaire_id' => $end->id)); $fam12 = Question::create(array('question' => 'Wenn ich an das Spiel denke, bin ich etwas beunruhigt.', 'questionnaire_id' => $end->id)); $fam13 = Question::create(array('question' => 'Eine solches Spiel würde ich auch in meiner Freizeit spielen.', 'questionnaire_id' => $end->id)); $fam14 = Question::create(array('question' => 'Die konkreten Leistungsanforderungen hier lähmen mich.', 'questionnaire_id' => $end->id)); $frage1 = Question::create(array('question' => 'Das Spiel hat mir Spass gemacht', 'questionnaire_id' => $mittel->id)); $fammid1 = Question::create(array('question' => 'Ich mag solche Rätsel und Knobeleien', 'questionnaire_id' => $mittel->id)); $fammid15 = Question::create(array('question' => 'Ich glaube, der Schwierigkeit dieses Spiels gewachsen zu sein', 'questionnaire_id' => $mittel->id)); $fammid16 = Question::create(array('question' => 'Wahrscheinlich werde ich das Spiel nicht schaffen.', 'questionnaire_id' => $mittel->id)); $fammid1 = Question::create(array('question' => 'Bei dem Spiel mag ich die Rolle des Wissenschaftlers, der Zusammenhänge entdeckt.', 'questionnaire_id' => $mittel->id)); $fammid2 = Question::create(array('question' => 'Das Spiel ist eine richtige Herausforderung für mich.', 'questionnaire_id' => $mittel->id)); $fammid3 = Question::create(array('question' => 'Nach dem Lesen der Instruktion erscheint mir das Spiel sehr interessant.', 'questionnaire_id' => $mittel->id)); $fammid4 = Question::create(array('question' => 'Ich bin sehr gespannt darauf, wie gut ich hier abschneiden werde.', 'questionnaire_id' => $mittel->id)); $fammid5 = Question::create(array('question' => 'Ich fürchte mich ein wenig davor, dass ich mich hier blamieren könnte', 'questionnaire_id' => $mittel->id)); $fammid6 = Question::create(array('question' => 'Ich bin fest entschlossen, mich bei diesem Spiel voll anzustrengen.', 'questionnaire_id' => $mittel->id)); $fammid7 = Question::create(array('question' => 'Bei Spielen wie diesem brauche ich keine Belohnung, sie machen mir auch so viel Spaß. ', 'questionnaire_id' => $mittel->id)); $fammid8 = Question::create(array('question' => 'Es ist mir etwas peinlich, hier zu versagen.', 'questionnaire_id' => $mittel->id)); $fammid9 = Question::create(array('question' => 'Ich glaube, dass kann jeder schaffen', 'questionnaire_id' => $mittel->id)); $fammid10 = Question::create(array('question' => 'Ich glaube, ich schaffe dieses Spiel nicht', 'questionnaire_id' => $mittel->id)); $fammid11 = Question::create(array('question' => 'Wenn ich das Spiel schaffe, werde ich schon ein wenig stolz auf meine Tüchtigkeit sein.', 'questionnaire_id' => $mittel->id)); $fammid12 = Question::create(array('question' => 'Wenn ich an das Spiel denke, bin ich etwas beunruhigt.', 'questionnaire_id' => $mittel->id)); $fammid13 = Question::create(array('question' => 'Eine solches Spiel würde ich auch in meiner Freizeit spielen.', 'questionnaire_id' => $mittel->id)); $fammid14 = Question::create(array('question' => 'Die konkreten Leistungsanforderungen hier lähmen mich.', 'questionnaire_id' => $mittel->id)); }
public function run() { DB::table('Players')->delete(); DB::table('Questions')->delete(); DB::table('Questionnaires')->delete(); DB::table('Answers')->delete(); $kim = Questionnaire::create(array('name' => 'kim')); $frage1 = Question::create(array('question' => 'Das Spiel hat mir Spass gemacht', 'questionnaire_id' => $kim->id)); $playerJustus = Player::create(array('gender' => 'm', 'age' => '21', 'computer' => '4', 'game' => '3', 'questionnaire_id' => $kim->id)); $Testfrage = Answer::create(array('answer' => 'Test', 'player_id' => $playerJustus->id, 'question_id' => $frage1->id)); }
/** * Post method to process the form **/ public function postNew() { //first, let's validate the form $validation = Validator::make(Input::all(), Question::$add_rules); if ($validation->passes()) { //First, let's create the question $create = Question::create(array('userID' => Sentry::getUser()->id, 'title' => Input::get('title'), 'question' => Input::get('question'))); //We get the insert id of the question $insert_id = $create->id; //Now, we need to re-find the question to "attach" the tag to the question $question = Question::find($insert_id); //Now, we should check if tags column is filled, and split the string and add a new tag and a relation if (Str::length(Input::get('tags'))) { //let's explode all tags from the comma $tags_array = explode(',', Input::get('tags')); //if there are any tags, we will check if they are new, if so, we will add them to database //After checking the tags, we will have to "attach" tag(s) to the new question if (count($tags_array)) { foreach ($tags_array as $tag) { //first, let's trim and get rid of the extra space bars between commas //(tag1, tag2, vs tag1,tag2) $tag = trim($tag); //We should double check its length, because the user may have just typed "tag1,,tag2" (two or more commas) accidentally //We check the slugged version of the tag, because tag string may only be meaningless character(s), like "tag1,+++//,tag2" if (Str::length(Str::slug($tag))) { //the URL-Friendly version of the tag $tag_friendly = Str::slug($tag); //Now let's check if there is a tag with the url friendly version of the provided tag already in our database: $tag_check = Tag::where('tagFriendly', $tag_friendly); //if the tag is a new tag, then we will create a new one if ($tag_check->count() == 0) { $tag_info = Tag::create(array('tag' => $tag, 'tagFriendly' => $tag_friendly)); //If the tag is not new, this means There was a tag previously added on the same name to another question previously //We still need to get that tag's info from our database } else { $tag_info = $tag_check->first(); } } //Now the attaching the current tag to the question $question->tags()->attach($tag_info->id); } } } //lastly, we should return the user to the asking page with a permalink of the question return Redirect::route('ask')->with('success', 'Your question has been created successfully! ' . HTML::linkRoute('question_details', 'Click here to see your question', array('id' => $insert_id, 'title' => Str::slug($question->title)))); } else { return Redirect::route('ask')->withInput()->with('error', $validation->errors()->first()); } }
public function getCreate() { $validator = Validator::make(Input::all(), array('questionTitle' => 'required|max:155', 'question' => 'max:655')); if ($validator->fails()) { return Redirect::route('ask-question')->withErrors($validator)->withInput(); } else { $questionTitle = Input::get('questionTitle'); $question = Input::get('question'); $user_id = Auth::user()->user_id; $singlequestion = Question::create(array('user_id' => $user_id, 'questiontitle' => $questionTitle, 'question' => $question)); $insertPoint = User::find($user_id); $insertPoint->points = $insertPoint->points + 5; $insertPoint->save(); return Redirect::route('home')->with('global', 'Your Question Successfully Submitted'); } }
public function updatePoll() { $poll_title = Input::get('poll_title'); $poll_id = Input::get('poll_id'); $new_poll_questions = Input::get('new_poll_questions'); $new_poll_questions_count = count($new_poll_questions); $poll = Poll::find($poll_id); if (isset($poll_title)) { $poll->title = $poll_title; $poll->save(); } for ($i = 0; $i < $new_poll_questions_count; $i++) { if (isset($new_poll_questions[$i])) { $question = Question::create(array('created_by' => Auth::user()->id, 'content' => $new_poll_questions[$i], 'poll_id' => $poll_id)); $question->save(); } } foreach ($poll->questions as $question) { $save_question = Question::find($question->id); $save_question->content = Input::get('question-' . $question->id); $save_question->save(); foreach ($question->answers as $answer) { $save_answer = Answer::find($answer->id); $save_answer->content = Input::get('answer-' . $answer->id); $save_answer->save(); } $new_poll_answers = Input::get('new_poll_answers-' . $question->id); if (isset($new_poll_answers)) { $new_poll_answers_count = count($new_poll_answers); for ($i = 0; $i < $new_poll_answers_count; $i++) { if (isset($new_poll_answers[$i])) { $answer = Answer::create(array('created_by' => Auth::user()->id, 'content' => $new_poll_answers[$i], 'question_id' => $question->id)); $answer->save(); } } } } return Redirect::action('PollController@editPoll', array('title' => $poll_title)); // return View::make('edit-poll') // ->with('poll',$poll); }
/** * PUT request, we're using it here to mean 'replace the record with' */ public function update($id) { $v = Validator::make(Input::all(), ['name' => 'required|string', 'questions' => 'array', 'taggable' => 'array']); if ($v->fails()) { return Response::json($v->errors(), 400); } $questionnaire = Questionnaire::find($id); if (is_null($questionnaire)) { return Response::json(['error' => 'no such questionnaire found'], 404); } $questionIds = $questionnaire->questions->lists('id'); Question::destroy($questionIds); if (Input::has('questions')) { foreach (Input::get('questions') as $question) { Question::create(['question' => $question, 'questionnaire_id' => $questionnaire->id]); } } $tagListIds = $questionnaire->tagLists->lists('id'); $questionnaire->tagLists()->detach($tagListIds); if (Input::has('taggable')) { foreach (Input::get('taggable') as $tagList) { $T = TagList::firstOrNew(['name' => $tagList['name']]); $questionnaire->tagLists()->save($T); if (!$T->exists) { // it's a new one! $T->save(); } } } $questionnaire->name = Input::get('name'); $questionnaire->touch(); $questionnaire->push(); // if these are modified they won't be shown... $questionnaire->load('tagLists', 'tagLists.tags', 'questions'); return Response::json($this->reformatTagsAndQuestions($questionnaire), 200); }
if ($ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "gif") { $type = "image"; } else { if ($ext == "mp4" || $ext == "3gp" || $ext == "wmv" || $ext == "flv") { $type = "video"; } else { if ($ext == "mp3" || $ext == "wav" || $ext == "aac") { $type = "audio"; } } } } $question->type = $type; $question->points = $_POST['points']; $question->timer = $_POST['timer']; $question->create(); } else { if ($_POST['oper'] == 'edit') { $question = Question::get_by_id($_POST['id']); $question->group_id = $session->user_group_id; $question->text = $_POST['text']; $question->difficulty = $_POST['difficulty']; $question->answer = $_POST['answer']; $question->choice_a = $_POST['choice_a']; $question->choice_b = $_POST['choice_b']; $question->choice_c = $_POST['choice_c']; $question->file = $_POST['file']; $type = "text"; if (!empty($question->file)) { $ext = pathinfo($question->file, PATHINFO_EXTENSION); if ($ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "gif") {
/** * 用于上传EPQA, CPI, SCL 三个数据库 * @param unknown $name * @param unknown $data * @throws Exception * @return boolean */ public static function insertTkByName($name, $data) { if (self::dataFormatCheck($data) != 5 || self::dataFormatCheck($name) != 1) { throw new Exception("input type is not available"); } $name = strtoupper(trim($name)); $number = null; switch ($name) { case 'EPQA': $number = 88; $options = "是|不是"; break; case 'CPI': $number = 230; $options = "是|否"; break; case 'SCL': $number = 90; $options = "没有|很轻|中等|偏重|严重"; break; default: throw new Exception("no this Type data"); } $paper_data = Paper::getListByName($name); if (isset($paper_data->id)) { $paper_id = intval($paper_data->id); $question_data = Question::getQuestionsByPaperId($paper_id); $question_data_count = count($question_data); if ($question_data_count == $number) { throw new Exception("The {$name} data has already inserted, don't do again!"); } else { if ($question_data_count != 0) { throw new Exception("The DB data for {$name} may be ERROR!"); } else { try { $manager = new TxManager(); $transaction = $manager->get(); foreach ($data as $record) { $scl_question = new Question(); $scl_question->topic = $record[1]; $scl_question->number = intval($record[0]); $scl_question->options = $options; $scl_question->paper_id = $paper_id; if ($scl_question->create() == false) { $transaction->rollback("Cannot insert {$name} data"); } } $transaction->commit(); return true; } catch (TxFailed $e) { throw new Exception("Failed, reason: " . $e->getMessage()); } } } } else { return false; } }
public function run() { /****************************************************************************** * --- Test --- ******************************************************************************/ Test::create(array('name' => 'BURNOUT', 'idTestType' => '2')); /****************************************************************************** * --- Escalas --- ******************************************************************************/ Scale::create(array('idTest' => '4', 'description' => 'Reducida Sensación')); Scale::create(array('idTest' => '4', 'description' => 'Agotamiento')); Scale::create(array('idTest' => '4', 'description' => 'Devaluación')); /****************************************************************************** * --- Rangos Posibles --- ******************************************************************************/ Range::create(array('description' => 'Bajo', 'min' => '5.0', 'max' => '11.0')); Range::create(array('description' => 'Medio', 'min' => '12.0', 'max' => '18.0')); Range::create(array('description' => 'Alto', 'min' => '19.0', 'max' => '25.0')); /****************************************************************************** * --- Rangos por Escala --- ******************************************************************************/ // Reducida Sensación ScaleRange::create(array('idScale' => '12', 'idRange' => '10')); ScaleRange::create(array('idScale' => '12', 'idRange' => '11')); ScaleRange::create(array('idScale' => '12', 'idRange' => '12')); // Agotamiento ScaleRange::create(array('idScale' => '13', 'idRange' => '10')); ScaleRange::create(array('idScale' => '13', 'idRange' => '11')); ScaleRange::create(array('idScale' => '13', 'idRange' => '12')); // Devaluación ScaleRange::create(array('idScale' => '14', 'idRange' => '10')); ScaleRange::create(array('idScale' => '14', 'idRange' => '11')); ScaleRange::create(array('idScale' => '14', 'idRange' => '12')); /****************************************************************************** * --- Grupos --- ******************************************************************************/ Group::create(array()); // Burnout (orden normal) Con id = 5 Group::create(array()); // Burnout (orden inverso) Con id = 6 /****************************************************************************** * --- Posibles Respuestas --- ******************************************************************************/ // --- BURNOUT (orden normal) --- TestAnswer::create(array('number' => '1', 'description' => 'Casi nunca', 'idGroup' => '5')); TestAnswer::create(array('number' => '2', 'description' => 'Pocas veces', 'idGroup' => '5')); TestAnswer::create(array('number' => '3', 'description' => 'Algunas veces', 'idGroup' => '5')); TestAnswer::create(array('number' => '4', 'description' => 'A menudo', 'idGroup' => '5')); TestAnswer::create(array('number' => '5', 'description' => 'Casi siempre', 'idGroup' => '5')); // --- BURNOUT (orden inverso) --- TestAnswer::create(array('number' => '5', 'description' => 'Casi nunca', 'idGroup' => '6')); TestAnswer::create(array('number' => '4', 'description' => 'Pocas veces', 'idGroup' => '6')); TestAnswer::create(array('number' => '3', 'description' => 'Algunas veces', 'idGroup' => '6')); TestAnswer::create(array('number' => '2', 'description' => 'A menudo', 'idGroup' => '6')); TestAnswer::create(array('number' => '1', 'description' => 'Casi siempre', 'idGroup' => '6')); /****************************************************************************** * --- Preguntas --- ******************************************************************************/ $burnout = '4'; $reducidaSensacion = '12'; $agotamiento = '13'; $devaluacion = '14'; $grupoBurnoutNormal = '5'; $grupoBurnoutInverso = '6'; Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '1', 'description' => 'Siento que estoy logrando muchas cosas que valen la pena en mi deporte.', 'idGroup' => $grupoBurnoutInverso)); Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '2', 'description' => 'Me siento tan cansado de mis entrenamientos que tengo problemas al encontrar energía para hacer otras cosas.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '3', 'description' => 'El esfuerzo y tiempo que dedico a mi deporte estaría mejor invertido realizando otras actividades más productivas.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '4', 'description' => 'Me siento demasiado cansado debido a mis actividades en mi deporte.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '5', 'description' => 'No estoy consiguiendo logros importantes en mi deporte.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '6', 'description' => 'No me importa tanto mi rendimiento en mi deporte como antes.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '7', 'description' => 'No estoy rindiendo de acuerdo a mi verdadera capacidad en mi deporte.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '8', 'description' => 'Me siento "desgastado" física y emocionalmente por debido a mi deporte.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '9', 'description' => 'No estoy tan interesado en mi deporte como acostumbraba hacerlo antes.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '10', 'description' => 'Me siento físicamente agotado por debido a mi deporte.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '11', 'description' => 'Me siento menos preocupado por tener éxito en mi deporte de lo que solía hacerlo.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $agotamiento, 'number' => '12', 'description' => 'Estoy agotado por las exigencias físicas y mentales de mi deporte.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '13', 'description' => 'Parece que no importa lo que haga, no logro rendir tan bien como podría hacerlo.', 'idGroup' => $grupoBurnoutNormal)); Question::create(array('idTest' => $burnout, 'idScale' => $reducidaSensacion, 'number' => '14', 'description' => 'Me siento exitoso en mi deporte.', 'idGroup' => $grupoBurnoutInverso)); Question::create(array('idTest' => $burnout, 'idScale' => $devaluacion, 'number' => '15', 'description' => 'Tengo sentimientos y pensamientos negativos hacia mi deporte.', 'idGroup' => $grupoBurnoutNormal)); }
public function postSave() { $postData = Input::all(); if ($postData['formOrigin'] == "edit") { $rules = array('topic' => 'required', 'correct_answer' => 'required'); $validator = Validator::make($postData, $rules); if ($validator->fails()) { return Redirect::to('backends/quizz/edit/' . $postData['id'])->withInput()->withErrors($validator); } else { $question = Question::find($postData['id']); $question->topic = $postData['topic']; $question->correct_answer = $postData['correct_answer']; $question->save(); return Redirect::to('backends/quizz/edit/' . $question->id); } } else { $rules = array('topic' => 'required'); $validator = Validator::make($postData, $rules); if ($validator->fails()) { return Redirect::to('backends/quizz/add')->withInput()->withErrors($validator); } else { $question = Question::create(['topic' => $postData['topic']]); return Redirect::to('backends/quizz/edit/' . $question->id); } } }
/** * Store a newly created resource in storage. * POST /questions * * @return Response */ public function store() { $question = Question::create(Input::all()); return $question; }
<?php include '../../inc/init.inc'; if ((!isset($title) || $title == "") && !isset($question_id) || (!isset($content) || $content == "")) { $res->load('questions', array()); } else { if (isset($title)) { $args['title'] = $title; } if (isset($question_id)) { $args['question_id'] = $question_id; } $args['content'] = $content; $args['user_id'] = $res->user->id; $question = Question::create($args); if (isset($tag_list_values)) { $tags = explode(',', $tag_list_values); foreach ($tags as $tagName) { $tagName = strtoupper($tagName); if (Tag::exists(array('name' => $tagName))) { $tag = Tag::find_by_name($tagName); } else { $tag = Tag::create(array('name' => $tagName)); } Questions_Tag::create(array('question_id' => $question->id, 'tag_id' => $tag->id)); } } } $res->load('question', array('id' => $question->id));
<?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | 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 Closure to execute when that URI is requested. | */ Route::get('/', function () { $questions = Question::orderBy('created_at', 'desc')->get(); return View::make('index')->with('questions', $questions); }); Route::post('/', function () { $body = Input::get('question'); if (!empty($body)) { $answer = Answer::orderByRaw("RAND()")->get()->first(); Question::create(array('body' => $body, 'answer' => $answer->body)); } $questions = Question::orderBy('created_at', 'desc')->get(); return View::make('index')->with('questions', $questions); });
<?php $path = 'assets/images/profile_pic/' . $user->profile_pic; echo envapi_get_html_for_reg_user('176644-3EaSQ9JhWGaxqDH2EJ91XS3smNIPajiD', $user->first_name, $user->last_name, $path, false, "HI"); ?> <?php $isError = false; if (isset($_POST['submit'])) { $new_question = new Question(); $new_question->question_content = $_POST['question_content']; $new_question->topic = $_POST['topic']; $new_question->description = $_POST['description']; $new_question->creator_id = $_SESSION['user_id']; $new_question->is_enabled = isset($_POST['is_enabled']) ? 'true' : 'false'; $new_question->create(); //Fetch the last entered id from 'Question'... $sql = "SELECT * FROM questions ORDER BY question_id desc limit 1"; $result_set = $database->execute_query($sql); $row = $database->fetch_array($result_set); $question_id = array_shift($row); //set default value 'false' to $if_created... //Used to display success of error message to user... $if_created = 'false'; $options = $_POST['option_content']; $option_id = 1; foreach ($options as $option) { $new_option = new Option(); $new_option->option_id = $option_id; $new_option->option_content = $option; $new_option->question_id = $question_id;
public function translateQuestions($old_slide_id, $new_slide_id, $source_arr, $language) { $questions_array = array(); $questions = array(); $translator = new LanguageTranslator('AIzaSyBlwXdmxJZ__ZNScwe4zq5r3qh3ebXb26k'); $questions_array = $this->dbQuery('SELECT * FROM questions INNER JOIN users on questions.user_id = users.id WHERE questions.based_on IS NULL AND questions.mark = "accepted" AND questions.item_id=' . $old_slide_id); if (count($questions_array)) { foreach ($questions_array as $row) { $question = new Question(); $question->createFromID($row['0']); $lastId = $question->getLastRevision(); $lastRevision = new Question(); $lastRevision->createFromID($lastId); $questions[] = $lastRevision; } } if (count($questions)) { $source = $source_arr['id']; $target_arr = explode('-', $language); $target = $target_arr[0]; foreach ($questions as $question) { $answers = array(); $answers = $question->getAnswers(); $q = $question->question; $question->question = $translator->translate($q, $target, $source); $question->item_id = $new_slide_id; $question->based_on = NULL; $question->user->id = $this->user->id; $question->id = $question->create(); if (count($answers)) { foreach ($answers as $answer) { $q = $answer['answer']; $answer['answer'] = $translator->translate($q, $target, $source); $q = $answer['explanation']; if ($q != '') { $answer['explanation'] = $translator->translate($q, $target, $source); } $question->addAnswer($answer['answer'], $answer['explanation'], $answer['is_right']); } } } } }
public function store(QuestionRequest $request) { $request->merge(['ip_address' => $this->request->getClientIp(true)]); $question = Question::create($request->all()); return redirect('quotes/lists'); }