Example #1
0
 public function update($id)
 {
     // save updated
     $record = $this->records->find($id);
     if (!$record) {
         Practice::create(Input::all());
         return $this->respond($record);
     }
     $record->fill(Input::all())->save();
     return $this->respond($record);
 }
Example #2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     // 提交查询
     if ($request->has('user_id') && $request->has('wav_name')) {
         $user_id = $request->get('user_id');
         $wav_name = $request->get('wav_name');
         // 查找practice表的信息
         $practice = Practice::with(['user' => function ($query) {
             $query->select('uid', 'nickname');
         }, 'music' => function ($query) {
             $query->select('id', 'name');
         }])->where('uid', $user_id)->where('wav_path', '/midis/' . $user_id . '/' . $wav_name)->first();
         // 查找match_for_tests表的信息
         $results = MatchForTest::where('practice_id', $practice['pid'])->orderBy('id', 'desc')->paginate(100)->appends($request->all());
         return view('wav_test.index')->with($request->all())->with('results', $results)->with('practice', $practice);
     } else {
         return view('wav_test.index')->with('practice', []);
     }
 }
Example #3
0
 public function getPic(Request $request)
 {
     $id = 468;
     // $id = $request->get('id');
     $user = \App\StudentUser::findOrFail($id);
     /**
      * 今日练习的所有曲目
      */
     $start_time = Carbon::now('Asia/ShangHai')->subYear();
     $end_time = Carbon::now('Asia/ShangHai');
     $musics = \App\Practice::with(['music' => function ($query) {
         $query->select('id', 'name');
     }])->select(DB::raw('SUM(practice_time) as sum_time'), 'music_id')->where('uid', $id)->whereBetween('practice_date', [$start_time, $end_time])->groupBy('music_id')->get();
     foreach ($musics as $v) {
         $data_arr[] = $v->sum_time;
         $lab_arr[] = $v->music->name;
     }
     $pic_name = $id . '-' . time() . '-' . mt_rand() . '.png';
     return $this->drawChart($data_arr, $lab_arr, $pic_name);
 }
Example #4
0
 public function recordReportChart($id)
 {
     /**
      * 绘制图表所需数据
      */
     $start_time = Carbon::now('Asia/ShangHai')->startOfDay()->toDateTimeString();
     $end_time = Carbon::now('Asia/ShangHai')->endOfDay()->toDateTimeString();
     $text_data = Practice::with(['music' => function ($query) {
         $query->withTrashed();
     }])->select('music_id', 'rating', DB::raw('SUM(practice_time) as one_music_duration'))->whereBetween('practice_date', [$start_time, $end_time])->where('uid', $id)->groupBy('music_id')->get();
     $rating_data = Practice::select('rating', DB::raw('COUNT(*) as count'))->whereBetween('practice_date', [$start_time, $end_time])->where('uid', $id)->whereNotNull('rating')->groupBy('rating')->orderBy('rating')->get();
     $colors = ['#E76543', '#4A8EB6', '#8B3A8B', '#53B657', '#FDBD1A'];
     foreach ($text_data as $k => $v) {
         $temp['value'] = $v->one_music_duration;
         $temp['color'] = $colors[$k];
         $data[] = $temp;
     }
     $colors1 = ['#E76543', '#4A8EB6', '#8B3A8B', '#53B657', '#FDBD1A', '#FD341C'];
     foreach ($rating_data as $v) {
         $temp1['value'] = $v->count;
         $temp1['color'] = $colors1[ceil($v->rating) / 2];
         $data1[] = $temp1;
     }
     $all_data = [];
     if (isset($data)) {
         $all_data['data'] = $data;
     }
     if (isset($data1)) {
         $all_data['data1'] = $data1;
     }
     return $all_data;
 }