1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\File;
- use App\Http\Services\EmailService;
- use App\Models\AccountInvite;
- use App\Models\AppSession;
- use App\Models\Invoice;
- use App\Models\FinancialTransaction;
- use App\Models\CompanyClient;
- use App\Models\Appointment;
- use Illuminate\Support\Facades\Cookie;
- class EmailController extends Controller
- {
- protected $performer;
- protected $sessionKey;
- public $appUrl;
- protected $emailService;
- public $appInternalName;
- public $stringMappingConfig;
- protected $emailFromName;
- public function __construct(EmailService $emailService)
- {
- $this->sessionKey = Cookie::get('sessionKey');
- $this->performer = AppSession::where('session_key', $this->sessionKey)->first();
- $this->emailFromName = config('app.emailFromName');
- $this->appUrl = config('app.url');
- $this->emailService = $emailService;
- $this->appInternalName = config('app.internalName');
- $this->stringMappingConfig = config('constants.' . $this->appInternalName);
- }
- public function previewEmail($email = null)
- {
- $pro = @$this->performer->pro;
- if (!$pro) {
- abort(404);
- }
- $appInternalName = $this->appInternalName;
- $stringMappingConfig = $this->stringMappingConfig;
- if ($email) {
- $destinationPath = resource_path('views/emails/templates/' . $email . '.blade.php');
- if (File::exists($destinationPath)) {
- $content = File::get($destinationPath);
- $appUrl = $this->appUrl;
- $emailFromName = $this->emailFromName;
- $toEmailAddress = $this->pro ? $this->pro->email_address : 'john@doe.com';
- $toName = $this->pro ? $this->pro->displayName() : 'John Doe';
- $message = 'Client information has been updated';
- $appointment = Appointment::first();
- $accountInvite = AccountInvite::first();
- return view('emails/templates/' . $email, compact(
- 'appUrl',
- 'toEmailAddress',
- 'toName',
- 'message',
- 'stringMappingConfig',
- 'appInternalName',
- 'emailFromName',
- 'appointment',
- 'accountInvite'
- ));
- } else {
- abort(404);
- }
- }
- $files = File::allFiles(resource_path('views/emails/templates/'));
- $fileNames = [];
- foreach ($files as $file) {
- $fileName = $file->getFilename();
- $fileNameParts = explode('.', $fileName);
- $fileRef = @$fileNameParts[0];
- if ($fileRef) array_push($fileNames, $fileRef);
- }
- return view('emails.preview-email', compact('fileNames'));
- }
- }
|