/** * Create an issue of a product. * @param Product $product - the product which the issue points to * @param String $productVersion - the version of the product where the issue found * @param String $issueCategorySlug - the unique slug of the category of the issue * @param User $hunter - the user who found the issue * @param String $issueTitle - the title of the issue * @param String $issueDescription - the description of the issue * @param boolean $isTokenValid - whether the CSRF token is correct * @return an array with data validation result */ public function createIssue($product, $productVersion, $issueCategorySlug, $hunter, $issueTitle, $issueDescription, $isTokenValid) { $issueCategory = $this->getIssueCategoryObjectUsingSlug($issueCategorySlug); $result = array('isSuccessful' => false, 'isProductExists' => $product != NULL, 'isProductVersionEmpty' => empty($productVersion), 'isProductVersionLegal' => $this->isProductVersionLegal($productVersion), 'isIssueCategoryEmpty' => $issueCategory == NULL, 'isUserLoggedIn' => $hunter != NULL, 'isIssueTitleEmpty' => empty($issueTitle), 'isIssueTitleLegal' => $this->isIssueTitleLegal($issueTitle), 'isDescriptionEmpty' => empty($issueDescription), 'isTokenValid' => $isTokenValid); $result['isSuccessful'] = $result['isProductExists'] && !$result['isProductVersionEmpty'] && $result['isProductVersionLegal'] && !$result['isIssueCategoryEmpty'] && $result['isUserLoggedIn'] && !$result['isIssueTitleEmpty'] && $result['isIssueTitleLegal'] && !$result['isDescriptionEmpty'] && $result['isTokenValid']; if ($result['isSuccessful']) { $issueStatus = IssueStatus::findFirst("issue_status_slug = 'unconfirmed'"); $issue = new Issue(); $issue->setProduct($product); $issue->setProductVersion($productVersion); $issue->setIssueCategory($issueCategory); $issue->setIssueStatus($issueStatus); $issue->setHunter($hunter); $issue->setIssueTitle($issueTitle); $issue->setIssueDescription($issueDescription); if (!$issue->create()) { $result['isSuccessful'] = false; } else { $result['issueId'] = $issue->getIssueId(); } } return $result; }