Esempio n. 1
0
 public static function notify($type, User $fromUser, User $toUser, Topic $topic, Reply $reply = null)
 {
     if ($fromUser->id == $toUser->id) {
         return;
     }
     if (Notification::isNotified($fromUser->id, $toUser->id, $topic->id, $type)) {
         return;
     }
     $nowTimestamp = Carbon::now()->toDateTimeString();
     $data[] = ['from_user_id' => $fromUser->id, 'user_id' => $toUser->id, 'topic_id' => $topic->id, 'reply_id' => $reply ? $reply->id : 0, 'body' => $reply ? $reply->body : '', 'type' => $type, 'created_at' => $nowTimestamp, 'updated_at' => $nowTimestamp];
     $toUser->increment('notification_count', 1);
     Notification::insert($data);
 }
Esempio n. 2
0
 public static function NewTopicNotify($type, User $fromUser, $users, Topic $topic)
 {
     $nowTimestamp = Carbon::now()->toDateTimeString();
     $data = [];
     foreach ($users as $toUser) {
         if ($fromUser->id == $toUser->id) {
             continue;
         }
         $data[] = ['from_user_id' => $fromUser->id, 'user_id' => $toUser->id, 'topic_id' => $topic->id, 'reply_id' => 0, 'body' => $topic->body, 'type' => $type, 'created_at' => $nowTimestamp, 'updated_at' => $nowTimestamp];
         $toUser->increment('notification_count', 1);
     }
     if (count($data)) {
         Notification::insert($data);
     }
     foreach ($data as $value) {
         self::pushNotification($value);
     }
 }
 /**
  * Set up for Vendor as well as guzzle/cookies
  **/
 public final function setUp()
 {
     parent::setUp();
     $vendorId = null;
     $contactName = "Trevor Rigler";
     $vendorEmail = "*****@*****.**";
     $vendorName = "TruFork";
     $vendorPhoneNumber = "5053594687";
     $this->vendor = new Vendor($vendorId, $contactName, $vendorEmail, $vendorName, $vendorPhoneNumber);
     $this->vendor->insert($this->getPDO());
     $locationId = null;
     $description = "Front Stock";
     $storageCode = 12;
     $this->location = new Location($locationId, $storageCode, $description);
     $this->location->insert($this->getPDO());
     $unitId = null;
     $unitCode = "pk";
     $quantity = 10.5;
     $this->unitOfMeasure = new UnitOfMeasure($unitId, $unitCode, $quantity);
     $this->unitOfMeasure->insert($this->getPDO());
     $alertCode = "78";
     $alertFrequency = "56";
     $alertPoint = 1.4;
     $alertOperator = "A";
     $this->alertLevel = new AlertLevel(null, $alertCode, $alertFrequency, $alertPoint, $alertOperator);
     $this->alertLevel->insert($this->getPDO());
     $notificationId = null;
     $alertId = $this->alertLevel->getAlertId();
     $emailStatus = false;
     $notificationDateTime = null;
     $notificationHandle = "unit test";
     $notificationContent = "place holder";
     $notificationDateTime = DateTime::createFromFormat("Y-m-d H:i:s", "1985-06-28 04:26:03");
     $this->notification = new Notification($notificationId, $alertId, $emailStatus, $notificationDateTime, $notificationHandle, $notificationContent);
     $this->notification->insert($this->getPDO());
     // create and insert a GuzzleHttp
     $this->guzzle = new \GuzzleHttp\Client(['cookies' => true]);
 }
    public static function register()
    {
        global $https, $store_home;
        $trigger = new Notification();
        Database::register_trigger($trigger);
        $dir = dirname($_SERVER['PHP_SELF']);
        if ($dir != '/') {
            $dir .= '/';
        }
        $protocol = $https ? 'https' : 'http';
        $url = "{$protocol}://{$_SERVER['HTTP_HOST']}{$dir}";
        Notification::$insert = <<<end
Your affiliate account has been credited with a new order.  The details are as
follows:
end;
        Notification::$update = <<<end
An order in your affiliate account has been changed.  The details are as
follows:
end;
        Notification::$signoff = <<<end
You are receiving this message because you signed up to be an affiliate of
{$store_home} .

If you no longer wish to receive these emails, you can turn them off by
visiting {$url} and clicking ‘Your Account’.
This will take you to a page where you can set your email preferences.

If you have any questions, please feel free to contact us at any time.
However, this email was sent from an address which is not monitored, so a reply
will not reach us.

Thank you for being a member of our affiliate programme.
end;
    }
 /**
  * test grabbing all Notifications
  **/
 public function testGetValidAllNotifications()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("notification");
     // create a new notification and insert to into mySQL
     $notification = new Notification(null, $this->alertLevel->getAlertId(), $this->VALID_emailStatus, $this->VALID_notificationDateTime, $this->VALID_notificationHandle, $this->VALID_notificationContent);
     $notification->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoNotification = Notification::getAllNotifications($this->getPDO(), $this->VALID_notificationId);
     foreach ($pdoNotification as $note) {
         $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("notification"));
         $this->assertSame($note->getAlertId(), $this->alertLevel->getAlertId());
         $this->assertSame($note->getEmailStatus(), $this->VALID_emailStatus);
         $this->assertEquals($note->getNotificationDateTime(), $this->VALID_notificationDateTime);
         $this->assertSame($note->getNotificationHandle(), $this->VALID_notificationHandle2);
         $this->assertSame($note->getNotificationContent(), $this->VALID_notificationContent);
     }
 }
 /**
  * test grabbing valid product by alertId
  **/
 public function testGetValidProductByAlertId()
 {
     // create a new notification and insert to into mySQL
     $newNotification = new Notification(null, $this->alertLevel->getAlertId(), $this->VALID_emailStatus, $this->VALID_notificationDateTime, $this->VALID_notificationHandle, $this->VALID_notificationContent);
     $newNotification->insert($this->getPDO());
     // grab the data from guzzle
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/notification/?alertId=' . $newNotification->getAlertId());
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $notification = json_decode($body);
     $this->assertSame(200, $notification->status);
 }
Esempio n. 7
0
                            }
                            $reply->data = $notifications;
                        } else {
                            throw new InvalidArgumentException("no parameters given", 405);
                        }
                    }
                }
            }
        }
        // post to a new Notification
    } else {
        if ($method === "POST") {
            // convert POSTed JSON to an object
            verifyXsrf();
            $requestContent = file_get_contents("php://input");
            $requestObject = json_decode($requestContent);
            $notificationDateTime = new DateTime();
            $notificationDateTime->setTimestamp($requestObject->notificationDateTime / 1000);
            $notification = new Notification(null, $requestObject->alertId, $requestObject->emailStatus, $requestObject->notificationDateTime, $requestObject->notificationHandle, $requestObject->notificationContent);
            $notification->insert($pdo);
            $reply->data = "Notification created OK";
        }
    }
    // create an exception to pass back to the RESTful caller
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
    unset($reply->data);
}
header("Content-type: application/json");
echo json_encode($reply);