Esempio n. 1
0
 /**
  * Update the specified resource in storage.
  * PUT /answers/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $answers = Answer::where('id', $id)->update(Input::all());
     if ($answers) {
         return ['status' => true, 'data' => $answers];
     } else {
         return ['status' => false];
     }
 }
Esempio n. 2
0
 public function getActivity()
 {
     $data['user'] = User::find(Auth::user()->id);
     $data['userQustions'] = Question::where('user_id', '=', User::find(Auth::user()->id)->id)->orderBy('created_at', 'desc')->get();
     $data['questionsCount'] = $data['userQustions']->count();
     $data['userAnswers'] = Answer::where('user_id', '=', User::find(Auth::user()->id)->id)->orderBy('created_at', 'desc')->get();
     $data['answersCount'] = $data['userAnswers']->count();
     return View::make('profile.activity')->with($data);
 }
Esempio n. 3
0
 public function download($testId, $countIt = FALSE)
 {
     $testId = (int) $testId;
     $test = new Test();
     $cvs = 'id,姓名,学号';
     $test->get_by_id($testId);
     if ($test->id) {
         $topics = $test->topic->get();
         $users = $test->user->where(array('uType' => 'student'))->get();
         $topicsData = new Stdclass();
         $usersData = new StdClass();
         $answersData = new Stdclass();
         foreach ($topics->all as $topic) {
             $topicsData->{$topic->id} = $topic->to_array();
             for ($i = 1; $i <= $topic->tocMax; $i++) {
                 $cvs .= ',' . $topic->tocTitle . '_' . $i;
             }
         }
         foreach ($users->all as $user) {
             $usersData->{$user->id} = $user->to_array();
             $answers = new Answer();
             $answers->where(array('user_id' => $user->id))->get();
             $cvs .= "\n" . $user->id . ',' . $user->uName . ',' . (string) $user->uStudId;
             foreach ($answers->all as $answer) {
                 $answersData->{$answer->topic_id} = explode(',', $answer->aChoose);
             }
             foreach ($topicsData as $topic_id => $topic) {
                 if (isset($answersData->{$topic_id})) {
                     $aChoose = $answersData->{$topic_id};
                 }
                 for ($i = 0; $i < $topic['tocMax']; $i++) {
                     if (isset($aChoose[$i])) {
                         $cvs .= ',' . $aChoose[$i];
                     } else {
                         $cvs .= ',' . '0';
                     }
                 }
                 $aChoose = NULL;
             }
             $answersData = NULL;
             //原来没有重置,导致问题
             $answers = NULL;
         }
         $this->load->helper('download');
         $cvs = iconv('UTF-8', 'GB2312', $cvs);
         if ($countIt) {
             $cvsCount = $this->downloadCount($cvs);
             force_download('result_' . $testId . '.csv', $cvsCount);
         } else {
             force_download('origin_' . $testId . '.csv', $cvs);
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Requests\ExamRequest $request)
 {
     $result;
     $selected;
     $count = 0;
     foreach ($request->all() as $index => $answer) {
         $results = Answer::where('question_id', $index)->lists('answer');
         foreach ($results as $result) {
             if ($result == $answer) {
                 $count++;
             }
         }
     }
     return $count;
 }
 public function getEdit($id = 0)
 {
     $data['id'] = $id;
     $data['question'] = Question::find($id);
     $data['pageTitle'] = "Quizzler | Edit";
     $data['urlAddBack'] = "backends/dashboard";
     $data['btnAddBack'] = '<i class="icon-reply"></i><span>Back<span>';
     $data['labelPage'] = "Edit Question";
     $data['activeD'] = 'active';
     $data['formOrigin'] = "edit";
     $data['answers'] = Answer::where('question_id', $id)->get();
     $correctArr = ['' => '-- Select correct answer --'];
     $data['correctAnswer'] = array();
     foreach ($data['answers'] as $val) {
         $correctArr[$val->id] = $val->answer_title;
         $data['correctAnswer'] = $correctArr;
     }
     $data['correctAn'] = $data['question']->correct_answer;
     return View::make('backends.quizz.quizzAddEdit', $data);
 }
Esempio n. 6
0
 protected function _save($data)
 {
     $obj = new Answer();
     $condition = array('user_id' => $this->_user->id, 'topic_id' => $data->topic_id);
     $obj->where($condition)->get();
     if (isset($data->selected) and $data->selected) {
         foreach ($data->selected as $tid => $choose) {
             $newData = new StdClass();
             $newData->topic_id = $tid;
             $newData->aChoose = $choose;
             $this->_save($newData);
         }
     }
     $obj->aChoose = implode(',', $data->aChoose);
     $obj->topic_id = $data->topic_id;
     $obj->user_id = $this->_user->id;
     if ($obj->save()) {
         return $obj->to_array();
     } else {
         return array('error' => $obj->error->string);
     }
 }
Esempio n. 7
0
 public static function action_vote($id = null)
 {
     if (!$id) {
         if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
             return Response::error(404);
         } else {
             $id = (int) Param::post('id');
             $answers = Param::post('answers');
             $poll = Poll::get($id);
             $poll->various_answers = '0' != $poll->various_answers;
             $cookiename = 'p_' . $poll->id . '_v';
             // Si no hay respuestas o hay más de una respuesta
             if (count($answers) === 0 || !$poll->various_answers && count($answers) > 1) {
                 Redirect::to(Url::get('vote', $id, 'vote_error=true'));
             }
             if (Vote::where('voter_ip', '=', CURRENT_USER_IP)->and_where('poll_id', '=', $id)->first() || Cookie::get($cookiename)) {
                 Cookie::set($cookiename, !$poll->various_answers ? (string) $answers[0] : 'true', 360);
                 Redirect::to(Url::get('view', $poll->slug, 'poll_already_voted=true'));
             }
             Cookie::set($cookiename, !$poll->various_answers ? (string) $answers[0] : 'true', 360);
             Vote::create(array('voter_ip' => CURRENT_USER_IP, 'poll_id' => $id, 'answer_id' => !$poll->various_answers ? $answers[0] : 0));
             foreach ($answers as $answer_id) {
                 Answer::find($answer_id)->set(array('nofilter:votes' => '`votes` + 1'));
             }
             Poll::find($id)->set(array('nofilter:total_votes' => '`total_votes` + 1'));
             Redirect::to(Url::get('view', $poll->slug, 'voted=true'));
         }
     } elseif (!is_numeric($id)) {
         return Response::error(404);
     }
     $id = intval($id, 10);
     if (!($poll = Poll::get($id))) {
         return Response::error(404);
     }
     $answers = Answer::where('poll_id', '=', $poll->id)->get();
     return View::make('vote')->add_var('poll', $poll)->add_var('answers', $answers);
 }
Esempio n. 8
0
 /**
  * Store new version of the test
  */
 public function storeVersionAction()
 {
     $data = Input::all();
     $id = $data['id'];
     unset($data['id']);
     $validation = Validator::make($data, Test::$rules);
     if (!$validation->passes()) {
         return Redirect::route('version.create', ['id' => $id])->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
     }
     if (!$data['category_id']) {
         return Redirect::route('version.create', ['id' => $id])->withInput()->with('message', 'Укажите категорию теста.');
     }
     /**
      * Check name duplicates
      */
     if (count(Test::where('name', $data['name'])->where('version', (int) $data['version'])->get())) {
         /**
          * This test exists, generate new version
          */
         $data['version'] = $this->getNextVersion($data['name']);
     }
     $data['user_id'] = Auth::user()->getId();
     $data['active'] = false;
     $data['duration'] = $data['duration'] * 60;
     $test = Test::create($data);
     /**
      * Clone all Questions and Answers
      */
     $questions = Question::where('test_id', $id)->get();
     foreach ($questions as $q) {
         $new = $q->replicate();
         $new->test_id = $test->id;
         $new->save();
         $answers = Answer::where('question_id', $q->id)->get();
         foreach ($answers as $a) {
             $newa = $a->replicate();
             $newa->question_id = $new->id;
             $newa->save();
         }
     }
     return Redirect::route('tests.show', $test->id);
 }
Esempio n. 9
0
                  
					<div class="portlet-body">
						{{ Form::open(array('url' => 'backends/quizz', 'role' => 'form')) }}
							<div class="form-body">
								<?php 
$i = 1;
?>
								{{ Form::hidden('questionsLenght', sizeof($questions), array('id' => 'questions')) }}
								@foreach($questions as $question)
									{{ Form::hidden('currentQuestion'.$i, $question->id) }} 
									<div class="form-group">
										<div class="col-md-11">
											{{ $i++ }} - {{ Form::label('topic', $question->topic) }}

											<?php 
$answers = Answer::where('question_id', $question->id)->orderBy('id', 'asc')->get();
?>
											@foreach($answers as $answer)	
												<div class="radio-list">
													<label>
														@if($formOrigin=='dashboard')
														<?php 
$j = $i - 1;
?>
														{{ Form::radio('optionsRadios'.$j.$question->id, $answer->id, (Input::old('optionsRadios'.$j) == $answer->id), array('id'=>'optionsRadio', 'class'=>'radio optionsRadios'.$j)) }}
														@endif
														{{ Form::label($answer->id , $answer->answer_title) }}
													</label>
												</div>
											@endforeach	
										</div>
Esempio n. 10
0
 public function getSearch()
 {
     $keyword = Input::get('keyword');
     return View::make('audiopedia.result')->with('answers', Answer::where('title', 'LIKE', '%' . $keyword . '%')->get())->with('keyword', $keyword);
 }
 public function getDeletequestion()
 {
     Question::find($_GET['keyword'])->delete();
     Answer::where('question_id', $_GET['keyword'])->delete();
     return Redirect::to('backends/dashboard');
 }
Esempio n. 12
0
 function questionaire_save()
 {
     /*echo '<pre>';
     		print_r($_POST);
     		echo '</pre>';
     		exit();*/
     foreach ($_POST['question_id'] as $key => $value) {
         if ($_POST['type'][$key] == "text" || $_POST['type'][$key] == "textarea" || $_POST['type'][$key] == "radio" || $_POST['type'][$key] == "scale") {
             if (@$_POST['answer'][$value]) {
                 $answer = new Answer();
                 if (is_login()) {
                     $answer->where('user_id', $this->session->userdata('id'));
                     $answer->where('questionaire_id', $value)->get();
                     $answer->user_id = $this->session->userdata('id');
                 }
                 $answer->questionaire_id = $value;
                 $answer->answer = $_POST['answer'][$value];
                 $answer->save();
             }
         } elseif ($_POST['type'][$key] == "radio") {
             if (@$_POST['answer'][$value]) {
                 $answer = new Answer();
                 if (is_login()) {
                     $answer->where('user_id', $this->session->userdata('id'));
                     $answer->where('questionaire_id', $value)->get();
                     $answer->user_id = $this->session->userdata('id');
                 }
                 $answer->questionaire_id = $value;
                 $answer->choice_id = $_POST['answer'][$value];
                 $answer->save();
             }
         } elseif ($_POST['type'][$key] == "checkbox") {
             if (@$_POST['answer'][$value]) {
                 $answer = new Answer();
                 $answer->where('user_id', $this->session->userdata('id'));
                 $answer->where('questionaire_id', $value)->get()->delete_all();
                 foreach ($_POST['answer'][$value] as $key => $ans) {
                     if (is_login()) {
                         $answer = new Answer();
                         $answer->user_id = $this->session->userdata('id');
                     }
                     $answer->questionaire_id = $value;
                     $answer->choice_id = $ans;
                     $answer->save();
                 }
             }
         } elseif ($_POST['type'][$key] == "grid") {
             if (@$_POST['answer'][$value]) {
                 foreach ($_POST['answer'][$value] as $key => $ans) {
                     $answer = new Answer();
                     if (is_login()) {
                         $answer->where('user_id', $this->session->userdata('id'));
                         $answer->where('choice_id', $key);
                         $answer->where('questionaire_id', $value)->get();
                         $answer->user_id = $this->session->userdata('id');
                     }
                     $answer->questionaire_id = $value;
                     $answer->choice_id = $key;
                     $answer->answer = $ans;
                     $answer->save();
                 }
             }
         }
     }
 }
Esempio n. 13
0
 public static function action_edit($id = null)
 {
     if (!IS_ADMIN) {
         Redirect::to(Url::get('admin@login', null, 'redirect-to=' . urlencode(Url::current())));
     }
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         if ($id === 'delete-answer') {
             if (($answer_id = Param::post('answer_id')) && is_numeric($answer_id)) {
                 $answer = Answer::get((int) $answer_id);
                 Answer::find((int) $answer_id)->delete();
                 $votes = Vote::where('answer_id', '=', $answer_id)->count();
                 if ($votes) {
                     Poll::find($answer->poll_id)->set(array('nofilter:total_votes' => "`total_votes` - {$votes}"));
                 }
                 return Response::json(array('status' => 200, 'deleted' => true));
             } else {
                 return Response::json(array('status' => 0, 'deleted' => false));
             }
         } elseif ($id) {
             return Response::error(404);
         } else {
             $id = Param::post('id');
             if ($answer_id = Param::post('remove_answer')) {
                 Answer::find((int) $answer_id)->and_where('poll_id', '=', $id)->delete();
                 $votes = Vote::where('answer_id', '=', $answer_id)->count();
                 if ($votes) {
                     Poll::find($id)->set(array('nofilter:total_votes' => "`total_votes` - {$votes}"));
                 }
                 Redirect::to(Url::get('admin@edit', $id, 'answer_deleted=true'));
             }
             if (Param::post('remove_poll')) {
                 Poll::find($id)->delete();
                 Redirect::to(Url::get('admin', null, 'poll_deleted=true'));
             }
             if (is_numeric($id) && ($poll = Poll::get((int) $id))) {
                 foreach ($_POST as $key => $value) {
                     if (isset($poll->{$key}) && (!empty($_POST[$key]) || $_POST[$key] === "0")) {
                         $poll->{$key} = is_numeric($_POST[$key]) ? intval($_POST[$key], 10) : $_POST[$key];
                     } elseif (false !== strpos($key, 'answer-')) {
                         $answer_id = explode('-', $key);
                         $answer_id = $answer_id[1];
                         if (is_numeric($answer_id)) {
                             Answer::find((int) $answer_id)->set(array('text' => $value));
                         }
                     } elseif ($key === 'new_answers') {
                         foreach ($value as $new_answer) {
                             if (!empty($new_answer)) {
                                 Answer::create(array('poll_id' => (int) $poll->id, 'text' => $new_answer));
                             }
                         }
                     }
                 }
                 Poll::save($poll);
                 Redirect::to(Url::get('admin', null, 'success=' . $_POST['id'] . '&updated=true'));
             } else {
                 return Response::error(500);
             }
         }
     }
     if (!$id || !is_numeric($id) || !($poll = Poll::get((int) $id))) {
         return Response::error(404);
     } else {
         $answers = Answer::where('poll_id', '=', $poll->id)->get();
         return View::make('admin.edit')->add_var('answers', $answers)->add_var('poll', $poll);
     }
 }
Esempio n. 14
0
 private function getAttributeForNext($listAnsPoint)
 {
     $getInteractionCount = function ($idAttribute) {
         $interactionTable = Interaction::getTableName();
         return Answer::where('id_attribute', $idAttribute)->join($interactionTable, $interactionTable . '.id_answer_from', '=', Answer::getTableName() . '.id')->count(DB::raw('DISTINCT ' . $interactionTable . '.id_answer_to'));
     };
     $tempScoreAttribute = [];
     foreach ($listAnsPoint as $ansPoint) {
         if (empty($tempScoreAttribute[$ansPoint['attribute']])) {
             $tempScoreAttribute[$ansPoint['attribute']] = ['hasScore' => 0, 'numAns' => 0, 'levelMin' => self::VC, 'numInter' => $getInteractionCount($ansPoint['attribute']), 'id' => $ansPoint['attribute']];
         }
         $tempScoreAttribute[$ansPoint['attribute']]['numAns']++;
         if ($ansPoint['point'] !== null) {
             $tempScoreAttribute[$ansPoint['attribute']]['hasScore']++;
             $tempScoreAttribute[$ansPoint['attribute']]['levelMin'] = min($tempScoreAttribute[$ansPoint['attribute']]['levelMin'], $ansPoint['level']);
         }
     }
     usort($tempScoreAttribute, function ($a, $b) use($getInteractionCount) {
         $conA = $a['numAns'] - $a['hasScore'];
         $conB = $b['numAns'] - $b['hasScore'];
         return $b['levelMin'] > $a['levelMin'] || $b['levelMin'] > $a['levelMin'] && $conB > $conA || $b['levelMin'] > $a['levelMin'] && $conB == $conA && $b['numInter'] > $a['numInter'] || $b['levelMin'] > $a['levelMin'] && $conB == $conA && $b['numInter'] == $a['numInter'] && $b['levelMin'] > $a['levelMin'];
     });
     $item = $tempScoreAttribute[0];
     if ($item['hasScore'] == $item['numAns'] && $item['levelMin'] == 1) {
         return null;
     }
     return $item['id'];
 }
 public function postDeleteuser()
 {
     $userid = Input::get('id');
     $user = User::find($userid);
     $event = Input::get('event');
     $useranswers = Answer::where('user_id', '=', $userid)->get();
     $userranks = Supplierrank::where('userid', '=', $userid)->get();
     if ($event == "Rescom Summit Bangalore 2016") {
         $qid1 = "3124";
     }
     if ($event == "Design Mission Turkey 2016") {
         $qid1 = "5707";
     }
     if ($event == "Design Mission South West 2016") {
         $qid1 = "5197";
     }
     if ($event == "Design Mission South Africa 2016") {
         $qid1 = "4687";
     }
     if ($event == "Design Mission Saudi Arabia 2016") {
         $qid1 = "3667";
     }
     if ($event == "Design Mission North East 2016") {
         $qid1 = "4177";
     }
     if ($event == "Design Mission Asia 2016") {
         $qid1 = "6217";
     }
     if ($event == "Healthscape Series 2016") {
         $qid1 = "6727";
     }
     if ($event == "Hotelier Summit Africa 2016") {
         $qid1 = "7205";
     }
     if ($event == "Design Mission Middle East 2016") {
         $qid1 = "7654";
     }
     if ($event == "Hotelier Summit India Ose 2016") {
         $qid1 = "8103";
     }
     if ($event == "Hotelier Summit India Ffe 2016") {
         $qid1 = "8552";
     }
     foreach ($userranks as $rank) {
         $rank->delete();
     }
     foreach ($useranswers as $answer) {
         $answer->delete();
     }
     $user->delete();
     $users = User::where('event', '=', $event)->orderby('name')->with(array('answer' => function ($q) use($qid1) {
         $q->where('question_id', '=', $qid1)->orWhere('question_id', '=', $qid1 + 1);
     }))->get();
     return Redirect::to('admin/listuser')->with(array('liusers' => $users, 'liev' => $event, 'createusermessage' => 'User records Deleted'));
 }
Esempio n. 16
0
 public static function userAnswerCount($uid)
 {
     $qCount = Answer::where('user_id', '=', $uid);
     return $qCount->count();
 }
Esempio n. 17
0
														<div class="top-news">
															<a class="{{ $styleAnswer }}" href="#">
																<span>{{ $urAnswer }}</span>
																<em>
																{{ Form::label($answerSelect['id'] , $answerSelect['answer_title'], array('style' => "")) }}
																</em>
																<i class="{{ $iconAnswer }}"></i>
															</a>
														</div>

													</label>
												</div>

												<?php 
$answers = Answer::where('question_id', $questionId)->get();
?>
												@foreach($answers as $answer)	
													@if($question->correct_answer==$answer->id)
														@if($answer->id!=$answerSelect['id'])
															<div class="top-news" style="margin-top: -10px;">
																<a class="btn green" href="#">
																	<span>Correct Answer.</span>
																	<em>
																	{{ Form::label($answer->id , $answer->answer_title, array('style' => '')) }} 
																	</em>
																	<i class="icon-ok top-news-icon"></i>
																</a>
															</div>
														@endif
													@endif
Esempio n. 18
0
    return View::make('site.question')->with($data);
});
Route::get('users', function () {
    $data['users'] = User::orderBy('reputation', 'desc')->paginate(20);
    return View::make('site.users')->with($data);
});
Route::get('user/{id}/{slug}', function ($id, $slug) {
    $data['user'] = User::find($id);
    //return var_dump($data['user']->website);
    return View::make('profile.index')->with($data);
});
Route::get('activity/{id}/{slug}', function ($id, $slug) {
    $data['user'] = User::find($id);
    $data['userQustions'] = Question::where('user_id', '=', $id)->orderBy('created_at', 'desc')->paginate(4);
    $data['questionsCount'] = $data['userQustions']->count();
    $data['userAnswers'] = Answer::where('user_id', '=', $id)->orderBy('created_at', 'desc')->paginate(4);
    $data['answersCount'] = $data['userAnswers']->count();
    return View::make('profile.activity')->with($data);
});
Route::get('unanswer', function () {
    $data['users'] = User::all();
    $data['unanswer'] = Question::where('status', '=', NULL)->orderBy('created_at', 'desc')->paginate(10);
    $data['count'] = $data['unanswer']->count();
    return View::make('site.unansweredquestions')->with($data);
});
Route::get('search', function () {
    $data['users'] = User::all();
    $data['searchResults'] = Question::where('description', 'like', '%' . Input::get('search') . '%')->paginate(10);
    $data['count'] = $data['searchResults']->count();
    return View::make('site.searchresults')->with($data);
});