-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_ads.php
37 lines (28 loc) · 1.07 KB
/
handle_ads.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
use App\Database\Database;
use App\Models\Subscription;
use App\Models\User;
use App\Services\AdService;
use App\Services\MailService;
require_once(__DIR__ . '/vendor/autoload.php');
require_once(__DIR__ . '/App/Config/database.php');
require_once(__DIR__ . '/App/Config/mail.php');
/** @var $connection */
/** @var $mailParams */
$db = new Database($connection);
$user = new User($db);
$subscription = new Subscription($db, $user);
$subscriptions = $subscription->getAllWithUsers();
$adService = new AdService();
$mailService = new MailService($mailParams);
if(!is_null($subscriptions)) {
foreach ($subscriptions as $key => $subscription) {
$result = $adService->getSource($subscription['url'])->getPriceAndCurrencyCode();
if ($result['price'] != $subscription['price']) {
foreach (current($subscription['email']) as $email) {
$mailService($email, $result['price'], $subscription['price'], $result['currencyCode'], $subscription['url']);
echo 'Mail to: ' . $email . ' has sent' . PHP_EOL;
}
}
}
}