Ejemplo n.º 1
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         Code::generateCode($this->poll_id, $this->id)->save();
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Code model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($poll_id, $member_id)
 {
     $member = Member::findOne($member_id);
     if ($member) {
         if ($member->hasValidCode()) {
             $code = $member->getValidCode();
             $code->invalidate();
             $code->save();
         }
         Code::generateCode($poll_id, $member_id)->save();
     }
     // else {
     //Yii::$app->getSession()->setFlash('error', 'This member already has a valid voting code');
     //}
     return $this->redirect(PollUrl::toRoute(['member/view', 'poll_id' => $poll_id, 'id' => $member_id]));
 }
 /**
  * Creates a new Code model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Code();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $count = $model->count;
         $codes = [];
         for ($i = 0; $i < $count; $i++) {
             $codeModel = clone $model;
             $codeModel->code = Code::generateCode();
             $codeModel->used = 0;
             $codeModel->save();
             $codes[] = $codeModel->z_b_id . str_pad($codeModel->z_p_id, 3, '0', STR_PAD_LEFT) . $codeModel->code;
         }
         return $this->render('create-summary', ['codes' => $codes, 'bank' => Bank::findOne($codeModel->z_b_id), 'count' => $count]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 4
0
 public function createSpecificCode($bezeichnung = null)
 {
     /*if($bezeichnung == null){
           $banks = Bank::find()->where('klasse = :klasse', ['klasse' => $this->f_klasse])->all();
           $b_id = $banks[0]->b_id;
       }else{
           $banks = Bank::find()->where('bezeichnung = :bezeichnung', ['bezeichnung' => $bezeichnung])->all();
           $b_id = $banks[0]->b_id;
       }*/
     $b_id = $bezeichnung;
     $code = new Code();
     $code->z_b_id = $b_id;
     $code->z_p_id = $this->f_p_id;
     $code->code = Code::generateCode();
     $code->used = 0;
     $code->count = 1;
     $code->save();
     return $code;
 }