created advanced search form
This commit is contained in:
		@@ -374,7 +374,7 @@ function materio_search_api_block_info() {
 | 
			
		||||
    'cache' => DRUPAL_NO_CACHE
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  $blocks['materio_search_api_advanced_search'] = array(
 | 
			
		||||
  $blocks['materio_sa_adv_search'] = array(
 | 
			
		||||
    'info' => t('Materio search api advanced search'),
 | 
			
		||||
    'cache' => DRUPAL_NO_CACHE
 | 
			
		||||
  );
 | 
			
		||||
@@ -428,7 +428,7 @@ function materio_search_api_block_view($delta = '') {
 | 
			
		||||
    //     $block['content'] = theme('materio_search_api_filters_block', array());
 | 
			
		||||
    //   }
 | 
			
		||||
    //   break;
 | 
			
		||||
    case 'materio_search_api_advanced_search':
 | 
			
		||||
    case 'materio_sa_adv_search':
 | 
			
		||||
      if(user_access('use materio search api advanced search')){
 | 
			
		||||
        $block['subject'] = t('Advanced Search');
 | 
			
		||||
        $block['content'] = theme('materio_search_api_advanced_search_block', array());
 | 
			
		||||
@@ -596,10 +596,175 @@ function materio_search_api_search_form_submit($form, &$form_state){
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * materiobase_search_form()
 | 
			
		||||
 */
 | 
			
		||||
function materio_search_api_advanced_search_form($form, &$form_state){
 | 
			
		||||
  //  dsm($form_state, 'form_state');
 | 
			
		||||
  // dsm($form, 'form');
 | 
			
		||||
  // global $user;
 | 
			
		||||
 | 
			
		||||
  $form = array();
 | 
			
		||||
 | 
			
		||||
  $vocabularies = variable_get('advancedsearchvocs', array());
 | 
			
		||||
 | 
			
		||||
  foreach ($vocabularies as $vid) {
 | 
			
		||||
    $voc = taxonomy_vocabulary_load($vid);
 | 
			
		||||
    // dsm($voc, 'voc');
 | 
			
		||||
 | 
			
		||||
    // $form['voc-'.$vid] = array(
 | 
			
		||||
    //   '#type' => 'fieldset',
 | 
			
		||||
    //   '#title' => $voc->name,
 | 
			
		||||
    //   '#tree' => true,
 | 
			
		||||
    // );
 | 
			
		||||
 | 
			
		||||
    $tree = taxonomy_get_tree($vid, 0, 1);
 | 
			
		||||
    // dsm($tree, 'tree');
 | 
			
		||||
 | 
			
		||||
    # don't know how to add parent term condition
 | 
			
		||||
    // $query = new EntityFieldQuery();
 | 
			
		||||
    // $result = $query->entityCondition('entity_type', 'taxonomy_term')
 | 
			
		||||
    //   ->propertyCondition('vid', $vid)
 | 
			
		||||
    //   // ->propertyCondition('parent', 0)
 | 
			
		||||
    //   // ->fieldCondition('field_used_on_advanced_search', 'value', 0, "!=")
 | 
			
		||||
    //   ->propertyOrderBy('weight')
 | 
			
		||||
    //   ->execute();
 | 
			
		||||
 | 
			
		||||
    // dsm($result, 'result');
 | 
			
		||||
 | 
			
		||||
    // if (!empty($result['taxonomy_term'])) {
 | 
			
		||||
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
    foreach ($tree as $term) {
 | 
			
		||||
      $term = taxonomy_term_load($term->tid);
 | 
			
		||||
      // dsm($term, "term");
 | 
			
		||||
      if($term->field_used_on_advanced_search['und'][0]['value'] == 0){
 | 
			
		||||
       continue;
 | 
			
		||||
      }
 | 
			
		||||
      $children = taxonomy_get_children($term->tid, $vid);
 | 
			
		||||
      // dsm($children, "children");
 | 
			
		||||
 | 
			
		||||
      $form['tree-'.$term->tid] = array(
 | 
			
		||||
        '#type' => 'fieldset',
 | 
			
		||||
        // '#title' => $term->name,
 | 
			
		||||
        '#attributes' => array("class"=>array("treelevel1")),
 | 
			
		||||
        '#tree' => true,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      $form['tree-'.$term->tid]['children'] = array(
 | 
			
		||||
        '#type' => 'select',
 | 
			
		||||
        '#title' => $term->name,
 | 
			
		||||
        '#attributes' => array(
 | 
			
		||||
          "class"=>array("treelevel1"),
 | 
			
		||||
          "title"=>"-Please select-",
 | 
			
		||||
        ), //, "form-control"
 | 
			
		||||
        '#theme_wrappers' => array('materio_search_api_form_element'),
 | 
			
		||||
        '#empty_option' => '-Please select-',
 | 
			
		||||
        '#empty_value' => 1,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      $options = array();
 | 
			
		||||
      foreach ($children as $tid => $child) {
 | 
			
		||||
        // $child = taxonomy_term_load($child->tid);
 | 
			
		||||
        // if($child->field_used_on_advanced_search['und'][0]['value'] == 0){
 | 
			
		||||
        //  continue;
 | 
			
		||||
        // }
 | 
			
		||||
 | 
			
		||||
        $children2 = taxonomy_get_children($child->tid, $vid);
 | 
			
		||||
        // dsm($children2, "children2");
 | 
			
		||||
 | 
			
		||||
        if(count($children2))
 | 
			
		||||
          $options[$tid] = $child->name;
 | 
			
		||||
 | 
			
		||||
        $options2 = [];
 | 
			
		||||
        foreach ($children2 as $tid2 => $child2) {
 | 
			
		||||
          // $child2 = taxonomy_term_load($child2->tid);
 | 
			
		||||
          // if($child2->field_used_on_advanced_search['und'][0]['value'] == 0){
 | 
			
		||||
          //  continue;
 | 
			
		||||
          // }
 | 
			
		||||
 | 
			
		||||
          $options2[$tid2] = $child2->name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(count($options2))
 | 
			
		||||
          $form['tree-'.$term->tid]['tid-'.$child->tid] = array(
 | 
			
		||||
            '#type' => 'select',
 | 
			
		||||
            '#title' => $child->name,
 | 
			
		||||
            '#multiple' => true,
 | 
			
		||||
            '#attributes' => array(
 | 
			
		||||
              "class" => array("treelevel2", $child->tid), // , "form-control"
 | 
			
		||||
              "title" => "-Please select-",
 | 
			
		||||
            ),
 | 
			
		||||
            '#theme_wrappers' => array('materio_search_api_form_element'),
 | 
			
		||||
            '#empty_option' => '-Please select-',
 | 
			
		||||
            '#empty_value' => 1,
 | 
			
		||||
            '#options' => $options2,
 | 
			
		||||
          );
 | 
			
		||||
 | 
			
		||||
        // $form['tree-'.$term->tid]['child-'.$tid] = array(
 | 
			
		||||
        //   '#type' => 'checkbox',
 | 
			
		||||
        //   '#title' => $child->name,
 | 
			
		||||
        //   // '#options' => $options,
 | 
			
		||||
        // );
 | 
			
		||||
      }
 | 
			
		||||
      $form['tree-'.$term->tid]['children']['#options'] = $options;
 | 
			
		||||
      // break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $form['show'] = array(
 | 
			
		||||
    '#type' => 'submit',//'image_button',
 | 
			
		||||
    // '#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
 | 
			
		||||
    '#value' => t('Find'),
 | 
			
		||||
    '#attributes' => array("class"=>array("btn","btn-lg")),
 | 
			
		||||
    '#prefix' => '<div class="submits">',
 | 
			
		||||
    '#suffix' => '</div>',
 | 
			
		||||
  );
 | 
			
		||||
  return $form;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function materio_search_api_advanced_search_form_validate($form, &$form_state){
 | 
			
		||||
  // dsm($form, '$form');
 | 
			
		||||
  // dsm($form_state, '$form_state');
 | 
			
		||||
  // dsm(strlen($form_state['values']['searchfield']));
 | 
			
		||||
  // if (strlen(trim($form_state['values']['searchfield'])) <= 1) {
 | 
			
		||||
  //   form_set_error('searchfield', 'Please enter at least 2 characters keyword.');
 | 
			
		||||
  // }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function materio_search_api_advanced_search_form_submit($form, &$form_state){
 | 
			
		||||
  // dsm($form_state, 'form_state');
 | 
			
		||||
  // global $user;
 | 
			
		||||
  // if(user_access('use materio search api filters')){
 | 
			
		||||
  //   foreach($form_state['values']['bundles_filter'] as $bundle => $value)
 | 
			
		||||
  //     if($value)
 | 
			
		||||
  //       $bundles[] = $bundle;
 | 
			
		||||
 | 
			
		||||
  //   # if no filter checked we checked them all by default
 | 
			
		||||
  //   if(!isset($bundles))
 | 
			
		||||
  //     foreach($form_state['values']['bundles_filter'] as $bundle => $value)
 | 
			
		||||
  //         $bundles[] = $bundle;
 | 
			
		||||
  // }else{
 | 
			
		||||
  //   # if user have no access to filters
 | 
			
		||||
  //   $index = search_api_index_load(variable_get('mainsearchindex', -1));
 | 
			
		||||
  //   $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
 | 
			
		||||
 | 
			
		||||
  //   foreach ($indexed_bundles as $bundle) {
 | 
			
		||||
  //     $bundles[] = $bundle;
 | 
			
		||||
  //   }
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // user_save($user, array("data"=>array('materiosearchapi_bundlesfilter' => $bundles)));
 | 
			
		||||
 | 
			
		||||
  // $form_state['redirect'] = 'explore/'.$form_state['values']['searchfield'];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * viewmode
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
function _materio_search_api_change_viewmode($vm){
 | 
			
		||||
  // dsm($vm, '_materio_search_api_change_viewmode');
 | 
			
		||||
 | 
			
		||||
@@ -675,7 +840,10 @@ function materio_search_api_theme($existing, $type, $theme, $path) {
 | 
			
		||||
      'template' => 'materio-search-api-advanced-search-block',
 | 
			
		||||
      'path' => drupal_get_path('module', 'materio_search_api').'/templates',
 | 
			
		||||
      'arguments' => array(),
 | 
			
		||||
    )
 | 
			
		||||
    ),
 | 
			
		||||
    'materio_search_api_form_element' => array(
 | 
			
		||||
      'render element' => 'element',
 | 
			
		||||
    ),
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -869,11 +1037,85 @@ function template_preprocess_materio_search_api_actuality(&$vars){
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function template_preprocess_materio_search_api_advanced_search_block(&$vars){
 | 
			
		||||
  dsm($vars, "vars");
 | 
			
		||||
  // dsm($vars, "vars");
 | 
			
		||||
  $vars['searchform'] = drupal_get_form("materio_search_api_advanced_search_form");
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function theme_materio_search_api_form_element($variables) {
 | 
			
		||||
  // dsm($variables, 'variables');
 | 
			
		||||
 | 
			
		||||
  $element = &$variables['element'];
 | 
			
		||||
 | 
			
		||||
  // This function is invoked as theme wrapper, but the rendered form element
 | 
			
		||||
  // may not necessarily have been processed by form_builder().
 | 
			
		||||
  $element += array(
 | 
			
		||||
    '#title_display' => 'before',
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  // Add element #id for #type 'item'.
 | 
			
		||||
  if (isset($element['#markup']) && !empty($element['#id'])) {
 | 
			
		||||
    $attributes['id'] = $element['#id'];
 | 
			
		||||
  }
 | 
			
		||||
  // Add element's #type and #name as class to aid with JS/CSS selectors.
 | 
			
		||||
  $attributes['class'] = array('form-item');
 | 
			
		||||
  if (!empty($element['#type'])) {
 | 
			
		||||
    $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
 | 
			
		||||
  }
 | 
			
		||||
  if (!empty($element['#name'])) {
 | 
			
		||||
    $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
 | 
			
		||||
  }
 | 
			
		||||
  // Add a class for disabled elements to facilitate cross-browser styling.
 | 
			
		||||
  if (!empty($element['#attributes']['disabled'])) {
 | 
			
		||||
    $attributes['class'][] = 'form-disabled';
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  # adding element class to wrapper
 | 
			
		||||
  foreach ($element['#attributes']['class'] as $value) {
 | 
			
		||||
    $attributes['class'][] = $value;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  // If #title is not set, we don't display any label or required marker.
 | 
			
		||||
  if (!isset($element['#title'])) {
 | 
			
		||||
    $element['#title_display'] = 'none';
 | 
			
		||||
  }
 | 
			
		||||
  $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
 | 
			
		||||
  $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
 | 
			
		||||
 | 
			
		||||
  switch ($element['#title_display']) {
 | 
			
		||||
    case 'before':
 | 
			
		||||
    case 'invisible':
 | 
			
		||||
      $output .= ' ' . theme('form_element_label', $variables);
 | 
			
		||||
      $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 'after':
 | 
			
		||||
      $output .= ' ' . $prefix . $element['#children'] . $suffix;
 | 
			
		||||
      $output .= ' ' . theme('form_element_label', $variables) . "\n";
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case 'none':
 | 
			
		||||
    case 'attribute':
 | 
			
		||||
      // Output no label and no required marker, only the children.
 | 
			
		||||
      $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!empty($element['#description'])) {
 | 
			
		||||
    $output .= '<div class="description">' . $element['#description'] . "</div>\n";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $output .= "</div>\n";
 | 
			
		||||
 | 
			
		||||
  return $output;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* - - - - - - - - - - - -  SEARCH API PAGE  - - - - - - - - - - - -
 | 
			
		||||
*/
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user