本文整理汇总了PHP中Answer类的典型用法代码示例。如果您正苦于以下问题:PHP Answer类的具体用法?PHP Answer怎么用?PHP Answer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Answer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:rcom10002,项目名称:codeslab,代码行数:25,代码来源:answer_correction_processor.class.php
示例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;
}
开发者ID:rcom10002,项目名称:codeslab,代码行数:28,代码来源:answer_others_processor.class.php
示例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();
}
开发者ID:ayooby,项目名称:whatisit,代码行数:40,代码来源:AnswerController.php
示例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;
}
开发者ID:rcom10002,项目名称:codeslab,代码行数:33,代码来源:answer_short_answer_processor.class.php
示例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)));
}
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:40,代码来源:MainController.php
示例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;
}
开发者ID:Biobanques,项目名称:cbsd_platform,代码行数:67,代码来源:QuestionnaireController.php
示例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());
}
}
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:35,代码来源:ExerciseController.php
示例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());
}
}
开发者ID:jvlstudio,项目名称:ask,代码行数:38,代码来源:AnswerController.php
示例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);
}
}
}
开发者ID:htom78,项目名称:peersay,代码行数:53,代码来源:tests.php
示例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));
}
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:33,代码来源:VoteController.php
示例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();
}
}
开发者ID:phucps89,项目名称:Tour,代码行数:28,代码来源:Question.php
示例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;
}
开发者ID:schwarer2006,项目名称:wikia,代码行数:26,代码来源:WidgetFounderBadge.php
示例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;
}
开发者ID:stan5621,项目名称:jp_edu_online,代码行数:7,代码来源:UserInfo.php
示例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());
}
}
开发者ID:jvlstudio,项目名称:ask,代码行数:25,代码来源:CommentController.php
示例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);
}
开发者ID:andyfoster,项目名称:tenantplus,代码行数:27,代码来源:tenants.php
示例16: actionBatchDelete
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'));
}
开发者ID:kinghinds,项目名称:kingtest2,代码行数:27,代码来源:FeedbackController.php
示例17: run
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));
}
}
开发者ID:lumotroph,项目名称:TSS-cloud,代码行数:7,代码来源:AnswerSeeder.php
示例18: Insert
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());
}
}
开发者ID:Gonxis,项目名称:TOMO2_Project,代码行数:9,代码来源:AnswerModel.php
示例19: answerQuestion
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');
}
}
开发者ID:AnwarAbir18,项目名称:mushkil-asan,代码行数:18,代码来源:AnswerController.php
示例20: next
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');
}
开发者ID:b-kaxa,项目名称:perld,代码行数:9,代码来源:default_controller.php
注:本文中的Answer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论