public static function map(Product $product, array $properties) { if (array_key_exists('product_id', $properties)) { $product->setProductId($properties['product_id']); } if (array_key_exists('product_name', $properties)) { $product->setProductName($properties['product_name']); } if (array_key_exists('price', $properties)) { $product->setPrice($properties['price']); } }
/** * The handler of creating product. * @param String $productName - the name of product in JSON format * @param String $productCategorySlug - the unique slug of the product category * @param User $developer - the user object of the developer of the product * @param String $productLogoUrl - the URL of the logo of the product * @param String $latestVersion - the latest version of the product * @param String $productUrl - the homepage of the product * @param String $prerequisites - the prerequisites of testing in JSON format * @param String $description - the description of the product in JSON format * @param boolean $isTokenValid - whether the CSRF token is valid * @return an array infers whether the creation is successful */ public function createProduct($productName, $productCategorySlug, $developer, $productLogoUrl, $latestVersion, $productUrl, $prerequisites, $description, $isTokenValid) { $productCategory = $this->getProductCategoryUsingSlug($productCategorySlug); $result = array('isSuccessful' => false, 'isProductNameEmpty' => $this->isProductNameEmpty($productName), 'isProductNameLegal' => $this->isProductNameLegal($productName), 'isProductCategoryLegal' => $productCategory != NULL, 'isDeveloperLegal' => $developer != NULL, 'isProductLogoEmpty' => empty($productLogoUrl), 'isProductLogoLegal' => $this->isProductLogoLegal($productLogoUrl), 'isLatestVersionEmpty' => empty($latestVersion), 'isLatestVersionLegal' => $this->isLatestVersionLegal($latestVersion), 'isProductUrlEmpty' => empty($productUrl), 'isProductUrlLegal' => $this->isProductUrlLegal($productUrl), 'isPrerequisitesEmpty' => $this->isPrerequisitesEmpty($prerequisites), 'isPrerequisitesLegal' => $this->isPrerequisitesLegal($prerequisites), 'isDescriptionEmpty' => $this->isDescriptionEmpty($description), 'isDescriptionLegal' => $this->isDescriptionLegal($description), 'isTokenValid' => $isTokenValid); $result['isSuccessful'] = !$result['isProductNameEmpty'] && $result['isProductNameLegal'] && $result['isProductCategoryLegal'] && $result['isDeveloperLegal'] && !$result['isProductLogoEmpty'] && $result['isProductLogoLegal'] && !$result['isLatestVersionEmpty'] && $result['isLatestVersionLegal'] && !$result['isProductUrlEmpty'] && $result['isProductUrlLegal'] && !$result['isPrerequisitesEmpty'] && $result['isPrerequisitesLegal'] && !$result['isDescriptionEmpty'] && $result['isDescriptionLegal'] && $result['isTokenValid']; if ($result['isSuccessful']) { $product = new Product(); $product->setProductName($productName); $product->setProductCategory($productCategory); $product->setDeveloper($developer); $product->setProductLogo($productLogoUrl); $product->setLatestVersion($latestVersion); $product->setProductUrl($productUrl); $product->setPrerequisites($prerequisites); $product->setDescription($description); if (!$product->create()) { $result['isSuccessful'] = false; } } return $result; }
<?php require_once "/etc/apache2/capstone-mysql/encrypted-config.php"; require_once "product.php"; $pdo = connectToEncryptedMySQL("/etc/apache2/data-design/jfindley2.ini"); $product = new Product(null, "imagefile", 10, "Info", "Detail", "Tech", "Name"); $product->insert($pdo); $product->setProductName("This is the new name"); $product->update($pdo); $product->delete($pdo);
/** * Populate product object * * @param array $product * @return object */ protected function getProductObject($product) { if (empty($product)) { throw new BuyatException('Malformed response from server'); } $productObject = new Product(); $productObject->setProductID($product['product_id']); $productObject->setProductSKU($product['product_sku']); $productObject->setProductURL($product['product_url']); $productObject->setProductName($product['product_name']); $productObject->setBrandName($product['brand_name']); $productObject->setDescription($product['description']); $productObject->setOnlinePrice($product['online_price']); $productObject->setCurrency($product['currency']); $productObject->setCurrencySymbol($product['currency_symbol']); $productObject->setImageURL($product['image_url']); $productObject->setProgrammeName($product['programme_name']); $productObject->setProgrammeURL($product['programme_url']); $productObject->setProgrammeID($product['programme_id']); $productObject->setLevel1CategoryID($product['level1_category_id']); $productObject->setLevel1CategoryName($product['level1_category_name']); $productObject->setLevel2CategoryID($product['level2_category_id']); $productObject->setLevel2CategoryName($product['level2_category_name']); $productObject->setFeedID($product['feed_id']); $productObject->setFeedName($product['feed_name']); return $productObject; }