checkLogin(); // 로그인 상태 체크 $userId = $this->session->get('useremail'); $model = new UserModel(); $data['user'] = $model->getUserByEmail($userId); $data['current_date'] = date('Y-m-d'); $data['current_time'] = date('H:i:s'); return $this->view('play', $data); } public function basicstart($pid=null,$dates=null) { try { $this->checkLogin(); // 로그인 상태 체크 if(!empty($dates)){ if($this->session->get('todate') != $dates){ $model = new DailyLearningLogModel(); // 날짜 형식을 YYYY-MM로 설정 $email = $this->session->get('useremail'); // 데이터베이스에서 데이터 검색 $data = $model->where('user_email',$email)->where('todate', $dates) ->select('num, todate, total_time,repetition_count,daily_words,last_json_key, interrupted_key') ->find(); } } $interruptedKey = $this->session->get('interrupted_key'); if (empty($interruptedKey)) { throw new \Exception('No interrupted key found in session.'); } $min_key = min(array_keys($interruptedKey)); $max_key = max(array_keys($interruptedKey)); if (!empty($pid) && ($min_key > $pid || $max_key < $pid) && $pid != 9999999) { throw new \Exception('Invalid pid value.'); } if (empty($pid)) { $DailyLearningLogModel = new DailyLearningLogModel(); $DailyLearningLogModel->update($this->session->get('dailyLearningLog_num'), ['start_time' => date('H:i:s')]); if (empty($this->session->get('last_json_key'))) { $pid = $min_key; } else { $pid = $this->session->get('last_json_key'); } } else if ($pid == 9999999) { $pid = $min_key; $repetition_count = $this->session->get('repetition_count'); $this->session->set('repetition_count', $repetition_count + 1); $this->session->set('last_json_key',$pid); $DailyLearningLogModel = new DailyLearningLogModel(); $DailyLearningLogModel->update($this->session->get('dailyLearningLog_num'), ['repetition_count' => $repetition_count + 1]); // 특정 값을 세션에 플래시 데이터로 설정 session()->setFlashdata('word_alert', true); session()->setFlashdata('word_alert_text', '수고하셨습니다. ' . $repetition_count . "번째 학습이 끝났습니다."); session()->setFlashdata('word_alert_class', 'alert-primary'); // 예: 'alert-primary', 'alert-danger' return redirect()->to('/basicstart/'.$pid); } if (empty($interruptedKey[$pid])) { throw new \Exception('Invalid pid value, key not found in interrupted key.'); } $wordid = $interruptedKey[$pid]; $model = new WordModel(); $modelDetails = new WordDetailsModel(); $favoriteWordModel = new FavoriteWordModel(); $word = $model->getWord($wordid); if (!$word) { throw new \Exception('Word not found.'); } $wordDetails = $modelDetails->getWord_detailList($wordid); // examplesentence 분리 if (isset($word['examplesentence'])) { // 영어 문장과 한글 문장을 구분 $pattern = '/([A-Za-z0-9.,\'\"\-\s]+)([가-힣\s]+)/'; preg_match($pattern, $word['examplesentence'], $matches); $word['english_sentence'] = trim($matches[1] ?? ''); $word['korean_sentence'] = trim($matches[2] ?? ''); } else { $word['english_sentence'] = ''; $word['korean_sentence'] = ''; } //관심단어 확인 if ($favoriteWordModel->isFavorite($this->session->get('useremail'), $pid)) { $word['is_favorite'] = true; } else { $word['is_favorite'] = false; } // 데이터를 is_first_row 값에 따라 분리 list($first_row, $second_row) = split_by_is_first_row($wordDetails); $this->session->set('last_json_key', $pid); $viewData = [ 'word' => $word, 'pid' => $pid, 'max'=>$max_key, 'min'=>$min_key, 'first_row'=>$first_row, 'second_row' => $second_row ]; return $this->view('words', $viewData); } catch (\Exception $e) { // 예외 처리 return redirect()->to('/play')->with('error', $e->getMessage()); } } public function speedmodify($pid,$speed) { $this->checkLogin(); // 로그인 상태 체크 $this->session->set('screenlayout',$speed); return redirect()->to('/basicstart/'.$pid); } public function playdatajson() { $model = new DailyLearningLogModel(); // 날짜 형식을 YYYY-MM로 설정 $email = $this->session->get('useremail'); // 데이터베이스에서 데이터 검색 $data = $model->where('user_email',$email) ->select('num, todate, total_time,repetition_count,daily_words,last_json_key, interrupted_key') ->findAll(); // 이벤트 배열 생성 $events = []; foreach ($data as $item) { $returnTxt = " 공부시간 : ".$item['total_time']."분
반복횟수 : ".$item['repetition_count']."번
학습단어 : ".$item['daily_words']."개"; $events[] = [ "id" => $item['num'], "start" => $item['todate'], "editable" => false, "display" => "background", "color" => "blue", "description" => $returnTxt, ]; } // Response 객체를 이용하여 JSON으로 변환하여 반환 return $this->response->setJSON($events); } public function replaysession($date){ $this->checkLogin(); // 로그인 상태 체크 $email = $this->session->get('useremail'); $model = new DailyLearningLogModel(); $retestData = $model->where('user_email', $email)->where('todate', $date) ->select('num, todate, total_time, repetition_count, daily_words, last_json_key, interrupted_key') ->first(); if (!$retestData) { echo "false"; } else { // 데이터 접근 시에는 결과가 객체인지 배열인지에 따라 접근 방식을 조정 $ses_data = [ 'repetition_count' => $retestData['repetition_count'], 'daily_words' => $retestData['daily_words'], 'interrupted_key' => json_decode($retestData['interrupted_key'], true), 'last_studied_key' => $retestData['last_json_key'], ]; session()->set($ses_data); echo "ok"; } exit; //헤더 노출때문에 } }