|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
-
- namespace frontend\models;
-
- use Yii;
- use yii\base\Model;
- use common\models\UserEtablissement;
-
- /**
- * ContactForm is the model behind the contact form.
- */
- class AddEtablissementForm extends Model
- {
- public $id_etablissement;
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- ['id_etablissement', 'required', 'message' => 'Champs obligatoire'],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id_etablissement' => 'Ajouter une boulangerie',
- ];
- }
-
- /**
- * Sends an email to the specified email address using the information collected by this model.
- *
- * @param string $email the target email address
- * @return boolean whether the email was sent
- */
- public function add()
- {
- $user_etablissement_exist = UserEtablissement::find()
- ->where(['id_user'=>Yii::$app->user->identity->id, 'id_etablissement' =>$this->id_etablissement])
- ->one() ;
-
- if(!$user_etablissement_exist)
- {
- $user_etablissement = new UserEtablissement() ;
- $user_etablissement->id_user = Yii::$app->user->identity->id ;
- $user_etablissement->id_etablissement = $this->id_etablissement ;
- $user_etablissement->save() ;
- }
- }
- }
|