Example #1
0
         } else {
             if (empty($notificationDateTime) === false) {
                 $notificationDateTimeInt = new DateTime();
                 $notificationDateTimeInt->setTimestamp($notificationDateTime / 1000);
                 $reply->data = Notification::getNotificationByNotificationDateTime($pdo, $notificationDateTimeInt);
             } else {
                 if (empty($alertId) === false) {
                     $reply->data = Notification::getProductByAlertId($pdo, $alertId);
                 } else {
                     if ($page >= 0) {
                         $notifications = Notification::getAllNotifications($pdo, $page)->toArray();
                         foreach ($notifications as $index => $notification) {
                             $product = null;
                             $productAlert = ProductAlert::getProductAlertByAlertId($pdo, $notification->getAlertId());
                             if ($productAlert !== null) {
                                 $product = Product::getProductByProductId($pdo, $productAlert->getProductId());
                             }
                             $notifications[$index] = json_decode(json_encode($notification));
                             $notifications[$index]->product = $product;
                         }
                         $reply->data = $notifications;
                     } else {
                         throw new InvalidArgumentException("no parameters given", 405);
                     }
                 }
             }
         }
     }
     // post to a new Notification
 } else {
     if ($method === "POST") {
Example #2
0
                    $productAlerts = ProductAlert::getProductAlertByProductId($pdo, $productId);
                    foreach ($productAlerts as $productAlert) {
                        $productAlert->delete($pdo);
                    }
                    $finishedProducts = FinishedProduct::getFinishedProductByRawMaterialId($pdo, $productId);
                    foreach ($finishedProducts as $finishedProduct) {
                        $finishedProduct->delete($pdo);
                    }
                    $productLocations = ProductLocation::getProductLocationByProductId($pdo, $productId);
                    foreach ($productLocations as $productLocation) {
                        $productLocation->delete($pdo);
                    }
                    $movements = Movement::getMovementByProductId($pdo, $productId);
                    foreach ($movements as $movement) {
                        $movement->delete($pdo);
                    }
                    $product = Product::getProductByProductId($pdo, $productId);
                    $product->delete($pdo);
                    $reply->data = "Product deleted 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);
Example #3
0
 /**
  * test grabbing a Product that does not exist
  **/
 public function testGetInvalidProductByProductId()
 {
     // grab a Product id that exceeds the maximum allowable Product id
     $product = Product::getProductByProductId($this->getPDO(), InventoryTextTest::INVALID_KEY);
     $this->assertNull($product);
 }