data = $data; } /** * Build the message. * * @return $this */ public function build() { $this->joinFileIfProvided(); return $this ->subject(sprintf('Nouveau message consommateur Le Gaulois (%s)', $this->data->type->label)) ->view('emails.contact') ->text('emails.contact-plain') ->with('data', $this->data) ->attachData( $this->makeCsvFile(), sprintf('contact_le_gaulois_%d.csv', time()), ['mime' => 'text/csv'] ); } /** * Attach a joined file if given in data * * @return void */ protected function joinFileIfProvided(): void { if ($this->data->joinFile) { $this->joinedFileName = sprintf( 'LEGAULOIS_PASS_MESSAGE-PJ-%s.%s', date("YmdHis"), $this->data->joinFile->extension() ); $this->attach($this->data->joinFile, [ 'as' => $this->joinedFileName, 'mime' => $this->data->joinFile->getMimeType() ]); $this->data->joinFile = $this->joinedFileName; } } /** * @return string */ protected function makeCsvFile(): string { //we create the CSV into memory // FILENAME $csv = Writer::createFromFileObject(new SplTempFileObject()); $csv->setDelimiter(';'); $csv->setEnclosure('"'); $csv->setOutputBOM(Writer::BOM_UTF8); //we insert the CSV header $csv->insertOne([ 'EMETTEUR_DATE', 'EMETTEUR_HEURE', 'EMETTEUR_CIVILITE', 'EMETTEUR_NOM', 'EMETTEUR_PRENOM', 'EMETTEUR_ADRESSE', 'EMETTEUR_CP', 'EMETTEUR_VILLE', 'EMETTEUR_EMAIL', 'EMETTEUR_OBJETDEMANDE', 'EMETTEUR_MESSAGE', 'EMETTEUR_CATEGORIE', 'EMETTEUR_ACTIVITE', 'REPONSE_ETAT', 'TYPE_REPONSE' ]); $csv->insertOne($this->data->exportToArcadiaDataArray()); return $csv->getContent(); } }