本文整理汇总了PHP中Answer::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Answer::whereIn方法的具体用法?PHP Answer::whereIn怎么用?PHP Answer::whereIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Answer
的用法示例。
在下文中一共展示了Answer::whereIn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
}
示例2: emergencyUse
public function emergencyUse()
{
//for($i=0;$i<10;$i++)
//{
ini_set('max_execution_time', 1000);
$start = microtime(true);
$userIds = array();
$users = DB::select(DB::raw("select * from users where role!='admin_dd' and role!='sales_dd' and batchUpdate=2 Limit 10"));
// $users = User::where('role','!=','admin_dd')->orWhere('role','!=','sales_dd')->orderby('name')->get();
$userQuestion = array();
$count = 1;
foreach ($users as $user) {
$userEvent_tmp[] = $user->event;
$userIds[] = $user->id;
}
if (count($userIds) < 1) {
dd("No User to be updated");
}
$userEvent = array_unique($userEvent_tmp);
$questions_tmp = Question::whereIn('event', $userEvent)->get();
$answerpair = Answer::whereIn('user_id', $userIds)->get();
foreach ($questions_tmp as $question) {
$userQuestionx[$question->event][] = $question;
}
foreach ($answerpair as $answer) {
$userAnswers[$answer->question_id][] = $answer->user_id;
}
// $result = DB::select(DB::raw("select user_id,question_id from answers where "));
foreach ($users as $user) {
foreach ($userQuestionx[$user->event] as $question) {
// foreach($users as $user)
$userQuestion[] = array($question->id, $user->id);
}
}
$updated = false;
foreach ($userQuestion as $pairval) {
$answerx = new Answer();
?>
<div style="margin-bottom:30px;background:pink"><?php
if (!array_key_exists($pairval[0], $userAnswers)) {
echo "<div style='background:yellow'>The Question answer is updated</div><br/>";
$answerx->question_id = $pairval[0];
$answerx->user_id = $pairval[1];
$answerx->answer_text = '';
//$answerx->save;
//DB::select(DB::raw("insert into updatedanswertable (`questionid`,`userid`) values ('$pairval[0]','$pairval[1]') "));
DB::select(DB::raw("insert into answers (`question_id`,`user_id`,`answer_text`) values ('{$pairval['0']}','{$pairval['1']}','') "));
echo $pairval[0] . ",";
echo $pairval[1] . "<br/>";
$updated = true;
} else {
echo "The Question answer pair is already there<br/>";
echo $pairval[0] . ",";
echo $pairval[1] . "<br/>";
$updated = true;
}
?>
</div><?php
if ($updated == true) {
DB::select(DB::raw("update users set batchUpdate=12 where id='{$pairval['1']}' "));
}
}
$total = microtime(true) - $start;
echo "Time to execute :" . $total;
//sleep(10 * 60);
//}
}