Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XAPI: Crud for tincan files imported - refs BT#16742
- Loading branch information
Showing
10 changed files
with
978 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/* For licensing terms, see /license.txt */ | ||
|
||
use Chamilo\PluginBundle\XApi\Importer\TinCanImporter; | ||
use Chamilo\PluginBundle\XApi\Parser\TinCanParser; | ||
|
||
require_once __DIR__.'/../../../main/inc/global.inc.php'; | ||
|
||
api_protect_course_script(true); | ||
api_protect_teacher_script(); | ||
|
||
$course = api_get_course_entity(); | ||
$session = api_get_session_entity(); | ||
|
||
$plugin = XApiPlugin::create(); | ||
$langAddActivity = $plugin->get_lang('AddActivity'); | ||
|
||
$frmActivity = new FormValidator('frm_activity', 'post', api_get_self().'?'.api_get_cidreq()); | ||
$frmActivity->addHeader($langAddActivity); | ||
$frmActivity->addFile('file', $plugin->get_lang('TinCanPackage')); | ||
$frmActivity->addButtonAdvancedSettings('advanced_params'); | ||
$frmActivity->addHtml('<div id="advanced_params_options" style="display:none">'); | ||
$frmActivity->addText('title', get_lang('Title'), false); | ||
$frmActivity->addTextarea('description', get_lang('Description')); | ||
$frmActivity->addHtml('</div>'); | ||
$frmActivity->addButtonImport(get_lang('Import')); | ||
$frmActivity->addRule('file', get_lang('ThisFileIsRequired'), 'required'); | ||
$frmActivity->addRule( | ||
'file', | ||
$plugin->get_lang('OnlyZipAllowed'), | ||
'filetype', | ||
['zip'] | ||
); | ||
$frmActivity->applyFilter('title', 'trim'); | ||
$frmActivity->applyFilter('description', 'trim'); | ||
|
||
if ($frmActivity->validate()) { | ||
$values = $frmActivity->exportValues(); | ||
$zipFileInfo = $_FILES['file']; | ||
|
||
try { | ||
$tinCanFile = TinCanImporter::create($zipFileInfo, $course)->import(); | ||
|
||
$toolLaunch = TinCanParser::create($tinCanFile, $course, $session)->parse(); | ||
} catch (Exception $e) { | ||
Display::addFlash( | ||
Display::return_message($e->getMessage(), 'error') | ||
); | ||
|
||
exit; | ||
} | ||
|
||
if (!empty($values['title'])) { | ||
$toolLaunch->setTitle($values['title']); | ||
} | ||
|
||
if (!empty($values['description'])) { | ||
$toolLaunch->setDescription($values['description']); | ||
} | ||
|
||
$em = Database::getManager(); | ||
$em->persist($toolLaunch); | ||
$em->flush(); | ||
|
||
$plugin->createLaunchCourseTool($toolLaunch); | ||
|
||
Display::addFlash( | ||
Display::return_message($plugin->get_lang('ActivityImported'), 'success') | ||
); | ||
|
||
header('Location: '.api_get_course_url()); | ||
exit; | ||
} | ||
|
||
$pageTitle = $plugin->get_title(); | ||
$pageContent = $frmActivity->returnForm(); | ||
|
||
$interbreadcrumb[] = ['url' => 'list.php', 'name' => $pageTitle]; | ||
|
||
$view = new Template($langAddActivity); | ||
$view->assign('header', $pageTitle); | ||
$view->assign('content', $pageContent); | ||
$view->display_one_col_template(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/* For licensing terms, see /license.txt */ | ||
|
||
use Chamilo\PluginBundle\Entity\XApi\ToolLaunch; | ||
use Symfony\Component\HttpFoundation\Request as HttpRequest; | ||
|
||
require_once __DIR__.'/../../../main/inc/global.inc.php'; | ||
|
||
api_protect_course_script(true); | ||
api_protect_teacher_script(); | ||
|
||
$request = HttpRequest::createFromGlobals(); | ||
|
||
$em = Database::getManager(); | ||
|
||
$toolLaunch = $em->find( | ||
ToolLaunch::class, | ||
$request->query->getInt('delete') | ||
); | ||
|
||
if (null === $toolLaunch | ||
|| $toolLaunch->getCourse()->getId() !== api_get_course_entity()->getId() | ||
) { | ||
api_not_allowed(true); | ||
} | ||
|
||
$plugin = XApiPlugin::create(); | ||
|
||
$courseTool = $plugin->getCourseToolFromLaunchTool($toolLaunch); | ||
|
||
$em = Database::getManager(); | ||
$em->remove($courseTool); | ||
$em->remove($toolLaunch); | ||
$em->flush(); | ||
|
||
Display::addFlash( | ||
Display::return_message($plugin->get_lang('ActivityDeleted'), 'success') | ||
); | ||
|
||
header('Location: '.api_get_course_url()); | ||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/* For licensing terms, see /license.txt */ | ||
|
||
use Chamilo\PluginBundle\Entity\XApi\ToolLaunch; | ||
use Symfony\Component\HttpFoundation\Request as HttpRequest; | ||
|
||
require_once __DIR__.'/../../../main/inc/global.inc.php'; | ||
|
||
api_protect_course_script(true); | ||
api_protect_teacher_script(); | ||
|
||
$request = HttpRequest::createFromGlobals(); | ||
|
||
$em = Database::getManager(); | ||
|
||
$toolLaunch = $em->find( | ||
ToolLaunch::class, | ||
$request->query->getInt('edit') | ||
); | ||
|
||
if (null === $toolLaunch) { | ||
header('Location: '.api_get_course_url()); | ||
exit; | ||
} | ||
|
||
$course = api_get_course_entity(); | ||
$session = api_get_session_entity(); | ||
|
||
$cidReq = api_get_cidreq(); | ||
|
||
$plugin = XApiPlugin::create(); | ||
|
||
$langEditActivity = $plugin->get_lang('EditActivity'); | ||
|
||
$frmActivity = new FormValidator('frm_activity', 'post', api_get_self()."?$cidReq&edit={$toolLaunch->getId()}"); | ||
$frmActivity->addHeader($langEditActivity); | ||
$frmActivity->addText('title', get_lang('Title')); | ||
$frmActivity->addTextarea('description', get_lang('Description')); | ||
$frmActivity->addButtonAdvancedSettings('advanced_params'); | ||
$frmActivity->addHtml('<div id="advanced_params_options" style="display:none">'); | ||
$frmActivity->addUrl('launch_url', $plugin->get_lang('ActivityLaunchUrl'), true); | ||
$frmActivity->addUrl('activity_id', $plugin->get_lang('ActivityId'), true); | ||
$frmActivity->addUrl('activity_type', $plugin->get_lang('ActivityType'), true); | ||
$frmActivity->addHtml('</div>'); | ||
$frmActivity->addButtonUpdate(get_lang('Update')); | ||
$frmActivity->applyFilter('title', 'trim'); | ||
$frmActivity->applyFilter('description', 'trim'); | ||
|
||
if ($frmActivity->validate()) { | ||
$values = $frmActivity->exportValues(); | ||
|
||
$toolLaunch | ||
->setTitle($values['title']) | ||
->setDescription(empty($values['description']) ? null : $values['description']) | ||
->setLaunchUrl($values['launch_url']) | ||
->setActivityId($values['activity_id']) | ||
->setActivityType($values['activity_type']); | ||
|
||
$courseTool = $plugin->getCourseToolFromLaunchTool($toolLaunch); | ||
$courseTool->setName($values['title']); | ||
|
||
$em->persist($courseTool); | ||
$em->persist($toolLaunch); | ||
$em->flush(); | ||
|
||
Display::addFlash( | ||
Display::return_message($plugin->get_lang('ActivityUpdated'), 'success') | ||
); | ||
|
||
header('Location: '.api_get_course_url()); | ||
exit; | ||
} | ||
|
||
$frmActivity->setDefaults( | ||
[ | ||
'title' => $toolLaunch->getTitle(), | ||
'description' => $toolLaunch->getDescription(), | ||
'activity_id' => $toolLaunch->getActivityId(), | ||
'activity_type' => $toolLaunch->getActivityType(), | ||
'launch_url' => $toolLaunch->getLaunchUrl(), | ||
] | ||
); | ||
|
||
$actions = Display::url( | ||
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM), | ||
'list.php?'.api_get_cidreq() | ||
); | ||
|
||
$pageTitle = $plugin->get_title(); | ||
$pageContent = $frmActivity->returnForm(); | ||
|
||
$interbreadcrumb[] = ['url' => 'list.php', 'name' => $pageTitle]; | ||
|
||
$view = new Template($langEditActivity); | ||
$view->assign('header', $pageTitle); | ||
$view->assign( | ||
'actions', | ||
Display::toolbarAction( | ||
'xapi_actions', | ||
[$actions] | ||
) | ||
); | ||
$view->assign('content', $pageContent); | ||
$view->display_one_col_template(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?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) { | ||
return $em | ||
->createQuery('SELECT COUNT(tl) FROM ChamiloPluginBundle:XApi\ToolLaunch tl') | ||
->getSingleScalarResult(); | ||
}, | ||
function ($start, $limit, $orderBy, $orderDir) use ($em) { | ||
$tools = $em->getRepository('ChamiloPluginBundle:XApi\ToolLaunch') | ||
->findBy( | ||
[], | ||
['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('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(); |
Oops, something went wrong.