extra_field.ajax.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once '../global.inc.php';
  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. $field_id,
  14. $option_value_id,
  15. true
  16. );
  17. }
  18. break;
  19. case 'search_tags':
  20. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
  21. $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
  22. $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : null;
  23. $extraFieldOption = new ExtraFieldOption($type);
  24. $result = [];
  25. $tags = Database::getManager()
  26. ->getRepository('ChamiloCoreBundle:Tag')
  27. ->createQueryBuilder('t')
  28. ->where("t.tag LIKE :tag")
  29. ->andWhere('t.fieldId = :field')
  30. ->setParameter('field', $fieldId)
  31. ->setParameter('tag', "$tag%")
  32. ->getQuery()
  33. ->getResult();
  34. foreach ($tags as $tag) {
  35. $result[] = [
  36. 'caption' => $tag->getTag(),
  37. 'value' => $tag->getTag()
  38. ];
  39. }
  40. echo json_encode($result);
  41. break;
  42. default:
  43. exit;
  44. break;
  45. }
  46. exit;