Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Heine’s picture

Early April is all I can commit to. Patches are always appreciated.

Fayna’s picture

Lovely!! It doesn't matter how long it takes :)

I'm not much of a programmer so I wish I could help more.

BTMash’s picture

I may be using user badges on our site so I'll post up the patches if I get through it. There was one question I had.

I see some functions in there that looks like they extend other APIs. Could you please let me know which ones those are (I'll place them in a separate file since it might be better to split core functionality from optional).

BTMash’s picture

An update re: the user badges module...I have the forms working at this stage. Granted, I don't have the product or ecommerce module so I haven't tested that (are they the same thing??). But everything else seems to be working so far. Should I put it up in a patch format?

BTMash’s picture

I'm attaching in patch format - it should hopefully patch correctly. Please take a look through to see if I've missed anything.

BTMash’s picture

Ok, there were a few mistakes that I had made (in the values for the fields) - I cleaned up some parts where I could as well. Please take a look at this patch instead.

Fayna’s picture

Hi BTMash,

I don't know if I'm doing something wrong or what but this is what I get when trying to apply your latest patch.

Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file README.txt.rej
patching file user_badges.info
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file user_badges.info.rej
patching file user_badges.install
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file user_badges.install.rej
patching file user_badges.module
Hunk #1 FAILED at 1.
Hunk #8 FAILED at 283.
Hunk #9 FAILED at 291.
Hunk #10 FAILED at 320.
Hunk #11 succeeded at 378 (offset 1 line).
Hunk #12 succeeded at 466 (offset 1 line).
Hunk #13 FAILED at 483.
Hunk #14 succeeded at 511 (offset 1 line).
Hunk #15 FAILED at 527.
Hunk #16 FAILED at 538.
Hunk #17 succeeded at 551 (offset 1 line).
Hunk #18 succeeded at 564 (offset 1 line).
Hunk #19 FAILED at 591.
Hunk #20 FAILED at 720.
Hunk #21 succeeded at 731 (offset 1 line).
9 out of 21 hunks FAILED -- saving rejects to file user_badges.module.rej
patching file user_badges_products.info
patching file user_badges_products.install
patching file user_badges_products.module
BTMash’s picture

Fayna, were you trying to patch it against the Drupal 5 version of user badges or against the first patch that was above?

Fayna’s picture

The Drupal 5 version of User Badges.

BTMash’s picture

FileSize
10.53 KB

I'm going to attach the user_badges 6.x version - I'm confused on the patches myself now (it **should** have worked) >_<

Fayna’s picture

That worked great!! I was able to upload an image for one of the badges, save it, but wasn't sure how to assign a role to it. Both roles I have created only have one drop-down option of "Inactive." So far I haven't noticed any errors or problems. Thanks!!

Flying Drupalist’s picture

Are we going to see an official development snapshot soon?

BTMash’s picture

FileSize
12.81 KB

The images getting deleted was a mistake on my part - I didn't realize the files uploaded temporarily unless verified - so I perform the verification that the files are valid and it seems to work properly now.

The zipped format is the new version.

scotese’s picture

Category: feature » bug

Thanks,

I did update to the new code above but still have the exact same problem -- will not let me have more than 7 badges -- the image appears fine -- but when I go to assign the image to a badge name it never appears.

Heine’s picture

Category: bug » feature
Status: Active » Needs work
Heine’s picture

#13 seems largely functional except for
- no display of assigned badges on the user profile 'view' page (unless I missed something).
- a large amount of NOTICEs

It is best to develop Drupal 6 modules against Drupal 6.x-dev or when using a release, modify common.inc:

change if ($errno & (E_ALL ^ E_NOTICE)) {
to  if ($errno & (E_ALL)) {
scotese’s picture

My problem was solved by uploading the badges directly to my server rather than using the upload command within the Badges Module. Now working like a charm.

Rosamunda’s picture

+1!
I really need this [excellent!] module for my Drupal 6 site!

floretan’s picture

Status: Needs work » Needs review
FileSize
9.21 KB
43.13 KB

Here's an updated version of the zip file from #13, and a patch since that's the recommended way of doing (against the DRUPAL-5 branch, that's where the latest code seems to be).

Fixed the bug with the badges not showing up on the profile page (hook_user($op = 'view') now uses drupal_render()).

Passes the coder module test, and E_ALL compliant. Also fixed some minor coding style issues.

BTMash already did most of the work, so I would say that this is ready.

Edit: note that I haven't touched the user_badges_product module, only user_badges.

Rosamunda’s picture

Status: Reviewed & tested by the community » Needs review

THANKS for the archives!!
I´m sorry for this [probably silly] question, but could this patched version be tagged as 6.x dev version? I mean, isn´t it safe enough? I don´t quite understand how Drupal CVS works, and applying patches is [still] quite an issue for me. And it´s probably a difficult task for some people here aswell :)

Heine’s picture

Status: Needs review » Reviewed & tested by the community

Excellent; I'll add this to CVS asap.

aaron’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
433 bytes
1.71 KB

I've begun work on the views handlers for this. Currently, this just creates a 'User Badges' field handler, which works after a fashion, although not in the most optimal way for views. (Plus, it returns a row per badge per user, which is not really what is needed.)

Still, I figure this is a good start if someone wants to figure out what I'm doing wrong here.

Requires the following in the module too:

/**
 *  Implementation of hook_views_api().
 */
function user_badges_views_api() {
  return array(
    'api' => 2.0,
  );
}

(Not doing a patch, because I'm not sure what to patch against here, since HEAD doesn't seem to be updated with the previous patch yet. Just rename the two included files as .inc)

aaron’s picture

And here are actions. Again, nothing to patch against. Just add this to user_badges.module:

/**
* Implementation of hook_action_info().
*/
function user_badges_action_info() {
  return array(
    'user_badges_add_badge_action' => array(
      'description' => t('Add badge'),
      'type' => 'user',
      'configurable' => TRUE,
      'hooks' => array(
        'any' => TRUE,
       ),
      ),
    'user_badges_remove_badge_action' => array(
      'description' => t('Remove badge'),
      'type' => 'user',
      'configurable' => TRUE,
      'hooks' => array(
        'any' => TRUE,
       ),
    ),
  );
}

/**
* Implementation of a Drupal action.
* Adds a badge to the current user.
*/
function user_badges_add_badge_action(&$account, $context = array()) {
  if (isset($account->uid)) {
    $uid = $account->uid;
  }
  elseif (isset($context['uid'])) {
    $uid = $context['uid'];
  }
  else {
    global $user;
    $uid = $user->uid;
  }
  $success = TRUE;
  $badges = user_badges_get_badges('all');

  foreach ($context['badges'] as $bid) {
    $success = (boolean) user_badges_user_add_badge($uid, $bid, 'uid');
    if ($success) {
      watchdog('action', 'Added user badge %badge to user %name.', array('%name' => check_plain($user->name), '%badge' => check_plain($badges[$bid]->name)));
    }
    else {
      watchdog('action', 'Unable to add user badge %badge to user %name.', array('%name' => check_plain($user->name), '%badge' => check_plain($badges[$bid]->name)), WATCHDOG_WARNING);
    }
  }
}

function user_badges_add_badge_action_form($context) {
  $form['badges'] = array('#tree' => TRUE);

  $badges = user_badges_get_badges('all');
  $context['badges'] = is_array($context['badges']) ? $context['badges'] : array();

  foreach ($badges as $badge) {
    $form['badges'][$badge->bid] = array(
      '#type' => 'checkbox',
      '#title' => theme('user_badge', $badge),
      '#return_value' => 1,
      '#default_value' => $context['badges'][$badge->bid],
      '#description' => check_plain($badge->name),
    );
  }

  return $form;
}

function user_badges_add_badge_action_submit($form, $form_state) {
  $badges = array();
  foreach ($form_state['values']['badges'] as $badge => $set) {
    if ($set) {
      $badges[$badge] = $badge;
    }
  }
  return array('badges' => $badges);
}

/**
* Implementation of a Drupal action.
* Removes a badge to the current user.
*/
function user_badges_remove_badge_action(&$account, $context = array()) {
  if (isset($account->uid)) {
    $uid = $account->uid;
  }
  elseif (isset($context['uid'])) {
    $uid = $context['uid'];
  }
  else {
    global $user;
    $uid = $user->uid;
  }
  $success = TRUE;
  $badges = user_badges_get_badges('all');

  foreach ($context['badges'] as $bid) {
    $success = (boolean) user_badges_user_remove_badge($uid, $bid, 'uid');
    if ($success) {
      watchdog('action', 'Removed user badge %badge to user %name.', array('%name' => check_plain($user->name), '%badge' => check_plain($badges[$bid]->name)));
    }
    else {
      watchdog('action', 'Unable to remove user badge %badge to user %name.', array('%name' => check_plain($user->name), '%badge' => check_plain($badges[$bid]->name)), WATCHDOG_WARNING);
    }
  }
}

function user_badges_remove_badge_action_form($context) {
  $form['badges'] = array('#tree' => TRUE);

  $badges = user_badges_get_badges('all');
  $context['badges'] = is_array($context['badges']) ? $context['badges'] : array();

  foreach ($badges as $badge) {
    $form['badges'][$badge->bid] = array(
      '#type' => 'checkbox',
      '#title' => theme('user_badge', $badge),
      '#return_value' => 1,
      '#default_value' => $context['badges'][$badge->bid],
      '#description' => check_plain($badge->name),
    );
  }

  return $form;
}

function user_badges_remove_badge_action_submit($form, $form_state) {
  $badges = array();
  foreach ($form_state['values']['badges'] as $badge => $set) {
    if ($set) {
      $badges[$badge] = $badge;
    }
  }
  return array('badges' => $badges);
}
aaron’s picture

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

duh, I forgot I can just diff the whole thing...

here's the latest, against HEAD. incorporates 19, 22, and 23.

aaron’s picture

Status: Needs review » Needs work

I'm getting an error when using this d6 patch:

user warning: Duplicate entry '3-1-uid' for key 1 query: INSERT INTO user_badges_user (uid, bid, type) VALUES (1, 3, 'uid') in /home/www/sites/all/modules/user_badges/user_badges.module on line 302.
aaron’s picture

That's when creating any node.

aaron’s picture

would be nice to create a dev release so we can file issues against this 6.x patch.

the latest bug i found with this patch is that when an admin creates a new user of a role, role-assigned badges are not assigned.

chasz’s picture

+1

aaron’s picture

FileSize
55.94 KB

this fixes the bug at #25, and rolls all other functionality, patched against current HEAD. the bug at #27 still needs attention. could we roll a dev release to make the patches a little more manageable?

nikitac’s picture

Ever since I upgraded Advanced Forum to the lastest version, badges dont show up anymore, please let me know how to fix it. I'm using version created on June. Thanks in advance.

andypost’s picture

subscribe

zilla’s picture

per #19 above, could this be rolled into a downloadable zip again for folks like me who know nada about patching??? or alternatively, could it be rolled up and moved to the project page as a dev release or alpha??

Rosamunda’s picture

+ 1 to your idea zilla!
:)

Lucretia9’s picture

Could a new zip be provided for D6? I just tried the nightly head branch and patched it, but there are quite a few failures. It seems that some of these patches have been included. I dunno.

Thanks,
Luke.

krisvannest’s picture

Ditto & subscribe... I've started to read up on patching, but have a long way to go before I'm versed enough to actually do it on my site so a standalone dev/alpha v6 release would be super. BTW this is one of my most used mods, so great job on it so far and really looking forward to working with v6 support when available.

Shyin’s picture

I would love to see this also.

Shyin

andypost’s picture

Suppose it's good to make 6.x-dev to make more people test this module

Rosamunda’s picture

DNDV!

(desperately needing dev. version :)

hankpalan.com’s picture

+1 for a Dev. I would love to start testing this.

Heine’s picture

Status: Needs work » Fixed

I've committed #24. A dev tarball should appear within 12 hours. Problems can be worked out in additional, separate issues.

Thanks a lot folks.

nilocd’s picture

subscribing...

pjb’s picture

Was this checked in fully? I'm still not seeing any dev tarballs on the project page for D6.

Heine’s picture

http://drupal.org/node/24411/release

The release is not for consumption.

HS’s picture

waiting for 6.X version as well. Love the module.

nunoveloso’s picture

Assigned: Unassigned » nunoveloso

Dear Drupalers,

As you may have noticed, Heine handed me the reins of this module so I'll do my best. However, for now I just intend to support and fix bugs and don't plan any extra features development (besides description URL).

I had a different version (customised for personal use) from the current ones in dev. I tried to merge those to versions, did some code improvements and added/modified some features. So I will now release the first "stable" versions (D5 & D6). Here is a list of what has been added/modified:

I hope it will be useful for all of you. Thank you for your feedback! Don't forget there are some todo's like

  • query optimisation (I am thinking on it)
  • support for private file upload
  • etc.

Enjoy!

HS’s picture

Thank you so much!

Lucretia9’s picture

Excellent!

Shyin’s picture

I should have time soon to set this up on my testbed and give it a good workout. Great to see one of the modules I have been waiting for updated to D-6. Thank you so much.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.