edit_item.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $categories = $em
  4. ->getRepository('ChamiloCoreBundle:PortfolioCategory')
  5. ->findBy([
  6. 'user' => $user,
  7. ]);
  8. $form = new FormValidator('edit_portfolio', 'post', $baseUrl."action=edit_item&id={$item->getId()}");
  9. if (api_get_configuration_value('save_titles_as_html')) {
  10. $form->addHtmlEditor('title', get_lang('Title'), true, false, ['ToolbarSet' => 'NotebookStudent']);
  11. } else {
  12. $form->addText('title', get_lang('Title'));
  13. $form->applyFilter('title', 'trim');
  14. }
  15. $form->addHtmlEditor('content', get_lang('Content'), true, false, ['ToolbarSet' => 'NotebookStudent']);
  16. $form->addSelectFromCollection('category', get_lang('Category'), $categories, [], true, '__toString');
  17. $form->addButtonUpdate(get_lang('Update'));
  18. $form->setDefaults([
  19. 'title' => $item->getTitle(),
  20. 'content' => $item->getContent(),
  21. 'category' => $item->getCategory() ? $item->getCategory()->getId() : '',
  22. ]);
  23. if ($form->validate()) {
  24. $values = $form->exportValues();
  25. $currentTime = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
  26. $item
  27. ->setTitle($values['title'])
  28. ->setContent($values['content'])
  29. ->setUpdateDate($currentTime)
  30. ->setCategory(
  31. $em->find('ChamiloCoreBundle:PortfolioCategory', $values['category'])
  32. );
  33. $em->persist($item);
  34. $em->flush();
  35. Display::addFlash(
  36. Display::return_message(get_lang('ItemUpdated'), 'success')
  37. );
  38. header("Location: $baseUrl");
  39. exit;
  40. }
  41. $toolName = get_lang('EditPortfolioItem');
  42. $interbreadcrumb[] = [
  43. 'name' => get_lang('Portfolio'),
  44. 'url' => $baseUrl,
  45. ];
  46. $actions[] = Display::url(
  47. Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
  48. $baseUrl
  49. );
  50. $content = $form->returnForm();