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() { $userManager = UserManager::getInstance(); $creditHistoryManager = CreditHistoryManager::getInstance(); $producerManager = ProducerManager::getInstance(); if ($this->validate()) { $user = $userManager->findOneUserById($this->id_user); $creditHistoryManager->createCreditHistory( $this->type, $this->amount, GlobalParam::getCurrentProducer(), $user, Yii::$app->user->identity, $this->mean_payment ); // 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' => $producerManager->getEmailOpendistrib($producer), 'from_name' => $producer->name, 'to_email' => $user->email, 'to_name' => $userManager->getUsername($user), '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); } } } }