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


PHP Answer::find方法代码示例

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


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

示例1: action_vote

 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);
 }
开发者ID:jruizdes,项目名称:encuestamanki,代码行数:37,代码来源:home.php

示例2: getAcceptanswer

 public function getAcceptanswer($aID, $qID, $uID)
 {
     //return $aID. ' '. $qID;
     $answerToAccept = Answer::find($aID);
     $answerToAccept->status = 'accepted';
     $answerToAccept->save();
     $questionToUpdate = Question::find($qID);
     $questionToUpdate->status = 'solved';
     $questionToUpdate->save();
     $userToUpdate = User::find($uID);
     $reputation = $userToUpdate->reputation;
     $userToUpdate->reputation = $reputation + 15;
     $userToUpdate->save();
     $answerReputation = new Areputation();
     $answerReputation->user_id = $uID;
     $answerReputation->answer_id = $aID;
     $answerReputation->points = "+15";
     $answerReputation->action = "accept";
     $answerReputation->save();
     $authReputation = new Areputation();
     $authReputation->user_id = Auth::user()->id;
     $authReputation->answer_id = $aID;
     $authReputation->points = "+2";
     $authReputation->action = "accept";
     $authReputation->save();
     $userReputation = User::find(Auth::user()->id);
     $rep = $userReputation->reputation;
     $userReputation->reputation = $rep + 2;
     $userReputation->save();
     return Redirect::back();
 }
开发者ID:Roc4rdho,项目名称:ubexchange,代码行数:31,代码来源:ProfileController.php

示例3: savepage6data

 public function savepage6data()
 {
     $aa = Input::except(array('_token', 'back', 'save', 'next'));
     $afc = Input::file();
     $count = 0;
     foreach ($aa as $key => $value) {
         $ids = explode("|", $key);
         //var_dump($ids);
         if (isset($ids[0]) && $ids[0] != "file") {
             if (isset($ids[1]) && $ids[1] != "") {
                 $ans = Answer::find($ids[1]);
                 $ans->answer_text = $value;
                 $ans->save();
             } else {
                 $ans = new Answer();
                 $ans->question_id = $ids[0];
                 if (isset($ids[2]) && $ids[2] != "") {
                     $ans->choice_id = $ids[2];
                 }
                 $ans->user_id = Session::get('userid');
                 $ans->answer_text = $value;
                 $ans->save();
             }
         }
     }
     foreach ($afc as $key => $value) {
         $ids = explode("|", $key);
         if (isset($ids[0]) && $ids[0] == "file") {
             //If file Values are not printing then please check if
             // form has FIle=true
             //dd(Input::file($key));
             $userid = Session::get('userid');
             $event = Session::get('event');
             $fileTblObj = new fileHandler();
             $ans = Answer::find($ids[2]);
             if (isset($afc[$key])) {
                 if (Input::file($key)->isValid()) {
                     $count++;
                     $destinationPath = 'app/uploads/' . $event . '/' . $userid . '/6';
                     // upload path
                     $extension = Input::file($key)->getClientOriginalExtension();
                     // getting image extension
                     $name = Input::file($key)->getClientOriginalName();
                     $curFilesize = Input::file($key)->getClientSize();
                     $mime = Input::file($key)->getMimeType();
                     // dd($mime);
                     //$fileName = $name; // renameing image
                     //$exstFileSize = Input::file($destinationPath, $fileName);
                     if (!File::exists($destinationPath . "/" . $count . $name)) {
                         //creating details for saving inthe file_handler Table
                         $fileTblObj->user_id = $userid;
                         $fileTblObj->eventName = $event;
                         $fileTblObj->fileName = $count . $name;
                         $fileTblObj->formPage = 6;
                         $fileTblObj->filePath = $destinationPath . "/";
                         $fileTblObj->mime = $mime;
                         $ans->answer_text = 'Yes';
                         $ans->save();
                         Input::file($key)->move($destinationPath, $count . $name);
                         // uploading file to given path
                         //Save filedetails
                         $fileTblObj->save();
                         Session::flash('success', 'Upload successfully');
                     } else {
                         if (File::size($destinationPath . "/" . $name) != $curFilesize) {
                             $fileDtls = $fileTblObj->where('uid', $userid)->where('fileName', $name)->where('formPage', 6)->first();
                             Input::file($key)->move($destinationPath, $name);
                             $ans->answer_text = 'Yes';
                             $ans->save();
                             $fileTblObj->where('id', $fileDtls->id)->update(array('updated_at' => date("Y-m-d h:m:s", time())));
                         }
                     }
                     //return Redirect::to('upload');
                 }
             } else {
                 if ($ans->answer_text == '') {
                     $ans->answer_text = 'No';
                     $ans->save();
                 }
             }
         }
     }
 }
开发者ID:harshithanaiduk,项目名称:ideconnect_2016,代码行数:83,代码来源:FormController.php

示例4: submitQuestion

 public function submitQuestion()
 {
     $answer_id = Input::get('answer_id');
     $user_answer = UserAnswer::create(array('answer_id' => $answer_id, 'user_id' => Auth::user()->id));
     $user_answer->save();
     return View::make('question-chart')->with('question', Answer::find($answer_id)->question);
 }
开发者ID:netintelpro,项目名称:laravel-app,代码行数:7,代码来源:PollController.php

示例5: savepage3data

 public function savepage3data()
 {
     $aa = Input::except(array('_token', 'back', 'save', 'next'));
     //dd($aa);
     foreach ($aa as $key => $value) {
         $ids = explode("|", $key);
         if (isset($ids[0]) && $ids[0] != "catven") {
             if (isset($ids[1]) && $ids[1] != "") {
                 $ans = Answer::find($ids[1]);
                 $ans->answer_text = $value;
                 $ans->save();
             } else {
                 $ans = new Answer();
                 $ans->question_id = $ids[0];
                 if (isset($ids[2]) && $ids[2] != "") {
                     $ans->choice_id = $ids[2];
                 }
                 $ans->user_id = Session::get('userid');
                 $ans->answer_text = $value;
                 $ans->save();
             }
         } else {
             // dd($value);
             if (isset($ids[2]) && $ids[2] != "") {
                 $catvenans = Categoryvendoranswer::find($ids[2]);
                 $catvenans->answer = $value;
                 $catvenans->save();
             } else {
                 $catvenans = new Categoryvendoranswer();
                 $catvenans->categoryvendor_id = $ids[1];
                 $catvenans->user_id = Session::get('userid');
                 $catvenans->answer = $value;
                 $catvenans->save();
             }
         }
     }
 }
开发者ID:harshithanaiduk,项目名称:ideconnect_2016,代码行数:37,代码来源:FormController.php

示例6: getEditanswer

 public function getEditanswer()
 {
     $answer = Answer::find($_GET['keyword']);
     $answer->answer_title = $_GET['keyword2'];
     $answer->save();
     return Redirect::to('backends/quizz/edit/' . $_GET['keyword1']);
 }
开发者ID:imranshuvo,项目名称:QuizzApps,代码行数:7,代码来源:AdminQuizzController.php

示例7: action_edit

 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);
     }
 }
开发者ID:jruizdes,项目名称:encuestamanki,代码行数:66,代码来源:admin.php

示例8: getDownvoteanswer

 public function getDownvoteanswer($id, $uID)
 {
     if (Auth::check() == NULL) {
         return Redirect::back()->with('alertError', "you have to be logged in to perform this action.");
     }
     $data['answer'] = Answer::find($id);
     //return $data['answer']->user_id . '==' . Auth::user()->id;
     if ($data['answer']->user_id == Auth::user()->id) {
         return Redirect::back()->with('alertError', "You can not downvote your own answer.");
     }
     $hasUserVoted = Avote::where('user_id', '=', User::find(Auth::user()->id)->id)->where('answer_id', '=', $id)->count();
     if ($hasUserVoted == 0) {
         $reputationTest = User::find(Auth::user()->id);
         if ($reputationTest->reputation < 125) {
             return Redirect::back()->with('alertError', "You need 125 reputation to downvote an answer.");
         } else {
             //return $reputationTest;
             $vote = new Avote();
             $vote->user_id = User::find(Auth::user()->id)->id;
             $vote->answer_id = $id;
             $vote->save();
             /*-----------------------------------------------*/
             $userToUpdate = User::find($uID);
             $reputation = $userToUpdate->reputation;
             $reputation -= 2;
             //$userToUpdate->reputation = $reputation - 2;
             if ($reputation < 1) {
                 $userToUpdate->reputation = 1;
             } else {
                 $userToUpdate->reputation = $reputation;
             }
             $userToUpdate->save();
             /*-----------------------------------------------*/
             /*-----------------------------------------------*/
             $authUser = $reputationTest->reputation;
             $authUser -= 1;
             if ($authUser < 1) {
                 $reputationTest->reputation = 1;
             } else {
                 $reputationTest->reputation = $authUser;
             }
             $reputationTest->save();
             /*-----------------------------------------------*/
             /*-----------------------------------------------*/
             $answerReputation = new Areputation();
             $answerReputation->user_id = $uID;
             $answerReputation->answer_id = $id;
             $answerReputation->points = "-2";
             $answerReputation->action = "downvote";
             $answerReputation->save();
             /*----------------------------------------------*/
             /*-----------------------------------------------*/
             $authReputation = new Areputation();
             $authReputation->user_id = Auth::user()->id;
             $authReputation->answer_id = $id;
             $authReputation->points = "-2";
             $authReputation->action = "downvote";
             $authReputation->save();
             /*----------------------------------------------*/
             $answerToDownVote = Answer::find($id);
             $votes = $answerToDownVote->votes;
             $answerToDownVote->votes = $votes - 1;
             $answerToDownVote->save();
             return Redirect::back();
         }
     } else {
         return Redirect::back()->with('alertError', "you have already voted this answer.");
     }
 }
开发者ID:Roc4rdho,项目名称:ubexchange,代码行数:69,代码来源:VoteController.php

示例9: storeAction

 /**
  * Store the answer
  *
  * @return mixed
  */
 public function storeAction()
 {
     $token = $this->getToken();
     if (!$token) {
         return Redirect::route('info')->with('message', 'Токен не найден');
     }
     if ($token->status != Token::TOKEN_STATUS_STARTED) {
         return Redirect::route('token.index', ['token' => $token->token]);
     }
     if (!$this->isTokenValid($token)) {
         Session::forget('token_string');
         $token->status = Token::TOKEN_STATUS_EXPIRED;
         $token->save();
         return Redirect::route('info')->with('message', 'Время теста истекло, ответ не засчитан');
     }
     $questionId = Session::get('question_id', false);
     $testAnswers = Session::get('test_answers', []);
     if (!$questionId || !is_numeric($questionId)) {
         return Redirect::route('info')->with('message', 'Ошибка данных сессии.');
     }
     $question = Question::find((int) $questionId);
     if (!$question) {
         return Redirect::route('info')->with('message', 'Ошибка данных сессии. Вопрос не найден.');
     }
     $data = Input::all();
     $result = new Result();
     $result->token = $token->token;
     $result->test_id = $token->test->id;
     $result->question_id = (int) $questionId;
     $result->q_text = $question->text;
     $result->q_image = $question->image;
     /**
      * Process the answer depending on question type
      */
     switch ($question->type) {
         case Question::TYPE_RADIO:
             if (!isset($data['answer']) || !$data['answer']) {
                 return Redirect::route('info')->with('message', 'Ожидается ответ.');
             }
             foreach ($testAnswers as $id => $hash) {
                 if ($hash == $data['answer']) {
                     $answer = Answer::find($id);
                 }
             }
             if (!$answer) {
                 return Redirect::route('info')->with('message', 'Такой ответ не найден.');
             }
             $result->a_text = $answer->text;
             $result->a_image = $answer->image;
             $result->is_correct = $answer->is_correct;
             $result->weight = $answer->weight;
             break;
         case Question::TYPE_CHECKBOX:
             $answer = isset($data['answer']) ? $data['answer'] : [];
             // has to be an array
             if (!is_array($answer)) {
                 return Redirect::route('info')->with('message', 'Ответ должен быть массивом.');
             }
             $answer_ = $answer;
             // we need to find real answer ids
             $answer = [];
             foreach ($testAnswers as $id => $hash) {
                 foreach ($answer_ as $a_) {
                     if ($hash == $a_) {
                         $answer[] = Answer::find($id)->id;
                     }
                 }
             }
             if (!empty($answer)) {
                 $answers = DB::table('answer')->whereIn('id', $answer)->get();
             } else {
                 $answers = [];
             }
             $isThereACorrectAnswer = false;
             $correctNum = 0;
             // Is there at least one correct answer?
             foreach ($question->answers as $ans) {
                 if ($ans->is_correct) {
                     $isThereACorrectAnswer = true;
                     $correctNum++;
                 }
             }
             $result->a_text = '';
             if (!$isThereACorrectAnswer && count($answers) > 0) {
                 // There are no correct answers, but user have chosen something
                 $result->is_correct = false;
             } elseif (!$isThereACorrectAnswer && count($answers) == 0) {
                 $result->is_correct = true;
             } elseif ($isThereACorrectAnswer && count($answers) == 0) {
                 $result->is_correct = false;
             } elseif ($isThereACorrectAnswer && count($answers) > 0 && count($answers) != $correctNum) {
                 $result->is_correct = false;
             } elseif ($isThereACorrectAnswer && count($answers) > 0 && count($answers) == $correctNum) {
                 // check if all correct answers selected
                 $result->is_correct = true;
//.........这里部分代码省略.........
开发者ID:himor,项目名称:testing,代码行数:101,代码来源:TestController.php


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