/** * Create a new object, initializing the table name and whitelisted columns. * */ public function __construct($properties = []) { $table_schema = Database::getSchemaTable(static::$_table_id); $this->table = $table_schema->name; $this->fillable = $table_schema->columns; if (!static::$app) { static::$app = UserFrosting::getInstance(); } parent::__construct($properties); }
public static function sendNewBookingMail($booking, $userId) { $user = User::where('id', $userId)->first(); $date = strftime('%A %e %B %Y, %H.%M (%Z)', $booking->startUts); $twig = UserFrosting::getInstance()->view()->getEnvironment(); $template = $twig->loadTemplate("mail/sendNewBookingMail.twig"); $subject = 'Ny taxibokning'; if ($booking->originCity && $booking->destinationCity) { $subject = 'Ny taxibokning från ' . $booking->originCity . ' till ' . $booking->destinationCity; if ($booking->originCity == $booking->destinationCity) { $subject = 'Ny taxibokning inom ' . $booking->originCity; } } $notification = new Notification($template); $notification->from("*****@*****.**", $user->title, $user->email, $user->title); // future bookings $bookings = Booking::where('user_id', $userId)->where('id', '!=', $booking->id)->where('startUts', '>', time() - 21600)->get(); $htmlRows = array(); $statuses = array('new' => 'Ohanterat', 'accepted' => 'Accepterad', 'rejected' => 'Avvisad'); foreach ($bookings as $key => $futureBooking) { $backgroundColor = $key % 2 == 0 ? '#e9e9e9' : '#ffffff'; $style = "background-color: {$backgroundColor}; font-size: 12px; padding: 10px"; $buttonHtml = ''; if ($futureBooking->status == 'new') { $buttonHtml = '<a href="' . UserFrosting::getInstance()->site->uri['public'] . '/booking/' . $futureBooking->id . '/accept/' . $futureBooking->hash . '" style="background-color: #8ea604; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Acceptera</a><a href="' . UserFrosting::getInstance()->site->uri['public'] . '/booking/' . $futureBooking->id . '/reject/' . $futureBooking->hash . '" style="background-color: #c00000; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Avslå</a>'; //$buttonHtml = '<a href="http://taxibooking.allanth.dk/?action=accept&bookingId=' . $futureBooking->id . '&hash=' . $futureBooking->hash . '&c=' . $client->name . '" style="background-color: #8ea604; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Acceptera</a><a href="http://taxibooking.allanth.dk/?action=reject&bookingId=' . $futureBooking->id . '&hash=' . $futureBooking->hash . '&c=' . $client->name . '" style="background-color: #C00000; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Avslå</a>'; } $htmlRows[] = "\n <tr valign=\"top\">\n <td style=\"{$style}\" colspan=\"2\">Från <strong>" . htmlspecialchars($futureBooking->origin) . "</strong> till <strong>" . htmlspecialchars($futureBooking->destination) . "</strong></td>\n </tr>\n <tr valign=\"top\">\n <td style=\"{$style}\" width=\"60%\">\n Avresedatum: " . htmlspecialchars(strftime('%A %e %B %Y, %H.%M (%Z)', $futureBooking->startUts)) . "<br />\n Namn: " . htmlspecialchars($futureBooking->name) . "<br />\n Email: " . htmlspecialchars($futureBooking->email) . "<br />\n Telefon: " . htmlspecialchars($futureBooking->phone) . "<br /><br />\n Avstånd: " . htmlspecialchars($futureBooking->distance) . "<br />\n Körtid: " . htmlspecialchars($futureBooking->duration) . "<br />\n Pris: " . htmlspecialchars($futureBooking->price) . ":- kr.\n </td>\n <td style=\"{$style}\" width=\"40%\"><span style=\"font-size: 20px\">Tur: " . htmlspecialchars($futureBooking->alphaId) . "</span>\n <br />Status: " . htmlspecialchars($statuses[$futureBooking->status]) . "<br /><br />{$buttonHtml}</td> \n </tr>"; } $futureBookingsHtml = ''; if (count($htmlRows)) { $futureBookingsHtml = "\n <p><strong>Kommende bookings</strong></p>\n <table cellspacing=\"0\">" . implode("", $htmlRows) . " \n </table>\n "; } $notification->addEmailRecipient($user->email, $user->title, ['date' => $date, 'booking' => $booking, 'client' => $user, 'headerLine1' => $user->title, 'headerLine2' => $subject, 'footerLine' => "Skickat " . strftime('%A %e %B %Y, %H.%M (%Z)'), 'subject' => $subject, 'futureBookingsHtml' => $futureBookingsHtml]); $success = NULL; try { $success = $notification->send(); } catch (\phpmailerException $e) { print $e->errorMessage(); $app->halt(500); } return $success; }