I have a view of content type documents wherein I want the logged in user to request access for each document and after it approved or rejected the status next to that list of documents should show approved or rejected respectively.
I created a custom module to capture the node id, the user id of the requester and the status of the request.
I then created a mymodule.view.inc
file to add the fields of this custom module using handlers. This is the below code:
<?php
function mymodule_views_data() {
$data = array();
$data['mymodule']['table']['group'] = t('Document Approval');
$data['mymodule']['table']['join']['node'] = array(
'left_field' => 'nid',
'field' => 'nid',
);
$data['mymodule']['nid'] = array(
'title' => t('Nid'),
'help' => t('The node id of the approval node'),
'field' => array(
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),
'argument' => array(
'handler' =>'views_handler_argument_node_nid',
'name field' => 'title',
'numeric' => TRUE,
'validate type' => 'nid',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'label' => t('Node'),
'base' => 'node',
'base field' => 'nid',
),
);
$data['mymodule']['uid'] = array(
'title' => t('Uid'),
'help' => t('The user id of the user requested access'),
'field' => array(
'handler' => 'views_handler_field_user',
'click sortable' => TRUE,
),
'argument' => array(
'handler' =>'views_handler_argument_user_uid',
'name field' => 'title',
'numeric' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'label' => t('User'),
'base' => 'users',
'base field' => 'uid',
),
);
$data['mymodule']['status'] = array(
'title' => t('Status'),
'help' => t('The status of the approval node'),
'field' => array(
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),
'argument' => array(
'handler' =>'views_handler_argument_node_nid',
'name field' => 'title',
'numeric' => TRUE,
'validate type' => 'nid',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
/*'relationship' => array(
'label' => t('Node'),
'base' => 'node',
'base field' => 'nid',
),*/
);
return $data;
}
I am able to see these fields in my view. I am confused as to how do I further use this in my views to get what I want. I want the user to see the status in front of each node.He should see all nodes. And for the user whose no record is found in my custom table he should also see all nodes with "request access" status.
I tried creating a relationship using nid of my custom table and adding a field status with requiring relationship, but I get duplicate results.
I would also like to know if there is any better way of handling this use case.