extra_field.ajax.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Tag;
  4. $action = isset($_GET['a']) ? $_GET['a'] : '';
  5. switch ($action) {
  6. case 'get_second_select_options':
  7. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
  8. $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
  9. $option_value_id = isset($_REQUEST['option_value_id']) ? $_REQUEST['option_value_id'] : null;
  10. if (!empty($type) && !empty($field_id) && !empty($option_value_id)) {
  11. $field_options = new ExtraFieldOption($type);
  12. echo $field_options->get_second_select_field_options_by_field(
  13. $option_value_id,
  14. true
  15. );
  16. }
  17. break;
  18. case 'search_tags':
  19. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
  20. $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
  21. $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : null;
  22. $extraFieldOption = new ExtraFieldOption($type);
  23. $result = [];
  24. $tags = Database::getManager()
  25. ->getRepository('ChamiloCoreBundle:Tag')
  26. ->createQueryBuilder('t')
  27. ->where("t.tag LIKE :tag")
  28. ->andWhere('t.fieldId = :field')
  29. ->setParameter('field', $fieldId)
  30. ->setParameter('tag', "$tag%")
  31. ->getQuery()
  32. ->getResult();
  33. /** @var Tag $tag */
  34. foreach ($tags as $tag) {
  35. $result[] = [
  36. 'key' => $tag->getTag(),
  37. 'value' => $tag->getTag()
  38. ];
  39. }
  40. echo json_encode($result);
  41. break;
  42. default:
  43. exit;
  44. break;
  45. }
  46. exit;