Esempio n. 1
0
});
$app->post('/offer', function () use($app) {
    /**
     * @var $config array
     */
    global $config;
    $body = json_decode($app->request->getBody());
    $offer = new Offer();
    $offer->setUser($body->user);
    $offer->setRestaurant($body->restaurant);
    $offer->setOrderUntil($body->order_until);
    $offer->save();
    // Load user
    $user = User::getById($body->user);
    // Load restaurant
    $restaurant = Restaurant::getById($body->restaurant);
    // Send Mail
    $mailSubscriptions = MailSubscription::getAll();
    $receivers = array();
    foreach ($mailSubscriptions as $mailSubscription) {
        $receivers[] = User::getById($mailSubscription->getUser());
    }
    $mail = new Message();
    $mail->setFrom('Mittagessen Plattform <*****@*****.**>')->setSubject($user->getName() . ' holt Essen bei ' . $restaurant->getName())->setBody("Wenn du auch was willst, schaue auf " . $config['platform_url'] . "/app/#/offers/" . $offer->getId());
    foreach ($receivers as $receiver) {
        $mail->addTo($receiver->getEmail());
    }
    switch ($config['mail_method']) {
        case "sendmail":
            $mailer = new SendmailMailer();
            break;
<?php

$db = new PDO('mysql:dbname=mittagesser;host=localhost', 'test', 'testpw');
use Bahuma\GHMittagessen\Offer;
use Bahuma\GHMittagessen\Participation;
use Bahuma\GHMittagessen\Restaurant;
use Carbon\Carbon;
require_once '../vendor/autoload.php';
// Restaurants
$restaurant1 = new Restaurant();
$restaurant1->setName("Bella Italia");
$restaurant1->setSpeisekartenUrl("http://test.de");
$restaurant1->save();
print "Created Restaurant 1 with id " . $restaurant1->getId();
$restaurant2 = new Restaurant();
$restaurant2->setName("Burgerladen");
$restaurant2->setSpeisekartenUrl("http://test2.de");
$restaurant2->save();
print "Created Restaurant 2 with id " . $restaurant2->getId();
// Offers
$offer1 = new Offer();
$offer1->setRestaurant($restaurant1->getId());
$offer1->setUser(1);
$offer1->setOrderUntil(new Carbon());
$offer1->save();
print "Created Offer 1 at Restaurant 1 with id " . $offer1->getId();
$offer2 = new Offer();
$offer2->setRestaurant($restaurant2->getId());
$offer2->setUser(1);
$offer2->setOrderUntil(new Carbon());
$offer2->save();