本文整理汇总了PHP中Answer类的典型用法代码示例。如果您正苦于以下问题:PHP Answer类的具体用法?PHP Answer怎么用?PHP Answer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Answer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
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;
}
示例2: parse
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;
}
示例3: postAnswer
/**
* 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();
}
示例4: parse
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;
}
示例5: actionView
/**
* 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)));
}
示例6: saveQuestionnaireAnswers
/**
* 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;
}
示例7: copyQuestionAction
/**
* @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());
}
}
示例8: actionCheckAnswer
/**
* 验证回答
*/
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());
}
}
示例9: download
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);
}
}
}
示例10: actionCreate
/**
* 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));
}
示例11: bestAnswer
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();
}
}
示例12: WidgetFounderBadge
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;
}
示例13: getBestAnswer
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;
}
示例14: actionCheckAnswer
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());
}
}
示例15: post_create_document
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);
}