parent
b10ebaefd3
commit
ae04beda71
@ -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(); |
||||
@ -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; |
||||
@ -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(); |
||||
@ -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(); |
||||
@ -0,0 +1,285 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\Entity\XApi; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use DateTime; |
||||
use Doctrine\ORM\Mapping as ORM; |
||||
|
||||
/** |
||||
* Class ToolLaunch. |
||||
* |
||||
* @package Chamilo\PluginBundle\Entity\XApi |
||||
* |
||||
* @ORM\Table(name="xapi_tool_launch") |
||||
* @ORM\Entity() |
||||
*/ |
||||
class ToolLaunch |
||||
{ |
||||
/** |
||||
* @var int |
||||
* |
||||
* @ORM\Column(type="integer") |
||||
* @ORM\Id() |
||||
* @ORM\GeneratedValue() |
||||
*/ |
||||
private $id; |
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="title", type="string") |
||||
*/ |
||||
private $title; |
||||
/** |
||||
* @var string|null |
||||
* |
||||
* @ORM\Column(name="description", type="text", nullable=true) |
||||
*/ |
||||
private $description; |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\Course |
||||
* |
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course") |
||||
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false) |
||||
*/ |
||||
private $course; |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\Session|null |
||||
* |
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") |
||||
* @ORM\JoinColumn(name="session_id", referencedColumnName="id") |
||||
*/ |
||||
private $session; |
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="launch_url", type="string") |
||||
*/ |
||||
private $launchUrl; |
||||
/** |
||||
* @var string|null |
||||
* |
||||
* @ORM\Column(name="activity_id", type="string", nullable=true) |
||||
*/ |
||||
private $activityId; |
||||
/** |
||||
* @var string|null |
||||
* |
||||
* @ORM\Column(name="activity_verb_id", type="string", nullable=true) |
||||
*/ |
||||
private $activityVerbId; |
||||
/** |
||||
* @var string|null |
||||
* |
||||
* @ORM\Column(name="activity_type", type="string", nullable=true) |
||||
*/ |
||||
private $activityType; |
||||
/*** |
||||
* @var \DateTime |
||||
* |
||||
* @ORM\Column(name="created_at", type="datetime") |
||||
*/ |
||||
private $createdAt; |
||||
|
||||
/** |
||||
* @return int |
||||
*/ |
||||
public function getId(): int |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setId(int $id): ToolLaunch |
||||
{ |
||||
$this->id = $id; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function getTitle(): string |
||||
{ |
||||
return $this->title; |
||||
} |
||||
|
||||
/** |
||||
* @param string $title |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setTitle(string $title): ToolLaunch |
||||
{ |
||||
$this->title = $title; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return string|null |
||||
*/ |
||||
public function getDescription(): ?string |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
/** |
||||
* @param string|null $description |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setDescription(?string $description): ToolLaunch |
||||
{ |
||||
$this->description = $description; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return \Chamilo\CoreBundle\Entity\Course |
||||
*/ |
||||
public function getCourse(): Course |
||||
{ |
||||
return $this->course; |
||||
} |
||||
|
||||
/** |
||||
* @param \Chamilo\CoreBundle\Entity\Course $course |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setCourse(Course $course): ToolLaunch |
||||
{ |
||||
$this->course = $course; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return \Chamilo\CoreBundle\Entity\Session|null |
||||
*/ |
||||
public function getSession(): ?Session |
||||
{ |
||||
return $this->session; |
||||
} |
||||
|
||||
/** |
||||
* @param \Chamilo\CoreBundle\Entity\Session|null $session |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setSession(?Session $session): ToolLaunch |
||||
{ |
||||
$this->session = $session; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function getLaunchUrl(): string |
||||
{ |
||||
return $this->launchUrl; |
||||
} |
||||
|
||||
/** |
||||
* @param string $launchUrl |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setLaunchUrl(string $launchUrl): ToolLaunch |
||||
{ |
||||
$this->launchUrl = $launchUrl; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return string|null |
||||
*/ |
||||
public function getActivityId(): ?string |
||||
{ |
||||
return $this->activityId; |
||||
} |
||||
|
||||
/** |
||||
* @param string|null $activityId |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setActivityId(?string $activityId): ToolLaunch |
||||
{ |
||||
$this->activityId = $activityId; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return string|null |
||||
*/ |
||||
public function getActivityVerbId(): ?string |
||||
{ |
||||
return $this->activityVerbId; |
||||
} |
||||
|
||||
/** |
||||
* @param string|null $activityVerbId |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setActivityVerbId(?string $activityVerbId): ToolLaunch |
||||
{ |
||||
$this->activityVerbId = $activityVerbId; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return \DateTime |
||||
*/ |
||||
public function getCreatedAt(): DateTime |
||||
{ |
||||
return $this->createdAt; |
||||
} |
||||
|
||||
/** |
||||
* @param \DateTime $createdAt |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setCreatedAt(DateTime $createdAt): ToolLaunch |
||||
{ |
||||
$this->createdAt = $createdAt; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return string|null |
||||
*/ |
||||
public function getActivityType(): ?string |
||||
{ |
||||
return $this->activityType; |
||||
} |
||||
|
||||
/** |
||||
* @param string|null $activityType |
||||
* |
||||
* @return ToolLaunch |
||||
*/ |
||||
public function setActivityType(?string $activityType): ToolLaunch |
||||
{ |
||||
$this->activityType = $activityType; |
||||
|
||||
return $this; |
||||
} |
||||
} |
||||
@ -0,0 +1,129 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\Importer; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use DocumentManager; |
||||
use Exception; |
||||
use PclZip; |
||||
use Symfony\Component\Filesystem\Filesystem; |
||||
|
||||
/** |
||||
* Class AbstractImporter. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\Importer |
||||
*/ |
||||
abstract class AbstractImporter |
||||
{ |
||||
/** |
||||
* @var \Chamilo\CoreBundle\Entity\Course |
||||
*/ |
||||
protected $course; |
||||
/** |
||||
* @var string |
||||
*/ |
||||
protected $relCourseDir; |
||||
/** |
||||
* @var string |
||||
*/ |
||||
protected $packageDir; |
||||
/** |
||||
* @var \PclZip |
||||
*/ |
||||
protected $zipFile; |
||||
|
||||
/** |
||||
* AbstractImporter constructor. |
||||
* |
||||
* @param array $fileInfo |
||||
* @param string $directoryName |
||||
* @param \Chamilo\CoreBundle\Entity\Course $course |
||||
*/ |
||||
protected function __construct(array $fileInfo, $directoryName, Course $course) |
||||
{ |
||||
$this->course = $course; |
||||
$this->relCourseDir = api_get_course_path($this->course->getCode()).'/'.$directoryName; |
||||
$this->zipFile = new PclZip($fileInfo['tmp_name']); |
||||
|
||||
$filePathInfo = pathinfo($fileInfo['name']); |
||||
$fileBaseName = str_replace(".{$filePathInfo['extension']}", '', $filePathInfo['basename']); |
||||
|
||||
$this->packageDir = '/'.api_replace_dangerous_char($fileBaseName); |
||||
} |
||||
|
||||
/** |
||||
* @param array $fileInfo |
||||
* @param \Chamilo\CoreBundle\Entity\Course $course |
||||
* |
||||
* @return \Chamilo\PluginBundle\XApi\Importer\AbstractImporter |
||||
*/ |
||||
abstract public static function create(array $fileInfo, Course $course); |
||||
|
||||
/** |
||||
* @throws \Exception |
||||
*/ |
||||
public function import() |
||||
{ |
||||
$this->validPackage(); |
||||
|
||||
$sysCourseDir = api_get_path(SYS_COURSE_PATH).$this->relCourseDir; |
||||
|
||||
if (!$this->isEnoughSpace()) { |
||||
throw new Exception('Not enough space to storage package.'); |
||||
} |
||||
|
||||
$fullSysPackageDir = $sysCourseDir.$this->packageDir; |
||||
|
||||
$fs = new Filesystem(); |
||||
$fs->mkdir( |
||||
$fullSysPackageDir, |
||||
api_get_permissions_for_new_directories() |
||||
); |
||||
|
||||
$this->zipFile->extract($fullSysPackageDir); |
||||
|
||||
return "$fullSysPackageDir/tincan.xml"; |
||||
} |
||||
|
||||
/** |
||||
* @throws \Exception |
||||
*/ |
||||
protected function validPackage() |
||||
{ |
||||
$zipContent = $this->zipFile->listContent(); |
||||
|
||||
if (empty($zipContent)) { |
||||
throw new Exception('Package file is empty'); |
||||
} |
||||
|
||||
foreach ($zipContent as $zipEntry) { |
||||
if (preg_match('~.(php.*|phtml)$~i', $zipEntry['filename'])) { |
||||
throw new Exception("File \"{$zipEntry['filename']}\" contains a PHP script"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @return bool |
||||
*/ |
||||
private function isEnoughSpace() |
||||
{ |
||||
$zipRealSize = array_reduce( |
||||
$this->zipFile->listContent(), |
||||
function ($accumulator, $zipEntry) { |
||||
return $accumulator + $zipEntry['size']; |
||||
} |
||||
); |
||||
|
||||
$courseSpaceQuota = DocumentManager::get_course_quota($this->course->getCode()); |
||||
|
||||
$sysCourseDir = api_get_path(SYS_COURSE_PATH).$this->relCourseDir; |
||||
|
||||
if (!enough_size($zipRealSize, $sysCourseDir, $courseSpaceQuota)) { |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\Importer; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Exception; |
||||
|
||||
/** |
||||
* Class TinCanImporter. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\Importer |
||||
*/ |
||||
class TinCanImporter extends AbstractImporter |
||||
{ |
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public static function create(array $fileInfo, Course $course) |
||||
{ |
||||
return new self($fileInfo, 'tincan', $course); |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
protected function validPackage() |
||||
{ |
||||
parent::validPackage(); |
||||
|
||||
$zipContent = $this->zipFile->listContent(); |
||||
|
||||
$isValid = false; |
||||
|
||||
foreach ($zipContent as $zipEntry) { |
||||
if ('tincan.xml' === $zipEntry['filename']) { |
||||
$isValid = true; |
||||
} |
||||
} |
||||
|
||||
if (!$isValid) { |
||||
throw new Exception('Incorrect package. Missing "tincan.xml" file'); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,102 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\PluginBundle\XApi\Parser; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\PluginBundle\Entity\XApi\ToolLaunch; |
||||
use Database; |
||||
use Symfony\Component\DomCrawler\Crawler; |
||||
|
||||
/** |
||||
* Class TinCanParser. |
||||
* |
||||
* @package Chamilo\PluginBundle\XApi\Parser |
||||
*/ |
||||
class TinCanParser |
||||
{ |
||||
/** |
||||
* @var string |
||||
*/ |
||||
private $filePath; |
||||
/** |
||||
* @var Course |
||||
*/ |
||||
private $course; |
||||
/** |
||||
* @var Session|null |
||||
*/ |
||||
private $session; |
||||
|
||||
protected function __construct($filePath, Course $course, Session $session = null) |
||||
{ |
||||
$this->filePath = $filePath; |
||||
$this->course = $course; |
||||
$this->session = $session; |
||||
} |
||||
|
||||
public static function create($filePath, Course $course, Session $session = null) |
||||
{ |
||||
return new self($filePath, $course, $session); |
||||
} |
||||
|
||||
/** |
||||
* @return \Chamilo\PluginBundle\Entity\XApi\ToolLaunch |
||||
*/ |
||||
public function parse() |
||||
{ |
||||
$content = file_get_contents($this->filePath); |
||||
|
||||
$xml = new Crawler($content); |
||||
|
||||
$activityNode = $xml->filter('tincan activities activity')->first(); |
||||
$nodeName = $activityNode->filter('name'); |
||||
$nodeDescription = $activityNode->filter('description'); |
||||
$nodeLaunch = $activityNode->filter('launch'); |
||||
|
||||
$toolLaunch = new ToolLaunch(); |
||||
$toolLaunch |
||||
->setCourse($this->course) |
||||
->setSession($this->session) |
||||
->setCreatedAt(api_get_utc_datetime(null, false, true)) |
||||
->setActivityId($activityNode->attr('id')) |
||||
->setActivityVerbId($activityNode->attr('verbid')) |
||||
->setActivityType($activityNode->attr('type')) |
||||
->setLaunchUrl($this->parseLaunchUrl($nodeLaunch)); |
||||
|
||||
if ($nodeName) { |
||||
$toolLaunch->setTitle($nodeName->text()); |
||||
} |
||||
|
||||
if ($nodeDescription) { |
||||
$toolLaunch->setDescription($nodeDescription->text() ?: null); |
||||
} |
||||
|
||||
return $toolLaunch; |
||||
} |
||||
|
||||
/** |
||||
* @param \Symfony\Component\DomCrawler\Crawler $launchNode |
||||
* |
||||
* @return string |
||||
*/ |
||||
private function parseLaunchUrl(Crawler $launchNode) |
||||
{ |
||||
$launchUrl = $launchNode->text(); |
||||
|
||||
$urlInfo = parse_url($launchUrl); |
||||
|
||||
if (empty($urlInfo['scheme'])) { |
||||
$baseUrl = str_replace( |
||||
api_get_path(SYS_COURSE_PATH), |
||||
api_get_path(WEB_COURSE_PATH), |
||||
dirname($this->filePath) |
||||
); |
||||
|
||||
return "$baseUrl/$launchUrl"; |
||||
} |
||||
|
||||
return $launchUrl; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue