Initial commit: 교육 프로젝트 배포
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once dirname(__DIR__, 2) . '/db_conn.php';
|
||||
|
||||
$memberId = (string)($_SESSION['member_id'] ?? $_SESSION['user_id'] ?? '');
|
||||
$sysCompCode = (string)($_SESSION['sys_comp_code'] ?? $_SESSION['company'] ?? '');
|
||||
|
||||
if ($memberId === '') {
|
||||
http_response_code(401);
|
||||
echo json_encode(['success' => false, 'message' => 'not_logged_in'], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rawBody = file_get_contents('php://input');
|
||||
$input = is_string($rawBody) && $rawBody !== '' ? json_decode($rawBody, true) : [];
|
||||
if (!is_array($input)) {
|
||||
$input = $_POST;
|
||||
}
|
||||
|
||||
$contentId = trim((string)($input['content_id'] ?? ''));
|
||||
if ($contentId === '') {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'content_id_required'], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = db_conn();
|
||||
|
||||
// 학습 이력 조회
|
||||
$sql = 'SELECT watch_tm, content_tm, completed_at, last_viewed_at
|
||||
FROM edu_learning_histories
|
||||
WHERE member_id = ? AND content_id = ?';
|
||||
$params = [$memberId, $contentId];
|
||||
|
||||
if ($sysCompCode !== '') {
|
||||
$sql .= ' AND sys_comp_code = ?';
|
||||
$params[] = $sysCompCode;
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY last_viewed_at DESC LIMIT 1';
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// 콘텐츠 상세정보 조회 (description)
|
||||
$stmtContent = $pdo->prepare('SELECT description FROM edu_contents WHERE content_id = ? LIMIT 1');
|
||||
$stmtContent->execute([$contentId]);
|
||||
$contentRow = $stmtContent->fetch(PDO::FETCH_ASSOC);
|
||||
$description = ($contentRow['description'] ?? '');
|
||||
|
||||
// 북마크 상태 조회
|
||||
$bookmarkSql = 'SELECT is_active FROM edu_content_wishlist WHERE content_id = ? AND member_id = ?';
|
||||
$bookmarkParams = [$contentId, $memberId];
|
||||
if ($sysCompCode !== '') {
|
||||
$bookmarkSql .= ' AND sys_comp_code = ?';
|
||||
$bookmarkParams[] = $sysCompCode;
|
||||
}
|
||||
$bookmarkSql .= ' LIMIT 1';
|
||||
$stmtBookmark = $pdo->prepare($bookmarkSql);
|
||||
$stmtBookmark->execute($bookmarkParams);
|
||||
$bookmarkRow = $stmtBookmark->fetch(PDO::FETCH_ASSOC);
|
||||
$isBookmarked = (($bookmarkRow['is_active'] ?? '0') === '1');
|
||||
|
||||
$result = [
|
||||
'success' => true,
|
||||
'watch_tm' => (int)($row['watch_tm'] ?? 0),
|
||||
'content_tm' => (int)($row['content_tm'] ?? 0),
|
||||
'completed_at' => $row['completed_at'] ?? null,
|
||||
'last_viewed_at' => $row['last_viewed_at'] ?? null,
|
||||
'description' => $description,
|
||||
'is_bookmarked' => $isBookmarked,
|
||||
];
|
||||
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
} catch (Throwable $e) {
|
||||
error_log('[get_video_time] ' . $e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'server_error'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
Reference in New Issue
Block a user