Example #1
0
 // sanitize getUnitOfMeasures
 $getUnitOfMeasures = filter_input(INPUT_GET, "getUnitOfMeasures", FILTER_VALIDATE_BOOLEAN);
 // sanitize getFinishedProducts
 $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 location by product
  **/
 public function testGetValidLocationByProductId()
 {
     // 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());
     $quantity = 5.9;
     // create a new product and insert to into mySQL
     $productLocation = new ProductLocation($this->location->getLocationId(), $product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity);
     $productLocation->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoLocationArray = Product::getLocationByProductId($this->getPDO(), $product->getProductId());
     for ($i = 0; $i < count($pdoLocationArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoLocationArray[$i]->getVendorId(), $this->vendor->getVendorId());
             $this->assertSame($pdoLocationArray[$i]->getDescription(), $this->VALID_description);
             $this->assertSame($pdoLocationArray[$i]->getLeadTime(), $this->VALID_leadTime);
             $this->assertSame($pdoLocationArray[$i]->getSku(), $this->VALID_sku);
             $this->assertSame($pdoLocationArray[$i]->getTitle(), $this->VALID_title);
         } else {
             $this->assertSame($pdoLocationArray[$i]->getLocationId(), $this->location->getLocationId());
             $this->assertSame($pdoLocationArray[$i]->getStorageCode(), $this->location->getStorageCode());
             $this->assertSame($pdoLocationArray[$i]->getDescription(), $this->location->getDescription());
         }
     }
 }