Hi,
I have been doing a lot of work w/ your module, and have really been enjoying it. There are several code-level modifications I've made for my site's purposes, some of which I thought might interest the community (and I'd love some feedback). Your default maximum # of listings feature, which can be overridden manually by an admin, is great. I'm really interested, however, in having per-role maximums for different subscription levels, etc. I've found a way to do it with minimum alterations to your code; however I know it's hacky and would appreciate anyone's input on a better way to achieve this.
In listing.module, I added these lines of code to the function listing_admin_settings(), just before the 'listing_default_listing_max' form field is generated:
$form['listing_role_defaults'] = array(
'#type' => 'fieldset',
'#title' => t('Set default max listings per user role.'),
'#collapsible' => TRUE,
'#weight' => 1,
);
$sql = db_query("SELECT * FROM {role} WHERE rid > 2"); // I didn't want defaults for anonymous or authenticated users
while ($role = db_fetch_object($sql)) {
$var = 'listing_default_listing_max_'. $role->name;
$form['listing_role_defaults'][$var] = array(
'#type' => 'textfield',
'#title' => t('Default Max Listing').' ('. $role->name .')',
'#default_value' => variable_get($var, 10),
'#description' => t('The initial max posting limit when a user gets a role. This number can later be changed by the Admin.'),
'#size' => 5,
);
}Then, I added these few lines after the other $fields are set to be submitted (~ line 500):
$sql1 = db_query("SELECT * FROM {role} WHERE rid > 2");
while ($role = db_fetch_object($sql1)) {
$fields[] .= 'listing_default_listing_max_'. $role->name;
}That got me per-role variables; then I edited listing_form.php, adding these lines towards the top of function listing_form (here's the hackier part):
$usermax = $user->listing_max;
foreach ($user->roles as $key => $role) {
if ($key > 2) {
$max = variable_get('listing_default_listing_max_'. $role, 0);
$usermax = max($usermax, $max);
}
}
$listingsleft = $usermax - rlistingapi_listing_num($user->uid);
drupal_set_message('You are currently allowed to create '. $listingsleft .' more listings.');
if ($usermax > rlistingapi_listing_num($user->uid) || $user->uid == $node->uid || ... show the formThis all works quite nicely, however the per-role maximums are not updating the $user->listing_max data, and I haven't yet done testing on how this all affects pending / sold listings, which I definitely don't want to count towards a user's quota.
I also hacked your requirement of node_images, so that I could roll my own flash-based montage system for dealing w/ listing images. I'd think as this module matures people are going to want the option of using other image handling systems w/ it.... if so I'd be happy to contribute that basic code as well.
Comments