Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

57 lines
1.4KB

  1. <?php
  2. namespace frontend\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use common\models\UserEtablissement;
  6. /**
  7. * ContactForm is the model behind the contact form.
  8. */
  9. class AddEtablissementForm extends Model
  10. {
  11. public $id_etablissement;
  12. /**
  13. * @inheritdoc
  14. */
  15. public function rules()
  16. {
  17. return [
  18. ['id_etablissement', 'required', 'message' => 'Champs obligatoire'],
  19. ];
  20. }
  21. /**
  22. * @inheritdoc
  23. */
  24. public function attributeLabels()
  25. {
  26. return [
  27. 'id_etablissement' => 'Ajouter une boulangerie',
  28. ];
  29. }
  30. /**
  31. * Sends an email to the specified email address using the information collected by this model.
  32. *
  33. * @param string $email the target email address
  34. * @return boolean whether the email was sent
  35. */
  36. public function add()
  37. {
  38. $user_etablissement_exist = UserEtablissement::find()
  39. ->where(['id_user'=>Yii::$app->user->identity->id, 'id_etablissement' =>$this->id_etablissement])
  40. ->one() ;
  41. if(!$user_etablissement_exist)
  42. {
  43. $user_etablissement = new UserEtablissement() ;
  44. $user_etablissement->id_user = Yii::$app->user->identity->id ;
  45. $user_etablissement->id_etablissement = $this->id_etablissement ;
  46. $user_etablissement->save() ;
  47. }
  48. }
  49. }