Example #1
0
 /**
  * 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;
 }