exec("SET NAMES 'utf8mb4'"); // 현재년도 $currentYear = (int)date('Y'); // 현재 분기코드 (CA200Q01 ~ CA200Q04) $currentQuarterNum = (int)ceil((int)date('m') / 3); $currentQuarterCode = sprintf('CA200Q%02d', $currentQuarterNum); // --------------------------------------------------------- // 1. 마이클래스(CA10001) 진도율 // - 마이페이지와 동일 기준: // percent = SUM(watch_tm) / SUM(content_tm) * 100 // - 현재년도 기준: YEAR(last_viewed_at) = 현재년도 // --------------------------------------------------------- $stmtMyclass = $pdo->prepare(" SELECT fn_get_progress_rate(:sys_comp_code,:current_year,:member_id,'CA10001',:quarter_code) AS percent ; "); // $stmtMyclass = $pdo->prepare(" // SELECT // CASE // WHEN COALESCE(SUM(lh.content_tm), 0) > 0 // THEN ROUND(COALESCE(SUM(lh.watch_tm), 0) / SUM(lh.content_tm) * 100) // ELSE 0 // END AS percent // FROM edu_learning_histories lh // INNER JOIN edu_contents c // ON c.content_id = lh.content_id // WHERE lh.member_id = :member_id // AND lh.sys_comp_code = :sys_comp_code // AND c.category_code = 'CA10001' // AND YEAR(lh.last_viewed_at) = :current_year // "); $stmtMyclass->execute([ ':member_id' => $memberId, ':sys_comp_code' => $sysCompCode, ':current_year' => $currentYear, ':quarter_code' => $currentQuarterCode, ]); $header_myclass_percent = (int)$stmtMyclass->fetchColumn(); // --------------------------------------------------------- // 2. 온보딩(CA10002) 진도율 // - 마이페이지와 동일 기준: // percent = SUM(watch_tm) / SUM(content_tm) * 100 // - 현재년도 기준: YEAR(last_viewed_at) = 현재년도 // --------------------------------------------------------- $stmtOnboarding = $pdo->prepare(" SELECT fn_get_progress_rate(:sys_comp_code,:current_year,:member_id,'CA10002','') AS percent ; "); // $stmtOnboarding = $pdo->prepare(" // SELECT // CASE // WHEN COALESCE(SUM(lh.content_tm), 0) > 0 // THEN ROUND(COALESCE(SUM(lh.watch_tm), 0) / SUM(lh.content_tm) * 100) // ELSE 0 // END AS percent // FROM edu_learning_histories lh // INNER JOIN edu_contents c // ON c.content_id = lh.content_id // WHERE lh.member_id = :member_id // AND lh.sys_comp_code = :sys_comp_code // AND c.category_code = 'CA10002' // AND YEAR(lh.last_viewed_at) = :current_year // "); $stmtOnboarding->execute([ ':member_id' => $memberId, ':sys_comp_code' => $sysCompCode, ':current_year' => $currentYear, ]); $header_onboarding_percent = (int)$stmtOnboarding->fetchColumn(); // --------------------------------------------------------- // 3. 법정교육(CA10003) 진도율 // - 마이페이지와 동일 기준: // percent = SUM(watch_tm) / SUM(content_tm) * 100 // - 현재년도 기준: YEAR(last_viewed_at) = 현재년도 // --------------------------------------------------------- $stmtLegal = $pdo->prepare(" SELECT fn_get_progress_rate(:sys_comp_code,:current_year,:member_id,'CA10003','') AS percent ; "); // $stmtLegal = $pdo->prepare(" // SELECT // CASE // WHEN COALESCE(SUM(lh.content_tm), 0) > 0 // THEN ROUND(COALESCE(SUM(lh.watch_tm), 0) / SUM(lh.content_tm) * 100) // ELSE 0 // END AS percent // FROM edu_learning_histories lh // INNER JOIN edu_contents c // ON c.content_id = lh.content_id // WHERE lh.member_id = :member_id // AND lh.sys_comp_code = :sys_comp_code // AND c.category_code = 'CA10003' // AND YEAR(lh.last_viewed_at) = :current_year // "); $stmtLegal->execute([ ':member_id' => $memberId, ':sys_comp_code' => $sysCompCode, ':current_year' => $currentYear, ]); $header_legal_percent = (int)$stmtLegal->fetchColumn(); // --------------------------------------------------------- // 예외 방어: 0~100 범위 보정 // --------------------------------------------------------- $header_myclass_percent = max(0, min(100, $header_myclass_percent)); $header_onboarding_percent = max(0, min(100, $header_onboarding_percent)); $header_legal_percent = max(0, min(100, $header_legal_percent)); if($memberId=="M21420" ){ //echo "test=".$memberId.":".$header_myclass_percent; //echo "test=".$memberId.":".$header_onboarding_percent; //echo "test=".$memberId.":".$header_legal_percent; //exit; } } catch (Throwable $e) { // 헤더는 페이지 공통영역이므로, 오류가 나더라도 전체 화면이 죽지 않게 // 기본값 0 유지 $header_myclass_percent = 0; $header_onboarding_percent = 0; $header_legal_percent = 0; //echo "test 11=".$memberId.":".$header_myclass_percent; // 필요시 개발단계에서만 로그 확인 // error_log('[init_data_for_header.php] ' . $e->getMessage()); }