I currently have not learned Git yet, so I will post the changes required for D7 here. These are cumulative and to be applied on top of the current -dev release. I will also include a zip of the current complete module.

Comments

nancydru’s picture

StatusFileSize
new32.96 KB
new17.99 KB
new13.95 KB

This contains:

Remaining known issues:

  • .Install file: Review current upgrade process. (Probably does not handle location schema, i.e. "public://".
  • .Install file: D6 Imagecache used preset ID, D7 uses name.
  • Token support.
  • Views support #1305796: Views 3 integration: update badge handlers
  • Role badge problems (see #5)
Refineo’s picture

I tested these patches with the following test scenario.

User Badges test scenario

Environment

Drupal 7.8
User Badges 7.x-1.x-dev + patches in #1306032: Cumulative D7 Changes

Summary

Error when trying to delete user badges.

Test steps

1. Go to Configuration>People>Badges>List (admin/config/people/user_badges)

At the beginning screen loads, you should see no badges at all ...................OK

2. Go to Configuration>People>Badges>Add (admin/config/people/user_badges/add)

Screen loads ....OK

3. Enter the following data into the form

Name = blank, Image Url = blank, Weight = 0, Description URL = blank
[X] Cannot be hidden
[X] Fixed Weight
[X] Does Not Cound to Limit
4. Click Save badge

You should get error message
"Name field is required.
You need to either enter an image URL or select an image from the library. Your badge needs an image." ... OK

5. Enter the following data into the form

Enter Name = Test Badge 1, Image Url = blank, Weight = 0, Description URL = blank
[X] Cannot be hidden
[X] Fixed Weight
[X] Does Not Cound to Limit

You should get error message
"You need to either enter an image URL or select an image from the library. Your badge needs an image." ... OK

6. Enter the following data into the form

Enter Name = Test Badge 1, Image Url = http://www.centralscrutinizer.it/wp-content/uploads/2006/09/sergey.gif

, Weight = 0, Description URL = blank
[X] Cannot be hidden
[X] Fixed Weight
[X] Does Not Cound to Limit

You should get message "Badge Test Badge 1 saved."

7. Go to List again

YOu should see the new Test Badge 1 and the badge image on the list.

8. Go to Configuration>People>Badges>Images (admin/config/people/user_badges/images)

You should not see the Test Badge 1 image here because it was not added to the library first. ... OK

9. Upload the new badge image

Click the button under Upload image and select a badge.jpg file from your local folder.
Click Open
Click Upload
You should see the badge.jpg image on the list below. ... OK

10. Go to Configuration>People>Badges>Roles

Assign the badge to blocked user
Save Role Badges
You should see badge images next to the blocked user ... OK

11.Assign the badge to your roles

Save Role Badges
You should see badge images next to the role name ... OK

12. Go to Configuration>People>Badges>Settings

Number of badges to display = 0
Only show blocked user badge = Yes
Allow users to reorder badges = No
Image style to size badges =
"No badges" message = leave it blank
Default badge link URL = leave it blank
Vocabulary =
Click Save configuration
You should see Configuration saved. ...........OK

13. Go to Configuration>People>Badges>Images (admin/config/people/user_badges/images)

14. Check the checkbox [X] next to the badge.jpg image.

15. Click Delete ...
ERROR

Error:
Trying to delete 2 badges at once (I had one more badge added before) results in error:

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of 

/***/includes/entity.inc).
Recoverable fatal error: Argument 1 passed to file_delete() must be an instance of stdClass, boolean given, called in 

/***/sites/all/modules/contrib/user_badges/user_badges.admin.inc on line 540 and defined in file_delete() (line 1229 of 

/***/includes/file.inc).

Trying to delete 1 badge results in error:

Please select images to delete.
Warning: preg_match() expects parameter 2 to be string, array given in transliteration_process() (line 32 of 

/***/sites/all/modules/contrib/transliteration/transliteration.inc).

Trying to delete 1 badge again results in error:

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of 

/***/includes/entity.inc).
Recoverable fatal error: Argument 1 passed to file_delete() must be an instance of stdClass, boolean given, called in 

/***/sites/all/modules/contrib/user_badges/user_badges.admin.inc on line 540 and defined in file_delete() (line 1229 of /***/includes/file.inc).

Warning: preg_match() expects parameter 2 to be string, array given in /***/sites/all/modules/contrib/transliteration/transliteration.inc on line 32
Refineo’s picture

I found one more warning message on a frontpage:

Notice: Undefined index: roles in user_badges_user_presave() (line 265 of /***/sites/all/modules/contrib/user_badges/user_badges.module).
nancydru’s picture

Hmm, 6 and 7 fail for me - no image.

Interesting, I have no problems deleting badges (even two at a time). I'll have to check for which code I have uploaded.

On both Add and Images, there is an image scaling issue.

Blocked users: "There was a problem saving roles to the database"

nancydru’s picture

I think there are some major problems with the way role badges are handled that are pervasive throughout the module. That may be why there are so many issues open here. For now, I would say, let's pretend that feature is not present and just make sure everything else works okay.

  1. The success logic doesn't work on D7 (returns object, not Boolean)
  2. The queries need to be converted.
  3. Adding a user entry for everybody in that role is just plain wrong.
  4. Function user_badges_for_uid can now get role badges by role. (User_badges_for_user does not.)
  5. Role badges should be either "unhideable" or "does not count" by definition.

This may result in significant rewrite needs.

nancydru’s picture

StatusFileSize
new22.8 KB
new18.35 KB
new33.08 KB

This contains:

Remaining known issues:

  • .Install file: Review current upgrade process. (Probably does not handle location schema, i.e. "public://".
  • .Install file: D6 Imagecache used preset ID, D7 uses name.
  • Token support.
  • Image weighting
  • Views support #1305796: Views 3 integration: update badge handlers
  • Role badge problems (see #5)
nancydru’s picture

StatusFileSize
new33.31 KB
new19.76 KB
new25.08 KB

This contains:

Remaining known issues:

  • .Install file: Review current upgrade process. (Probably does not handle location schema, i.e. "public://".
  • .Install file: D6 Imagecache used preset ID, D7 uses name.
  • Image weighting
  • Views support #1305796: Views 3 integration: update badge handlers
  • Role badge problems (see #5)

To be tested: Does Private file system now work?

boran’s picture

I've done some testing.. I am calling user_badges_for_user(array('uid'=>123)) from a module of mine. But this resulted in the error:

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 374 of /disk2/www/drupal-7.8/includes/entity.inc).

Fix: In user_badges_for_user() replace:
//$account = user_load($load);
$account = user_load($load[uid]);

user_load does not expect an array in D7, see also http://api.drupal.org/api/drupal/modules--user--user.module/function/use...

If you want I can create the D7 branch in git and do the initial commit, but I'd need (provisional) maintainer status for that. Or I can guide you through it, but you'll need to install git.

Sean.

Satori42’s picture

Using this most recent patch (in Comment #7), Token support is still having some difficulties. It's not crucial to me, but I thought you'd like more data on it.

For the following lines near the end of the module:

 $replacements = array();
  dsm(print_r($type,true));
  dsm(print_r($tokens,true));
  dsm(print_r($data,true));

Drupal can't find the dsm function. I've done a personal workaround by commenting the lines out.

Additionally, when you go to work on #5, Role Badges, here's more info:

I associated a sample badge with a Role. I used Rules to give the Role - not the Badge - to a user. The user had the Role, but not the Badge. When I went to manually remove the Role from the User, Drupal gave this:

Warning: key_exists() [function.key-exists]: The first argument should be either a string or an integer in user_badges_user_presave() (line 295 of C:\xampplite\htdocs\drupal\modules\user_badges\user_badges.module).

If we're still pretending the Role Badges issue's not there, we can pretend I didn't give you that info. =)

nancydru’s picture

Dsm is a Devel module debugging statement. It should always be safe to remove them - or turn on Devel to see what I was looking at.

Actually, I wondered why that function was there, but hadn't looked hard at it yet, so now I know. I suspect it will go away when I figure out what to do with role badges. I write a summary on that (#1319230: D7 Role badges, User weighting, Limit count (6.x users take note)), because there are complications with doing what I'd like to do. Role badges are really bad right now - even in the 6.x branch.

I can also tell you to pretend user weighting of badges isn't there either. That's part of the role badge related problems.

nancydru’s picture

StatusFileSize
new23.51 KB
new47.3 KB

This contains:

A new version of the documentation page is included in the zip file.

Remaining known issues:

  • .Install file: Review current upgrade process. (Probably does not handle location schema, i.e. "public://".
  • .Install file: D6 Imagecache used preset ID, D7 uses name.
  • Image weighting
  • Views support #1305796: Views 3 integration: update badge handlers
  • Role badge problems (see #5)
  • Use preprocess to create badges section; extra_fields to expose to CCK and DS.

To be tested: Does Private file system now work?

spaceknight’s picture

Hello NancyDru, I hope that you can deliver a D7 compatible release asap. Did you by change forget to attach the zip file in #11?

spaceknight’s picture

Testing the zip from #7,

I get following notice when

Configuration >> People >> Badges >> ADD

Notice: Undefined variable: userpoints_goal in userpoints_badges_form_alter() (line 14 of C:\xampp\htdocs\drupal\sites\all\modules\userpoints_contrib\userpoints_badges\userpoints_badges.module).

however this is a notice from userpoints_badges.module.

nancydru’s picture

StatusFileSize
new38.68 KB
new57.3 KB
new24.4 KB

A full D7 version is going to require resolving the role badge issue and I need user feedback on that (#1319230: D7 Role badges, User weighting, Limit count (6.x users take note)).

I guess I should break down and test out Userpoints.

This contains:

A new version of the documentation page is included in the zip file, as is the code that has been moved to separate files.

Remaining known issues:

To be tested: Does Private file system now work?

spaceknight’s picture

And this is what I get after submitting the ADD form:

Fatal error: Call to undefined function db_result() in C:\xampp\htdocs\drupal\sites\all\modules\userpoints_contrib\userpoints_badges\userpoints_badges.module on line 75

nancydru’s picture

It looks like the Userpoints_Badges module has not been converted to 7.x yet.

nancydru’s picture

@spaceknight: Since you are already set up, you can test this better. #1321082: Userpoints_badges for 7.x
Please post issues there.

berdir’s picture

Status: Active » Needs work

Quick at your changes, not very detailed but a few hints.

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -16,21 +16,37 @@
+ * Open code.
+ * Include code that is only needed if other modules are present.
+ */
+if (module_exists('token')) {
+  include_once(drupal_get_path('module', 'user_badges') . '/user_badges.tokens.inc');
+}
+
+// Add any other module that can initiate actions.
+if (module_exists('trigger') || module_exists('rules')) {
+  include_once(drupal_get_path('module', 'user_badges') . '/user_badges.actions.inc');
+}
+
+if (module_exists('autoassignrole')) {
+  include_once(drupal_get_path('module', 'user_badges') . '/user_badges.autoassignrole.inc');
+}

module_exists() outside of any functions is not reliably, just like any other functions. Drupal is only partially initialized at this point. Better do it in hook_init().

For tokens, any call of an token hook should automatically include the yourmodule.tokens.inc file, thanks to http://api.drupal.org/api/drupal/modules--system--system.module/function....

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -57,19 +72,27 @@ function user_badges_help($path, $arg) {
+    'access user badges' => array(
+      'title' => t('access user badges'),
+      'description' => t('Display user badges to the user.'),
+      ),
     'manage badges' => array(
       'title' => t('manage badges'),
-      'description' => t('TODO Add a description for \'manage badges\''),
-    ),
+      'description' => t('Access the User Badges administration pages.'),

You should uppercase the first character of permission titles, to be in line with others.

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -77,97 +100,105 @@ function user_badges_permission() {
-  $items['admin/user/user_badges'] = array(

As said before, I suggest admin/config/people/user_badges for the admin path, I think this is more a configuration/setup task, unlike managing users.

You might also want to add a description, so that it shows up in the configuration overview.

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -358,12 +401,15 @@ function user_badges_user_OLD($op, &$edi
 function _user_badges_class($badge) {
   // Doing separate lines makes changing the algorithm easier.
   $class = $badge->name;
+  // Make it 'safe.'
   $class = strip_tags($class, '');
+  // Lower case.
   $class = drupal_strtolower($class);
+  // Remove quotes.
   $class = str_replace(array('"', "'"), '', $class);
+  // Change underscores and spaces to dashes.
   $class = str_replace(array('_', ' '), '-', $class);
 
-//  dsm("_user_badges_class: badge->name = $badge->name becomes $class.");
   return $class;

Maybe this function can be replaced completely with http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ht... ?

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -538,16 +593,18 @@ function user_badges_badge_autocomplete(
+      -> orderBy(array('weight', 'name'))

This doesn't look like valid orderBy() syntax to me.

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -593,15 +650,20 @@ function user_badges_badge_autocomplete_
+    $account = array_shift(user_load_multiple(array($uid)));

This doesn't make sense, why not simply use user_load()? You're doing exactly what user_load() does. That's not what the comment was about...

Also, this code results in an E_STRICT notice, because array_shift() expectes a variable.

Also, if possible, this should be cleaned up so that always a user object is passed in.

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -626,21 +686,43 @@ function user_badges_userweight_page($ui
+        $item[] = array('data' => theme('item_list', array('items' => $accts)), 'class' => 'user-badges-whoelse');

Doesn't this require class to be an array as well?

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -742,9 +828,15 @@ function user_badges_change_form_submit(
-    drupal_set_message(t('!removalcount badge(s) removed.', array('!removalcount' => count($badges_to_go))));
+    drupal_set_message(t('@removalcount badge(s) removed.', array('@removalcount' => count($badges_to_go))));

Should use format_plural() instead of that badge(s) thing.

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -956,66 +1045,57 @@ function user_badges_delete_form($form, 
+    ->condition('bid', $bid)
+    ->execute();

As mentioned in my userpoints_badges review, a module_invoke('user_badges_delete', $bid) would be awesome here (including documentation in a .api.php file), so that modules like userpoints_badages can act when badges are deleted.

Another improvement would be API functions which are just called by the submit callback, so that modules can create/delete badges through code.

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -956,66 +1045,57 @@ function user_badges_delete_form($form, 
-  $query = db_select('user_badges_roles', 'ubr')    
-    -> fields('ubr', array('rid', 'bid'))  
-    -> fields('ubb', array('name', 'image', 'weight', 'href', 'tid'));
-    
   if ($rid) {
-    $query -> condition('ubr.rid', $rid);
+    $records = db_query("SELECT ubr.rid, ubb.* FROM {user_badges_roles} ubr INNER JOIN {user_badges_badges} ubb ON ubb.bid = ubr.bid WHERE ubr.rid = :rid ", array(':rid' => $rid));
+  }
+  else {
+    $records = db_query("SELECT ubr.rid, ubb.* FROM {user_badges_roles} ubr INNER JOIN {user_badges_badges} ubb ON ubb.bid = ubr.bid ");
   }
-    
-  $alias = $query -> join('user_badges_badges', 'ubb', 'ubr.bid = ubb.bid');

Interestingly, here where we actually have a reason for a dynamic query (different conditions based on arguments), you replaced it with hardcoded queries? just wondering why?

+++ new\user_badges.module	2011-10-25 00:15:07.406250000 -0400
@@ -1048,22 +1131,46 @@ function user_badges_save_roles($roles) 
+        if ($rid > 2) {
+          $query->condition();

I don't think this is a valid condition() usage. not sure what you're trying to do here.

nancydru’s picture

Thanks, I'll go through these in detail in a little while (got a customer call just now). The last one is the beginning of trying to clean up the whole role badge stuff, which is, IMHO, all wrong (there is an issue about that).

nancydru’s picture

Status: Needs work » Active
StatusFileSize
new39.72 KB
new96.96 KB

This contains:

A new version of the documentation page is included in the zip file, as is the code that has been moved to separate files.

Remaining known issues:

To be tested: Does Private file system now work?

boran’s picture

I tried the above zip and had to do one fix, when viewing the user profile.
at the top of the function user_badges_for_user()

1261,1264c1261
< // @todo: hang on, uid array received.
< if (is_array($uid)) {
< $uid=$uid['uid'];
< }
---
>

to solve errors like:
Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in user_badges_for_user() (line 1267 of /disk2/www/drupal-7.8/sites/all/
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 184 of /disk2/www/drupal-7.8/includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 375 of /disk2/www/drupal-7.8/includes/entity.inc).
Warning: Illegal offset type in user_badges_for_user() (line 1285 of /disk2/www/drupal-7.8/sites/all/modules/custom/user_badges/user_badges.module).
Warning: Illegal offset type in user_badges_for_user() (line 1300 of /disk2/www/drupal-7.8/sites/all/modules/custom/user_badges/user_badges.module).

nancydru’s picture

Is this the zip from #20? I got this long ago, but not now.

boran’s picture

Yes I pulled:
wget http://drupal.org/files/user_badges_3.zip
unzip user_badges_3.zip
The CHANGELOG.html in there is basically the post from #20

nancydru’s picture

I don't have that code in my version:

function user_badges_for_user($uid, $list = FALSE) {
  static $save = array(0 => FALSE);

  if (isset($save[$uid])) {
    return $save[$uid];
  }

  $account = user_load($uid);

  $badges = array();
  foreach ($account->badges as $badge) {
    $badges[] = theme('user_badge', array('badge' => $badge, 'account' => $account));
  }

  if ($list) {
    $badges = array(theme('item_list', array('items' => $badges)));
    $save[$uid] = $badges;
    return $badges;
  }

  if ($badges) {
    $save[$uid] = theme('user_badge_group', array('badgeimages' => $badges));
  }
  else {
    // Do we have a "no badges" message?
    if ($nobadges = variable_get('user_badges_nobadges', '')) {
      $nobadges = array('<div class="user_badges_no_badges">'
        . filter_xss_admin(t($nobadges))
        . '</div>');
      $save[$uid] = theme('user_badge_group', array('badgeimages' => $nobadges));
    }
    else {
      $save[$uid] = FALSE;
    }
  }

  return $save[$uid];
}
boran’s picture

Yes, I had to add in:
if (is_array($uid)) {
$uid=$uid['uid'];
}

after:
static $save = array(0 => FALSE);

to fix the log messages noted above.
uid was coming in as an array.

nancydru’s picture

Really? How did you get there? I cannot recreate this.

boran’s picture

When I view my user profile page.

spaceknight’s picture

I got this error when I tried to uninstall User Badges:

Fatal error: Call to undefined function file_create_path() in C:\xampp\htdocs\drupal7\sites\all\modules\user_badges\user_badges.install on line 170

That happens when I select the module, click the Uninstall button, and the page with error is

http://localhost/drupal7/admin/modules/uninstall/confirm

And the module is not being uninstalled, is still there.

nancydru’s picture

Yes, the .install file needs work. That's why I say this should not be used to upgrade from D6 yet.

Uninstall never removes a module, only its data; it will continue to show up on the module admin page.

spaceknight’s picture

I am posting my findings here:

EDIT:

- When trying to edit a badge, the link takes me to People page. I guess the link is generated as (program/admin/people/user_badges/edit/2), and it should be (program/admin/config/people/user_badges/edit/2)

ADD:

- There are two form buttons named (Save Badge) at the bottom (you already are aware of this).

LIST:

- Can we put Userpoints Goal as a new column (if userpoints_badges is enabled) ?

berdir’s picture

Status: Active » Needs work

Another review. Also applied the patch, some general issues:
- All the new files (token, actions, ..) are missing in the patch.
- See below, I don't have a doc_page.html, just a README.txt ?
- The usual issues with your patch being against the snapshot and containing windows line endings :)
- Image styles don't seem to be working for me, but that part needs work anyway, see below.
- This is a mix of required bugfixes and new features. This results in a huge patch and the new features which need more discussion/work are stopping the smaller bugfixes from being commited. I can see that you're doing this because the single, simple patches aren't commited either but this is still a problem :) I usually do this kind of thing by having a separate branch for every thing I work on in my local git repository.

diff -up old/user_badges/doc_page.html new/user_badges/doc_page.html
--- old/user_badges/doc_page.html	2011-10-25 23:18:36.546875000 -0400

Where is doc_page.html coming from? That is not in Git nor in the -dev snapshot? Both just have a README.txt.

+++ new/user_badges/doc_page.html	2011-10-25 23:29:16.093750000 -0400
@@ -30,21 +33,18 @@ Once the module is activated, go to Admi
diff -up old/user_badges/user_badges.admin.inc new/user_badges/user_badges.admin.inc

diff -up old/user_badges/user_badges.admin.inc new/user_badges/user_badges.admin.inc
--- old/user_badges/user_badges.admin.inc	2011-09-13 16:52:48.000000000 -0400

--- old/user_badges/user_badges.admin.inc	2011-09-13 16:52:48.000000000 -0400
+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400

The path should not contain the module name, this currently requires -p2 so that it can be applied.

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -20,50 +20,102 @@
+  // Which will be the default sort order?
+  if (variable_get('user_badges_userweight', 0)) {
+    $form['header']['weight']['#value']['sort'] = 'asc';
+  }
+  else {
+    $form['header']['#value']['name']['sort'] = 'asc';
+  }

The order of the weight thing looks wrong, should have #value first.

I would also recommend using #header then you don't need the additional nesting within #value.

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -20,50 +20,102 @@
+    $options = array();
+    if ($badge->unhideable) {
+      $options[] = t('Cannot be hidden');
+    }
+    if ($badge->doesnotcounttolimit) {
+      $options[] = t('Does not count to limit');
+    }
+
+    $form['options'][$badge->bid] = array(
+      '#type' => 'value',
+      '#value' => implode("<br />", $options),

Not too sure about this part, it should at least use real sentences with dots and stuff. Is this really necessary?

According to UX guidelines, tables shouldn't contain too much information...

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -20,50 +20,102 @@
+    if ($show_users) {
+
+      $query = db_select('user_badges_user', 'ubu');
+      $query->join('users', 'u', 'u.uid = ubu.uid');
+      $query->fields('u', array('uid', 'name'))
+        ->condition('ubu.bid', $badge->bid);
+      $users = $query->execute();
+
+      $u_list = array();
+      foreach ($users as $acct) {
+        $u_list[$acct->uid] = l(format_username($acct), "user/$acct->uid/badges");
+      }
+      if (!$u_list) {
+        $u_list[] = t('None');
+      }
+
+      $form['users'][$badge->bid] = array('#value' => theme('item_list', array('items' => $u_list)));

Same here, wondering if there is a better way to do this, but it's disabled by default so what... :)

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -156,9 +212,6 @@ function theme_user_badges_badgelist_for
-  // Render any remaining form elements.
-  //$output .= drupal_render_children($form);

Why did you remove this? This is IMHO correct and is for rendering additional stuff like hidden form fields.

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -199,7 +251,7 @@ function user_badges_edit_form($form, $f
     '#description' => t('Name for the badge. Will be displayed as a tooltip when rolling over the badge.'),
     '#required' => TRUE,
-  );
+    );
   $form['imageurl'] = array(

Also, this change looks wrong to me, this seemed to be correctly indented? The closing ) needs to be on the same level as the $form... line.

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -241,41 +293,44 @@ function user_badges_edit_form($form, $f
+        '#value' => t('Install the !link module if you want this URL to include dynamic elements such as badge ID numbers.',
+        array('!link' => l('Token', 'http://drupal.org/project/token', array('absolute' => TRUE))

The preferred way to have links in translated text is to embed the directly in the text just embed the url with url(). This allows to see the context of the link when translating it.

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -358,24 +422,36 @@ function user_badges_edit_form_validate(
   $edit = $form_state['values'];
+  ¶
+  // Let other modules know about this.
+  module_invoke_all('user_badges_edit_badge', $edit);
+  ¶
   $edit = (object) $edit;

Trailing spaces.

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -383,30 +459,31 @@ function user_badges_edit_form_submit($f
-  $form_state['redirect'] = 'admin/user/user_badges';
+
+  $form_state['redirect'] = 'admin/people/user_badges/list';

The redirect should not point to main menu link, not the deafault local task. Meaning, without /list

+++ new/user_badges/user_badges.admin.inc	2011-10-25 23:07:19.515625000 -0400
@@ -383,30 +459,31 @@ function user_badges_edit_form_submit($f
-  $form = array('#skip_duplicate_check' => TRUE);  
+  $form = array('#skip_duplicate_check' => TRUE);
   $form['new']['upload'] = array(
     '#type' => 'file',
     '#title' => t('Upload image'),
-    '#size' => 40,

Use managed_file instead of file. Then you can drop 90% of the code. The file will be automatically saved and you can work with the resulting $file object in your form submit functions. Consequently, you should work with the file id (fid) instead of the path in the image selection form. See http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html#managed_file

+++ new/user_badges/user_badges.module	2011-10-25 23:07:50.546875000 -0400
@@ -48,126 +61,141 @@ function user_badges_help($path, $arg) {
-  $items['admin/user/user_badges/add'] = array(
+  $items['admin/people/user_badges/add'] = array(
     'title' => 'Add',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('user_badges_edit_form'),
-    'access arguments' => $access,
+    'access arguments' => array('manage badges'),
     'type' => MENU_LOCAL_TASK,
     'file' => 'user_badges.admin.inc',
-  );

Should be a MENU_LOCAL_ACTION.

diff -up old/user_badges/doc_page.html new/user_badges/doc_page.html
--- old/user_badges/doc_page.html	2011-10-25 23:18:36.546875000 -0400
+++ new/user_badges/doc_page.html	2011-10-25 23:29:16.093750000 -0400

The path should be old/doc_page.html, without the module name. Same for everything else.

This applies but requires -p2 which is very uncommon.

Also very uncommon is having a html page for the documentation.

+++ new/user_badges/doc_page.html	2011-10-25 23:29:16.093750000 -0400
@@ -8,18 +8,21 @@ You can also set a special badge for blo
 User Product Badges (sub-module) requires:
 ecommerce

I assume that this sub-module does not exist anymore.

+++ new/user_badges/doc_page.html	2011-10-25 23:29:16.093750000 -0400
@@ -8,18 +8,21 @@ You can also set a special badge for blo
 User Product Badges (sub-module) requires:

You can probably drop this part..

+++ new/user_badges/user_badges.module	2011-10-25 23:07:50.546875000 -0400
@@ -48,126 +61,141 @@ function user_badges_help($path, $arg) {
-  $items['admin/user/user_badges/edit/%'] = array(
+  $items['admin/people/user_badges/edit/%'] = array(
     'title' => 'Edit badge',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('user_badges_edit_form', 4),
-    'access arguments' => $access,
+    'access arguments' => array('manage badges'),
     'type' => MENU_CALLBACK,
     'file' => 'user_badges.admin.inc',
-  );

This should use MENU_VISIBLE_IN_BREADRUMB or maybe actually MENU_LOCAL_TASK so that you still see the other local tasks and the breadcrumb to navigate back if you want to. Same for delete.

+++ new/user_badges/user_badges.module	2011-10-25 23:07:50.546875000 -0400
@@ -176,65 +204,78 @@ function user_badges_menu() {
 /**
- * Implements hook_user_load().
+ * Implements  hook_user_load().
+ * Gets all badges for the user and the limited badges.

A space too much after implements.

Also, there should be an empty line between those too.

nancydru’s picture

I am using the diff program from Gnuwin32. If I need to use other parameters, I'll be happy to change. Currently I use "-up" because that used to be the standard. My code has Unix line endings, so the Win stuff must be coming in the diff process. The extra "module name" in the diff lines is an artifact of trying to produce a consolidated patch. I cannot keep doing a diff for each file.

And, until I learn Git, I will keep working with the -dev download (which someone else created).

The "new features" are either to solve issues in this queue, or are a result of having problems during testing and I think may be nice for adopters of the module.

The "doc_page.html" is a copy of what the "Documentation" link on the project page points to. It will not be part of the project when I can commit again.

"#header" is apparently new in D7, but I guess the Coder upgrade didn't suggest it to the guy who originally ported this code. Have you got an example of how to use it? The API doc is skimpy. Same with "#managed_file," which looks much better than hand coding that stuff.

The "Cannot be hidden" and "Does not count to limit" stuff helped me debug some issues in testing and I think can be useful to adopters. The text is the same as the form "#title" so that a single translate string can handle both instances. If I add a period, then it will take two strings, which may not be translated the same way. I don't think this is "too much information." I added the user name list also because of debugging and found it to be useful. It is disabled by default because it could result in a very large page on some sites.

"MENU_LOCAL_ACTION" - the API docs read almost the same as "MENU_LOCAL_TASK." What is the distinction? If I change it, the "Add" tab goes away - definitely not what I want.

I have no idea what the status of "User Product Badges" is. I'll worry about it when I get the core functionality stabilized.

You're the one who said that "Implements" should have two spaces. I didn't look up the standard, but it seemed awfully arbitrary. Coder doesn't seem to care either way.

berdir’s picture

Try -N so that newly added files show up in the diff for a start :)

#header is nothing special. It's simply relying on the fact that the form API does basically ignore it due to the leading # and you can just write $form['#header'] to access it instead of having to use $form['header']['#value'].

I don't have an example at hand for file_managed, but it's not that complex. Just use that type, set the desired properties like allowed file extensions, upload directory and in the submit callback, just use file_usage_add() like you already do.

MENU_LOCAL_ACTION results in a "+ link" on top of the page and is the default for all links which add something. Have a look at admin/content or admin/people for example. And yes, this removes the tab and that's ok :)

Regarding Implements, I think that was a misunderstanding. One of your patches had two spaces already in some cases and I meant that they should be removed. Coder.module never even looks at documentation AFAIK.

nancydru’s picture

Thanks. I looked at the diff --help and missed that parameter.

Refineo’s picture

Hello,

After installing the patch using the wget http://drupal.org/files/user_badges_3.zip as in comment #23
I am still getting this warning:

Notice: Undefined index: roles in user_badges_user_presave() (line 307 of /sites/all/modules/contrib/user_badges/user_badges.module).

nancydru’s picture

I know role support is a mess right now. I've been fighting with managed_file and am about to dump it and go back to not using it. Then I can get back to tackling either Git or roles.

berdir’s picture

Feel free to post what you have and what you're stuck with. I'll try to help if I find the time.

nancydru’s picture

The first issue is that when it uploads the new image, it doesn't display it, but the link will. Then the other images all show "upload" rather than "remove."

fasdalf@fasdalf.ru’s picture

Could someone roll up an archive and post here current version, so i could join tests and try to fix bugs?

seanr’s picture

Re #39, that'd be pretty helpful for me too. I'm trying to figure out exactly where this is at right now as we're going to need something like this for an upcoming D7 (from scratch) project, and this thread has gotten a tad unwieldy. ;-)

We're really just looking for basic badges based on userpoints - no roles stuff etc. Simpler the better. If there are some good alternatives, that'd be helpful as well.

boran’s picture

"If there are some good alternatives, that'd be helpful as well."
I switched to the achievements module myself for D7. Its well maintained and has an interesting approach.

RogueM’s picture

for those looking for badges assigned to roles, it is indeed not working properly currently. What I have found is that you can only assign badges to one role, with any subsequent attempt overwriting the previous, or failing altogether, with net result that only 1 role can be tagged wit ha badge.

That said it is better than nothing and in my case I was able to make use of the current code state with a combination of role and manual assignment (for the lesser roles, in manageable numbers in my case). So while not perfect, depending on your requirement 'user_badges_3.zip' is useful nonetheless in that respect.

computerology’s picture

I took a look at Achievements, however the developer has purposely made the module require coding and hooking into an API. While it's a neat module and I may use it for special things like MVP or passing qualification tests, it does not really replace the role badges as a combo of userpoints_role and user_badges.

If you are looking for something that will allow you to award images that are never taken away and have no link to continuous activity, Acheivements may work.

In the meantime, we must wait with bated breath for the role badges in user_badges to get working in D7.

Osuryn’s picture

I try to add a badge to my website, and it gives this error:
how can i solve this?

Notice: Undefined property: stdClass::$bid in user_badges_edit_form_submit() (line 367 of /home/brokendi/public_html/sites/all/modules/user_badges/user_badges.admin.inc).
PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1: INSERT INTO {user_badges_badges} (bid, name) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1_0, :db_insert_placeholder_1_image, :db_insert_placeholder_1_weight, :db_insert_placeholder_1_href, :db_insert_placeholder_1_unhideable, :db_insert_placeholder_1_fixedweight, :db_insert_placeholder_1_doesnotcounttolimit, :db_insert_placeholder_1_tid); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1_0] => test badge [:db_insert_placeholder_1_image] => public://th_Admin_badge[1].png [:db_insert_placeholder_1_weight] => 0 [:db_insert_placeholder_1_href] => [:db_insert_placeholder_1_unhideable] => 0 [:db_insert_placeholder_1_fixedweight] => 0 [:db_insert_placeholder_1_doesnotcounttolimit] => 0 [:db_insert_placeholder_1_tid] => ) in user_badges_edit_form_submit() (line 378 of /home/brokendi/public_html/sites/all/modules/user_badges/user_badges.admin.inc).
The website encountered an unexpected error. Please try again later.

SheilaRuth’s picture

Is this D7 port still being worked on? It doesn't look like there has been much activity recently, and I'm just wondering if this is still an active project. Thanks.

nancydru’s picture

With some luck, there will be a new -dev this evening.

Refineo’s picture

@NancyDru, please let us know when we could expect the new dev release for D7 ?

nancydru’s picture

Well, the project page shows it having been generated on 2012-Mar-18. It should include all the patches above.

Refineo’s picture

I tested the 2012-Mar-18 version of 7.x-1.x-dev today and I got this on frontpage:

Notice: Undefined index: roles in user_badges_user_presave() (line 315 of /***/sites/all/modules/contrib/user_badges/user_badges.module)

on Pressflow 7 (Drupal 7.12) with apc + boost (fresh install without content)

Royce Kimmons’s picture

Status: Needs work » Patch (to be ported)
StatusFileSize
new9.44 KB

Created a patch that corrects several errors in the administrative area and image displays including the following:

  • Fixed improper class attribution for badges (rogue PHP was in the class tag).
  • Fixed broken images in autocomplete.
  • Replaced calls to theme for image rendering to theme_image.
  • Added CSS to display badges horizontally in the admin area (to prevent massive scrolling).
  • Made some label elements uppercase that were lower case.
  • Fixed the badges list table to use the empty variable and to show the proper number of columns when no rows are returned.

Cheers!

Royce Kimmons’s picture

StatusFileSize
new10.17 KB

This patch includes the previous and also gives a header to the table on the user badge page.

berdir’s picture

Status: Patch (to be ported) » Needs review

patch (to be ported) means a patch has been commited to one major version and needs to be updated to work with another one. needs review is what you're looking for.

That said, I strongly recommend to mark this issue fixed asap (e.g. after your patch has been commited) and create separate new issues for the things you're working on. That makes it easier to write useful commit messages and you're not sending 28 notification mails every time someone comments in here ;)

Royce Kimmons’s picture

Will do, and thanks for the advice!

computerology’s picture

Category: bug » task

Any idea how much work is left for the D7 port with role badges?

Would money help to prioritize this project? I can toss some bones but I'm not rich. I need this module esp with role badges working and the ability to only show the highest ranking badge.

I have been waiting for this to be D7 ported for a year. I am fully understanding that the devs are volunteering their time so I dont intend to be brash at all, please dont take this the wrong way.

I replaced standard forum software with Drupal, and virtually every forum board software has the ability to show a "rank" badge. On my site especially being a paramilitary site everyone chomps at the bit to show off their rank. The only thing I'm missing is user badges with role badges to complete the picture.

Perhaps some flat rate price quotes, if it's above my pay grade maybe a bunch of the admins in here chomping at the bit could chip in together so we can get this puppy to a stable release?

cherrysuede’s picture

I would also donate some $$ to help move this port across the finish line :)

delty’s picture

As would I...

halloffame’s picture

Just start testing out the dev version guys. Report problems and we deal this thing on a per-bug basis and speed up the process.

delty’s picture

FYI the patches in #50 and #51 break the application of Media > Image Styles to badges.

cherrysuede’s picture

StatusFileSize
new52.55 KB

Hey guys - using latest dev and even with patch in #51

unable to save a badge assignment to a role - i get these errors (attached a screenshot)

Any suggestions?

Thanks guys!

cherrysuede’s picture

StatusFileSize
new123.69 KB

sorry attached the wrong screenshot - it's this one

cherrysuede’s picture

Sorry guys - found the patch in a different - saving is now working.

And I apologize if i'm not in the right thread - finding my way around.

SebCorbin’s picture

Willing to help on this, but the patch from #51 is to apply against which version/commit?

SebCorbin’s picture

Status: Needs review » Closed (fixed)

Closing this issue as it gets a bit messy. Please open another issue for each problem you may encounter.

Thanks to you all for porting the module to D7!