/** * Signs user up. * * @return Users|null the saved model or null if saving fails */ public function register() { $user = null; $transaction = Yii::$app->db->beginTransaction(); try { $group = new Groups(); $group->name = $this->email; if ($group->save()) { $user = parent::register($group->id); for ($i = 0; $i < $this->beacon_count; $i++) { $beacon = new Beacons(); $beacon->name = Yii::$app->security->generateRandomString(16); $beacon->title = "Such title {$i}"; $beacon->description = "So description {$i}"; $beacon->minor = $group->id . $user->id . $i; $beacon->major = $group->id . $user->id . $i; $beacon->place = "Wow Place {$i}"; $beacon->uuid = UUID::v4(); $beacon->groupToBind = $group->id; $beacon->save(); } } $transaction->commit(); return $user; } catch (Exception $e) { if ($transaction->isActive) { $transaction->rollBack(); } return null; } }
/** * Creates a new Beacons model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Beacons(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('beacon-form', ['model' => $model]); } }