function reactivate($params){
     if(isset($params['code']) && !empty($params['code'])){
         $premcode = PremiumCode::find()->where(array('code' => $params['code']))->first();
         if($premcode){
             if($premcode->reactivate()){
                 Event::trigger(Event::TYPE_PREMCODE_REACTIVATE, User::$current->account, $premcode);
                 $this->render_ajax('success', 'reactivated code ' . $premcode->code);
             } else {
                 $this->render_ajax('error', $premcode->errors[0]);
             }
         } else {
             $this->render_ajax('error', "Code ({$params['code']}) not found or invalid");
         }
     } else {
         $this->render_ajax('error', 'No code selected');
     }
 }
Exemplo n.º 2
0
    private function generate_code(){
	$code = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'), 0, 8);
	$premcode = PremiumCode::find()->where(array('code' => $code))->first();
	
	if($premcode) 
            $code = $this->generate_code();
        
        return $code;
    }