Skip to content

Instantly share code, notes, and snippets.

@zetas
Created May 20, 2017 22:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zetas/26bbe2320ee07b3a08877ffe08618479 to your computer and use it in GitHub Desktop.
Save zetas/26bbe2320ee07b3a08877ffe08618479 to your computer and use it in GitHub Desktop.
<?php
namespace app\extensions\data\behavior;
use nzedb\Users;
use lithium\aop\Filters;
class Vip extends \li3_behaviors\data\model\Behavior
{
protected static $_defaults = ['user_id' => false];
protected static function _filters($model, $behavior)
{
Filters::apply($model, 'save', function ($params, $next) use ($behavior) {
$params['data']['user_id'] = $behavior->config('user_id');
return $next($params);
});
}
protected static function _finders($model, $behavior)
{
$model::finder('existingVIPDonation', function ($params, $next) use ($behavior) {
// Set up default conditions
$defaults = [
'completed' => null,
'user_id' => $behavior->config('user_id'),
];
// Merge with supplied params
$params['options']['conditions'] = $defaults + (array)$params['options']['conditions'];
return $next($params);
});
}
public function completeDonation($model, $behavior, $entity) {
$u = new Users();
$uid = $behavior->config('user_id');
if ($uid === false)
return false;
$return = $u->upgradeToVIP($uid);
if ($return !== false) {
$model::$isComplete = true;
return $return;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment