Hi, I have been working on an Drupal implementation for a Business Directory for some time now and are a bit stuck on how different user roles could be set up.
Let's say that I have two different user types. One Standard Customer and one Premium Customer. The idea is that everyone should be able to register as a Standard Customer and add some limited information (i.e. Company Name and Company Description). The Premium Customer can pay a fee and are then allowed to add an URL to a Company web site and upload an image. The fee will also give those customers other advantages such as being highlighted in all listing etc. See the attached image for a sketch.
I tried setting this up by creating two Roles; one Standard Customer and one Premium Customer. Each role had permissions to edit one content type. The Standard Customer could edit the content type Standard Customer Content Type and the Premium Customer could edit the Premium Customer Content Type.
I think I have one problem with my implementation though. If a customer should be upgraded or downgraded (i.e. a paying customer wouldn't like to renew it's subscription) we manually need to do the following steps:
- Change the customer type to Standard Customer
- Remove the Premium Customer Data for that customer
- Create new customer data in the Standard Customer Data Type
To manage the customer type will we probably do manually anyways but it feels a bit strange to first remove the data and then insert almost the same data again. It might be acceptable but it is not a good solution. Is there any better solution available?
I have looked into using only one data type (which I think I would prefer) and use the http://drupal.org/node/105165/ CCK Field Permissions module as suggested by other people in this forum but I'm a bit scared that the module seems to be unmaintained. Are there any other known solutions?
I have also another problem that needs to be solved. When a customer signs up as a Premium Customer I would like to have the possibility to set some time limit for this subscription. It will probably be OK if this is done manually since we are going to call our customers up anyways (we will send them an invoice so no automatic payment is needed at this point). Any ideas how this can be managed?
Please see my examples above as just examples to be able to discuss the problem and not how reasonable my content types are.
Have a nice weekend! Best regards,
Ola
| Attachment | Size |
|---|---|
| 071025_BussinessDirectory_UserRolesPermissions.png | 30.83 KB |

Comments
CCK Field Permissions module
I have now been testing the CCK Field Permissions module. It was pretty easy to set it up but I'm having some issues deciding if this module does what I want or not. The more I think about it the more uncertain am I.
My initial idea was to set up the permissions as the CCK Field Permissions module does by limiting the data a certain user (with a certain role) can input. For example if the user that's logged in is a Premium Customer that customer can see / edit all fields after logging in . If the logged in customer is a Standard Customer the same fields are visible / editable, the data is saved to the database but the data isn't visible on the page.
I think it would be great if it was possible to do the following:
I don't really know if it's smart to check if we should display the Premium Customer Content Group by looking for the author of that node but I can't really think of any better solution. I guess the implementation would be pretty much in the theme / theme engine (I haven't looked into that yet) or maybe to add some PHP code to a View? It would be great if it was possible to find out if the content is generated by a premium or standard customer in some global functionality since it would be great if it was possible to highlight (or display a logo) Premium Customers in listings etc. as well.
I might be totally wrong here? Any ideas?
Going node based instead of role based
After some hours of researching and testing my role based solution (above) without any luck I turned to the Drupal support IRC channel and discussed my solution. Michelle (http://drupal.org/user/23570/) described her solution which seemed to be a much better way. Instead of using roles to see if the author of a created node is a premium customer or not I set a field on each node that tells if that node is a premium node or not.
For my new solution I did the following:
Override the Views HTML
I had a lot of problems figuring out how to make my view output the HTML I wanted (to only show the logo for premium customers in my listings) instead of the default view. After some hours of reading I finally made it. You can follow my progress in this forum thread: http://drupal.org/node/187530
Code to override HTML in View
Instead of having one premium and one standard customer (as described above) I need to have one premium, one standard and one free customer types. In this listing the difference is that the premium and the standard customers will have their logo printed in the listings while the free will not. Therefore I created two different date fields (editing limited to the administrator) See the screen shot of my view here: http://static.olalindberg.com/drupal/071102_CompanyListing.jpg
I'm not sure if this code is optimal and I'll look into that later.
In template.php
<?php
/<strong>
* Override the HTML the company_list view outputs
*/
function phptemplate_views_view_list_company_list($view, $nodes, $type)
{
$table = array();
foreach ($nodes as $i => $node)
{
//Get the node
$node = node_load($node->nid);
// If this customer node is a premium customer we should include the company image in the table
$logoObj = null;
if(is_premium_customer($node)){
$logoObj = theme('image', $node->field_logo_low_resolution[0]['filepath']);
}
//Create a linked title object for this customer
$companyTitleObj = l($node->title, 'node/' . $node->nid);
//Generate the table array
$table[] = array($logoObj, $companyTitleObj);
}
//Create the header for the table
$tableHeader[] = array('Logo','Company Name');
return theme_table($tableHeader, $table);
}
/</strong>
* Finds out if the given node is a premium customer or not
*/
function is_premium_customer($node)
{
//Note: The name of this node must be customized according to the field
$premiumOfferUntil = $node->field_premium_offer_until[0]["value"];
//Note: The name of this node must be customized according to the field
$standardOfferUntil = $node->field_standard_offer[0]["value"];
$todaysDate = time();
$isPremium = false;
if(($premiumOfferUntil > $todaysDate) || ($standardOfferUntil > $todaysDate))
{
$isPremium = true;
}
return $isPremium;
}
?>
Future Work
I will try to add more fields to the table as well as making the table sortable etc.
It would also be nice if I could find a way to remove the hard-coded node fields both for the premium customer special listing (field_premium_offer_until and field_standard_offer) and which nodes to display (theme(field_logo_low_resolution & title) by making some kind of administration module but I don't really know how that's done.
I will also make some custom output of the actual nodes (and not as here just the list) to display different fields depending on if the value of the premium until field but that's for next week!
Not sure if you have
Not sure if you have checkout the module scheduler, just saw the module but have not tried it out. you may want to check it out. hope it help
subscribe
link
Cool, subscribing Thanks
Florida Drupal Group, We meet Every 3rd Saturday in Orlando
http://groups.drupal.org/florida
Florida Drupal Group, We meet Every 3rd Saturday in Orlando
http://groups.drupal.org/florida