XAPI: Manage tincan packages in one course tool - refs BT#16742

pull/3680/head
Angel Fernando Quiroz Campos 6 years ago
parent 2cbca90be0
commit 40173e07a4
  1. 2
      plugin/xapi/src/Hook/XApiCreateCourseHookObserver.php
  2. 53
      plugin/xapi/src/XApiPlugin.php
  3. 6
      plugin/xapi/tincan/add.php
  4. 3
      plugin/xapi/tincan/delete.php
  5. 8
      plugin/xapi/tincan/edit.php
  6. 127
      plugin/xapi/tincan/index.php
  7. 105
      plugin/xapi/tincan/list.php
  8. 4
      plugin/xapi/tincan/stats.php
  9. 15
      plugin/xapi/tincan/tool.php

@ -31,7 +31,7 @@ class XApiCreateCourseHookObserver extends HookObserver implements HookCreateCou
$plugin = XApiPlugin::create();
if (HOOK_EVENT_TYPE_POST == $type) {
$plugin->addCourseTool($courseInfo['real_id']);
$plugin->addCourseToolForTinCan($courseInfo['real_id']);
}
}
}

@ -386,13 +386,13 @@ class XApiPlugin extends Plugin implements HookPluginInterface
/**
* @param int $courseId
*/
public function addCourseTool($courseId)
public function addCourseToolForTinCan($courseId)
{
$this->createLinkToCourseTool(
$this->get_title().':teacher',
$this->get_title(),
$courseId,
null,
'xapi/tincan/list.php'
'xapi/tincan/index.php'
);
}
@ -403,7 +403,7 @@ class XApiPlugin extends Plugin implements HookPluginInterface
->getResult();
foreach ($courses as $course) {
$this->addCourseTool($course['id']);
$this->addCourseToolForTinCan($course['id']);
}
}
@ -411,50 +411,7 @@ class XApiPlugin extends Plugin implements HookPluginInterface
{
Database::getManager()
->createQuery('DELETE FROM ChamiloCourseBundle:CTool t WHERE t.category = :category AND t.link LIKE :link')
->execute(['category' => 'plugin', 'link' => 'xapi/tincan/list.php%']);
Database::getManager()
->createQuery('DELETE FROM ChamiloCourseBundle:CTool t WHERE t.category = :category AND t.link LIKE :link')
->execute(['category' => 'plugin', 'link' => 'xapi/tincan/tool.php%']);
}
/**
* @param \Chamilo\PluginBundle\Entity\XApi\ToolLaunch $toolLaunch
*
* @return \Chamilo\CourseBundle\Entity\CTool|null
*/
public function createLaunchCourseTool(ToolLaunch $toolLaunch)
{
$link ='xapi/tincan/tool.php?'.http_build_query(
[
'id' => $toolLaunch->getId(),
]
);
return $this->createLinkToCourseTool(
$toolLaunch->getTitle(),
$toolLaunch->getCourse()->getId(),
null,
$link
);
}
/**
* @param \Chamilo\PluginBundle\Entity\XApi\ToolLaunch $toolLaunch
*
* @return \Chamilo\CourseBundle\Entity\CTool
*/
public function getCourseToolFromLaunchTool(ToolLaunch $toolLaunch)
{
/** @var CTool $tool */
$tool = Database::getManager()
->getRepository(CTool::class)
->findOneBy([
'link' => 'xapi/tincan/tool.php?id='.$toolLaunch->getId(),
'cId' => $toolLaunch->getCourse()->getId(),
]);
return $tool;
->execute(['category' => 'plugin', 'link' => 'xapi/tincan/index.php%']);
}
/**

@ -106,8 +106,6 @@ if ($frmActivity->validate()) {
$em->persist($toolLaunch);
$em->flush();
$plugin->createLaunchCourseTool($toolLaunch);
Display::addFlash(
Display::return_message($plugin->get_lang('ActivityImported'), 'success')
);
@ -120,12 +118,12 @@ $frmActivity->setDefaults(['allow_multiple_attempts' => true]);
$actions = Display::url(
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
'list.php?'.api_get_cidreq()
'index.php?'.api_get_cidreq()
);
$pageContent = $frmActivity->returnForm();
$interbreadcrumb[] = ['url' => 'list.php', 'name' => $plugin->get_title()];
$interbreadcrumb[] = ['url' => 'index.php', 'name' => $plugin->get_title()];
$view = new Template($langAddActivity);
$view->assign('header', $langAddActivity);

@ -27,10 +27,7 @@ if (null === $toolLaunch
$plugin = XApiPlugin::create();
$courseTool = $plugin->getCourseToolFromLaunchTool($toolLaunch);
$em = Database::getManager();
$em->remove($courseTool);
$em->remove($toolLaunch);
$em->flush();

@ -96,10 +96,6 @@ if ($frmActivity->validate()) {
->setLrsAuthPassword($values['lrs_auth_password']);
}
$courseTool = $plugin->getCourseToolFromLaunchTool($toolLaunch);
$courseTool->setName($values['title']);
$em->persist($courseTool);
$em->persist($toolLaunch);
$em->flush();
@ -127,12 +123,12 @@ $frmActivity->setDefaults(
$actions = Display::url(
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
'list.php?'.api_get_cidreq()
'index.php?'.api_get_cidreq()
);
$pageContent = $frmActivity->returnForm();
$interbreadcrumb[] = ['url' => 'list.php', 'name' => $plugin->get_title()];
$interbreadcrumb[] = ['url' => 'index.php', 'name' => $plugin->get_title()];
$view = new Template($langEditActivity);
$view->assign('header', $langEditActivity);

@ -0,0 +1,127 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\PluginBundle\Entity\XApi\ToolLaunch;
require_once __DIR__.'/../../../main/inc/global.inc.php';
api_protect_course_script(true);
api_block_anonymous_users();
$plugin = XApiPlugin::create();
$isAllowedToEdit = api_is_allowed_to_edit();
$em = Database::getManager();
$course = api_get_course_entity();
$session = api_get_session_entity();
$cidReq = api_get_cidreq();
$table = new SortableTable(
'tbl_xapi',
function () use ($em, $course) {
return $em
->createQuery('SELECT COUNT(tl) FROM ChamiloPluginBundle:XApi\ToolLaunch tl WHERE tl.course = :course')
->setParameter('course', $course)
->getSingleScalarResult();
},
function ($start, $limit, $orderBy, $orderDir) use ($em, $course, $isAllowedToEdit) {
$tools = $em->getRepository('ChamiloPluginBundle:XApi\ToolLaunch')
->findBy(
['course' => $course],
['title' => $orderDir],
$limit,
$start
);
$data = [];
/** @var ToolLaunch $toolLaunch */
foreach ($tools as $toolLaunch) {
$datum = [];
$datum[] = [$toolLaunch->getId(), $toolLaunch->getTitle(), $toolLaunch->getDescription()];
if ($isAllowedToEdit) {
$datum[] = $toolLaunch->getId();
}
$data[] = $datum;
}
return $data;
},
0
);
$table->set_header(0, $plugin->get_lang('ActivityTitle'), true);
$table->set_column_filter(
0,
function (array $toolInfo) use ($cidReq) {
list($id, $title, $description) = $toolInfo;
$data = Display::url($title, "tool.php?id=$id&$cidReq", ['class' => 'show']);
if ($description) {
$data .= PHP_EOL.Display::tag('small', $description, ['class' => 'text-muted']);
}
return $data;
}
);
if ($isAllowedToEdit) {
$table->set_header(1, get_lang('Actions'), false, ['class' => 'text-right'], ['class' => 'text-right']);
$table->set_column_filter(
1,
function ($id) use ($cidReq, $isAllowedToEdit) {
$actions = [];
if ($isAllowedToEdit) {
$actions[] = Display::url(
Display::return_icon('statistics.png', get_lang('Reporting')),
"stats.php?$cidReq&id=$id"
);
$actions[] = Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
"edit.php?$cidReq&edit=$id"
);
$actions[] = Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
"delete.php?$cidReq&delete=$id"
);
}
return implode(PHP_EOL, $actions);
}
);
}
$pageTitle = $plugin->get_title();
$pageContent = Display::return_message($plugin->get_lang('NoActivities'), 'info');
if ($table->get_total_number_of_items() > 0) {
$pageContent = $table->return_table();
}
$view = new Template($pageTitle);
$view->assign('header', $pageTitle);
if ($isAllowedToEdit) {
$actions = Display::url(
Display::return_icon('add.png', get_lang('Add'), [], ICON_SIZE_MEDIUM),
"add.php?$cidReq"
);
$view->assign(
'actions',
Display::toolbarAction(
'xapi_actions',
[$actions]
)
);
}
$view->assign('content', $pageContent);
$view->display_one_col_template();

@ -1,105 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\PluginBundle\Entity\XApi\ToolLaunch;
require_once __DIR__.'/../../../main/inc/global.inc.php';
api_protect_course_script(true);
api_protect_teacher_script();
$plugin = XApiPlugin::create();
$em = Database::getManager();
$course = api_get_course_entity();
$session = api_get_session_entity();
$cidReq = api_get_cidreq();
$table = new SortableTable(
'tbl_xapi',
function () use ($em, $course) {
return $em
->createQuery('SELECT COUNT(tl) FROM ChamiloPluginBundle:XApi\ToolLaunch tl WHERE tl.course = :course')
->setParameter('course', $course)
->getSingleScalarResult();
},
function ($start, $limit, $orderBy, $orderDir) use ($em, $course) {
$tools = $em->getRepository('ChamiloPluginBundle:XApi\ToolLaunch')
->findBy(
['course' => $course],
['title' => $orderDir],
$limit,
$start
);
return array_map(
function (ToolLaunch $toolLaunch) {
return [
[$toolLaunch->getTitle(), $toolLaunch->getDescription()],
$toolLaunch->getId(),
];
},
$tools
);
},
0
);
$table->set_header(0, $plugin->get_lang('ActivityTitle'), true);
$table->set_header(1, get_lang('Actions'), false, ['class' => 'text-right'], ['class' => 'text-right']);
$table->set_column_filter(
0,
function (array $toolInfo) {
list($title, $description) = $toolInfo;
return "<span class='show'>$title</span>"
.($description ? "<small class='text-muted'>$description</small>" : null);
}
);
$table->set_column_filter(
1,
function ($id) use ($cidReq) {
$actions = [];
$actions[] = Display::url(
Display::return_icon('statistics.png', get_lang('Reporting')),
"stats.php?$cidReq&id=$id"
);
$actions[] = Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
"edit.php?$cidReq&edit=$id"
);
$actions[] = Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
"delete.php?$cidReq&delete=$id"
);
return implode(PHP_EOL, $actions);
}
);
$actions = Display::url(
Display::return_icon('add.png', get_lang('Add'), [], ICON_SIZE_MEDIUM),
"add.php?$cidReq"
);
$pageTitle = $plugin->get_title();
if ($table->get_total_number_of_items() > 0) {
$pageContent = $table->return_table();
} else {
$pageContent = Display::return_message($plugin->get_lang('NoActivities'), 'info');
}
$view = new Template($pageTitle);
$view->assign('header', $pageTitle);
$view->assign(
'actions',
Display::toolbarAction(
'xapi_actions',
[$actions]
)
);
$view->assign('content', $pageContent);
$view->display_one_col_template();

@ -107,7 +107,7 @@ $content .= $pagination;
// View
$interbreadcrumb[] = [
'name' => $plugin->get_title(),
'url' => 'list.php',
'url' => 'index.php',
];
$htmlHeadXtra[] = "<script>
@ -148,7 +148,7 @@ $htmlHeadXtra[] = "<script>
$actions = Display::url(
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
"list.php?$cidReq"
"index.php?$cidReq"
);
$view = new Template($toolLaunch->getTitle());

@ -140,6 +140,8 @@ if ($stateDocument) {
$table->setColAttributes(2, ['class' => 'text-center']);
}
$interbreadcrumb[] = ['url' => 'index.php', 'name' => $plugin->get_title()];
$pageTitle = $toolLaunch->getTitle();
$pageContent = '';
@ -161,8 +163,21 @@ if ($stateDocument) {
$pageContent .= $table->toHtml();
}
$actions = Display::url(
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
'index.php?'.api_get_cidreq()
);
$view = new Template($pageTitle);
$view->assign('header', $pageTitle);
$view->assign(
'actions',
Display::toolbarAction(
'xapi_actions',
[$actions]
)
);
$view->assign('content', $pageContent);
$view->display_one_col_template();

Loading…
Cancel
Save