16 hours ago, DisposableHero said:
In the above example
$balance is the amount we wish to give the award, entered manually by us at admin > awards page (it was $flight_minutes in your example)
$this->user->journal->balance is the user’s balance (it was $this->user->flight_time in your example)
When a user sends a pilot report and when it gets accepted (either manually or automatically) award checks are done too. So to test your new award class, you need to file / accept a pirep (no need to fly, just file a valid manual pirep and accept it)
Also, if something goes wrong you probably will not see an error page, but the pireps will not be accepted. You need to check your laravel logs to see where it fails (Most of the time it is awards, a missing one or a faulty one)
Thank you for your help so far.
I made the suggested edits however I got an error. Then I started again editing the Flight time Award ending up with this below.
Obviously I’ve missed something because this didn’t tigger an award after passing the monetary amount set in the Awards interface.
Can you see where I slipped up?
Thanks
Baz
<?php
namespace Modules\Awards\Awards;
use App\Contracts\Award;
use Illuminate\Support\Facades\Log;
/**
* All award classes need to extend Award and implement the check() method
* This award is based on the original PilotFlightAwards.php file but
* checks the Pilots money balance.
* This award means you can create an award for a pilot that completes any
* amount of money.
*
* See: https://docs.phpvms.net/developers/awards
*/
class PilotMoneyAwards extends Award
{
/**
* Set the name of this award class to make it easier to see when
* assigning to a specific award
*
* @var string
*/
public $name = ‘Pilot Earnings Award’;
/**
* The description to show under the parameters field, so the admin knows
* what the parameter actually controls. You can leave this blank if there
* isn’t a parameter.
*
* @var string
*/
public $param_description = ‘Money Earned by pilot as $$$$’;
/**
* If the user has over N dollar, then we can give them this award.
*
* @param int|null $balance The parameters passed in from the UI
*
* @return bool
*/
public function check($balance = null): bool
{
if (!is_numeric($balance)) {
Log::error(‘PilotMoneyAwards: Flight time "’.$balance.‘" is not a valid amount’);
return false;
}
return $this->user-> balance >= (int) $balance;
}
}