Index: advpoll.module =================================================================== --- advpoll.module (revision 1424) +++ advpoll.module (revision 1457) @@ -189,6 +189,15 @@ } /** + * Implementation of hook_init(). + */ +function advpoll_init() { + if (module_exists('views')) { + require_once(drupal_get_path('module', 'advpoll') .'/advpoll_views.inc'); + } +} + +/** * Implementation of hook_block(). */ function advpoll_block($op = 'list') { Index: advpoll_views.inc =================================================================== --- advpoll_views.inc (revision 0) +++ advpoll_views.inc (revision 1457) @@ -0,0 +1,147 @@ + "votingapi_vote", + "provider" => "votingapi", + "join" => array( + "left" => array( + "table" => "node", + "field" => "nid" + ), + "right" => array( + "field" => "content_id" + ), + "extra" => array( + 'content_type' => 'advpoll', + 'value_type' => 'option', + ), + ), + "fields" => array( + "value" => array( + 'name' => t('Advanced Poll: value'), + 'handler' => votingapi_get_formatters(array('value_type' => 'option')), + 'value_type' => 'option', + 'sortable' => TRUE, + ), + "timestamp" => array( + 'name' => t('Advanced Poll: timestamp'), + 'sortable' => TRUE, + 'handler' => + array( + "views_handler_field_date_small" => t('As Short Date'), + "views_handler_field_date" => t('As Medium Date'), + "views_handler_field_date_large" => t('As Long Date'), + "views_handler_field_since" => t('As Time Ago') + ), + 'sortable' => TRUE, + 'help' => "Display the time the vote was cast.", + ), + "uid" => array( + 'name' => t('Advanced Poll: user'), + 'handler' => 'votingapi_views_handler_field_username', + 'sortable' => TRUE, + ), + ), + "sorts" => array( + "value" => array('name' => t('Advanced Poll: vote')), + "uid" => array('name' => t('Advanced Poll: voter')), + "timestamp" => array('name' => t('Advanced Poll: timestamp')), + ), + 'filters' => array( + 'value' => array( + 'name' => t('Advanced Poll: value'), + 'operator' => 'views_handler_operator_gtlt', + 'handler' => 'votingapi_handler_filter_value', + 'value-type' => 'string', + 'help' => t('Filter nodes by values of the individual votes users cast for them.'), + ), + 'timestamp' => array( + 'name' => t('Advanced Poll: timestamp'), + 'operator' => 'views_handler_operator_gtlt', + 'value' => views_handler_filter_date_value_form(), + 'handler' => 'views_handler_filter_timestamp', + 'option' => 'string', + 'help' => t('Filter nodes by the date they were voted on.') + .' '. views_t_strings('filter date'), + ), + 'uid' => array( + 'name' => t('Advanced Poll: user'), + 'operator' => array('IS NOT NULL' => t('Has been voted on by'), 'IS NULL' => t('Has not been voted on by')), + 'list' => array('***CURRENT_USER***' => t('Currently Logged In User'), '***ANY_USER***' => t('Any user')), + 'list-type' => 'select', + 'handler' => 'votingapi_handler_filter_uid_voted', + 'help' => t('Filter nodes by whether the currently logged in user has voted.'), + 'content_type' => 'advpoll', + 'value_type' => 'option', + ) + ), + ); + + $tables['votingapi_advpoll_current_user'] = array( + "name" => "votingapi_vote", + "provider" => "votingapi", + "join" => array( + "left" => array( + "table" => "node", + "field" => "nid" + ), + "right" => array( + "field" => "content_id" + ), + "extra" => array( + 'content_type' => 'advpoll', + 'value_type' => 'option', + 'uid' => '***CURRENT_USER***' + ), + ), + "fields" => array( + "value" => array( + 'name' => t('Advanced Poll: value (current user only)'), + 'field' => 'value', + 'handler' => votingapi_get_formatters(array('value_type' => 'option')), + 'value_type' => 'option', + 'sortable' => TRUE, + ), + + "timestamp" => array( + 'name' => t('Advanced Poll: timestamp (current user only)'), + 'sortable' => TRUE, + 'handler' => + array( + "views_handler_field_date_small" => t('As Short Date'), + "views_handler_field_date" => t('As Medium Date'), + "views_handler_field_date_large" => t('As Long Date'), + "views_handler_field_since" => t('As Time Ago') + ), + 'sortable' => TRUE, + 'help' => "Display the time the vote was cast.", + ), + ), + "sorts" => array( + "value" => array('name' => t("Advanced Poll: !type vote", array('!type' => 'option'))), + "timestamp" => array('name' => t("Advanced Poll: !type timestamp", array('!type' => 'option'))), + ), + 'filters' => array( + 'value' => array( + 'name' => t('Advanced Poll: value (current user only)'), + 'operator' => 'views_handler_operator_gtlt', + 'handler' => 'votingapi_handler_filter_value', + 'value-type' => 'string', + 'help' => t("Filter nodes by values of the current user's vote for them."), + ), + 'timestamp' => array( + 'name' => t('Advanced Poll: timestamp (current user only)'), + 'operator' => 'views_handler_operator_gtlt', + 'value' => views_handler_filter_date_value_form(), + 'handler' => 'views_handler_filter_timestamp', + 'option' => 'string', + 'help' => t('Filter nodes by the date they were voted on by the current user.') + .' '. views_t_strings('filter date'), + ), + ), + ); + + return $tables; +}