add_category.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\PortfolioCategory;
  4. $form = new FormValidator('add_category', 'post', "$baseUrl&action=add_category");
  5. if (api_get_configuration_value('save_titles_as_html')) {
  6. $form->addHtmlEditor('title', get_lang('Title'), true, false, ['ToolbarSet' => 'TitleAsHtml']);
  7. } else {
  8. $form->addText('title', get_lang('Title'));
  9. $form->applyFilter('title', 'trim');
  10. }
  11. $form->addHtmlEditor('description', get_lang('Description'), false, false, ['ToolbarSet' => 'Minimal']);
  12. $form->addButtonCreate(get_lang('Create'));
  13. if ($form->validate()) {
  14. $values = $form->exportValues();
  15. $category = new PortfolioCategory();
  16. $category
  17. ->setTitle($values['title'])
  18. ->setDescription($values['description'])
  19. ->setUser($user);
  20. $em->persist($category);
  21. $em->flush();
  22. Display::addFlash(
  23. Display::return_message(get_lang('Category added'), 'success')
  24. );
  25. header("Location: $baseUrl");
  26. exit;
  27. }
  28. $toolName = get_lang('Add category');
  29. $interbreadcrumb[] = [
  30. 'name' => get_lang('Portfolio'),
  31. 'url' => $baseUrl,
  32. ];
  33. $actions[] = Display::url(
  34. Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
  35. $baseUrl
  36. );
  37. $content = $form->returnForm();