conditionReplaceString example

      $this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', ['function' => 'sum']);

      // Add the conditions set up by the search query to the views query.       $search_condition->condition("$search_index.type", $this->searchType);
      $search_dataset = $this->query->addTable('node_search_dataset');
      $conditions = $this->searchQuery->conditions();
      $condition_conditions =& $conditions->conditions();
      foreach ($condition_conditions as $key => &$condition) {
        // Make sure we just look at real conditions.         if (is_numeric($key)) {
          // Replace the conditions with the table alias of views.           $this->searchQuery->conditionReplaceString('d.', "$search_dataset.", $condition);
        }
      }
      $search_conditions =& $search_condition->conditions();
      $search_conditions = array_merge($search_conditions$condition_conditions);

      // Add the keyword conditions, as is done in       // SearchQuery::prepareAndNormalize(), but simplified because we are       // only concerned with relevance ranking so we do not need to normalize.       $or = $this->view->query->getConnection()->condition('OR');
      foreach ($words as $word) {
        $or->condition("$search_index.word", $word);
      }
      $this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', ['function' => 'sum']);

      // Add the conditions set up by the search query to the views query.       $search_condition->condition("$search_index.type", $this->searchType);
      $search_dataset = $this->query->addTable('node_search_dataset');
      $conditions = $this->searchQuery->conditions();
      $condition_conditions =& $conditions->conditions();
      foreach ($condition_conditions as $key => &$condition) {
        // Make sure we just look at real conditions.         if (is_numeric($key)) {
          // Replace the conditions with the table alias of views.           $this->searchQuery->conditionReplaceString('d.', "$search_dataset.", $condition);
        }
      }
      $search_conditions =& $search_condition->conditions();
      $search_conditions = array_merge($search_conditions$condition_conditions);

      // Add the keyword conditions, as is done in       // SearchQuery::prepareAndNormalize(), but simplified because we are       // only concerned with relevance ranking so we do not need to normalize.       $or = $this->view->query->getConnection()->condition('OR');
      foreach ($words as $word) {
        $or->condition("$search_index.word", $word);
      }

  public function conditionReplaceString($search$replace, &$condition) {
    if ($condition['field'] instanceof ConditionInterface) {
      $conditions =& $condition['field']->conditions();
      foreach ($conditions as $key => &$subcondition) {
        if (is_numeric($key)) {
          // As conditions can be nested, the function has to be called           // recursively.           $this->conditionReplaceString($search$replace$subcondition);
        }
      }
    }
    else {
      $condition['field'] = str_replace($search$replace$condition['field']);
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.