| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 | 
							- diff --git a/uc_roles/uc_roles.views.inc b/uc_roles/uc_roles.views.inc
 
- new file mode 100644
 
- index 0000000..558e461
 
- --- /dev/null
 
- +++ b/uc_roles/uc_roles.views.inc
 
- @@ -0,0 +1,110 @@
 
- +<?php
 
- +
 
- +/**
 
- + * @file
 
- + * Views 2 hooks and callback registries.
 
- + */
 
- +
 
- +
 
- +/**
 
- + * Implementation of hook_views_data().
 
- + */
 
- + 
 
- + function uc_roles_views_data() {
 
- +  $data['uc_roles_expirations']['table']['group']  = t('User');
 
- +
 
- +  $data['uc_roles_expirations']['table']['join'] = array(
 
- +    'users' => array(
 
- +      'left_field' => 'uid',
 
- +      'field' => 'uid',
 
- +    ),
 
- +  );
 
- +
 
- +
 
- +  // Expose the role expiration date
 
- +  $data['uc_roles_expirations']['expiration'] = array(
 
- +    'title' => t('Ubercart Role expiration date/time'),
 
- +    'help' => t('Date and time the role will expire. (See also Role expiration role.)'),
 
- +    'field' => array(
 
- +      'handler' => 'views_handler_field_date',
 
- +      'click sortable' => TRUE,
 
- +    ),
 
- +    'sort' => array(
 
- +      'handler' => 'views_handler_sort_date',
 
- +    ),
 
- +    'filter' => array(
 
- +      'handler' => 'views_handler_filter_date',
 
- +    ),
 
- +  );
 
- +
 
- +
 
- +  // Expose the role id from uc_roles_expirations
 
- +  $data['uc_roles_expirations']['rid'] = array(
 
- +    'title' => t('Ubercart Role expiration role'),
 
- +    'help' => t('The Role that corresponds with the Role expiration date/time'),
 
- +    // Information for displaying the rid
 
- +    'field' => array(
 
- +      'handler' => 'uc_roles_handler_field_rid',
 
- +      'click sortable' => TRUE,
 
- +    ),
 
- +    // Information for accepting a rid as an argument
 
- +    'argument' => array(
 
- +      'handler' => 'views_handler_argument_users_roles_rid',
 
- +      'name field' => 'title', // the field to display in the summary.
 
- +      'numeric' => TRUE,
 
- +      'validate type' => 'rid',
 
- +    ),
 
- +    // Information for accepting a uid as a filter
 
- +    'filter' => array(
 
- +      'handler' => 'views_handler_filter_user_roles',
 
- +    ),
 
- +    // Information for sorting on a uid.
 
- +    'sort' => array(
 
- +      'handler' => 'views_handler_sort',
 
- +    ),
 
- +  );
 
- +
 
- +
 
- +  return $data;
 
- +}
 
- +
 
- +class uc_roles_handler_field_rid extends views_handler_field {
 
- +
 
- +  // Derived from views_handler_field_user_roles
 
- +  // Purpose: get the *names* that correspond to the role_expire_rids.
 
- +  function pre_render($values) {
 
- +    $roles = array();
 
- +    $this->items = array();
 
- +
 
- +    // Get all the unique role ids into the keys of $roles. Initializing into
 
- +    // array_keys helps prevent us from having a list where the same rid appears
 
- +    // over and over and over.
 
- +    foreach ($values as $result) {
 
- +      $roles[$this->get_value($result, NULL, TRUE)] = FALSE;
 
- +    }
 
- +
 
- +    if ($roles) {
 
- +      $result = db_query("SELECT r.rid, r.name FROM {role} r WHERE r.rid IN (:rids) ORDER BY r.name",
 
- +        array(':rids' => array_keys($roles)));
 
- +      foreach ($result as $role) {
 
- +        $this->items[$role->rid]['role'] = check_plain($role->name);
 
- +        $this->items[$role->rid]['rid'] = $role->rid;
 
- +      }
 
- +    }
 
- +  }
 
- +
 
- +  // Render the rid as the role name.
 
- +  function render($values) {
 
- +
 
- +    // Return the role name corresponding to the role ID.
 
- +    // TODO: Should I be using this->get_value() here?
 
- +    $rid = $values->uc_roles_expirations_rid;
 
- +    if ($rid) {
 
- +      $role = $this->items[$rid]['role'];
 
- +      if (!empty($role)) {
 
- +        return $role;
 
- +      }
 
- +    }
 
- +  }
 
- +}
 
- +
 
- diff --git a/uc_roles/uc_roles.info b/uc_roles/uc_roles.info
 
- index f7c899e..ccd2d43 100644
 
- --- a/uc_roles/uc_roles.info
 
- +++ b/uc_roles/uc_roles.info
 
- @@ -2,8 +2,12 @@ name = Roles
 
-  description = Assigns permanent or expirable roles based on product purchases.
 
-  dependencies[] = uc_product
 
-  dependencies[] = uc_order
 
- +dependencies[] = views
 
-  package = Ubercart - core (optional)
 
-  core = 7.x
 
-  
 
-  ; Test cases
 
-  files[] = tests/uc_roles.test
 
- +
 
- +; Views handlers
 
- +files[] = uc_roles.views.inc
 
- diff --git a/uc_roles/uc_roles.module b/uc_roles/uc_roles.module
 
- index d7ee52c..65bdd74 100644
 
- --- a/uc_roles/uc_roles.module
 
- +++ b/uc_roles/uc_roles.module
 
- @@ -1278,3 +1278,9 @@ function _uc_roles_get_expiration($duration, $granularity, $start_time = NULL) {
 
-  
 
-    return strtotime($operator . $duration . ' ' . $granularity, $start_time);
 
-  }
 
- +/**
 
- + * Implements hook_views_api().
 
- + */
 
- +function uc_roles_views_api() {
 
- +  return array('api' => '3.0');
 
- +}
 
 
  |