/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new AutoTopupConfiguration();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['AutoTopupConfiguration'])) {
         $model->attributes = $_POST['AutoTopupConfiguration'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionIndex()
 {
     Yii::import('application.models.*');
     echo "Cleaning all AutoTopupConfiguration \n";
     AutoTopupConfiguration::model()->deleteAll();
     $allAccounts = RemoteDataCache::model()->findAll();
     foreach ($allAccounts as $currentAccount) {
         $freeVoipObject = FreeVoipAccounts::model()->findByAttributes(array('username' => 'jawdroppingcalls'));
         $autoTopUpConf = new AutoTopupConfiguration();
         $autoTopUpConf->activated = false;
         $autoTopUpConf->budget = 0;
         $autoTopUpConf->freeVoipAccount = $freeVoipObject->id;
         $autoTopUpConf->remote_data_cache = $currentAccount->id;
         $autoTopUpConf->topUpValue = 0;
         if ($autoTopUpConf->save(false)) {
             echo "AutoTopupConfiguration created for {$currentAccount->main_user} \n";
         } else {
             echo "Cant create configuration for {$currentAccount->main_user} \n";
         }
     }
 }
 protected function afterSave()
 {
     if ($this->isNewRecord) {
         /*create AutoTopUpConfiguration*/
         $freeVoipObject = FreeVoipAccounts::model()->findByAttributes(array('username' => 'jawdroppingcalls'));
         $autoTopUpConf = new AutoTopupConfiguration();
         $autoTopUpConf->activated = false;
         $autoTopUpConf->budget = 0;
         $autoTopUpConf->freeVoipAccount = $freeVoipObject->id;
         $autoTopUpConf->remote_data_cache = $this->id;
         $autoTopUpConf->topUpValue = 0;
         $autoTopUpConf->save(false);
     }
     parent::afterSave();
 }