1 | <?php |
||
2 | /* For license terms, see /license.txt */ |
||
3 | |||
4 | use Chamilo\CoreBundle\Entity\Skill; |
||
0 ignored issues
–
show
|
|||
5 | |||
6 | /** |
||
7 | * This script manages the skills, levels and profiles assignments. |
||
8 | */ |
||
9 | $cidReset = true; |
||
10 | require_once __DIR__.'/../inc/global.inc.php'; |
||
11 | api_protect_admin_script(); |
||
12 | $em = Database::getManager(); |
||
13 | $profiles = $em->getRepository('ChamiloSkillBundle:Profile')->findAll(); |
||
14 | $list = $em->getRepository('ChamiloCoreBundle:Skill')->findAll(); |
||
15 | |||
16 | $listAction = api_get_self(); |
||
17 | $toolbarAction = ''; |
||
18 | |||
19 | $action = ''; |
||
20 | if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete'])) { |
||
21 | $action = $_GET['action']; |
||
22 | } |
||
23 | |||
24 | $id = isset($_GET['id']) ? $_GET['id'] : ''; |
||
25 | |||
26 | $item = null; |
||
27 | if (!empty($id)) { |
||
28 | /** @var Skill $item */ |
||
29 | $item = $em->getRepository('ChamiloCoreBundle:Skill')->find($id); |
||
30 | if (!$item) { |
||
31 | api_not_allowed(); |
||
32 | } |
||
33 | } |
||
34 | |||
35 | $form = new FormValidator('Skill', 'GET', api_get_self().'?action='.$action.'&id='.$id); |
||
36 | $form->addSelectFromCollection('profile_id', get_lang('Profile'), $profiles, null, true); |
||
37 | $form->addHidden('action', $action); |
||
38 | $form->addHidden('id', $id); |
||
39 | $form->addButtonSave(get_lang('Update')); |
||
40 | |||
41 | if (!empty($item)) { |
||
42 | $profile = $item->getProfile(); |
||
43 | if ($profile) { |
||
44 | $form->setDefaults( |
||
45 | [ |
||
46 | 'profile_id' => $item->getProfile()->getId(), |
||
47 | ] |
||
48 | ); |
||
49 | } |
||
50 | $form->addHeader($item->getName()); |
||
51 | } |
||
52 | $formToDisplay = $form->returnForm(); |
||
53 | |||
54 | $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')]; |
||
55 | $interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('ManageSkillsLevels')]; |
||
56 | |||
57 | $tpl = new Template($action); |
||
58 | switch ($action) { |
||
59 | case 'edit': |
||
60 | $tpl->assign('form', $formToDisplay); |
||
61 | $toolbarAction = Display::toolbarAction('toolbar', [Display::url(get_lang('List'), $listAction)]); |
||
62 | |||
63 | if ($form->validate()) { |
||
64 | $values = $form->exportValues(); |
||
65 | $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']); |
||
66 | if ($profile) { |
||
67 | $item->setProfile($profile); |
||
68 | $em->persist($item); |
||
69 | $em->flush(); |
||
70 | Display::addFlash(Display::return_message(get_lang('Updated'))); |
||
71 | } |
||
72 | header('Location: '.$listAction); |
||
73 | exit; |
||
74 | } |
||
75 | break; |
||
76 | case 'delete': |
||
77 | $toolbarAction = Display::toolbarAction('toolbar', [Display::url(get_lang('List'), $listAction)]); |
||
78 | |||
79 | $em->remove($item); |
||
80 | $em->flush(); |
||
81 | header('Location: '.$listAction); |
||
82 | exit; |
||
83 | |||
84 | break; |
||
85 | default: |
||
86 | break; |
||
87 | } |
||
88 | |||
89 | $tpl->assign('list', $list); |
||
90 | $view = $tpl->get_template('admin/skill.tpl'); |
||
91 | $contentTemplate = $tpl->fetch($view); |
||
92 | $tpl->assign('actions', $toolbarAction); |
||
93 | $tpl->assign('content', $contentTemplate); |
||
94 | $tpl->display_one_col_template(); |
||
95 |
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: