Initial commit: 교육 프로젝트 배포
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
//=========================
|
||||
// 헤더 진도율 초기데이터
|
||||
// - 마이클래스 / 온보딩 / 법정교육
|
||||
// - 현재년도 기준
|
||||
// - 마이페이지 "나의 학습 활동"과 동일한 시간기준 진도율 사용
|
||||
//=========================
|
||||
require_once __DIR__ . '/../bbs/db_conn.php';
|
||||
|
||||
// 세션 시작
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// TODO: 실제 로그인 세션 연동 후 교체
|
||||
$memberId = $_SESSION['member_id'] ?? '';
|
||||
$sysCompCode = $_SESSION['sys_comp_code'] ?? '';
|
||||
// $memberId = 'U001';
|
||||
// $sysCompCode = 'COMP01';
|
||||
|
||||
|
||||
/*
|
||||
// ---------------------------------------------------------
|
||||
// 헤더에서 바로 사용할 기본 변수
|
||||
// ---------------------------------------------------------
|
||||
$header_myclass_percent = 0;
|
||||
$header_onboarding_percent = 0;
|
||||
$header_legal_percent = 0;
|
||||
*/
|
||||
// ---------------------------------------------------------
|
||||
// 세션값이 없으면 기본값 0으로 종료
|
||||
// ---------------------------------------------------------
|
||||
if ($memberId === '' || $sysCompCode === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = db_conn();
|
||||
$pdo->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());
|
||||
}
|
||||
Reference in New Issue
Block a user