<commit_before><?php

namespace App\Http\Controllers\Teacher;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Models\LessonLog;
use App\Models\Term;
use App\Models\Sclass;
use App\Models\School;
use App\Models\Teacher;
use \DB;
use \Auth;
use App\Http\Requests\LessonLogRequest;
use App\Libaries\pinyinfirstchar;


class LessonLogController extends Controller
{
    public function store(Request $request)
    {
        //TODO DO not readd the same lessonlog with the sanme teacher classe and lesson
        $teachersId = \Auth::guard("teacher")->id();
        $sclassesId = $request->get('sclassesId');
        $lessonsId = $request->session()->get('chooseLessonsId');

        if (0 == $sclassesId) {
            return redirect()->back()->withInput()->withErrors('请选择班级！');
        }
        if (!isset($lessonsId)) {
            return redirect()->back()->withInput()->withErrors('请选择课程！');
        }
        $oldlLessonLog = LessonLog::where(['teachers_id' => $teachersId, "sclasses_id" => $sclassesId, "lessons_id" => $lessonsId])->first();
            


        if($oldlLessonLog) {
            $request->session()->forget('chooseLessonsId');
            $oldlLessonLog->status = 'open';
            $oldlLessonLog->update();
            return redirect('teacher/takeclass');
        }

        
        $lessonLog = new LessonLog();

        $lessonLog->teachers_id = \Auth::guard("teacher")->id();
        $lessonLog->sclasses_id = $request->get('sclasses_id');
        $lessonLog->lessons_id = $request->get('lessons_id');
        $lessonLog->rethink = $request->get('rethink');
        $lessonLog->status = 'open';
        // dd($lessonLog);die();
        if ($lessonLog->save()) {
            $request->session()->forget('chooseLessonsId');
            return redirect('teacher/takeclass');
        } else {
            return redirect()->back()->withInput()->withErrors('保存失败！');
        }
    }

    public function update(Request $request)
    {
        $lessonLogId = $request->get('lessonLogId');
        $action = $request->get('action');
        if ("close-lesson-log" == $action) {
            $lessonLog = LessonLog::where(['id' => $lessonLogId])->first();
            $lessonLog->status = 'close';
        }
        if ($lessonLog->update()) {
            return "true";<commit_msg>update create lesson log at LessonLogController store<commit_after><?php

namespace App\Http\Controllers\Teacher;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Models\LessonLog;
use App\Models\Term;
use App\Models\Sclass;
use App\Models\School;
use App\Models\Teacher;
use \DB;
use \Auth;
use App\Http\Requests\LessonLogRequest;
use App\Libaries\pinyinfirstchar;


class LessonLogController extends Controller
{
    public function store(Request $request)
    {
        //TODO DO not readd the same lessonlog with the sanme teacher classe and lesson
        $teachersId = \Auth::guard("teacher")->id();
        $sclassesId = $request->get('sclassesId');
        $lessonsId = $request->session()->get('chooseLessonsId');

        if (0 == $sclassesId) {
            return redirect()->back()->withInput()->withErrors('请选择班级！');
        }
        if (!isset($lessonsId)) {
            return redirect()->back()->withInput()->withErrors('请选择课程！');
        }
        $oldlLessonLog = LessonLog::where(['teachers_id' => $teachersId, "sclasses_id" => $sclassesId, "lessons_id" => $lessonsId])->first();
            


        if($oldlLessonLog) {
            $request->session()->forget('chooseLessonsId');
            $oldlLessonLog->status = 'open';
            $oldlLessonLog->update();
            return redirect('teacher/takeclass');
        }

        
        $lessonLog = new LessonLog();

        $lessonLog->teachers_id = \Auth::guard("teacher")->id();
        $lessonLog->sclasses_id = $sclassesId;
        $lessonLog->lessons_id = $lessonsId;
        $lessonLog->rethink = "";
        $lessonLog->status = 'open';
        // dd($lessonLog);die();
        if ($lessonLog->save()) {
            $request->session()->forget('chooseLessonsId');
            return redirect('teacher/takeclass');
        } else {
            return redirect()->back()->withInput()->withErrors('保存失败！');
        }
    }

    public function update(Request $request)
    {
        $lessonLogId = $request->get('lessonLogId');
        $action = $request->get('action');
        if ("close-lesson-log" == $action) {
            $lessonLog = LessonLog::where(['id' => $lessonLogId])->first();
            $lessonLog->status = 'close';
        }
        if ($lessonLog->update()) {
            return "true";
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.00043010752688172043, 'mean_word_length': 2.6737756714060033, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1686941', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1450, 'n_words': 240}