Created
May 20, 2017 22:13
-
-
Save zetas/26bbe2320ee07b3a08877ffe08618479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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