Skip to content
Snippets Groups Projects
Commit 4c22368c authored by bewe's avatar bewe
Browse files

fix: add video handling

parent d6121b7e
No related merge requests found
......@@ -31,28 +31,21 @@ if (isset($_POST['delete'])) {
$video_model->deleteVideo($video_id);
// Get all user IDs
$user_ids = $user_model->getAllUserIds();
// Loop through each user
foreach ($user_ids as $user_id) {
$user_id = $user_id['user_id'];
// Get the video count and finished video count for the user
$video_count = $video_model->getVideoCountByModuleId($module_id);
$video_finished_count = $progress_model->getUserVideoFinishedCount($user_id, $module_id);
// Check if all videos for the module are finished
if ($video_count == $video_finished_count) {
// Check if the user has progress for the module
$isProgress = $progress_model->isProgress($user_id, $module_id);
// If the user has no progress, add a module result
if ($isProgress == 0) {
$progress_model->addModuleResult($user_id, $module_id);
}
}
// If there are no videos for the module, delete progress
if ($video_count == 0) {
$progress_model->deleteProgress($user_id, $module_id);
}
......
......@@ -5,9 +5,11 @@ require_once '../../app/core/App.php';
require_once '../../app/core/Database.php';
require_once '../../app/models/VideoModel.php';
require_once '../../app/models/ProgressModel.php';
require_once '../../app/models/UserModel.php';
$video_model = new VideoModel();
$progress_model = new ProgressModel();
$user_model = new UserModel();
$xml = file_get_contents('php://input');
$data = json_decode($xml, true);
......@@ -32,8 +34,15 @@ if (isset($_POST['videoName']) && isset($_POST['new-video']) && isset($_POST['or
$video_model->addVideo($data);
$isProgress = $progress_model->isProgress($_POST['user_id'], $data['module_id']);
if ($isProgress == 1) {
$progress_model->deleteProgress($_POST['user_id'], $data['module_id']);
$userIds = $user_model->getAllUserIds();
foreach ($userIds as $user) {
$user_id = $user['user_id'];
$isProgress = $progress_model->isProgress($user_id, $data['module_id']);
if ($isProgress == 1) {
$progress_model->deleteProgress($user_id, $data['module_id']);
}
}
header('Location: /admin/manage/' . $_POST['languageId'] . '/' . $data['module_id']);
echo json_encode(array('status' => 'success', 'message' => 'Video created'));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment