get_second_select_field_options_by_field( $option_value_id, true ); } break; case 'search_tags': header('Content-Type: application/json'); $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null; $tag = isset($_REQUEST['q']) ? $_REQUEST['q'] : null; $result = []; if (empty($tag)) { echo json_encode(['items' => $result]); exit; } $extraFieldOption = new ExtraFieldOption($type); $tags = Database::getManager() ->getRepository('ChamiloCoreBundle:Tag') ->createQueryBuilder('t') ->where("t.tag LIKE :tag") ->andWhere('t.fieldId = :field') ->setParameter('field', $fieldId) ->setParameter('tag', "$tag%") ->getQuery() ->getResult(); /** @var Tag $tag */ foreach ($tags as $tag) { $result[] = [ 'id' => $tag->getTag(), 'text' => $tag->getTag() ]; } echo json_encode(['items' => $result]); break; case 'search_options_from_tags': $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null; $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : null; $extraFieldOption = new ExtraFieldOption($type); $from = isset($_REQUEST['from']) ? $_REQUEST['from'] : ''; $search = isset($_REQUEST['search']) ? $_REQUEST['search'] : ''; $options = isset($_REQUEST['options']) ? json_decode($_REQUEST['options']) : ''; $extraField = new ExtraField('session'); $result = $extraField->searchOptionsFromTags($from, $search, $options); $options = []; $groups = []; foreach ($result as $data) { $groups[$data['display_text']][] = [ 'id' => $data['id'], 'text' => $data['tag'] ]; } foreach ($groups as $key => $data) { $options[] = [ 'text' => $key, 'children' => $groups[$key] ]; } echo json_encode($options); break; case 'order': $variable = isset($_REQUEST['field_variable']) ? $_REQUEST['field_variable'] : ''; $save = isset($_REQUEST['save']) ? $_REQUEST['save'] : ''; $values = isset($_REQUEST['values']) ? json_decode($_REQUEST['values']) : ''; $extraField = new ExtraField('session'); $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable(str_replace('extra_', '', $variable)); $em = Database::getManager(); $search = [ 'user' => api_get_user_id(), 'field' => $extraFieldInfo['id'] ]; $extraFieldSavedSearch = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search); if ($save) { $extraField = new \Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch('session'); if ($extraFieldSavedSearch) { $extraFieldSavedSearch->setValue($values); $em->merge($extraFieldSavedSearch); $em->flush(); } } if ($extraFieldInfo) { /** @var \Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch $options */ $extraFieldSavedSearch = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search); $values = $extraFieldSavedSearch->getValue(); $url = api_get_self().'?a=order&save=1&field_variable='.$variable; $html = ' '; $html .= '