questions for Views not answered in documentation
Firstly, when I join two fields, do the field names have to be exactly the same? Or can I join two differently named fields that have the same values? (ie. in my code below, which doesn't work of course, I'm trying to join the "node" 'nid' with "content_field_name" 'field_name_nid').
Basically, my problem is this:
I have a separate content-type called 'Hours' where an admin can post an event name (under the Title field which was renamed to Event Name), select multiple users who have attended the event by their real names (which were entered during registration via Node Profile module rather than Profiles), and enter the number of hours that the event lasted for.
I then created a Views page, and I've been able to display the Event names and their corresponding Hours with a table and also filter by the type of node (content type being 'Hours').
But the problem is that I want to further filter out the nodes by the current user and whichever event s/he attended since the Views page lists all of the 'Hours' nodes.
The code below is very likely completely wrong (hence, it not showing under the Filters drop-down for Views when I load up the code as a module). As far as I know, I really only need 1 join with "content_field_name" to filter the nodes by the real names of the users... but I only have a vague idea of what I'm doing, even after reading the documentation...
Some notes:
-When a user registers and enters his/her real name, the name is created as a node authored by that user (as such, the table includes the uid of the user for the real name node). The real name node is stored in the "node" table and is assigned a uid and nid.
-When an admin creates a new node for 'Hours', the event title is stored under "node"
--but the selected list of users by their real names are stored under the "content_field_name" table under a field called "field_name_nid" (since the real name is a node, it's stored as a node ID under this field). Is also assigned an NID which refers back to the corresponding 'Hours' node. A separate entry is created for each name selected. (example: a new 'Hours' node created which has nid 8 contains two real names with nid 12 and 13. Two separate table entries for these users).
--the hours for the events are stored under table "content_type_hours". Each entry under this table has an nid which refers back to the corresponding 'Hours' node for the event. Separate field called "field_hours_value" which contains the number of hours for that event.
If any clarification is needed, please reply with that note. :)
<?php
function hours_views_tables() {
$tables['content_field_name'] = array(
'name' => 'content_field_name',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'field_name_nid'
),
),
);
$tables['content_type_hours'] = array(
'name' => 'content_type_hours',
'join' => array(
'left' => array(
'table' => 'content_field_name',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
),
),
'filter' => array(
'currentuid' => array(
'field' => 'nid',
'name' => t('Filter by Current User'),
'operator' => 'views_handler_operator_eqneq',
'value' => 'views_handler_filter_usercurrent',
'help' => t('This allows you to filter by events containing the name of the logged in user.'),
),
),
);
return $tables;
}
?>
Probably a silly question
I've not had a look at your code, but the first thing to try is clearing the views cache - admin/build/views then click on tools and then click "clear views cache" (or similar) - this might be enough to get your filter to appear in the picker and get you onto some proper debugging ... apologies if you have tried this already ...
Cheers,
Mike,
Computerminds offer Drupal development, consulting and training
Didn't work
Clearing the cache didn't have the filter appear, which must mean that I must be doing something absolutely wrong (no surprises there). I can understand how to do simple filters, but my scenario seems to be more complicated, involving fields with different names but having the same type of values and such...
Any ideas/enlightenment for my filter coding?