chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | /* For licensing terms, see /license.txt */ |
||
| 4 | |||
| 5 | use Chamilo\CoreBundle\Entity\Portfolio; |
||
| 6 | use Chamilo\CoreBundle\Entity\PortfolioCategory; |
||
| 7 | use Chamilo\CoreBundle\Entity\PortfolioComment; |
||
| 8 | use Chamilo\CoreBundle\Entity\Tag; |
||
| 9 | use Symfony\Component\HttpFoundation\Request as HttpRequest; |
||
|
0 ignored issues
–
show
|
|||
| 10 | |||
| 11 | // Make sure we void the course context if we are in the social network section |
||
| 12 | if (empty($_GET['cidReq'])) { |
||
| 13 | $cidReset = true; |
||
| 14 | } |
||
| 15 | require_once __DIR__.'/../inc/global.inc.php'; |
||
| 16 | |||
| 17 | api_block_anonymous_users(); |
||
| 18 | |||
| 19 | if (api_get_course_int_id()) { |
||
| 20 | api_protect_course_script(true); |
||
| 21 | } |
||
| 22 | |||
| 23 | if (false === api_get_configuration_value('allow_portfolio_tool')) { |
||
| 24 | api_not_allowed(true); |
||
| 25 | } |
||
| 26 | |||
| 27 | $httpRequest = HttpRequest::createFromGlobals(); |
||
| 28 | $action = $httpRequest->query->get('action', 'list'); |
||
| 29 | |||
| 30 | // It validates the management of categories will be only for admins |
||
| 31 | if (in_array($action, ['list_categories', 'add_category', 'edit_category']) && !api_is_platform_admin()) { |
||
| 32 | api_not_allowed(true); |
||
| 33 | } |
||
| 34 | |||
| 35 | // It includes the user language for translations |
||
| 36 | $checkUserLanguage = true; |
||
| 37 | if ($checkUserLanguage) { |
||
| 38 | global $_user; |
||
| 39 | $langPath = api_get_path(SYS_LANG_PATH).$_user['language'].'/trad4all.inc.php'; |
||
| 40 | if (file_exists($langPath)) { |
||
| 41 | require_once $langPath; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | $controller = new \PortfolioController(); |
||
| 46 | |||
| 47 | $em = Database::getManager(); |
||
| 48 | |||
| 49 | $htmlHeadXtra[] = api_get_js('portfolio.js'); |
||
| 50 | |||
| 51 | switch ($action) { |
||
| 52 | case 'translate_category': |
||
| 53 | $id = $httpRequest->query->getInt('id'); |
||
| 54 | $languageId = $httpRequest->query->getInt('sub_language'); |
||
| 55 | |||
| 56 | /** @var PortfolioCategory $category */ |
||
| 57 | $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); |
||
| 58 | |||
| 59 | if (empty($category)) { |
||
| 60 | break; |
||
| 61 | } |
||
| 62 | |||
| 63 | $languages = $em |
||
| 64 | ->getRepository('ChamiloCoreBundle:Language') |
||
| 65 | ->findAllPlatformSubLanguages(); |
||
| 66 | |||
| 67 | $controller->translateCategory($category, $languages, $languageId); |
||
| 68 | |||
| 69 | return; |
||
| 70 | case 'list_categories': |
||
| 71 | $controller->listCategories(); |
||
| 72 | |||
| 73 | return; |
||
| 74 | case 'add_category': |
||
| 75 | $controller->addCategory(); |
||
| 76 | |||
| 77 | return; |
||
| 78 | case 'edit_category': |
||
| 79 | $id = $httpRequest->query->getInt('id'); |
||
| 80 | |||
| 81 | /** @var PortfolioCategory $category */ |
||
| 82 | $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); |
||
| 83 | |||
| 84 | if (empty($category)) { |
||
| 85 | break; |
||
| 86 | } |
||
| 87 | |||
| 88 | $controller->editCategory($category); |
||
| 89 | |||
| 90 | return; |
||
| 91 | case 'hide_category': |
||
| 92 | case 'show_category': |
||
| 93 | $id = $httpRequest->query->getInt('id'); |
||
| 94 | |||
| 95 | $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); |
||
| 96 | |||
| 97 | if (empty($category)) { |
||
| 98 | break; |
||
| 99 | } |
||
| 100 | |||
| 101 | $controller->showHideCategory($category); |
||
| 102 | |||
| 103 | return; |
||
| 104 | case 'delete_category': |
||
| 105 | $id = $httpRequest->query->getInt('id'); |
||
| 106 | |||
| 107 | /** @var PortfolioCategory $category */ |
||
| 108 | $category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id); |
||
| 109 | |||
| 110 | if (empty($category)) { |
||
| 111 | break; |
||
| 112 | } |
||
| 113 | |||
| 114 | $controller->deleteCategory($category); |
||
| 115 | |||
| 116 | return; |
||
| 117 | case 'add_item': |
||
| 118 | $controller->addItem(); |
||
| 119 | |||
| 120 | return; |
||
| 121 | case 'edit_item': |
||
| 122 | $id = $httpRequest->query->getInt('id'); |
||
| 123 | |||
| 124 | /** @var Portfolio $item */ |
||
| 125 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
| 126 | |||
| 127 | if (empty($item)) { |
||
| 128 | break; |
||
| 129 | } |
||
| 130 | |||
| 131 | $controller->editItem($item); |
||
| 132 | |||
| 133 | return; |
||
| 134 | case 'visibility': |
||
| 135 | $id = $httpRequest->query->getInt('id'); |
||
| 136 | |||
| 137 | /** @var Portfolio $item */ |
||
| 138 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
| 139 | |||
| 140 | if (empty($item)) { |
||
| 141 | break; |
||
| 142 | } |
||
| 143 | |||
| 144 | $controller->showHideItem($item); |
||
| 145 | |||
| 146 | return; |
||
| 147 | case 'item_visiblity_choose': |
||
| 148 | $id = $httpRequest->query->getInt('id'); |
||
| 149 | |||
| 150 | /** @var Portfolio $item */ |
||
| 151 | $item = $em->find(Portfolio::class, $id); |
||
| 152 | |||
| 153 | if (empty($item)) { |
||
| 154 | break; |
||
| 155 | } |
||
| 156 | |||
| 157 | $controller->itemVisibilityChooser($item); |
||
| 158 | break; |
||
| 159 | case 'comment_visiblity_choose': |
||
| 160 | $id = $httpRequest->query->getInt('id'); |
||
| 161 | |||
| 162 | $comment = $em->find(PortfolioComment::class, $id); |
||
| 163 | |||
| 164 | if (empty($comment)) { |
||
| 165 | break; |
||
| 166 | } |
||
| 167 | |||
| 168 | $controller->commentVisibilityChooser($comment); |
||
| 169 | break; |
||
| 170 | case 'delete_item': |
||
| 171 | $id = $httpRequest->query->getInt('id'); |
||
| 172 | |||
| 173 | /** @var Portfolio $item */ |
||
| 174 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
| 175 | |||
| 176 | if (empty($item)) { |
||
| 177 | break; |
||
| 178 | } |
||
| 179 | |||
| 180 | $controller->deleteItem($item); |
||
| 181 | |||
| 182 | return; |
||
| 183 | case 'view': |
||
| 184 | $id = $httpRequest->query->getInt('id'); |
||
| 185 | |||
| 186 | /** @var Portfolio $item */ |
||
| 187 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
| 188 | |||
| 189 | if (empty($item)) { |
||
| 190 | break; |
||
| 191 | } |
||
| 192 | |||
| 193 | $urlUser = $httpRequest->query->getInt('user'); |
||
| 194 | |||
| 195 | $controller->view($item, $urlUser); |
||
| 196 | |||
| 197 | return; |
||
| 198 | case 'copy': |
||
| 199 | case 'teacher_copy': |
||
| 200 | $type = $httpRequest->query->getAlpha('copy'); |
||
| 201 | $id = $httpRequest->query->getInt('id'); |
||
| 202 | |||
| 203 | if ('item' === $type) { |
||
| 204 | $item = $em->find(Portfolio::class, $id); |
||
| 205 | |||
| 206 | if (empty($item)) { |
||
| 207 | break; |
||
| 208 | } |
||
| 209 | |||
| 210 | if ('copy' === $action) { |
||
| 211 | $controller->copyItem($item); |
||
| 212 | } elseif ('teacher_copy' === $action) { |
||
| 213 | $controller->teacherCopyItem($item); |
||
| 214 | } |
||
| 215 | } elseif ('comment' === $type) { |
||
| 216 | $comment = $em->find(PortfolioComment::class, $id); |
||
| 217 | |||
| 218 | if (empty($comment)) { |
||
| 219 | break; |
||
| 220 | } |
||
| 221 | |||
| 222 | if ('copy' === $action) { |
||
| 223 | $controller->copyComment($comment); |
||
| 224 | } elseif ('teacher_copy' === $action) { |
||
| 225 | $controller->teacherCopyComment($comment); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | break; |
||
| 230 | case 'mark_important': |
||
| 231 | api_protect_teacher_script(); |
||
| 232 | |||
| 233 | $item = $em->find(Portfolio::class, $httpRequest->query->getInt('item')); |
||
| 234 | $comment = $em->find(PortfolioComment::class, $httpRequest->query->getInt('id')); |
||
| 235 | |||
| 236 | if (empty($item) || empty($comment)) { |
||
| 237 | break; |
||
| 238 | } |
||
| 239 | |||
| 240 | $controller->markImportantCommentInItem($item, $comment); |
||
| 241 | |||
| 242 | return; |
||
| 243 | case 'details': |
||
| 244 | $controller->details($httpRequest); |
||
| 245 | |||
| 246 | return; |
||
| 247 | case 'export_pdf': |
||
| 248 | $controller->exportPdf($httpRequest); |
||
| 249 | break; |
||
| 250 | case 'export_zip': |
||
| 251 | $controller->exportZip($httpRequest); |
||
| 252 | break; |
||
| 253 | case 'qualify': |
||
| 254 | api_protect_teacher_script(); |
||
| 255 | |||
| 256 | if ($httpRequest->query->has('item')) { |
||
| 257 | if ('1' !== api_get_course_setting('qualify_portfolio_item')) { |
||
| 258 | api_not_allowed(true); |
||
| 259 | } |
||
| 260 | |||
| 261 | /** @var Portfolio $item */ |
||
| 262 | $item = $em->find( |
||
| 263 | Portfolio::class, |
||
| 264 | $httpRequest->query->getInt('item') |
||
| 265 | ); |
||
| 266 | |||
| 267 | if (empty($item)) { |
||
| 268 | break; |
||
| 269 | } |
||
| 270 | |||
| 271 | $controller->qualifyItem($item); |
||
| 272 | } elseif ($httpRequest->query->has('comment')) { |
||
| 273 | if ('1' !== api_get_course_setting('qualify_portfolio_comment')) { |
||
| 274 | api_not_allowed(true); |
||
| 275 | } |
||
| 276 | |||
| 277 | /** @var Portfolio $item */ |
||
| 278 | $comment = $em->find( |
||
| 279 | PortfolioComment::class, |
||
| 280 | $httpRequest->query->getInt('comment') |
||
| 281 | ); |
||
| 282 | |||
| 283 | if (empty($comment)) { |
||
| 284 | break; |
||
| 285 | } |
||
| 286 | |||
| 287 | $controller->qualifyComment($comment); |
||
| 288 | } |
||
| 289 | break; |
||
| 290 | case 'download_attachment': |
||
| 291 | $controller->downloadAttachment($httpRequest); |
||
| 292 | break; |
||
| 293 | case 'delete_attachment': |
||
| 294 | $controller->deleteAttachment($httpRequest); |
||
| 295 | break; |
||
| 296 | case 'highlighted': |
||
| 297 | api_protect_teacher_script(); |
||
| 298 | |||
| 299 | $id = $httpRequest->query->getInt('id'); |
||
| 300 | |||
| 301 | /** @var Portfolio $item */ |
||
| 302 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
| 303 | |||
| 304 | if (empty($item)) { |
||
| 305 | break; |
||
| 306 | } |
||
| 307 | |||
| 308 | $controller->markAsHighlighted($item); |
||
| 309 | break; |
||
| 310 | case 'template': |
||
| 311 | $id = $httpRequest->query->getInt('id'); |
||
| 312 | |||
| 313 | /** @var Portfolio $item */ |
||
| 314 | $item = $em->find('ChamiloCoreBundle:Portfolio', $id); |
||
| 315 | |||
| 316 | if (empty($item)) { |
||
| 317 | break; |
||
| 318 | } |
||
| 319 | |||
| 320 | $controller->markAsTemplate($item); |
||
| 321 | break; |
||
| 322 | case 'template_comment': |
||
| 323 | $id = $httpRequest->query->getInt('id'); |
||
| 324 | |||
| 325 | $comment = $em->find(PortfolioComment::class, $id); |
||
| 326 | |||
| 327 | if (empty($comment)) { |
||
| 328 | break; |
||
| 329 | } |
||
| 330 | |||
| 331 | $controller->markAsTemplateComment($comment); |
||
| 332 | break; |
||
| 333 | case 'edit_comment': |
||
| 334 | $id = $httpRequest->query->getInt('id'); |
||
| 335 | |||
| 336 | $comment = $em->find(PortfolioComment::class, $id); |
||
| 337 | |||
| 338 | if (!empty($comment)) { |
||
| 339 | $controller->editComment($comment); |
||
| 340 | } |
||
| 341 | |||
| 342 | break; |
||
| 343 | case 'delete_comment': |
||
| 344 | $id = $httpRequest->query->getInt('id'); |
||
| 345 | |||
| 346 | $comment = $em->find(PortfolioComment::class, $id); |
||
| 347 | |||
| 348 | if (!empty($comment)) { |
||
| 349 | $controller->deleteComment($comment); |
||
| 350 | } |
||
| 351 | break; |
||
| 352 | case 'tags': |
||
| 353 | case 'edit_tag': |
||
| 354 | $controller->listTags($httpRequest); |
||
| 355 | break; |
||
| 356 | case 'delete_tag': |
||
| 357 | $id = $httpRequest->query->getInt('id'); |
||
| 358 | |||
| 359 | $tag = $em->find(Tag::class, $id); |
||
| 360 | |||
| 361 | if (empty($tag)) { |
||
| 362 | break; |
||
| 363 | } |
||
| 364 | |||
| 365 | $controller->deleteTag($tag); |
||
| 366 | break; |
||
| 367 | case 'list': |
||
| 368 | default: |
||
| 369 | $controller->index($httpRequest); |
||
| 370 | |||
| 371 | return; |
||
| 372 | } |
||
| 373 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: