Creating custom trophies

bashy

Member
I have searched the forums but people post threads without putting descriptive titles :p
So I'm wanting to create a custom trophy when someone enters something in to a custom profile field I made.

Here's a preview of what I have so far but I don't think this box means "User value contains text", more of "User value contains THIS CERTAIN text"?

I want the user to get the trophy IF they enter text into it (every entry will be different so I need it to be anything a-z.)



And;

 

Martyn

Active member
maybe you can use some custom setting in the Custom User Field Criteria in the Trophy Options section?

like this "^[a-zA-Z0-9 _.]+$" unsure if it will work..
 

Martyn

Active member
I tried using regex and I also tried leaving the field blank! As surely if no requirements are set then anything warren I there would be classed as it being entered if you get me? :)
 

bashy

Member
I tried using regex and I also tried leaving the field blank! As surely if no requirements are set then anything warren I there would be classed as it being entered if you get me? :)
Yeah, I myself did try ticking the box and leaving it empty, no luck. Seems you can only set it for exact text in field, no rules.
Thanks for trying anyway, will see if someone else replies with a brainy idea or hack for it :)
 

Jake Bunce

XenForo moderator
Staff member
If you are curious about the code:

library/XenForo/Helper/Criteria.php

Code:
			// custom user fields
			if (strpos($criterion['rule'], self::$_userFieldPrefix) === 0)
			{
				$userFieldId = substr($criterion['rule'], self::$_userFieldPrefixLength);

				if (!isset($user['customFields'][$userFieldId]))
				{
					return false;
				}

				$userField = $user['customFields'][$userFieldId];

				// text fields - check that data exists within the text value
				if (isset($data['text']))
				{
					if (stripos($userField, $data['text']) === false)
					{
						return false;
					}
				}
				// choice fields - check that data is in the choice array
				else if (isset($data['choices']))
				{
					// multi-choice
					if (is_array($userField))
					{
						if (!array_intersect($userField, $data['choices']))
						{
							return false;
						}
					}
					// single choice
					else
					{
						if (!in_array($userField, $data['choices']))
						{
							return false;
						}
					}
				}
			}
There is no pattern matching. It checks specific values. You can modify this code, but then you have to redo it when you upgrade.
 

Martyn

Active member
maybe theres an away to add multiply options "User value contains text:" so maybe you could have multiple entrys? such as a,b,c,d,e etc or a;b;c;d;e? if you get me?
 

bashy

Member
There is no pattern matching. It checks specific values. You can modify this code, but then you have to redo it when you upgrade.
I don't mind about redoing code, doubt I'll be upgrading anytime soon either (unless there's some major new features of bug fixes).

So if I wanted a trophy to apply when someone enters ANY text into that custom field and maybe add another checkbox to the options "Award on completing field" what would I have to change/add?

I know basic PHP so any example would be helpful and apprecaited.
 

Jake Bunce

XenForo moderator
Staff member
I don't mind about redoing code, doubt I'll be upgrading anytime soon either (unless there's some major new features of bug fixes).

So if I wanted a trophy to apply when someone enters ANY text into that custom field and maybe add another checkbox to the options "Award on completing field" what would I have to change/add?

I know basic PHP so any example would be helpful and apprecaited.
Untested but...

Rich (BB code):
			// custom user fields
			if (strpos($criterion['rule'], self::$_userFieldPrefix) === 0)
			{
				$userFieldId = substr($criterion['rule'], self::$_userFieldPrefixLength);

				if (!isset($user['customFields'][$userFieldId]))
				{
					return false;
				}

				$userField = $user['customFields'][$userFieldId];

				// text fields - check that data exists within the text value
				if (isset($data['text']))
				{
					if ($data['text'] == 'anything' AND empty($userField))
					{
						return false;
					}
					else if ($data['text'] != 'anything' AND stripos($userField, $data['text']) === false)
					{
						return false;
					}
				}
				// choice fields - check that data is in the choice array
				else if (isset($data['choices']))
				{
					// multi-choice
					if (is_array($userField))
					{
						if (!array_intersect($userField, $data['choices']))
						{
							return false;
						}
					}
					// single choice
					else
					{
						if (!in_array($userField, $data['choices']))
						{
							return false;
						}
					}
				}
			}
This uses the word anything as a keyword to mean exactly that.
 

0xym0r0n

Well-known member
worked for me too.

Side note for people looking at this. Make sure you enter 'anything' in the text field that you want as a wildcard.
 

zastavra

Formerly Stevez
What if a user removes the text from that custom field? Are the related points also getting removed from his total trophy points?
 
Top