Example #1
0
 $getFinishedProducts = filter_input(INPUT_GET, "getFinishedProducts", FILTER_VALIDATE_BOOLEAN);
 // sanitize the page
 $page = filter_input(INPUT_GET, "page", FILTER_VALIDATE_INT);
 // grab the mySQL connection
 $pdo = connectToEncryptedMySql("/etc/apache2/capstone-mysql/invtext.ini");
 // handle all RESTful calls to Product
 // get some or all Products
 if ($method === "GET") {
     // set an XSRF cookie on GET requests
     setXsrfCookie("/");
     if (empty($productId) === false) {
         if ($getLocations === true) {
             $reply->data = Product::getLocationByProductId($pdo, $productId);
         } else {
             if ($getNotifications) {
                 $reply->data = Product::getNotificationByProductId($pdo, $productId);
             } else {
                 if ($getUnitOfMeasures) {
                     $reply->data = Product::getUnitOfMeasureByProductId($pdo, $productId);
                 } else {
                     if ($getFinishedProducts) {
                         $reply->data = Product::getFinishedProductByProductId($pdo, $productId);
                     } else {
                         $product = Product::getProductByProductId($pdo, $productId);
                         $quantityOnHand = $product->getQuantityOnHand($pdo);
                         $flatObject = json_decode(json_encode($product));
                         $flatObject->quantityOnHand = $quantityOnHand;
                         $reply->data = $flatObject;
                     }
                 }
             }
Example #2
0
 /**
  * test grabbing product by notification
  **/
 public function testGetValidNotificationByProductId()
 {
     // create a new product and insert to into mySQL
     $product = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $product->insert($this->getPDO());
     // create a new product and insert to into mySQL
     $productAlert = new ProductAlert($this->alertLevel->getAlertId(), $product->getProductId(), true);
     $productAlert->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoNotificationArray = Product::getNotificationByProductId($this->getPDO(), $product->getProductId());
     for ($i = 0; $i < count($pdoNotificationArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoNotificationArray[$i]->getVendorId(), $this->vendor->getVendorId());
             $this->assertSame($pdoNotificationArray[$i]->getDescription(), $this->VALID_description);
             $this->assertSame($pdoNotificationArray[$i]->getLeadTime(), $this->VALID_leadTime);
             $this->assertSame($pdoNotificationArray[$i]->getSku(), $this->VALID_sku);
             $this->assertSame($pdoNotificationArray[$i]->getTitle(), $this->VALID_title);
         } else {
             $this->assertSame($pdoNotificationArray[$i]->getNotificationId(), $this->notification->getNotificationId());
             $this->assertSame($pdoNotificationArray[$i]->getAlertId(), $this->notification->getAlertId());
             $this->assertSame($pdoNotificationArray[$i]->getEmailStatus(), $this->notification->getEmailStatus());
             $this->assertEquals($pdoNotificationArray[$i]->getNotificationDateTime(), $this->notification->getNotificationDateTime());
             $this->assertSame($pdoNotificationArray[$i]->getNotificationHandle(), $this->notification->getNotificationHandle());
             $this->assertSame($pdoNotificationArray[$i]->getNotificationContent(), $this->notification->getNotificationContent());
         }
     }
 }