You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
40 lines
1.0 KiB
<?php
|
|
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
use Chamilo\PluginBundle\Entity\TopLinks\TopLink;
|
|
|
|
/**
|
|
* Class TopLinksCreateCourseHookObserver.
|
|
*/
|
|
class TopLinksCreateCourseHookObserver extends HookObserver implements HookCreateCourseObserverInterface
|
|
{
|
|
/**
|
|
* XApiCreateCourseHookObserver constructor.
|
|
*/
|
|
protected function __construct()
|
|
{
|
|
parent::__construct('plugin/toplinks/src/TopLinksPlugin.php', 'toplinks');
|
|
}
|
|
|
|
public function hookCreateCourse(HookCreateCourseEventInterface $hook): int
|
|
{
|
|
$data = $hook->getEventData();
|
|
|
|
$type = $data['type'];
|
|
$courseInfo = $data['course_info'];
|
|
|
|
$plugin = TopLinksPlugin::create();
|
|
|
|
$em = Database::getManager();
|
|
$linkRepo = $em->getRepository(TopLink::class);
|
|
|
|
if (HOOK_EVENT_TYPE_POST == $type) {
|
|
foreach ($linkRepo->findAll() as $link) {
|
|
$plugin->addToolInCourse($courseInfo['real_id'], $link);
|
|
}
|
|
}
|
|
|
|
return (int) $courseInfo['real_id'];
|
|
}
|
|
}
|
|
|