'boolean', ]; parent::__construct('0.1', 'Angel Fernando Quiroz Campos', $settings); $this->isCoursePlugin = true; $this->addCourseTool = false; $this->setCourseSettings(); } /** * @return CourseHomeNotifyPlugin|null */ public static function create() { static $result = null; return $result ? $result : $result = new self(); } /** * Install process. * Create table in database. And setup Doctirne entity. * * @throws \Doctrine\ORM\Tools\ToolsException */ public function install() { $em = Database::getManager(); if ($em->getConnection()->getSchemaManager()->tablesExist(['course_home_notify_notification'])) { return; } $schemaTool = new SchemaTool($em); $schemaTool->createSchema( [ $em->getClassMetadata(Notification::class), $em->getClassMetadata(NotificationRelUser::class), ] ); } /** * Uninstall process. * Remove Doctrine entity. And drop table in database. */ public function uninstall() { $em = Database::getManager(); if (!$em->getConnection()->getSchemaManager()->tablesExist(['course_home_notify_notification'])) { return; } $schemaTool = new SchemaTool($em); $schemaTool->dropSchema( [ $em->getClassMetadata(Notification::class), $em->getClassMetadata(NotificationRelUser::class), ] ); } /** * @param string $region * * @return string */ public function renderRegion($region) { if ( 'main_bottom' !== $region || strpos($_SERVER['SCRIPT_NAME'], 'course_home/course_home.php') === false ) { return ''; } $courseId = api_get_course_int_id(); $userId = api_get_user_id(); if (empty($courseId) || empty($userId)) { return ''; } $course = api_get_course_entity($courseId); $user = api_get_user_entity($userId); $em = Database::getManager(); /** @var Notification $notification */ $notification = $em ->getRepository('ChamiloPluginBundle:CourseHomeNotify\Notification') ->findOneBy(['course' => $course]); if (!$notification) { return ''; } $modalFooter = ''; $modalConfig = ['show' => true]; if ($notification->getExpirationLink()) { /** @var NotificationRelUser $notificationUser */ $notificationUser = $em ->getRepository('ChamiloPluginBundle:CourseHomeNotify\NotificationRelUser') ->findOneBy(['notification' => $notification, 'user' => $user]); if ($notificationUser) { return ''; } $contentUrl = api_get_path(WEB_PLUGIN_PATH).$this->get_name().'/content.php?hash='.$notification->getHash(); $link = Display::toolbarButton( $this->get_lang('PleaseFollowThisLink'), $contentUrl, 'external-link', 'link', ['id' => 'course-home-notify-link', 'target' => '_blank'] ); $modalConfig['keyboard'] = false; $modalConfig['backdrop'] = 'static'; $modalFooter = ''; } $modal = ''; $modal .= ""; return $modal; } /** * Set the course settings. */ private function setCourseSettings() { if ('true' !== $this->get(self::SETTING_ENABLED)) { return; } $name = $this->get_name(); $button = Display::toolbarButton( $this->get_lang('SetNotification'), api_get_path(WEB_PLUGIN_PATH).$name.'/configure.php?'.api_get_cidreq(), 'cog', 'primary' ); $this->course_settings = [ [ 'name' => '

'.$this->get_comment().'

'.$button.'
', 'type' => 'html', ], ]; } }