public function parse()
 {
     // 定义题型样式
     $ap = $this->patterning(array($this->anp, $this->ap, $this->ep), 'umi');
     // 处理答案
     $answerTextArray = array();
     preg_match_all($ap, $this->_sectionText, $answerTextArray);
     if (count($answerTextArray) > 0 && count($answerTextArray[0]) > 0) {
         $answerTextArray = $answerTextArray[0];
     } else {
         return null;
     }
     // 处理答案
     $answerArray = array();
     foreach ($answerTextArray as $answerText) {
         // 拆解每个答案并生成对应的Answer
         $answer = new Answer();
         $answer->Set_content(ext_trim(preg_replace($ap, '$1', $answerText)));
         $answer->Set_type(AnswerType::CORRECTION);
         $answer->Set_desc(ext_trim(preg_replace($this->patterning(array($this->anp, $this->ap), 'umi'), '', $answerText)));
         $answerArray[] = $answer;
     }
     // 返回结果
     return $answerArray;
 }
 public function parse()
 {
     // 定义题型样式
     $ap = $this->patterning($this->ap, 'usi');
     // 处理答案
     $answerTextArray = array();
     preg_match_all($ap, $this->_sectionText, $answerTextArray);
     if (count($answerTextArray) > 0 && count($answerTextArray[0]) > 0) {
         $answerTextArray = $answerTextArray[0];
         $cp = $this->patterning($this->mp, 'usi');
         for ($i = 0; $i < count($answerTextArray); $i++) {
             $answerTextArray[$i] = preg_replace(array($cp, '/^\\s*|\\s*$/s'), '', $answerTextArray[$i]);
         }
     } else {
         return null;
     }
     // 处理答案
     $answerArray = array();
     foreach ($answerTextArray as $answerText) {
         // 拆解每个答案并生成对应的Answer
         $answer = new Answer();
         $answer->Set_content($answerText);
         $answer->Set_type(AnswerType::OTHERS);
         $answerArray[] = $answer;
     }
     // 返回结果
     return $answerArray;
 }
Exemplo n.º 3
0
 /**
  * Store a newly created post in storage.
  *
  * @return Response
  */
 public function postAnswer($question_id)
 {
     $validate = Validator::make(Input::all(), Answer::$rules);
     if ($validate->passes()) {
         //get file from input
         $audio = Input::file('audio');
         //get file's temporary path in server
         $file_temporary_path = $audio->getPathname();
         //create MP3 Object
         $audio_file = new MP3($file_temporary_path);
         $duration = $audio_file->getDuration();
         #Do same thing in 1 line:
         #$duration = with(new MP3($audio->getPathname()))->getDuration();
         //check if audio is less than/equal to 120 Seconds, then save it!
         if ($duration <= 120) {
             //seconds
             $name = time() . '-' . $audio->getClientOriginalName();
             //Move file from temporary folder to PUBLIC folder.
             //PUBLIC folder because we want user have access to this file later.
             $avatar = $audio->move(public_path() . '/answers/', $name);
             $answer = new Answer();
             $answer->title = Input::get('title');
             $answer->info = Input::get('info');
             $answer->audio = $name;
             if (Auth::check()) {
                 $answer->user_id = Auth::id();
             } else {
                 $answer->user_id = 0;
             }
             $answer->save();
         }
         return Redirect::action('AnswerController@index');
     }
     return Redirect::back()->withErrors($validate)->withInput();
 }
 public function parse()
 {
     // 定义题型样式
     $ap = $this->patterning(array($this->anp, $this->ap), 'umi');
     // 处理答案
     $answerTextArray = array();
     preg_match_all($ap, $this->_sectionText, $answerTextArray);
     if (count($answerTextArray) > 0 && count($answerTextArray[0]) > 0) {
         $answerTextArray = $answerTextArray[0];
     } else {
         return null;
     }
     // 处理答案
     $answerArray = array();
     foreach ($answerTextArray as $answerText) {
         // 拆解每个答案并生成对应的Answer
         $answer = new Answer(true);
         $answerText = preg_replace($this->patterning($this->anp), '', $answerText);
         $subAnswerTextArray = array();
         $subAnswerTextArray = preg_split($this->patterning($this->sas), $answerText);
         foreach ($subAnswerTextArray as $subAnswerText) {
             $subAnswer = new Answer();
             $subAnswer->Set_content(ext_trim($subAnswerText));
             $subAnswer->Set_type(AnswerType::SHORT_ANSWER);
             $subAnswers =& $answer->Get_answers();
             $subAnswers[] = $subAnswer;
         }
         $answer->Set_type(AnswerType::SHORT_ANSWER);
         $answerArray[] = $answer;
     }
     // 返回结果
     return $answerArray;
 }
 /** 
  * Controller action for viewing a questions.
  * Also provides functionality for creating an answer,
  * adding a comment and voting.
  */
 public function actionView()
 {
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $question = Question::model()->findByPk(Yii::app()->request->getParam('id'));
     if (isset($_POST['Answer'])) {
         $answerModel = new Answer();
         $answerModel->attributes = $_POST['Answer'];
         $answerModel->created_by = Yii::app()->user->id;
         $answerModel->post_type = "answer";
         $answerModel->question_id = $question->id;
         if ($answerModel->validate()) {
             $answerModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     if (isset($_POST['Comment'])) {
         $commentModel = new Comment();
         $commentModel->attributes = $_POST['Comment'];
         $commentModel->created_by = Yii::app()->user->id;
         $commentModel->post_type = "comment";
         $commentModel->question_id = $question->id;
         if ($commentModel->validate()) {
             $commentModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     // User has just voted on a question
     if (isset($_POST['QuestionVotes'])) {
         $questionVotesModel = new QuestionVotes();
         $questionVotesModel->attributes = $_POST['QuestionVotes'];
         QuestionVotes::model()->castVote($questionVotesModel, $question->id);
     }
     $this->render('view', array('author' => $question->user->id, 'question' => $question, 'answers' => Answer::model()->overview($question->id), 'related' => Question::model()->related($question->id)));
 }
 /**
  * save answers by this questionnaire.
  * for each question group then question save answer
  * //copy the questionnaire into answer
  * //then fill it with answers
  * @param questionnaire
  */
 public function saveQuestionnaireAnswers($model)
 {
     if (isset($_SESSION['datapatient'])) {
         $patients = $_SESSION['datapatient'];
     }
     $answer = new Answer();
     $answer->creator = ucfirst(Yii::app()->user->getPrenom()) . " " . strtoupper(Yii::app()->user->getNom());
     $answer->last_updated = DateTime::createFromFormat('d/m/Y', date('d/m/Y'));
     $answer->copy($model);
     $answer->type = $model->type;
     $answer->login = Yii::app()->user->id;
     $answer->id_patient = (string) $patients->id;
     $flagNoInputToSave = true;
     foreach ($answer->answers_group as $answer_group) {
         foreach ($answer_group->answers as $answerQuestion) {
             $input = $answer_group->id . "_" . $answerQuestion->id;
             if (isset($_POST['Questionnaire'][$input])) {
                 $flagNoInputToSave = false;
                 if ($answerQuestion->type != "number" && $answerQuestion->type != "expression" && $answerQuestion->type != "date") {
                     $answerQuestion->setAnswer($_POST['Questionnaire'][$input]);
                 } elseif ($answerQuestion->type == "date") {
                     $answerQuestion->setAnswerDate($_POST['Questionnaire'][$input]);
                 } else {
                     $answerQuestion->setAnswerNumerique($_POST['Questionnaire'][$input]);
                 }
             }
             //if array, specific save action
             if ($answerQuestion->type == "array") {
                 //construct each id input an dget the result to store it
                 $rows = $answerQuestion->rows;
                 $arrows = split(",", $rows);
                 $cols = $answerQuestion->columns;
                 $arcols = split(",", $cols);
                 $answerArray = "";
                 foreach ($arrows as $row) {
                     foreach ($arcols as $col) {
                         $idunique = $idquestiongroup . "_" . $question->id . "_" . $row . "_" . $col;
                         if (isset($_POST['Questionnaire'][$idunique])) {
                             $answerArray .= $_POST['Questionnaire'][$idunique] . ",";
                         }
                     }
                 }
                 $answerQuestion->setAnswer($answerArray);
             }
         }
     }
     if ($flagNoInputToSave == false) {
         if ($answer->save()) {
             Yii::app()->user->setFlash('success', Yii::t('common', 'patientFormSaved'));
         } else {
             Yii::app()->user->setFlash('error', Yii::t('common', 'patientFormNotSaved'));
             Yii::log("pb save answer" . print_r($answer->getErrors()), CLogger::LEVEL_ERROR);
         }
     } else {
         Yii::app()->user->setFlash('error', Yii::t('common', 'patientFormNotSaved'));
         //null result
         $answer = null;
     }
     return $answer;
 }
 /**
  * @param Application $app
  * @param int $exerciseId
  * @param int $questionId
  * @return Response
  */
 public function copyQuestionAction(Application $app, $exerciseId, $questionId)
 {
     $question = \Question::read($questionId);
     if ($question) {
         $newQuestionTitle = $question->selectTitle() . ' - ' . get_lang('Copy');
         $question->updateTitle($newQuestionTitle);
         //Duplicating the source question, in the current course
         $courseInfo = api_get_course_info();
         $newId = $question->duplicate($courseInfo);
         // Reading new question
         $newQuestion = \Question::read($newId);
         $newQuestion->addToList($exerciseId);
         // Reading Answers obj of the current course
         $newAnswer = new \Answer($questionId);
         $newAnswer->read();
         //Duplicating the Answers in the current course
         $newAnswer->duplicate($newId);
         /*$params = array(
               'cidReq' => api_get_course_id(),
               'id_session' => api_get_session_id(),
               'id' => $newId,
               'exerciseId' => $exerciseId
           );
           $url = $app['url_generator']->generate('exercise_question_pool', $params);
           return $app->redirect($url);*/
         $response = \Display::return_message(get_lang('QuestionCopied') . ": " . $newQuestionTitle);
         return new Response($response, 200, array());
     }
 }
Exemplo n.º 8
0
 /**
  * 验证回答
  */
 public function actionCheckAnswer()
 {
     //登入判断
     $this->checkAuth();
     $model = new AnswerForm();
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'answer-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     //var_dump($_POST['AnswerForm']);
     //启用事物处理 因为需要插入 Answer表及Question字段中的answer_count 字段
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $answer_model = new Answer();
         $answer_model->answer_content = $_POST['AnswerForm']['answer_content'];
         $answer_model->question_id = $_POST['AnswerForm']['question_id'];
         $answer_model->uid = Yii::app()->user->id;
         $answer_model->add_time = time();
         $answer_model->ip = Yii::app()->request->userHostAddress;
         if (!$answer_model->save()) {
             throw new ErrorException('回答失败1');
         }
         //更改question表中的answer_count 信息
         if (!Question::model()->updateByPk($answer_model->question_id, array('answer_count' => new CDbExpression('answer_count+1')))) {
             throw new ErrorException('回答失败2');
         }
         $transaction->commit();
         $this->redirect(Yii::app()->request->urlReferrer);
         //$this->success('回答成功');
     } catch (Exception $e) {
         $transaction->rollBack();
         //exit($e->getMessage());
         $this->error($e->getMessage());
     }
 }
Exemplo n.º 9
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);
         }
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new QuestionVotes();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['QuestionVotes'])) {
         $model->attributes = $_POST['QuestionVotes'];
         // TODO: I'd like to figure out a way to instantiate the model
         //			dynamically. I think they might do that with
         //			the 'activity' module. For now this will do.
         switch ($model->vote_on) {
             case "question":
                 $question_id = $model->post_id;
                 break;
             case "answer":
                 $obj = Answer::model()->findByPk($model->post_id);
                 $question_id = $obj->question_id;
                 break;
         }
         if (QuestionVotes::model()->castVote($model, $question_id)) {
             if ($_POST['QuestionVotes']['should_open_question'] == true) {
                 $this->redirect(array('//questionanswer/question/view', 'id' => $question_id));
             } else {
                 $this->redirect(array('//questionanswer/question/index'));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 11
0
 function bestAnswer($except = [])
 {
     $answerHistory = AdviceDetail::whereNotIn('id_question', array_merge(self::$_rootQuestionID, $except))->lists('id_answer');
     $answers = $this->answers;
     $listThisIDAnswer = $answers->lists('id_answer');
     $listIDTourSuggest = TourScore::select('*');
     foreach ($answerHistory as $ans) {
         $listIDTourSuggest->orWhere(function ($query) use($ans) {
             $query->where('id_answer', $ans)->where('score', 100);
         });
     }
     $listIDTourSuggest = $listIDTourSuggest->lists('id_tour');
     $listTourScoreOrder = TourScore::where(function ($query) use($answers, $listThisIDAnswer) {
         foreach ($listThisIDAnswer as $ans) {
             $query->orWhere(function ($query) use($ans) {
                 $query->where('id_answer', $ans)->where('score', '>=', 50);
             });
         }
     });
     $listTourScoreOrder->whereIn('id_tour', $listIDTourSuggest);
     $listTourScoreOrder = $listTourScoreOrder->get();
     $listBestIDAnswer = array_values(array_unique($listTourScoreOrder->lists('id_answer')));
     if ($listBestIDAnswer) {
         return Answer::whereIn('id', $listBestIDAnswer)->get();
     } else {
         return Answer::whereIn('id', $listThisIDAnswer)->get();
     }
 }
Exemplo n.º 12
0
function WidgetFounderBadge($id, $params)
{
    $output = "";
    wfProfileIn(__METHOD__);
    global $wgMemc;
    $key = wfMemcKey("WidgetFounderBadge", "user");
    $user = $wgMemc->get($key);
    if (is_null($user)) {
        global $wgCityId;
        $user = WikiFactory::getWikiById($wgCityId)->city_founding_user;
        $wgMemc->set($key, $user, 3600);
    }
    if (0 == $user) {
        return wfMsgForContent("widget-founderbadge-notavailable");
    }
    $key = wfMemcKey("WidgetFounderBadge", "edits");
    $edits = $wgMemc->get($key);
    if (empty($edits)) {
        $edits = AttributionCache::getInstance()->getUserEditPoints($user);
        $wgMemc->set($key, $edits, 300);
    }
    $author = array("user_id" => $user, "user_name" => User::newFromId($user)->getName(), "edits" => $edits);
    $output = Answer::getUserBadge($author);
    wfProfileOut(__METHOD__);
    return $output;
}
Exemplo n.º 13
0
 public function getBestAnswer()
 {
     //$sql = "select a.* from answer a left join answer_vote v on a.id=v.answerid where a.userId= 1 and v.value>0 group by a.id order by count(*) desc,a.addTime desc limit 1";
     $sql = "select a.* from ew_answer a left join  ew_entity e on a.voteableEntityId=e.id left join ew_vote v on e.id=v.voteableEntityId where a.userId= " . $this->id . " and v.value>0 order by a.addTime desc limit 1";
     $answer = Answer::model()->findBySql($sql);
     return $answer;
 }
Exemplo n.º 14
0
 public function actionCheckAnswer()
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $ac_models = new AnswerComments();
         $ac_models->message = $_POST['CommentForm']['message'];
         $ac_models->answer_id = $_POST['CommentForm']['comment_id'];
         $ac_models->uid = Yii::app()->user->id;
         $ac_models->time = time();
         if (!$ac_models->save()) {
             throw new Exception('评论失败');
         }
         //在question中的 comment_count字段+1
         if (!Answer::model()->updateByPk($ac_models->answer_id, array('comment_count' => new CDbExpression('comment_count+1')))) {
             throw new ErrorException('评论失败');
         }
         $transaction->commit();
         $this->redirect(Yii::app()->request->urlReferrer);
         //$this->success('评论成功');
     } catch (Exception $e) {
         $transaction->rollBack();
         //exit($e->getMessage());
         $this->error($e->getMessage());
     }
 }
Exemplo n.º 15
0
 public function post_create_document()
 {
     $document_id = Input::get('document_id');
     $user_id = Auth::user()->id;
     // we want to get all the input data
     //
     // take apart the name and value pairs
     //
     $inputs = Input::all();
     //dd($inputs);
     foreach (Input::all() as $name => $value) {
         if ($name != '0' || $name != 'csrf_token') {
             // for some reason, laravel id=gnores form fields with nums as
             // the name value so this will fix it
             //  along with the <input name="id45"..
             $name = str_replace('id', '', $name);
             Answer::create(array('document_id' => $document_id, 'user_id' => $user_id, 'field_id' => $name, 'answer' => $value));
         }
         // dd(array(
         //     'document_id' => $document_id,
         //     'user_id' => $user_id,
         //     'field_id' => $key,
         //     'answer' => $value
         // ));
     }
     return Redirect::to_route('tenant_view_document', $document_id);
 }
Exemplo n.º 16
0
 public function actionBatchDelete()
 {
     if (Yii::app()->user->checkAccess('deleteFeedback') == false) {
         throw new CHttpException(403);
     }
     $idList = Yii::app()->request->getPost('id', array());
     if (count($idList) > 0) {
         $criteria = new CDbCriteria();
         $criteria->addInCondition('id', $idList);
         $feedbacks = Feedback::model()->findAll($criteria);
         $flag = 0;
         foreach ($feedbacks as $feedback) {
             if ($feedback->delete()) {
                 $answer = Answer::model()->deleteAll('feedback_id=:feedbackID', array(':feedbackID' => $feedback->primaryKey));
                 $flag++;
             }
         }
         if ($flag > 0) {
             $this->setFlashMessage('问题咨询 已成功删除');
         } else {
             $this->setFlashMessage('问题咨询 删除失败', 'warn');
         }
     } else {
         $this->setFlashMessage('没有记录被选中', 'warn');
     }
     $this->redirect(array('index'));
 }
Exemplo n.º 17
0
 public function run()
 {
     $answers = ["Yes.", "Yes - definitely.", "Reply hazy, try again...", "Without a doubt.", "My sources say no.", "As I see it, yes.", "You may rely on it.", "Concentrate and ask again...", "Outlook not so good.", "It is decidedly so.", "Better not tell you now...", "Very doubtful...", "It is certain.", "Cannot predict now...", "Most likely...", "Ask again later...", "My reply is no.", "Outlook good.", "Don't count on it."];
     foreach ($answers as $answer) {
         Answer::create(array('body' => $answer));
     }
 }
Exemplo n.º 18
0
 public function Insert(Answer $data)
 {
     try {
         $query = "INSERT INTO Respuestas (id_event, respuesta, correct)\n                          VALUES (?, ?, ?)";
         $this->pdo->prepare($query)->execute(array($data->__GET('id_event'), $data->__GET('respuesta'), $data->__GET('correct')));
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Exemplo n.º 19
0
 public function answerQuestion()
 {
     $validator = Validator::make(Input::all(), Answer::$rules);
     $question_id = Input::get('question_id');
     if ($validator->fails()) {
         return Redirect::route('single-question', $question_id)->withErrors($validator)->withInput();
     } else {
         $insertAnswer = new Answer();
         $insertAnswer->user_id = Auth::user()->user_id;
         $insertAnswer->question_id = $question_id;
         $insertAnswer->answer = Input::get('answer');
         $insertAnswer->save();
         $insertPoint = User::find(Auth::user()->user_id);
         $insertPoint->points = $insertPoint->points + 3;
         $insertPoint->save();
         return Redirect::route('single-question', $question_id)->with('global', 'Answer is successfully posted');
     }
 }
Exemplo n.º 20
0
 public function next()
 {
     $q_id = Param::get('id');
     $selection_id = Param::get('selection');
     $question = Question::get();
     $answer = Answer::get($q_id);
     $this->set(['question' => $question, 'answer' => $answer, 'selection_id' => $selection_id]);
     $this->render('index');
 }
Exemplo n.º 21
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     ini_set('max_execution_time', 0);
     $data = DB::select('select * from option_ans');
     $insert = [];
     foreach ($data as $d) {
         $insert[] = ['id' => $d->id, 'name' => $d->opt_content];
     }
     Answer::insert($insert);
 }
 public function post($thread_id)
 {
     $user_name = $_POST['user_name'];
     $user_email = $_POST['user_email'];
     $answer_content = $_POST['answer_content'];
     Answer::post($user_name, $user_email, $answer_content, $thread_id);
     require_once ROOT . DS . 'application' . DS . 'model' . DS . 'class.thread.php';
     Thread::addAnswer($thread_id);
     header("Location: index.php?controller=thread&action=detail&query={$thread_id}");
 }
Exemplo n.º 23
0
 public function actionAnswer($id)
 {
     // get chosen variant IDs
     $chosenAnswers = array_values($_POST);
     // add answers for all answer variants for the given poll
     $poll = Poll::findById($id);
     foreach ($poll->questions as $question) {
         foreach ($question->variants as $variant) {
             $answer = new Answer();
             $answer->variant = $variant;
             $answer->answer = in_array($variant->id, $chosenAnswers);
             $answer->save(false);
             // but do not commit
         }
     }
     Model::flush();
     // commit
     $this->redirect($this->url('poll.stat', array('id' => $id)));
 }
Exemplo n.º 24
0
 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));
 }
Exemplo n.º 25
0
 public function submitPoll($data, $form)
 {
     $choices = Answer::get()->filter(array('ID' => $data['PollChoices']));
     if ($choices) {
         foreach ($choices as $choice) {
             $choice->Votecount = $choice->Votecount + 1;
             $choice->write();
             $choice->Poll()->markAsVoted();
         }
     }
     $this->controller->redirectBack();
 }
Exemplo n.º 26
0
 public function getStatusText()
 {
     $id = $this->id;
     $answer = Answer::model()->find('feedback_id=:feedbackID', array(':feedbackID' => $id));
     if ($this->is_reply == 0) {
         return '<font color="blue">未回复</font>&nbsp;&nbsp;<a href="index.php?r=answer/reply&feedbackid=' . $id . '">回复</a>';
     } else {
         if ($this->is_reply == 1) {
             return '<font color="green">已回复</font>&nbsp;&nbsp;<a href="index.php?r=answer/view&id=' . $answer->primaryKey . '">查看回复</a>';
         }
     }
 }
Exemplo n.º 27
0
 static function findById($search_id)
 {
     $found_answer = null;
     $returned_answers = Answer::getAll();
     foreach ($returned_answers as $answer) {
         $id = $answer->getId();
         if ($search_id == $id) {
             $found_answer = $answer;
         }
     }
     return $found_answer;
 }
Exemplo n.º 28
0
 /**
  * 计算用户在本小组内回答问题的次数
  * Enter description here ...
  * @param unknown_type $userId
  */
 public function getUserAnswerCount($userId)
 {
     $group = $this->getOwner();
     $answerCount = 0;
     foreach ($group->testQuestions as $question) {
         $answer = Answer::model()->findByAttributes(array('userId' => $userId, 'questionid' => $question->id));
         if ($answer) {
             $answerCount++;
         }
     }
     return $answerCount;
 }
Exemplo n.º 29
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);
     }
 }
 public function postGuardar()
 {
     $bandera = false;
     $id = Input::get('idQues');
     $ans = Input::get('res');
     $answers = Answer::all();
     $question = Question::find($id);
     $cantidad = Question::count();
     foreach ($answers as $a) {
         if ($a->id_question == $id) {
             $bandera = true;
             $answer = $a;
             break;
         }
     }
     if (!$bandera) {
         $answer = new Answer();
         $answer->id_question = $id;
         $ids = Auth::id();
         $student = Student::where('id_user', '=', $ids)->get()->first();
         $answer->id_student = $student->id;
         $answer->answer = $ans;
         $answer->result = QuestionsController::verifyAnswer($question, $ans);
         $answer->save();
     } else {
         $answer->result = QuestionsController::verifyAnswer($question, $ans);
         $answer->answer = $ans;
         $answer->save();
     }
     if ($cantidad == $id) {
         return Redirect::to('questions/exam?endTest=yes');
         //"holi ".$id." ".$ans;
     } else {
         if ($cantidad > $id) {
             return Redirect::to('questions/exam?numberQIn=' . ++$id);
         }
     }
 }