add_item.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Portfolio;
  4. $categories = $em
  5. ->getRepository('ChamiloCoreBundle:PortfolioCategory')
  6. ->findBy([
  7. 'user' => $user,
  8. ]);
  9. $form = new FormValidator('add_portfolio', 'post', $baseUrl.'action=add_item');
  10. if (api_get_configuration_value('save_titles_as_html')) {
  11. $form->addHtmlEditor('title', get_lang('Title'), true, false, ['ToolbarSet' => 'NotebookStudent']);
  12. } else {
  13. $form->addText('title', get_lang('Title'));
  14. $form->applyFilter('title', 'trim');
  15. }
  16. $form->addHtmlEditor('content', get_lang('Content'), true, false, ['ToolbarSet' => 'NotebookStudent']);
  17. $form->addSelectFromCollection('category', get_lang('Category'), $categories, [], true);
  18. $form->addButtonCreate(get_lang('Create'));
  19. if ($form->validate()) {
  20. $values = $form->exportValues();
  21. $currentTime = new DateTime(
  22. api_get_utc_datetime(),
  23. new DateTimeZone('UTC')
  24. );
  25. $portfolio = new Portfolio();
  26. $portfolio
  27. ->setTitle($values['title'])
  28. ->setContent($values['content'])
  29. ->setUser($user)
  30. ->setCourse($course)
  31. ->setSession($session)
  32. ->setCategory(
  33. $em->find('ChamiloCoreBundle:PortfolioCategory', $values['category'])
  34. )
  35. ->setCreationDate($currentTime)
  36. ->setUpdateDate($currentTime);
  37. $em->persist($portfolio);
  38. $em->flush();
  39. Display::addFlash(
  40. Display::return_message(get_lang('PortfolioItemAdded'), 'success')
  41. );
  42. header("Location: $baseUrl");
  43. exit;
  44. }
  45. $toolName = get_lang('AddPortfolioItem');
  46. $interbreadcrumb[] = [
  47. 'name' => get_lang('Portfolio'),
  48. 'url' => $baseUrl,
  49. ];
  50. $actions[] = Display::url(
  51. Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
  52. $baseUrl
  53. );
  54. $content = $form->returnForm();