/[drupal]/contributions/modules/cck/nodereference.module
ViewVC logotype

Diff of /contributions/modules/cck/nodereference.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.121, Tue Mar 25 13:12:41 2008 UTC revision 1.122, Wed Mar 26 22:21:21 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: nodereference.module,v 1.120 2008/03/24 01:59:03 yched Exp $  // $Id: nodereference.module,v 1.121 2008/03/25 13:12:41 karens Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 534  function nodereference_allowed_values($f Line 534  function nodereference_allowed_values($f
534   * for use in presenting the selection form to the user.   * for use in presenting the selection form to the user.
535   */   */
536  function _nodereference_potential_references($field, $return_full_nodes = FALSE, $string = '', $exact_string = false) {  function _nodereference_potential_references($field, $return_full_nodes = FALSE, $string = '', $exact_string = false) {
537    // TODO Once filtering by title is working, get rid of "empty($string)" constraint to use this with autocomplete.    if (module_exists('views')
538    if (empty($string) && module_exists('views') && isset($field['advanced_view']) && $field['advanced_view'] != '--' && ($view = views_get_view($field['advanced_view']))) {    && isset($field['advanced_view'])
539      && $field['advanced_view'] != '--'
540      && ($view = views_get_view($field['advanced_view']))) {
541      // advanced field : referenceable nodes defined by a view      // advanced field : referenceable nodes defined by a view
542      // let views.module build the query      // let views.module build the query
543    
544      $view->init();      $view->init();
545    
546      // TODO is this the right way to do this?      // TODO is this the right way to do this?
547      // make sure the fields get included in the query      // make sure the fields get included in the query.
     $view->set_display('page');  
     $view->display['page']->style_plugin = 'list';  
548    
549      // arguments for the view      // TODO Which display should we use here?
550        // In our Views 1 to Views 2 updates we are
551        // putting fields in the 'default' display.
552        $display = 'default';
553        $view->set_display($display);
554        $view->display[$display]->style_plugin = 'list';
555    
556        // Add arguments for the view.
557      if (isset($field['advanced_view_args'])) {      if (isset($field['advanced_view_args'])) {
558        // TODO: Support Tokens using token.module ?        // TODO: Support Tokens using token.module ?
559        $view_args = array();        $view_args = array();
# Line 554  function _nodereference_potential_refere Line 561  function _nodereference_potential_refere
561        $view->set_arguments($view_args);        $view->set_arguments($view_args);
562      }      }
563    
564      // TODO Filtering by title is not yet working in Views 2, can't do this yet??      if (isset($string)) {
565      //if (isset($string)) {        //We do need title field, so add it if not present (unlikely, but...)
566      //  views_view_add_filter($view, 'node', 'title', $exact_string ? '=' : 'contains', $string, null);        if (!array_key_exists('title', $view->display[$display]->display_options['fields'])) {
567      //}          $view->add_item($display, 'field', 'node', 'title');
568          }
569      // we do need title field, so add it if not present (unlikely, but...)        // We use the title filter in the view, so make sure it's there.
570      //$has_title = array_reduce($view->field, create_function('$a, $b', 'return ($b["field"] == "title") || $a;'), false);        if (!array_key_exists('title', $view->display[$display]->display_options['filters'])) {
571      //if (!$has_title) {          $view->add_item($display, 'filter', 'node', 'title');
572      //  views_view_add_field($view, 'node', 'title', '');        }
573      //}        // TODO Is this the best way to set values?
574      //views_load_cache();        $view->display[$display]->display_options['filters']['title']['value'] = $string;
575      //views_sanitize_view($view);        $view->display[$display]->display_options['filters']['title']['operator'] = $exact_string ? '=' : 'contains';
576        }
577    
578      // make sure the query is not cached      // Make sure the query is not cached
579      $view->is_cacheable = FALSE;      $view->is_cacheable = FALSE;
580    
581      $view->execute();      $view->execute();
# Line 642  function nodereference_autocomplete($fie Line 650  function nodereference_autocomplete($fie
650  function _nodereference_item($field, $item, $html = FALSE) {  function _nodereference_item($field, $item, $html = FALSE) {
651    if (module_exists('views') && isset($field['advanced_view']) && $field['advanced_view'] != '--' && ($view = views_get_view($field['advanced_view']))) {    if (module_exists('views') && isset($field['advanced_view']) && $field['advanced_view'] != '--' && ($view = views_get_view($field['advanced_view']))) {
652      $field_names = array();      $field_names = array();
653        $view->execute();
654      foreach ($view->field as $name => $viewfield) {      foreach ($view->field as $name => $viewfield) {
655        $field_names[] = $name;        $field_names[] = isset($viewfield->definition['content_field_name']) ? $viewfield->definition['content_field_name'] : $name;
656      }      }
657      $output = theme('nodereference_item_advanced', $item, $field_names, $view);      $output = theme('nodereference_item_advanced', $item, $field_names, $view);
658      if (!$html) {      if (!$html) {

Legend:
Removed from v.1.121  
changed lines
  Added in v.1.122

  ViewVC Help
Powered by ViewVC 1.1.2