extra_field.ajax.php 1.9 KB

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