I created a Block View designed to appear on a Project node type. My Project node contains a CCK User Reference field that links to 1 User of the site who is the project leader (but not necessarily that Project node's author). Users can be associated with more than one Project, hence the reason for my block view. When you view a Project, you see the other Projects that the Project leader is also leading.

So I am 95% done EXCEPT for the fact that i am currently querying the UID of the NODE AUTHOR and NOT the REFERENCED USER. I have been tearing my eyeballs out on these forums for hours and hours trying to find some PHP code that can provide my Argument with the UID of the REFERENCED USER, but it's all been dead ends so far.

This must be simple, I just don't know the PHP to make it work. Please, if anyone can give me some guidance here i would be most grateful. Below is my view code.

$view = new view;
$view->name = 'leader_projects_block';
$view->description = 'Block for displaying projects the leader of the current project is managing.';
$view->tag = 'leaders';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'field_leader_user_id_uid' => array(
    'label' => 'Leader User ID',
    'required' => 1,
    'delta' => -1,
    'id' => 'field_leader_user_id_uid',
    'table' => 'node_data_field_leader_user_id',
    'field' => 'field_leader_user_id_uid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'field_my_contact_page_nid',
  ),
));
$handler->override_option('arguments', array(
  'field_leader_user_id_uid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'user',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'field_leader_user_id_uid',
    'table' => 'node_data_field_leader_user_id',
    'field' => 'field_leader_user_id_uid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '4' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 0,
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'project' => 0,
      'book' => 0,
      'contact' => 0,
      'group' => 0,
      'member_profile' => 0,
      'page' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_is_member' => 'OG_VIEWS_DO_NOT_VALIDATE_MEMBERSHIP',
    'validate_argument_group_node_type' => array(
      'group' => 0,
    ),
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'project' => 'project',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'field_leader_user_id_uid' => array(
    'operator' => 'not empty',
    'value' => array(),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'field_leader_user_id_uid',
    'table' => 'node_data_field_leader_user_id',
    'field' => 'field_leader_user_id_uid',
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Also Leads');
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 0);
$handler->override_option('items_per_page', 25);
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', 'Leader - Also Leads');
$handler->override_option('block_caching', -1);

Comments

nodecode’s picture

Just to clarify: I have been entering various bits of PHP in the VIEWS > ARGUMENTS > PROVIDE DEFAULT ARGUMENT > PHP CODE section of the above view. I am trying to draw out the UID of the referenced user. Here is some code that I've tried and failed with:

return $node->field_leader_user_id[0]['uid'];

I've also tried many other variations. Any PHP gurus who can help?

nodecode’s picture

Component: Miscellaneous » block displays
merlinofchaos’s picture

Status: Active » Closed (won't fix)

I'm afraid I can't help you identify the proper variable in a $node to pull out a CCK value, but people in the general forums should be able to help.

You don't mention where you're getting the $node; at the very least, make sure you're doing a proper node_load() -- there's snippets all over for that.

nodecode’s picture

Thanks merlin!
Your comment has already got me headed in the right direction i think. BTW I'm loading the node that is currently being viewed.

nodecode’s picture

For anyone looking to do something similar, here is where I found all the answers to my original question:
http://drupal.org/node/598940#comment-2159524