materio_search_api.admin.inc 4.9 KB

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