Actualización
This commit is contained in:
250
plugin/embedregistry/EmbedRegistryPlugin.php
Normal file
250
plugin/embedregistry/EmbedRegistryPlugin.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Course;
|
||||
use Chamilo\CoreBundle\Entity\Session;
|
||||
use Chamilo\PluginBundle\Entity\EmbedRegistry\Embed;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
|
||||
/**
|
||||
* Class EmbedRegistryPlugin.
|
||||
*/
|
||||
class EmbedRegistryPlugin extends Plugin
|
||||
{
|
||||
public const SETTING_ENABLED = 'tool_enabled';
|
||||
public const SETTING_TITLE = 'tool_title';
|
||||
public const SETTING_EXTERNAL_URL = 'external_url';
|
||||
public const TBL_EMBED = 'plugin_embed_registry_embed';
|
||||
|
||||
/**
|
||||
* EmbedRegistryPlugin constructor.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
$authors = [
|
||||
'Angel Fernando Quiroz Campos',
|
||||
];
|
||||
|
||||
parent::__construct(
|
||||
'1.0',
|
||||
implode(', ', $authors),
|
||||
[
|
||||
self::SETTING_ENABLED => 'boolean',
|
||||
self::SETTING_TITLE => 'text',
|
||||
self::SETTING_EXTERNAL_URL => 'text',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTitle()
|
||||
{
|
||||
$title = $this->get(self::SETTING_TITLE);
|
||||
|
||||
if (!empty($title)) {
|
||||
return $title;
|
||||
}
|
||||
|
||||
return $this->get_title();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EmbedRegistryPlugin|null
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
static $result = null;
|
||||
|
||||
return $result ? $result : $result = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Doctrine\ORM\Tools\ToolsException
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$em = Database::getManager();
|
||||
|
||||
if ($em->getConnection()->getSchemaManager()->tablesExist([self::TBL_EMBED])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$schemaTool = new SchemaTool($em);
|
||||
$schemaTool->createSchema(
|
||||
[
|
||||
$em->getClassMetadata(Embed::class),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
$em = Database::getManager();
|
||||
|
||||
if (!$em->getConnection()->getSchemaManager()->tablesExist([self::TBL_EMBED])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$schemaTool = new SchemaTool($em);
|
||||
$schemaTool->dropSchema(
|
||||
[
|
||||
$em->getClassMetadata(Embed::class),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EmbedRegistryPlugin
|
||||
*/
|
||||
public function performActionsAfterConfigure()
|
||||
{
|
||||
$em = Database::getManager();
|
||||
|
||||
$this->deleteCourseToolLinks();
|
||||
|
||||
if ('true' === $this->get(self::SETTING_ENABLED)) {
|
||||
$courses = $em->createQuery('SELECT c.id FROM ChamiloCoreBundle:Course c')->getResult();
|
||||
|
||||
foreach ($courses as $course) {
|
||||
$this->createLinkToCourseTool($this->getToolTitle(), $course['id']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $courseId
|
||||
*/
|
||||
public function doWhenDeletingCourse($courseId)
|
||||
{
|
||||
Database::getManager()
|
||||
->createQuery('DELETE FROM ChamiloPluginBundle:EmbedRegistry\Embed e WHERE e.course = :course')
|
||||
->execute(['course' => (int) $courseId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $sessionId
|
||||
*/
|
||||
public function doWhenDeletingSession($sessionId)
|
||||
{
|
||||
Database::getManager()
|
||||
->createQuery('DELETE FROM ChamiloPluginBundle:EmbedRegistry\Embed e WHERE e.session = :session')
|
||||
->execute(['session' => (int) $sessionId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*
|
||||
* @return Embed
|
||||
*/
|
||||
public function getCurrentEmbed(Course $course, Session $session = null)
|
||||
{
|
||||
$embedRepo = Database::getManager()->getRepository('ChamiloPluginBundle:EmbedRegistry\Embed');
|
||||
$qb = $embedRepo->createQueryBuilder('e');
|
||||
$query = $qb
|
||||
->where('e.displayStartDate <= :now')
|
||||
->andWhere('e.displayEndDate >= :now')
|
||||
->andWhere(
|
||||
$qb->expr()->eq('e.course', $course->getId())
|
||||
);
|
||||
|
||||
$query->andWhere(
|
||||
$session
|
||||
? $qb->expr()->eq('e.session', $session->getId())
|
||||
: $qb->expr()->isNull('e.session')
|
||||
);
|
||||
|
||||
$query = $query
|
||||
->orderBy('e.displayStartDate', 'DESC')
|
||||
->setMaxResults(1)
|
||||
->setParameters(['now' => api_get_utc_datetime(null, false, true)])
|
||||
->getQuery();
|
||||
|
||||
return $query->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function formatDisplayDate(Embed $embed)
|
||||
{
|
||||
$startDate = sprintf(
|
||||
'<time datetime="%s">%s</time>',
|
||||
$embed->getDisplayStartDate()->format(DateTime::W3C),
|
||||
api_convert_and_format_date($embed->getDisplayStartDate())
|
||||
);
|
||||
$endDate = sprintf(
|
||||
'<time datetime="%s">%s</time>',
|
||||
$embed->getDisplayEndDate()->format(DateTime::W3C),
|
||||
api_convert_and_format_date($embed->getDisplayEndDate())
|
||||
);
|
||||
|
||||
return sprintf(get_lang('FromDateXToDateY'), $startDate, $endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getViewUrl(Embed $embed)
|
||||
{
|
||||
return api_get_path(WEB_PLUGIN_PATH).'embedregistry/view.php?id='.$embed->getId().'&'.api_get_cidreq();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Doctrine\ORM\Query\QueryException
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMembersCount(Embed $embed)
|
||||
{
|
||||
$dql = 'SELECT COUNT(DISTINCT tea.accessUserId) FROM ChamiloCoreBundle:TrackEAccess tea
|
||||
WHERE
|
||||
tea.accessTool = :tool AND
|
||||
(tea.accessDate >= :start_date AND tea.accessDate <= :end_date) AND
|
||||
tea.cId = :course';
|
||||
|
||||
$params = [
|
||||
'tool' => 'plugin_'.$this->get_name(),
|
||||
'start_date' => $embed->getDisplayStartDate(),
|
||||
'end_date' => $embed->getDisplayEndDate(),
|
||||
'course' => $embed->getCourse(),
|
||||
];
|
||||
|
||||
if ($embed->getSession()) {
|
||||
$dql .= ' AND tea.accessSessionId = :session ';
|
||||
|
||||
$params['session'] = $embed->getSession();
|
||||
}
|
||||
|
||||
$count = Database::getManager()
|
||||
->createQuery($dql)
|
||||
->setParameters($params)
|
||||
->getSingleScalarResult();
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function saveEventAccessTool()
|
||||
{
|
||||
$tableAccess = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
|
||||
$params = [
|
||||
'access_user_id' => api_get_user_id(),
|
||||
'c_id' => api_get_course_int_id(),
|
||||
'access_tool' => 'plugin_'.$this->get_name(),
|
||||
'access_date' => api_get_utc_datetime(),
|
||||
'access_session_id' => api_get_session_id(),
|
||||
'user_ip' => api_get_real_ip(),
|
||||
];
|
||||
Database::insert($tableAccess, $params);
|
||||
}
|
||||
|
||||
private function deleteCourseToolLinks()
|
||||
{
|
||||
Database::getManager()
|
||||
->createQuery('DELETE FROM ChamiloCourseBundle:CTool t WHERE t.category = :category AND t.link LIKE :link')
|
||||
->execute(['category' => 'plugin', 'link' => 'embedregistry/start.php%']);
|
||||
}
|
||||
}
|
||||
198
plugin/embedregistry/Entity/Embed.php
Normal file
198
plugin/embedregistry/Entity/Embed.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
namespace Chamilo\PluginBundle\Entity\EmbedRegistry;
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Course;
|
||||
use Chamilo\CoreBundle\Entity\Session;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Class EmbedRegistry.
|
||||
*
|
||||
* @package Chamilo\PluginBundle\Entity\EmbedRegistry
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="plugin_embed_registry_embed")
|
||||
*/
|
||||
class Embed
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="title", type="text")
|
||||
*/
|
||||
private $title;
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="display_start_date", type="datetime")
|
||||
*/
|
||||
private $displayStartDate;
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="display_end_date", type="datetime")
|
||||
*/
|
||||
private $displayEndDate;
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="html_code", type="text")
|
||||
*/
|
||||
private $htmlCode;
|
||||
/**
|
||||
* @var Course
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course")
|
||||
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false)
|
||||
*/
|
||||
private $course;
|
||||
/**
|
||||
* @var Session|null
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session")
|
||||
* @ORM\JoinColumn(name="session_id", referencedColumnName="id")
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Embed
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
*
|
||||
* @return Embed
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDisplayStartDate()
|
||||
{
|
||||
return $this->displayStartDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Embed
|
||||
*/
|
||||
public function setDisplayStartDate(\DateTime $displayStartDate)
|
||||
{
|
||||
$this->displayStartDate = $displayStartDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDisplayEndDate()
|
||||
{
|
||||
return $this->displayEndDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Embed
|
||||
*/
|
||||
public function setDisplayEndDate(\DateTime $displayEndDate)
|
||||
{
|
||||
$this->displayEndDate = $displayEndDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHtmlCode()
|
||||
{
|
||||
return $this->htmlCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $htmlCode
|
||||
*
|
||||
* @return Embed
|
||||
*/
|
||||
public function setHtmlCode($htmlCode)
|
||||
{
|
||||
$this->htmlCode = $htmlCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Course
|
||||
*/
|
||||
public function getCourse()
|
||||
{
|
||||
return $this->course;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Embed
|
||||
*/
|
||||
public function setCourse(Course $course)
|
||||
{
|
||||
$this->course = $course;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session|null
|
||||
*/
|
||||
public function getSession()
|
||||
{
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Embed
|
||||
*/
|
||||
public function setSession(Session $session = null)
|
||||
{
|
||||
$this->session = $session;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
14
plugin/embedregistry/README.md
Normal file
14
plugin/embedregistry/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Embed Registry
|
||||
|
||||
Add a new tool in every course to offer embedded content from external sources
|
||||
*and* track accesses to the content itself (so you can monitor the interest).
|
||||
|
||||
## Set up
|
||||
|
||||
Prior to installing/uninstalling this plugin, make sure the src/Chamilo/PluginBundle/Entity folder is
|
||||
temporarily writeable by the web server.
|
||||
|
||||
Enable the plugin. Suggest a default source for all the embedded content, then let teachers define the
|
||||
content (usually videos) they want to embed into their courses.
|
||||
|
||||
Time periods allow teachers to schedule the highlighting of some content above others at specific dates.
|
||||
4
plugin/embedregistry/install.php
Normal file
4
plugin/embedregistry/install.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
EmbedRegistryPlugin::create()->install();
|
||||
22
plugin/embedregistry/lang/english.php
Normal file
22
plugin/embedregistry/lang/english.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$strings['plugin_title'] = 'Embed Registry';
|
||||
$strings['plugin_comment'] = "Add a new course tool to include embedded content in a more structured way and track students' access to it.";
|
||||
|
||||
$strings['tool_enabled'] = 'Tool enabled';
|
||||
$strings['tool_title'] = 'Tool Title';
|
||||
$strings['tool_title_help'] = 'The title of the tool icon on the course homepage (usually the title of the service being shared).';
|
||||
$strings['external_url'] = 'External tool';
|
||||
$strings['external_url_help'] = 'The URL at which the external content is managed. Usually something like https://[provider.com]/my_account. This can be used as a shortcut by the teachers internally, but they can also decide to embed something completely different.';
|
||||
|
||||
$strings['YouNeedCreateContent'] = 'First you need to register external (embedded) content, then you will be able to make those embeds available to students into your course (through this tool).';
|
||||
$strings['CreateContent'] = 'Create external content';
|
||||
$strings['CreateEmbeddable'] = 'Add embedded content';
|
||||
$strings['EditEmbeddable'] = 'Edit embedded content';
|
||||
$strings['ContentNotFound'] = 'Content not found';
|
||||
$strings['EmbedTitleHelp'] = 'The title you wish to show for this embedded content in particular. If it requires a password to play, include it here to allow your users to unlock it.';
|
||||
$strings['EmbedDateRangeHelp'] = 'Within those dates, this embedded content will be shown directly in the top part of the page.';
|
||||
$strings['HtmlCode'] = 'HTML code';
|
||||
$strings['HtmlCodeHelp'] = 'The shared HTML code, as provided by the external service, when asking to share in Embedded format.';
|
||||
$strings['LaunchContent'] = 'Launch content';
|
||||
22
plugin/embedregistry/lang/french.php
Normal file
22
plugin/embedregistry/lang/french.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$strings['plugin_title'] = 'Registre de contenu incrusté (embedded)';
|
||||
$strings['plugin_comment'] = 'Ajoute un outil à chaque cours pour y afficher une liste de contenus partagés via code Embed depuis un service en ligne (externe). Enregistre les visualisations de ces contenus par vos utilisateurs.';
|
||||
|
||||
$strings['tool_enabled'] = 'Outil activé';
|
||||
$strings['tool_title'] = 'Titre de l\'outil';
|
||||
$strings['tool_title_help'] = 'Le titre de l\'outil qui apparaîtra sur la page principale du cours (il s\'agit généralement du nom du service externe qui est partagé).';
|
||||
$strings['external_url'] = 'URL service externe';
|
||||
$strings['external_url_help'] = 'L\'URL de la page de gestion du contenu extérieur sur le site du fournisseur de service correspondant. Habituellement quelque chose du genre https://[fournisseur.com]/my_account.';
|
||||
|
||||
$strings['YouNeedCreateContent'] = 'Vous devez d\'abord créer le contenu externe. Ensuite vous pourrez ajouter ce contenu au format Embed dans votre cours.';
|
||||
$strings['CreateContent'] = 'Créer contenu externe';
|
||||
$strings['CreateEmbeddable'] = 'Créer';
|
||||
$strings['EditEmbeddable'] = 'Éditer';
|
||||
$strings['ContentNotFound'] = 'Impossible de vérifier le contenu';
|
||||
$strings['EmbedTitleHelp'] = 'Le titre que vous souhaitez montrer pour ce contenu incrusté. S\'il requiert un mot de passe, ajoutez-le ici pour que vos utilisateurs puissent le débloquer.';
|
||||
$strings['EmbedDateRangeHelp'] = 'Entre ces dates, le contenu actif sera mis en évidence dans la partie supérieure de cette page.';
|
||||
$strings['HtmlCode'] = 'Code HTML';
|
||||
$strings['HtmlCodeHelp'] = 'Le code HTML partagé, tel que fourni par le service externe au moment de le partager au format "Embed".';
|
||||
$strings['LaunchContent'] = 'Voir le contenu';
|
||||
22
plugin/embedregistry/lang/spanish.php
Normal file
22
plugin/embedregistry/lang/spanish.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$strings['plugin_title'] = 'Registro de contenido Embed';
|
||||
$strings['plugin_comment'] = 'Agrega una herramienta de curso para llevar un registro del contenido Embed y registrar el acceso de los estudiantes a este.';
|
||||
|
||||
$strings['tool_enabled'] = 'Herramienta habilitada';
|
||||
$strings['tool_title'] = 'Título de la herramienta';
|
||||
$strings['tool_title_help'] = 'El título del icono de la herramienta en la página principal del curso (usualmente el título del servicio siendo compartido).';
|
||||
$strings['external_url'] = 'URL externa';
|
||||
$strings['external_url_help'] = 'La URL en la cual se puede gestionar el contenido que va a ser embedido en esta herramienta. Usualmente algo como https://[proveedor.com]/my_account, por ejemplo.';
|
||||
|
||||
$strings['YouNeedCreateContent'] = 'Necesita tener contenido externo para luego pegar su código embed aquí.';
|
||||
$strings['CreateContent'] = 'Crear contenido externo';
|
||||
$strings['CreateEmbeddable'] = 'Crear';
|
||||
$strings['EditEmbeddable'] = 'Editar';
|
||||
$strings['ContentNotFound'] = 'Contenido no encontrado';
|
||||
$strings['EmbedTitleHelp'] = 'El título que desea que tenga este contenido incrustado en particular. Si tiene contraseña, incluya la contraseña para que sus usuarios puedan abrirlo.';
|
||||
$strings['EmbedDateRangeHelp'] = 'Dentro de este rango de fechas, el contenido activo será resaltado en la parte superior de la página.';
|
||||
$strings['HtmlCode'] = 'Código HTML';
|
||||
$strings['HtmlCodeHelp'] = 'El código HTML compartido por la herramienta externa, al elegir compartir en formato Embed.';
|
||||
$strings['LaunchContent'] = 'Ingresar ahora';
|
||||
4
plugin/embedregistry/plugin.php
Normal file
4
plugin/embedregistry/plugin.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
$plugin_info = EmbedRegistryPlugin::create()->get_info();
|
||||
309
plugin/embedregistry/start.php
Normal file
309
plugin/embedregistry/start.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\PluginBundle\Entity\EmbedRegistry\Embed;
|
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php';
|
||||
|
||||
api_block_anonymous_users();
|
||||
api_protect_course_script(true);
|
||||
|
||||
$plugin = EmbedRegistryPlugin::create();
|
||||
|
||||
if ('false' === $plugin->get(EmbedRegistryPlugin::SETTING_ENABLED)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$isAllowedToEdit = api_is_allowed_to_edit(true);
|
||||
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
|
||||
|
||||
$em = Database::getManager();
|
||||
$embedRepo = $em->getRepository('ChamiloPluginBundle:EmbedRegistry\Embed');
|
||||
|
||||
$course = api_get_course_entity(api_get_course_int_id());
|
||||
$session = api_get_session_entity(api_get_session_id());
|
||||
|
||||
$actions = [];
|
||||
|
||||
$view = new Template($plugin->getToolTitle());
|
||||
$view->assign('is_allowed_to_edit', $isAllowedToEdit);
|
||||
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
if (!$isAllowedToEdit) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_self()
|
||||
);
|
||||
|
||||
$form = new FormValidator('frm_edit');
|
||||
$form->addText(
|
||||
'title',
|
||||
[get_lang('Title'), $plugin->get_lang('EmbedTitleHelp')],
|
||||
true
|
||||
);
|
||||
$form->addDateRangePicker(
|
||||
'range',
|
||||
[get_lang('DateRange'), $plugin->get_lang('EmbedDateRangeHelp')]
|
||||
);
|
||||
$form->addTextarea(
|
||||
'html_code',
|
||||
[$plugin->get_lang('HtmlCode'), $plugin->get_lang('HtmlCodeHelp')],
|
||||
['rows' => 5],
|
||||
true
|
||||
);
|
||||
$form->addButtonUpdate(get_lang('Add'));
|
||||
$form->addHidden('action', 'add');
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
|
||||
$startDate = api_get_utc_datetime($values['range_start'], false, true);
|
||||
$endDate = api_get_utc_datetime($values['range_end'], false, true);
|
||||
|
||||
$embed = new Embed();
|
||||
$embed
|
||||
->setTitle($values['title'])
|
||||
->setDisplayStartDate($startDate)
|
||||
->setDisplayEndDate($endDate)
|
||||
->setHtmlCode($values['html_code'])
|
||||
->setCourse($course)
|
||||
->setSession($session);
|
||||
|
||||
$em->persist($embed);
|
||||
$em->flush();
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Added'), 'success')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$view->assign('header', $plugin->get_lang('CreateEmbeddable'));
|
||||
$view->assign('form', $form->returnForm());
|
||||
|
||||
$externalUrl = $plugin->get(EmbedRegistryPlugin::SETTING_EXTERNAL_URL);
|
||||
|
||||
if (!empty($externalUrl)) {
|
||||
$view->assign('external_url', $externalUrl);
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
if (!$isAllowedToEdit) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_self()
|
||||
);
|
||||
|
||||
$embedId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
|
||||
if (!$embedId) {
|
||||
break;
|
||||
}
|
||||
|
||||
/** @var Embed|null $embed */
|
||||
$embed = $embedRepo->find($embedId);
|
||||
|
||||
if (!$embed) {
|
||||
Display::addFlash(Display::return_message($plugin->get_lang('ContentNotFound'), 'danger'));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$form = new FormValidator('frm_edit');
|
||||
$form->addText('title', get_lang('Title'), true);
|
||||
$form->addDateRangePicker('range', get_lang('DateRange'));
|
||||
$form->addTextarea('html_code', $plugin->get_lang('HtmlCode'), ['rows' => 5], true);
|
||||
$form->addButtonUpdate(get_lang('Edit'));
|
||||
$form->addHidden('id', $embed->getId());
|
||||
$form->addHidden('action', 'edit');
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
|
||||
$startDate = api_get_utc_datetime($values['range_start'], false, true);
|
||||
$endDate = api_get_utc_datetime($values['range_end'], false, true);
|
||||
|
||||
$embed
|
||||
->setTitle($values['title'])
|
||||
->setDisplayStartDate($startDate)
|
||||
->setDisplayEndDate($endDate)
|
||||
->setHtmlCode($values['html_code']);
|
||||
|
||||
$em->persist($embed);
|
||||
$em->flush();
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Updated'), 'success')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->setDefaults(
|
||||
[
|
||||
'title' => $embed->getTitle(),
|
||||
'range' => api_get_local_time($embed->getDisplayStartDate())
|
||||
.' / '
|
||||
.api_get_local_time($embed->getDisplayEndDate()),
|
||||
'html_code' => $embed->getHtmlCode(),
|
||||
]
|
||||
);
|
||||
|
||||
$view->assign('header', $plugin->get_lang('EditEmbeddable'));
|
||||
$view->assign('form', $form->returnForm());
|
||||
break;
|
||||
case 'delete':
|
||||
$embedId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
|
||||
if (!$embedId) {
|
||||
break;
|
||||
}
|
||||
|
||||
/** @var Embed|null $embed */
|
||||
$embed = $embedRepo->find($embedId);
|
||||
|
||||
if (!$embed) {
|
||||
Display::addFlash(Display::return_message($plugin->get_lang('ContentNotFound'), 'danger'));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$em->remove($embed);
|
||||
$em->flush();
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('Deleted'), 'success')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_self());
|
||||
exit;
|
||||
default:
|
||||
$currentEmbed = $plugin->getCurrentEmbed($course, $session);
|
||||
|
||||
/** @var array|Embed[] $embeds */
|
||||
$embeds = $embedRepo->findBy(['course' => $course, 'session' => $session]);
|
||||
|
||||
$tableData = [];
|
||||
|
||||
foreach ($embeds as $embed) {
|
||||
$data = [
|
||||
$embed->getTitle(),
|
||||
api_convert_and_format_date($embed->getDisplayStartDate()),
|
||||
api_convert_and_format_date($embed->getDisplayEndDate()),
|
||||
$embed,
|
||||
];
|
||||
|
||||
if ($isAllowedToEdit) {
|
||||
$data[] = $embed;
|
||||
}
|
||||
|
||||
$tableData[] = $data;
|
||||
}
|
||||
|
||||
if ($isAllowedToEdit) {
|
||||
$btnAdd = Display::toolbarButton(
|
||||
$plugin->get_lang('CreateEmbeddable'),
|
||||
api_get_self().'?action=add',
|
||||
'file-code-o',
|
||||
'primary'
|
||||
);
|
||||
|
||||
$view->assign(
|
||||
'actions',
|
||||
Display::toolbarAction($plugin->get_name(), [$btnAdd])
|
||||
);
|
||||
|
||||
if (in_array($action, ['add', 'edit'])) {
|
||||
$view->assign('form', $form->returnForm());
|
||||
}
|
||||
}
|
||||
|
||||
if ($currentEmbed) {
|
||||
$view->assign('current_embed', $currentEmbed);
|
||||
$view->assign(
|
||||
'current_link',
|
||||
Display::toolbarButton(
|
||||
$plugin->get_lang('LaunchContent'),
|
||||
$plugin->getViewUrl($embed),
|
||||
'rocket',
|
||||
'info'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$table = new SortableTableFromArray($tableData, 1);
|
||||
$table->set_header(0, get_lang('Title'));
|
||||
$table->set_header(1, get_lang('AvailableFrom'), true, 'th-header text-center', ['class' => 'text-center']);
|
||||
$table->set_header(2, get_lang('AvailableTill'), true, 'th-header text-center', ['class' => 'text-center']);
|
||||
|
||||
if ($isAllowedToEdit) {
|
||||
$table->set_header(3, get_lang('Members'), false, 'th-header text-right', ['class' => 'text-right']);
|
||||
$table->set_column_filter(
|
||||
3,
|
||||
function (Embed $value) use ($plugin) {
|
||||
return $plugin->getMembersCount($value);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
$table->set_header(
|
||||
$isAllowedToEdit ? 4 : 3,
|
||||
get_lang('Actions'),
|
||||
false,
|
||||
'th-header text-right',
|
||||
['class' => 'text-right']
|
||||
);
|
||||
$table->set_column_filter(
|
||||
$isAllowedToEdit ? 4 : 3,
|
||||
function (Embed $value) use ($isAllowedToEdit, $plugin) {
|
||||
$actions = [];
|
||||
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('external_link.png', get_lang('View')),
|
||||
$plugin->getViewUrl($value)
|
||||
);
|
||||
|
||||
if ($isAllowedToEdit) {
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('edit.png', get_lang('Edit')),
|
||||
api_get_self().'?action=edit&id='.$value->getId()
|
||||
);
|
||||
|
||||
$actions[] = Display::url(
|
||||
Display::return_icon('delete.png', get_lang('Delete')),
|
||||
api_get_self().'?action=delete&id='.$value->getId()
|
||||
);
|
||||
}
|
||||
|
||||
return implode(PHP_EOL, $actions);
|
||||
}
|
||||
);
|
||||
|
||||
$view->assign('embeds', $embeds);
|
||||
$view->assign('table', $table->return_table());
|
||||
}
|
||||
|
||||
$content = $view->fetch('embedregistry/view/start.tpl');
|
||||
|
||||
if ($actions) {
|
||||
$actions = implode(PHP_EOL, $actions);
|
||||
|
||||
$view->assign(
|
||||
'actions',
|
||||
Display::toolbarAction($plugin->get_name(), [$actions])
|
||||
);
|
||||
}
|
||||
|
||||
$view->assign('content', $content);
|
||||
$view->display_one_col_template();
|
||||
4
plugin/embedregistry/uninstall.php
Normal file
4
plugin/embedregistry/uninstall.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
EmbedRegistryPlugin::create()->uninstall();
|
||||
72
plugin/embedregistry/view.php
Normal file
72
plugin/embedregistry/view.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\PluginBundle\Entity\EmbedRegistry\Embed;
|
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php';
|
||||
|
||||
api_block_anonymous_users();
|
||||
api_protect_course_script(true);
|
||||
|
||||
$plugin = EmbedRegistryPlugin::create();
|
||||
|
||||
if ('false' === $plugin->get(EmbedRegistryPlugin::SETTING_ENABLED)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$isAllowedToEdit = api_is_allowed_to_edit(true);
|
||||
|
||||
$em = Database::getManager();
|
||||
$embedRepo = $em->getRepository('ChamiloPluginBundle:EmbedRegistry\Embed');
|
||||
|
||||
$course = api_get_course_entity(api_get_course_int_id());
|
||||
$session = api_get_session_entity(api_get_session_id());
|
||||
|
||||
$embedId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
|
||||
if (!$embedId) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
/** @var Embed|null $embed */
|
||||
$embed = $embedRepo->find($embedId);
|
||||
|
||||
if (!$embed) {
|
||||
api_not_allowed(
|
||||
true,
|
||||
Display::return_message($plugin->get_lang('ContentNotFound'), 'danger')
|
||||
);
|
||||
}
|
||||
|
||||
if ($course->getId() !== $embed->getCourse()->getId()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if ($session && $embed->getSession()) {
|
||||
if ($session->getId() !== $embed->getSession()->getId()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
}
|
||||
|
||||
$plugin->saveEventAccessTool();
|
||||
|
||||
$interbreadcrumb[] = [
|
||||
'name' => $plugin->getToolTitle(),
|
||||
'url' => api_get_path(WEB_PLUGIN_PATH).$plugin->get_name().'/start.php',
|
||||
];
|
||||
|
||||
$actions = Display::url(
|
||||
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
|
||||
api_get_path(WEB_PLUGIN_PATH).$plugin->get_name().'/start.php?'.api_get_cidreq()
|
||||
);
|
||||
|
||||
$view = new Template($embed->getTitle());
|
||||
$view->assign('header', $embed->getTitle());
|
||||
$view->assign('actions', Display::toolbarAction($plugin->get_name(), [$actions]));
|
||||
$view->assign(
|
||||
'content',
|
||||
'<p>'.$plugin->formatDisplayDate($embed).'</p>'
|
||||
.PHP_EOL
|
||||
.Security::remove_XSS($embed->getHtmlCode(), COURSEMANAGERLOWSECURITY)
|
||||
);
|
||||
$view->display_one_col_template();
|
||||
37
plugin/embedregistry/view/start.tpl
Normal file
37
plugin/embedregistry/view/start.tpl
Normal file
@@ -0,0 +1,37 @@
|
||||
{% if is_allowed_to_edit %}
|
||||
{% if external_url is defined %}
|
||||
<div class="alert alert-info">
|
||||
<p>
|
||||
{{ 'YouNeedCreateContent'|get_plugin_lang('EmbedRegistryPlugin') }}
|
||||
<a href="{{ external_url }}" class="btn btn-info" target="_blank">{{ 'CreateContent'|get_plugin_lang('EmbedRegistryPlugin') }}</a>
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if form is defined %}
|
||||
{{ form }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if current_embed is defined %}
|
||||
{% set start_date %}
|
||||
<time datetime="{{ current_embed.displayStartDate.format(constant('\DateTime::W3C')) }}">
|
||||
{{ current_embed.displayStartDate|api_convert_and_format_date }}
|
||||
</time>
|
||||
{% endset %}
|
||||
{% set end_date %}
|
||||
<time datetime="{{ current_embed.displayEndDate.format(constant('\DateTime::W3C')) }}">
|
||||
{{ current_embed.displayEndDate|api_convert_and_format_date }}
|
||||
</time>
|
||||
{% endset %}
|
||||
|
||||
<div class="well well-sm text-center">
|
||||
<p class="lead">{{ current_embed.title }}</p>
|
||||
<p>
|
||||
<small>{{ 'FromDateXToDateY'|get_lang|format(start_date, end_date) }}</small>
|
||||
</p>
|
||||
<p>{{ current_link }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{{ table }}
|
||||
Reference in New Issue
Block a user