Example #1
0
 public function addDolzhnost()
 {
     $organizaciya = $this->organizaciyaId ? Organizaciya::findOne($this->organizaciyaId) : new Organizaciya(['nazvanie' => $this->organizaciyaNazvanie, 'vedomstvo' => $this->organizaciyaVedomstvo, 'adresAdresnyjObjekt' => $this->organizaciyaVedomstvo, 'obschij' => false]);
     if (!$organizaciya->validate()) {
         return false;
     }
     if ($this->organizaciyaId) {
         $rabotaFizLica = RabotaFizLica::findOne(['fiz_lico' => $this->fizLicoId, 'organizaciya' => $this->organizaciyaId]);
     } else {
         $rabotaFizLica = null;
     }
     if (!$rabotaFizLica) {
         $rabotaFizLica = new RabotaFizLica(['fiz_lico' => $this->fizLicoId]);
     }
     if (!$rabotaFizLica->validate()) {
         return false;
     }
     $dolzhnost = $this->dolzhnostId ? Dolzhnost::findOne($this->dolzhnostId) : new Dolzhnost(['nazvanie' => $this->dolzhnostNazvanie, 'tip' => 'inaya', 'obschij' => false]);
     try {
         DolzhnostFizLicaNaRabote::getDb()->transaction(function () use($organizaciya, $rabotaFizLica, $dolzhnost) {
             $organizaciya->save(false);
             $dolzhnost->save(false);
             $rabotaFizLica->link('organizaciyaRel', $organizaciya);
             $dolzhnostFizLica = new DolzhnostFizLicaNaRabote(['dolzhnost' => $dolzhnost->id, 'etapObrazovaniya' => $this->etapObrazovaniya]);
             $dolzhnostFizLica->link('rabotaFizLicaRel', $rabotaFizLica);
         });
     } catch (Exception $e) {
         return false;
     }
     return ['rabota_fiz_lica_id' => $rabotaFizLica->id, 'dolhnost' => $dolzhnost->nazvanie . ', ' . $organizaciya->nazvanie];
 }
Example #2
0
 private function registerImpl()
 {
     if (!$this->validate()) {
         return false;
     }
     $fiz_lico = new FizLico(['familiya' => $this->familiya, 'imya' => $this->imya, 'otchestvo' => $this->otchestvo, 'email' => $this->email, 'formattedTelefon' => $this->telefon]);
     $polzovatel = new Polzovatel(['login' => $this->login, 'parol' => $this->parol, 'aktiven' => true, 'roliAsArray' => $this->roli]);
     $polzovatel->generateKlyuchAutentifikacii();
     $polzovatel->generateKodPodtverzhdeniyaEmail();
     list($organizaciya, $organizaciya_to_delete) = DirectoryHelper::getFromCombo(Organizaciya::className(), $this->rabotaOrgId, $this->rabotaOrgNazvanie, ['vedomstvo' => $this->rabotaOrgVedomstvo, 'adres_adresnyj_objekt' => $this->rabotaOrgAdres]);
     $rabota_fiz_lica = new RabotaFizLica(['formattedTelefon' => $this->rabotaTelefon]);
     list($dolzhnost, $dolzhnost_to_delete) = DirectoryHelper::getFromCombo(Dolzhnost::className(), $this->rabotaDolzhnostId, $this->rabotaDolzhnostNazvanie, null);
     $dolzhnost_fiz_lica_na_rabote = new DolzhnostFizLicaNaRabote(['etapObrazovaniyaAsEnum' => $this->rabotaEtapObrazovaniya]);
     $message = Yii::$app->mailer->compose('kadry/registraciya.php', ['model' => $this, 'polzovatel' => $polzovatel])->setTo($fiz_lico->email);
     if (!$message->send()) {
         $this->addError('email', 'Не удалось отправить E-Mail.');
         return false;
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         $fiz_lico->save(false);
         $polzovatel->link('fizLicoRel', $fiz_lico);
         $polzovatel->save(false);
         if ($organizaciya) {
             $organizaciya->save(false);
         }
         $rabota_fiz_lica->fizLico = $fiz_lico->id;
         $rabota_fiz_lica->link('organizaciyaRel', $organizaciya);
         $rabota_fiz_lica->save(false);
         if ($dolzhnost) {
             $dolzhnost->save(false);
         }
         $dolzhnost_fiz_lica_na_rabote->dolzhnost = $dolzhnost->id;
         $dolzhnost_fiz_lica_na_rabote->link('rabotaFizLicaRel', $rabota_fiz_lica);
         $dolzhnost_fiz_lica_na_rabote->save(false);
         if ($organizaciya_to_delete) {
             $organizaciya_to_delete->delete();
         }
         if ($dolzhnost_to_delete) {
             $dolzhnost_to_delete->delete();
         }
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         throw $e;
     }
     return true;
 }