Skip to content

Commit

Permalink
Course units: add h5p content as resource.
Browse files Browse the repository at this point in the history
--HG--
branch : 3.12
  • Loading branch information
jexi committed Oct 4, 2021
1 parent 4477c23 commit 3e6a0c5
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lang/el/messages.inc.php
Expand Up @@ -5908,6 +5908,7 @@
$langH5p = "Διαδραστικό περιεχόμενο";
$langH5pUpdateComplete = 'Η ενημέρωση των πακέτων και βιβλιοθηκών ολοκληρώθηκε!';
$langH5pInteractiveContent = 'Διαδραστικό περιεχόμενο τύπου H5P';
$langH5pNoContent = 'Δεν υπάρχει περιεχόμενο τύπου H5P';
$langH5pNoContent = 'Δεν υπάρχει διαδραστικό περιεχόμενο τύπου H5P';
$langH5pSaveSuccess = "Το διαδραστικό περιεχόμενο τύπου H5P αποθηκεύτηκε με επιτυχία";
$langH5pDeleteSuccess = "Το διαδραστικό περιεχόμενο τύπου H5P διαγράφτηκε με επιτυχία";
$langOfH5p = "διαδραστικού περιεχομένου";
1 change: 1 addition & 0 deletions lang/en/messages.inc.php
Expand Up @@ -5410,3 +5410,4 @@
$langH5pNoContent = 'There is no H5P content';
$langH5pSaveSuccess = "The H5P interactive content was successfully saved";
$langH5pDeleteSuccess = "The H5P interactive content was successfully deleted";
$langOfH5p = "interactive content";
44 changes: 44 additions & 0 deletions modules/units/functions.php
Expand Up @@ -302,6 +302,9 @@ function show_resource($info) {
case 'blog':
$tool_content .= show_blog($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
break;
case 'h5p':
$tool_content .= show_h5p($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
break;
case 'tc':
$tool_content .= show_tc($info->title, $info->comments, $info->id, $info->res_id, $info->visible);
break;
Expand Down Expand Up @@ -1254,6 +1257,47 @@ function show_blog($title, $comments, $resource_id, $blog_id, $visibility) {
</tr>';
}

/**
* @brief display h5p resources
* @param $title
* @param $comments
* @param $resource_id
* @param $h5p_id
* @param $visibility
*/
function show_h5p($title, $comments, $resource_id, $h5p_id, $visibility) {
global $urlServer, $is_editor, $langWasDeleted, $course_id, $course_code, $id;

$comment_box = '';
$title = q($title);
$h5p = Database::get()->querySingle("SELECT * FROM h5p_content WHERE course_id = ?d AND id = ?d", $course_id, $h5p_id);
if (!$h5p) { // check if it was deleted
if (!$is_editor) {
return '';
} else {
$imagelink = icon('fa-times');
$h5plink = "<span class='not_visible'>$title ($langWasDeleted)</span>";
}
} else {
//$link = "<a href='${urlServer}modules/units/view.php?course=$course_code&amp;res_type=chat&amp;conference_id=$chat_id&amp;unit=$id'>";
$link = "<a href='${urlServer}modules/h5p/view.php?course=$course_code&amp;id=$h5p_id'>";
$h5plink = $link . "$title</a>";
$imagelink = $link . "</a>" .icon('fa-tablet') . "";
}

if (!empty($comments)) {
$comment_box = "<br />$comments";
}

return "
<tr data-id='$resource_id'>
<td width='1'>$imagelink</td>
<td>$h5plink $comment_box</td>" .
actions('h5p', $resource_id, $visibility) . '
</tr>';

}


/**
* @brief display tc resources
Expand Down
5 changes: 5 additions & 0 deletions modules/units/index.php
Expand Up @@ -122,6 +122,11 @@
'icon' => 'fa fa-pencil-square-o',
'level' => 'secondary',
'show' => !is_module_disable(MODULE_ID_EXERCISE)),
array('title' => $langAdd.' '.$langOfH5p,
'url' => $base_url . 'h5p',
'icon' => 'fa fa-tablet',
'level' => 'secondary',
'show' => !is_module_disable(MODULE_ID_H5P)),
array('title' => $langAdd.' '.$langLearningPath1,
'url' => $base_url . 'lp',
'icon' => 'fa fa-ellipsis-h',
Expand Down
30 changes: 30 additions & 0 deletions modules/units/insert.php
Expand Up @@ -66,6 +66,8 @@
insert_text($id);
} elseif (isset($_POST['submit_lp'])) {
insert_lp($id);
} elseif (isset($_POST['submit_h5p'])) {
insert_h5p($id);
} elseif (isset($_POST['submit_video'])) {
insert_video($id);
} elseif (isset($_POST['submit_exercise'])) {
Expand Down Expand Up @@ -147,6 +149,10 @@
include "insert_tc.php";
list_tcs();
break;
case 'h5p': $pageName = "$langAdd $langOfH5p";
include "insert_h5p.php";
list_h5p();
break;
default: break;
}

Expand Down Expand Up @@ -262,6 +268,30 @@ function insert_lp($id) {
exit;
}

/**
* @brief insert h5p in database
* @param $id
*/
function insert_h5p($id) {
global $course_code, $course_id;

if(isset($_POST['h5p'])) {
$order = Database::get()->querySingle("SELECT MAX(`order`) AS maxorder FROM unit_resources WHERE unit_id = ?d", $id)->maxorder;
foreach ($_POST['h5p'] as $h5p_id) {
$order++;
$h5p = Database::get()->querySingle("SELECT * FROM h5p_content WHERE course_id = ?d AND id = ?d", $course_id, $h5p_id);
$q = Database::get()->query("INSERT INTO unit_resources SET unit_id = ?d, type='h5p', title = ?s, comments = '',
visible = 1, `order` = ?d, `date` = " . DBHelper::timeAfter() . ", res_id = ?d",
$id, $h5p->title, $order, $h5p->id);
$uresId = $q->lastInsertID;
Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_UNITRESOURCE, $uresId);
}
Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_COURSE, $course_id);
CourseXMLElement::refreshCourse($course_id, $course_code);
}
header('Location: index.php?course=' . $course_code . '&id=' . $id);
exit;
}

/**
* @brief insert video in database
Expand Down
39 changes: 39 additions & 0 deletions modules/units/insert_h5p.php
@@ -0,0 +1,39 @@
<?php

/**
* @brief display available h5p
*/
function list_h5p() {
global $id, $course_id, $tool_content, $urlServer,
$langAddModulesButton, $langChoice, $langH5pNoContent,
$course_code, $langH5p;

$result = Database::get()->queryArray("SELECT * FROM h5p_content WHERE course_id = ?d ORDER BY title", $course_id);
$h5pinfo = array();
foreach ($result as $row) {
$h5pinfo[] = array(
'id' => $row->id,
'title' => $row->title);
}
if (count($h5pinfo) == 0) {
$tool_content .= "<div class='alert alert-warning'>$langH5pNoContent</div>";
} else {
$tool_content .= "<form action='insert.php?course=$course_code' method='post'>" .
"<input type='hidden' name='id' value='$id'>" .
"<table class='table-default'>" .
"<tr class='list-header'>" .
"<th><div class='text-left'>&nbsp;$langH5p</div></th>" .
"<th width='80'>$langChoice</th>" .
"</tr>";
foreach ($h5pinfo as $entry) {
$tool_content .= "<tr>";
$tool_content .= "<td>&nbsp;" . icon('fa fa-tablet') . "&nbsp;&nbsp;<a href='${urlServer}modules/h5p/view.php?id=$entry[id]&amp;course=$course_code'>" . q($entry['title']) . "</a></td>";
$tool_content .= "<td class='text-center'><input type='checkbox' name='h5p[]' value='$entry[id]'></td>";
$tool_content .= "</tr>";
}
$tool_content .= "</table>";
$tool_content .= "<div class='text-right'>";
$tool_content .= "<input class='btn btn-primary' type='submit' name='submit_h5p' value='$langAddModulesButton'></div></form>";

}
}

0 comments on commit 3e6a0c5

Please sign in to comment.