where('user_id', $data['user_id'])->where('todate', $data['todate'])->first(); if (!$existingLog){ $log = $this->where('user_id', $data['user_id']) ->orderBy('todate', 'desc') ->limit(1) ->first(); if($log) { $interruptedKeys = json_decode($log['interrupted_key'], true); $maxkey = max(array_keys($interruptedKeys)) + 1; }else{ $maxkey = 1; } $learningInfojosn = json_decode($data['learningInfo'])->learning_data; $learningInfo = json_decode($learningInfojosn,true); $studyData = []; for ($i = $maxkey; $i < $maxkey + $data['daily_words']; $i++) { if (isset($learningInfo[$i])) { $studyData[$i] = $learningInfo[$i]; } else { break; } } $data['interrupted_key'] = json_encode($studyData); $data['last_json_key'] = $maxkey; $this->insert($data); $num = $this->getInsertID(); }else{ $num = $existingLog['num']; } $returndata = $this->where('num', $num)->first(); return $returndata; } public function logDailyLearning_mod($data) { try { $existingLog = $this->where('user_id', $data['user_id'])->where('todate', $data['todate'])->first(); if ($existingLog) { $log = $this->where('user_id', $data['user_id'])->where('todate <>', $data['todate']) ->orderBy('todate', 'desc') ->limit(1) ->first(); if ($log) { $interruptedKeys = json_decode($log['interrupted_key'], true); $maxkey = max(array_keys($interruptedKeys)) + 1; } else { $maxkey = 1; } $learningInfo = json_decode($data['learningInfo'], true); //전체 학습데이터 $studyData = []; for ($i = $maxkey; $i < $maxkey + $data['daily_words']; $i++) { if (isset($learningInfo[$i])) { $studyData[$i] = $learningInfo[$i]; } else { break; } } $data['interrupted_key'] = json_encode($studyData); $data['last_json_key'] = $maxkey; $this->update($existingLog['num'], $data); $num = $existingLog['num']; $returndata = $this->where('num', $num)->first(); return $returndata; }else{ throw new \Exception("The 'email' index is not defined in the provided data."); } }catch(\Exception $e){ log_message('error', 'today date null: ' . $e->getMessage()); throw $e; // Re-throw exception to be handled by the calling code } } public function getInterruptedKey($userId, $date) { return $this->select('interrupted_key')->where('user_id', $userId)->where('date', $date)->first(); } }