1 | <?php |
||||||
2 | /* For licensing terms, see /license.txt */ |
||||||
3 | |||||||
4 | require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||||
5 | |||||||
6 | use Chamilo\PluginBundle\Entity\CourseHomeNotify\Notification; |
||||||
0 ignored issues
–
show
|
|||||||
7 | |||||||
8 | $plugin = CourseHomeNotifyPlugin::create(); |
||||||
9 | $courseId = api_get_course_int_id(); |
||||||
10 | |||||||
11 | if ( |
||||||
12 | empty($courseId) || |
||||||
13 | 'true' !== $plugin->get(CourseHomeNotifyPlugin::SETTING_ENABLED) |
||||||
14 | ) { |
||||||
15 | api_not_allowed(true); |
||||||
16 | } |
||||||
17 | |||||||
18 | $action = isset($_GET['action']) ? $_GET['action'] : ''; |
||||||
19 | |||||||
20 | $course = api_get_course_entity($courseId); |
||||||
21 | |||||||
22 | $em = Database::getManager(); |
||||||
23 | /** @var Notification $notification */ |
||||||
24 | $notification = $em |
||||||
25 | ->getRepository('ChamiloPluginBundle:CourseHomeNotify\Notification') |
||||||
26 | ->findOneBy(['course' => $course]); |
||||||
27 | |||||||
28 | $actionLinks = ''; |
||||||
29 | |||||||
30 | if ($notification) { |
||||||
0 ignored issues
–
show
|
|||||||
31 | $actionLinks = Display::url( |
||||||
32 | Display::return_icon('delete.png', $plugin->get_lang('DeleteNotification'), [], ICON_SIZE_MEDIUM), |
||||||
33 | api_get_self().'?'.api_get_cidreq().'&action=delete' |
||||||
34 | ); |
||||||
35 | |||||||
36 | if ('delete' === $action) { |
||||||
37 | $em->remove($notification); |
||||||
38 | $em->flush(); |
||||||
39 | |||||||
40 | Display::addFlash( |
||||||
41 | Display::return_message($plugin->get_lang('NotificationDeleted'), 'success') |
||||||
42 | ); |
||||||
43 | |||||||
44 | header('Location: '.api_get_course_url()); |
||||||
45 | exit; |
||||||
46 | } |
||||||
47 | } else { |
||||||
48 | $notification = new Notification(); |
||||||
49 | } |
||||||
50 | |||||||
51 | $form = new FormValidator('frm_course_home_notify'); |
||||||
52 | $form->addHeader($plugin->get_lang('AddNotification')); |
||||||
53 | $form->applyFilter('title', 'trim'); |
||||||
54 | $form->addHtmlEditor('content', get_lang('Content'), true, false, ['ToolbarSet' => 'Minimal']); |
||||||
55 | $form->addUrl( |
||||||
56 | 'expiration_link', |
||||||
57 | [$plugin->get_lang('ExpirationLink'), $plugin->get_lang('ExpirationLinkHelp')], |
||||||
58 | false, |
||||||
59 | ['placeholder' => 'https://'] |
||||||
60 | ); |
||||||
61 | $form->addButtonSave(get_lang('Save')); |
||||||
62 | |||||||
63 | if ($form->validate()) { |
||||||
64 | $values = $form->exportValues(); |
||||||
65 | |||||||
66 | $notification |
||||||
67 | ->setContent($values['content']) |
||||||
0 ignored issues
–
show
The method
setContent() does not exist on Notification .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
68 | ->setExpirationLink($values['expiration_link']) |
||||||
69 | ->setCourse($course) |
||||||
70 | ->setHash(md5(uniqid())); |
||||||
71 | |||||||
72 | $em->persist($notification); |
||||||
73 | $em->flush(); |
||||||
74 | |||||||
75 | Display::addFlash( |
||||||
76 | Display::return_message($plugin->get_lang('NotificationAdded'), 'success') |
||||||
77 | ); |
||||||
78 | |||||||
79 | header('Location: '.api_get_course_url()); |
||||||
80 | exit; |
||||||
81 | } |
||||||
82 | |||||||
83 | if ($notification) { |
||||||
0 ignored issues
–
show
|
|||||||
84 | $form->setDefaults( |
||||||
85 | [ |
||||||
86 | 'content' => $notification->getContent(), |
||||||
0 ignored issues
–
show
The method
getContent() does not exist on Notification .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
87 | 'expiration_link' => $notification->getExpirationLink(), |
||||||
0 ignored issues
–
show
The method
getExpirationLink() does not exist on Notification .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
88 | ] |
||||||
89 | ); |
||||||
90 | } |
||||||
91 | |||||||
92 | $template = new Template($plugin->get_title()); |
||||||
93 | $template->assign('header', $plugin->get_title()); |
||||||
94 | |||||||
95 | if ($actionLinks) { |
||||||
96 | $template->assign('actions', Display::toolbarAction('course-home-notify-actions', ['', $actionLinks])); |
||||||
97 | } |
||||||
98 | |||||||
99 | $template->assign('content', $form->returnForm()); |
||||||
100 | $template->display_one_col_template(); |
||||||
101 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: