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


PHP Answer::whereIn方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:phucps89,项目名称:Tour,代码行数:28,代码来源:Question.php

示例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);
        //}
    }
开发者ID:harshithanaiduk,项目名称:ideconnect_2016,代码行数:67,代码来源:AdminController.php


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