Is there a way to include role expiration date into a view? I need a membership list for admins with expiration dates, but the only way I could do this is hardcoding database query into the template, and them I guess I need to do a lot of extra coding if I want sorting and filtering by expiration date. Is there an easier way, and if not, can this be a feature request?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Category: support » feature
Status: Active » Postponed
Issue tags: +views

That's a great idea for Views integration, but we won't be adding in any more of that until we start work on the next version unfortunately.

julia_g’s picture

So do you think you'll be able to do this within a few months? If not, I'll try to put something together myself.

neopoet’s picture

Did you managed to solve this?

Liliplanet’s picture

Definitely subscribe, thx!

mariuss’s picture

FileSize
1010 bytes

Implemented the feature as a separate module. In Views it provides a new field group called "Role Expirations" and for each role that is expired by uc_role there are two fields in this group: the expiry date and a flag that tells if the notification was sent already. Until this code makes it into uc_role just use the attached module.

It can easily be added into uc_role module:

  1. rename functions to start with uc_role instead of uc_role_views
  2. copy the uc_role_views_views_api function from uc_role_views.module to uc_role.module (and rename, see above)
  3. rename uc_role_views.views.inc to uc_role.views.inc (and rename functions, see above)

Did not create a patch because it is easier to use like this and based on first comment it may take a while. I can create a patch as well if that helps, let me know.

mariuss’s picture

Forgot to mention that the inspiration for this module/patch came from:
http://www.gregeisenman.info/blogs/greg/views-2-and-drupal-adding-custom...

tjjacobsen’s picture

Mariuss' little module works well...thank you.

Unfortunately it doesnt really meet our needs. We simply want a view that lists the user name and their current expiration date.

Does anyone have a simple way to do this? Im not afraid of coding if necessary, but Im not an expert and it would take me awhile to complete.

Any help?

Chad_Dupuis’s picture

sub

tjjacobsen’s picture

FileSize
821 bytes

Got it working!

With a few modifications to mariuss' code and some lessons from Greg Eisenman's posted link above, it was actually pretty simple and gave me just what my project needed.

I simply cloned mariuss' module, renamed it 'uc_role_admin', updated the .info and .module files to reflect this new name, and then modified the uc_role_admin.views.inc file with the attached function.

Hopefully this will help others out there. (and, of course, if anyone catches any errors, please let me know!)

hefox’s picture

(Note: uc_role_admin causes duplicates in views if a user has more than one role expiration; first should not cause this because each join to the table is different whereas uc_role_admin shares the join)

BenK’s picture

Subscribing....

darsic’s picture

Assigned: Unassigned » darsic
Priority: Normal » Critical

Hi,

Can someone tell me how can i make this module work, posted by mariuss.
I followed instructions, but nothing happens ... i can`t see Role Expiration fields in View.

Thank you.

darsic’s picture

I followed your instructions, bur i can`t see role fields in my view. :(

TR’s picture

Assigned: darsic » Unassigned
Priority: Critical » Normal
Status: Postponed » Active

@darsic: Please read http://drupal.org/node/314328 to what the issue "Priority" and "Assigned" fields mean.

If someone wants to roll a patch from #5, taking into account #9 and #10, I think this can be put into the uc_roles module.

TR’s picture

Issue tags: +uc_roles

Tagging

fidlertom’s picture

Has anyone else gotten #5 or #9 to work? I've tried both options as well as reading the link in #6 and for some reason it's still not showing in views. I'm using d6.16 and uc6.x-2.4.

Rhino’s picture

Subscribing!

hawkdrupal’s picture

+1

There's a huge need to have a module and/or view -- especially for sites that sell subscriptions. Users need to readily see the status of the subscription -- that is, the particular role that IS the subscription, and the role/subscription expiration date.

The view should be able to show ONLY the desired SUBSCRIPTION role and expiration, and not other roles such as "authenticated user"; that will just be confusing.

Also, this view must be available in a block so it can be displayed whenever the user is signed-in. It should not require the user to dig to find, but should be up-front so the user does not forget to renew.

Liliplanet’s picture

Here is a block to show the user their current role status and when it's due to expire ..

http://drupal.org/project/uc_expiry

gpiersol’s picture

I'm also very keen on being able to use the role expiration dates in views, and I've also been unable to successfully get the included custom module(s) in this thread to work for me.

I recently came across this helpful snippet of code : Drupal: Expose a Custom Field to Views 2.

I'd love to be able to create a custom module that does what the above link describes with a user's role expiration date, but I'm not sure where to start.

scotwith1t’s picture

Version: 6.x-2.0-beta5 » 6.x-2.x-dev

Thanks for this. It works beautifully and was absolutely essential to my project. Hope to see this essential functionality committed to the dev and ultimately the next UC release, so I'm updating version to maybe draw some attention to it. If not, this module works great. mariuss++

Liliplanet’s picture

With the http://drupal.org/project/role_expire In a view select filter 'Operator is greater or equal to' +365 days to see the newest members by role ..

dafeder’s picture

Folks - #9 works for me. Make sure you are using a user view, not a node view. If you need a view of profile nodes, make a user view and use relationships to pull in the profile fields.

interestingaftermath’s picture

subscribing

RedBob62’s picture

A small idea for those who struggled to get this to work.

When I first downloaded the file in #5 I noticed that it saved to my PC as 'uc_roles_.tar_'. I uploaded this and unpacked it but could not find the new module in the modules list.

I went pack to my PC and renamed the tar file to remove the final _ making the name 'uc_roles_.tar'. I then uploaded this and unpacked it. This time the module appeared and now works perfectly.

It might be an obvious fix but it worked for me :-)

Cheers

Bob

eric.chenchao’s picture

Thanks - #9 works for me.

francismacomber’s picture

FileSize
3.65 KB

Here's a modified version that works for me with UC 3 Beta 3 in Drupal 7.

TR’s picture

Status: Active » Needs work

There is still no patch here to review.

clr123’s picture

subscribing

Liliplanet’s picture

Hi, #27 from francismacomber works perfectly and Role Expirations TJ: Expiration is available as a field.

is there perhaps any chance of being able to have the TJ: Expiration field as a 'sort by' in sort criteria please?

Would like to create a view of the user expirations by date.

odisey’s picture

THANKS THANKS THANKS!!!

TR’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Component: Code » Roles
Issue tags: -views, -uc_roles

New features should go into 7.x-3.x first.

Still no patch here to review ...

webservant316’s picture

subscribe - looking for a patch for 6.x-2.x

clr123’s picture

subscribe

clr123’s picture

subscribe

scotwith1t’s picture

just putting this back towards the top of my queue so i can remember to try and put this patch together...can't promise anything but i've managed to do one for uc_varprice, so i'm sure i can manage...we'll see.

timb’s picture

would love to see this in 7

jukka792’s picture

Is this coming to d7 ? Or is it possible to create the expiration date just using views ?

hejeva’s picture

Issue summary: View changes
FileSize
1.92 KB

Here is version D7 using parts of this module and roles_expire/role_expire.views as guidelines.

TR’s picture

Please MAKE A PATCH. Posting a zip is not helpful. If you want to publish your own standalone module then open a sandbox project, don't post the code here. If you want to help improve Ubercart, then we need a PATCH.

scotwith1t’s picture

FileSize
4.23 KB

Not sure if this is right, but the gist is there. It's a patch file, it adds the 3 files hejeva was trying to add as the contribution (thanks for that!) as a sub-module uc_role_views. I haven't looked at or tried this, just trying to help hejeva out by providing the patch for TR.

TR’s picture

Status: Needs work » Needs review

Changing status so the testbot can try out the patch.

jsibley’s picture

Am I correct that the patch passed testing? If so, might we see a release soon? Thanks.

jsibley’s picture

Does this need additional testing or can it be committed now?

Thanks.

TR’s picture

No one has tested the patch in #41 yet. No one. Not even the guy who posted the patch. That's why the status is still "Needs review".

@jsibley: It sounds like this feature is of interest to you. If you would like to see this get into Ubercart, then please help. Try the patch, then post here in this issue what you tried and how you tested it and whether it worked as you expected or not. That is how progress is made in Drupal.

dzepol’s picture

FileSize
4.24 KB

I downloaded this and tested the patch. This patch creates a new sub-module as @scotself said and applied without error.

When I added the new views fields (expire and expire role) there was a problem. The expire role name caused an error as it was pointing to an invalid rid reference. I've fixed this to point to the correct reference.

@scotself had noted in the patch at the same line "TODO: Should I be using this->get_value() here?". Unfortunately, I don't know enough to be able to answer that question, but after making the change I mentioned, I found no other problems. I've updated it and attached it below.

dzepol’s picture

FileSize
4.19 KB

I thought about it a little bit, but I didn't think it made sense to have a completely new module created for this.

Anyways, I created a new patch with the same functions, against dev, which updates the existing uc_roles module. (This is my first attempt at creating a patch so bare with me!)

ydahi’s picture

Tested patch from #47 on:

UC 7.x-3.6
Views 7.x-3.8

root@system:/path/to/drupal/sites/all/modules/ubercart# patch -p1 < uc_role_views-419700.patch
patching file uc_roles/uc_roles.views.inc
patching file uc_roles/uc_roles.info
Hunk #1 FAILED at 2.
1 out of 1 hunk FAILED -- saving rejects to file uc_roles/uc_roles.info.rej
patching file uc_roles/uc_roles.module

Contents of uc_roles/uc_roles.info.rej

--- uc_roles/uc_roles.info
+++ uc_roles/uc_roles.info
@@ -2,8 +2,12 @@
 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

I am able to use both new fields in views. The patch does what it's supposed to do - wish I could help with the error...

TR’s picture

Patch applies fine for me. And it applies fine in the testbot in #47. So I suspect the problem is on your end ...

jsibley’s picture

I am also getting:

Hunk #1 FAILED at 2.

uc_roles.views.inc is created but the changes are not made to uc_roles.info as indicated in the reject file above.

Unfortunately, I don't know enough to know why it isn't working.

Anonymous’s picture

subscribe

TR’s picture

@ankos79: You do not have to / should not post just to subscribe to an issue on drupal.org. Instead, use the big green "Follow" button at the top of the page.

If this issue is important to you then please help out - test the proposed patch in #47 and report how it worked for you.

BenIPAQ’s picture

Applied the patch. Seems to work ok! Still there is a problem with the expiration date within a view. It looks like it's tied to the wrong content. Also I get this error:

Strict warning: Declaration of uc_role_views_handler_field_rid::pre_render() should be compatible with views_handler_field::pre_render(&$values) in require_once() (regel 71 van /Applications/MAMP/htdocs/test/sites/all/modules/ubercart/uc_role_views/uc_role_views.views.inc).
Notice: Undefined property: stdClass::$role_expire_rid in uc_role_views_handler_field_rid->render() (regel 101 van /Applications/MAMP/htdocs/test/sites/all/modules/ubercart/uc_role_views/uc_role_views.views.inc).

jsibley’s picture

Ubercart is now version 3.8.

Does the patch need to be re-rolled or was it ever incorporated into a release?

TR queued 47: uc_role_views-419700.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 47: uc_role_views-419700.patch, failed testing.

Status: Needs work » Needs review

TR queued 47: uc_role_views-419700.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 47: uc_role_views-419700.patch, failed testing.

TR’s picture

Testbot is currently broken: #2375345: Dependency on core module results in PHP Fatal error: Cannot redeclare system_requirements()

If you want to see if it still applies, you will have to try it yourself. It won't be committed until it has been tested and someone fixes the errors reported in #53.

Status: Needs work » Needs review

TR queued 47: uc_role_views-419700.patch for re-testing.

aniebel’s picture

Disregard this comment

aniebel’s picture

Update: My white screen was an urelated issue.
However, I am not seeing the fields available in Views.

aniebel’s picture

Update #2: This does, in fact, work.

aniebel’s picture

Status: Needs review » Reviewed & tested by the community
TR’s picture

@aniebel: Did you try to reproduce the problem described in #53? What do you mean by "it works"? Can you be little more specific about what you tested...

aniebel’s picture

Sorry about that. I do not get the error in #53 when using the Ubercart Role Expiration in a View at all. I am able to see and successfully use the field when creating Views with this field involved in them. Please let me know if you need more information.

aniebel’s picture

An additional note: as a future feature request, the date widget is an input field as opposed to other date fields that provide a pop-up calendar widget and more relative date options. I'm only mentioning this as my viewpoint from testing it and being transparent on what I found and, again, this seems more of an additional feature request.

aniebel’s picture

UPDATE: I just migrated to a new hosting company and am now getting an error when visiting any page similar to #53.

Strict warning: Declaration of uc_role_views_handler_field_rid::pre_render() should be compatible with views_handler_field::pre_render(&$values) in ctools_plugin_api_include() (line 160 of /var/www/vhtdocs/userweb63850/html/sites/all/modules/ctools/includes/plugins.inc).

bachbach’s picture

Hi,

patch #47 ran partially well for me with UC 7.x-3.8, it failled with uc_roles.info
i made it manually and it does the job, i can display and sort a view with role expiration date.

aniebel’s picture

WOW, I think I may have fixed the error but I need to figure out how to write a patch. In the meantime, line 75 of uc_roles.views:
function pre_render($values) {
should be:
function pre_render(&$values) {

aniebel’s picture

Ok, not sure if this is the proper way. Please advise but this has fixed the error being thrown for me.

texas-bronius’s picture

The patch being applied could be either a simple stand-alone module and made ready for download or as a patch against the ubercart project. The patch in #71 (only one I tried) appears to work for me in D7 Views 7.x-3.11 with uc_roles 7.x-3.8. I had some personal trouble wrangling in the patch, but that was likely just me..

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 71: uc_role_views-419700-71.patch, failed testing.

TR’s picture

Status: Needs work » Needs review
FileSize
4.19 KB

Patch format was bad - missing end-of-line character at the end of the file.
Re-rolled with no changes other than that. Please test.

aniebel’s picture

Additional feedback: I noticed that I'm not able to use relative dates as a filter in Views. Perhaps this is related to the limitations of granularity and date format picker I mentioned in #67.

SeanA’s picture

Status: Needs review » Reviewed & tested by the community

It works! Nothing broke, no complaints. Thanks guys.

TR’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
4.19 KB

Uploading the patch again so the new CI testbot will look at it.

TR’s picture

OK, it passed. I made a bunch of changes, mostly for coding standards. I separated the hook_views_data() and field handler into separate files and moved them into the views subdirectory. I removed the dependency on Views, since this module works fine without Views enabled. I also switched the Views api version from 3.0 to 2.0.

@SeanA: Can you give this new patch a try and make sure this still works for you? You will have to revert the old patch then apply the new patch. You will probably have to disable uc_roles then re-enable it to get Drupal to read the .info file. Don't forget to clear your caches!

SeanA’s picture

Status: Needs review » Reviewed & tested by the community

No problems, looks good.

  • TR committed 6f1e125 on 7.x-3.x
    Issue #419700 by TR, dzepol, aniebel, scotself: How to include role...
TR’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Thank you for testing that SeanA.

Committed to 7.x-3.x. Moving to 8.x-4.x for porting.

bisonbleu’s picture

I'm using the role expiration date in a view. I can see the list of roles that will expire in the future. But the view returns no result (null) when I search for roles that have recently expired e.g. last month.

Am I doing something wrong or is it that it's just not possible? In theory, expiration dates remain available in the uc_roles_expirations table, doesn't matter whether they are past or future.

Use case - having access to the recently expired roles in Views would make it easier to send out custom reminder emails.

TR’s picture

@bisonbleu: I assume you're doing that in 7.x-3.x? Since that code has been in Ubercart for a year, if it doesn't work correctly it's a bug. Please open a separate issue for that bug (you can add a link back to this issue for reference).

This issue is now for porting the patch in #78 from D7 to D8.

bisonbleu’s picture

Sorry for the noise.

Not a bug. I created a separate issue where I'm suggesting how this can be done. Cheers!

TR’s picture

Thanks for the related issue - I'm sure that will help someone.