90 lines
3.2 KiB
PHP
90 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Models\UserModel;
|
|
use App\Models\DailyLearningLogModel;
|
|
use App\Models\UserLearningInfoModel;
|
|
|
|
class UserController extends BaseController
|
|
{
|
|
public function editLearningGoal()
|
|
{
|
|
$this->checkLogin();
|
|
$model = new UserModel();
|
|
$id = $this->session->get('userid');
|
|
$data['user'] = $model->getUserByEmail($id);
|
|
|
|
if (!$data['user']) {
|
|
session()->setFlashdata('error', 'User not found.');
|
|
return redirect()->to('/'); // 에러 페이지로 리디렉션
|
|
}
|
|
|
|
return $this->view('edit_learning_goal', $data);
|
|
}
|
|
|
|
public function updateLearningGoal()
|
|
{
|
|
$this->checkLogin();
|
|
|
|
$model = new UserModel();
|
|
$id = $this->request->getPost('id');
|
|
$data = [
|
|
'learning_days' => implode(',', $this->request->getPost('learning_days')),
|
|
'daily_words' => $this->request->getPost('daily_words'),
|
|
'repetition' => $this->request->getPost('repetition'),
|
|
'review_percentage' => $this->request->getPost('review_percentage'),
|
|
'screenlayout' => $this->request->getPost('screen_layout'),
|
|
'test_mode' => $this->request->getPost('test_mode')
|
|
];
|
|
|
|
if ($model->updateUserLearning($id, $data)) {
|
|
|
|
$learningInfoModel = new UserLearningInfoModel();
|
|
$learningInfo = $learningInfoModel->getLearningInfoByUserId(session()->get('useremail'));
|
|
|
|
$dailydata = [
|
|
'user_id' => $id,
|
|
'todate' => date('Y-m-d'),
|
|
'daily_words' => $data['daily_words'], // 학습 단어 수 가져오기
|
|
'screenlayout' => $data['screenlayout'],
|
|
'review_percentage' => $data['review_percentage'],
|
|
'test_mode' => $data['test_mode'],
|
|
'repetition' => $data['repetition'],
|
|
'repetition_count' => 0,
|
|
'learningInfo' => $learningInfo['learning_data']
|
|
];
|
|
|
|
$DailyLearningLogModel = new DailyLearningLogModel();
|
|
$LearningData = $DailyLearningLogModel->logDailyLearning_mod($dailydata);
|
|
|
|
$ses_data = [
|
|
'repetition' => $data['repetition'],
|
|
'repetition_count' => 0,
|
|
'review_percentage' => $data['review_percentage'],
|
|
'screenlayout' => $data['screenlayout'],
|
|
'test_mode' => $data['test_mode'],
|
|
'daily_words' => $LearningData['daily_words'],
|
|
'interrupted_key' => json_decode($LearningData['interrupted_key'], true),
|
|
'last_studied_key' => $LearningData['last_json_key'],
|
|
];
|
|
session()->set($ses_data);
|
|
|
|
if($LearningData){
|
|
session()->setFlashdata('success', 'Learning goals updated successfully.');
|
|
return redirect()->to('/');
|
|
}else{
|
|
session()->setFlashdata('error', 'Failed to update learning goals session.');
|
|
return redirect()->to('/editLearningGoal');
|
|
}
|
|
|
|
} else {
|
|
session()->setFlashdata('error', 'Failed to update learning goals.');
|
|
return redirect()->to('/editLearningGoal');
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|