255], [['comment'], 'string', 'max' => 2048], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id_user' => 'Utilisateur', 'id_user_action' => 'Utilisateur', 'date' => 'Date', 'amount' => 'Montant', 'type' => 'Type', 'id_producer' => 'Producteur', 'mean_payment' => 'Moyen de paiement', 'comment' => 'Commentaire', 'send_mail' => 'Prévenir l\'utilisateur', ]; } /** * Enregistre un modèle CreditHistorique. */ public function save() { if ($this->validate()) { $creditHistory = new CreditHistory; $creditHistory->id_user = $this->id_user; $creditHistory->id_user_action = Yii::$app->user->identity->id; $creditHistory->id_producer = GlobalParam::getCurrentProducerId() ; $creditHistory->type = $this->type ; $creditHistory->comment = $this->comment ; $creditHistory->amount = $this->amount ; $creditHistory->mean_payment = $this->mean_payment ; $creditHistory->save(); // on prévient l'utilisateur que son compte vient d'être crédité if($this->send_mail) { $user = User::findOne($this->id_user) ; $producer = GlobalParam::getCurrentProducer() ; $userProducer = UserProducer::searchOne([ 'id_user' => $this->id_user ]); $paramsEmail = [ 'from_email' => $producer->getEmailOpendistrib(), 'from_name' => $producer->name, 'to_email' => $user->email, 'to_name' => $user->getUsername(), 'subject' => '['.$producer->name.'] Mouvement de crédit', 'content_view_text' => '@common/mail/creditUser-text.php', 'content_view_html' => '@common/mail/creditUser-html.php', 'content_params' => [ 'user' => $user, 'producer' => $producer, 'userProducer' => $userProducer, 'creditForm' => $this ] ] ; Mailjet::sendMail($paramsEmail); } } } }