materio_search_api.admin.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. function materio_search_api_settings(){
  3. $indexes = search_api_index_load_multiple(false);
  4. // dsm($indexes, '$indexes');
  5. foreach ($indexes as $machine_name => $index) {
  6. if($index->enabled == 1)
  7. $index_options[$index->machine_name] = $index->name;
  8. }
  9. $languages = locale_language_list();
  10. // dsm($languages, 'languages');
  11. $form = array();
  12. // Solr indexes by language
  13. foreach ($languages as $lcode => $name) {
  14. $form['fulltextsearchindex_'.$lcode] = array(
  15. '#type'=>'select',
  16. '#options'=>$index_options,
  17. '#default_value' => variable_get('fulltextsearchindex_'.$lcode, -1),
  18. '#title' => t('Full text search api index for %lang contents.', array('%lang'=>$name)),
  19. );
  20. $form['taxonomysearchindex_'.$lcode] = array(
  21. '#type'=>'select',
  22. '#options'=>$index_options,
  23. '#default_value' => variable_get('taxonomysearchindex_'.$lcode, -1),
  24. '#title' => t('Taxonomy search api index for %lang contents.', array('%lang'=>$name)),
  25. );
  26. $form['brevessearchindex_'.$lcode] = array(
  27. '#type'=>'select',
  28. '#options'=>$index_options,
  29. '#default_value' => variable_get('brevessearchindex_'.$lcode, -1),
  30. '#title' => t('Breves search api index for %lang contents.', array('%lang'=>$name)),
  31. );
  32. $form['autocompletesearchindex_'.$lcode] = array(
  33. '#type'=>'select',
  34. '#options'=>$index_options,
  35. '#default_value' => variable_get('autocompletesearchindex_'.$lcode, -1),
  36. '#title' => t('Autocomplete search api index for %lang contents.', array('%lang'=>$name)),
  37. );
  38. }
  39. // view modes
  40. // TODO: select the activated viewmodes for change view mode and selected view mode
  41. $entity_infos = entity_get_info();
  42. // dsm($entity_infos, 'entity_infos');
  43. foreach ($entity_infos['node']['view modes'] as $viewmode => $value) {
  44. $viewmode_options[$viewmode] = $value['label'];
  45. }
  46. $form['availableviewmodes'] = array(
  47. '#type'=>'select',
  48. '#options'=>$viewmode_options,
  49. '#default_value' => variable_get('availableviewmodes', array()),
  50. '#title' => t('Availble View modes'),
  51. '#multiple' => true,
  52. );
  53. $form['defaultviewmode'] = array(
  54. '#type'=>'select',
  55. '#options'=>$viewmode_options,
  56. '#default_value' => variable_get('defaultviewmode', 'full'),
  57. '#title' => t('Defalut View mode'),
  58. );
  59. // limits by view mode
  60. foreach (variable_get('availableviewmodes', array()) as $viewmode => $value) {
  61. $form[$viewmode.'_limite'] = array(
  62. '#type'=>'textfield',
  63. '#size'=>5,
  64. '#default_value' => variable_get($viewmode.'_limite', '10'),
  65. '#title' => t('@vm limite', array('@vm'=>$viewmode)),
  66. );
  67. }
  68. // advanced search vocabulary
  69. $vocs = taxonomy_get_vocabularies();
  70. // dsm($vocs, 'vocs');
  71. $vocs_options = array();
  72. foreach ($vocs as $vid => $voc) {
  73. $vocs_options[$vid] = $voc->name;
  74. }
  75. $form['msa-advancedsearchvocabulary'] = array(
  76. '#type' => 'select',
  77. '#options' => $vocs_options,
  78. '#default' => variable_get('msa-advancedsearchvocabulary', null),
  79. '#title' => t('advanced search vocabulary'),
  80. '#description' => 'Choose which vocabulary will be used for advanced search form',
  81. );
  82. // advanced search hide some taxonomy terms
  83. if($vid = variable_get('msa-advancedsearchvocabulary', null)){
  84. $tree = msa_taxonomy_get_nested_tree(taxonomy_get_tree($vid));
  85. // dsm($tree, "tree");
  86. $tree_options = array();
  87. msa_get_nested_tree_options($tree, $tree_options);
  88. // dsm($tree_options, 'tree_options');
  89. $form['msa-hiddentaxoterms'] = array(
  90. '#type' => 'select',
  91. '#options' => $tree_options,
  92. '#default_value' => variable_get('msa-hiddentaxoterms', array()),
  93. '#multiple' => TRUE,
  94. '#title' => t('Hidden taxonomy terms'),
  95. '#description' => t('Select terms which will be hidden from advanced search form')
  96. );
  97. }
  98. return system_settings_form($form);
  99. }
  100. function msa_taxonomy_get_nested_tree($terms = array(), $max_depth = NULL, $parent = 0, $parents_index = array(), $depth = 0) {
  101. if (is_int($terms)) {
  102. $terms = taxonomy_get_tree($terms);
  103. }
  104. foreach($terms as $term) {
  105. foreach($term->parents as $term_parent) {
  106. if ($term_parent == $parent) {
  107. $return[$term->tid] = $term;
  108. }
  109. else {
  110. $parents_index[$term_parent][$term->tid] = $term;
  111. }
  112. }
  113. }
  114. foreach($return as &$term) {
  115. if (isset($parents_index[$term->tid]) && (is_null($max_depth) || $depth < $max_depth)) {
  116. $term->children = msa_taxonomy_get_nested_tree($parents_index[$term->tid], $max_depth, $term->tid, $parents_index, $depth + 1);
  117. }
  118. }
  119. return $return;
  120. }
  121. function msa_get_nested_tree_options($tree, &$options, $prefix = ""){
  122. foreach ($tree as $tid => $term) {
  123. $options[$tid] = $prefix . $term->name;
  124. if(isset($term->children)){
  125. msa_get_nested_tree_options($term->children, $options, $prefix."$term->name - ");
  126. }
  127. }
  128. }