Example #1
0
 /**
  * This method calculate start date and validate funding period.
  *
  * @param CrowdFundingTableProject $table
  *
  * @throws Exception
  */
 protected function prepareTable(&$table)
 {
     // Calculate start and end date if the user publish a project for first time.
     $fundingStartDate = new ITPrismValidatorDate($table->funding_start);
     if (!$fundingStartDate->isValid($table->funding_start)) {
         $fundingStart = new JDate();
         $table->funding_start = $fundingStart->toSql();
         // If funding type is "days", calculate end date.
         if ($table->get("funding_days")) {
             $fundingStartDate = new CrowdFundingDate($table->get("funding_start"));
             $endDate = $fundingStartDate->calculateEndDate($table->get("funding_days"));
             $table->set("funding_end", $endDate->format("Y-m-d"));
         }
     }
     // Get parameters
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $params = $app->getParams();
     /** @var  $params Joomla\Registry\Registry */
     $minDays = $params->get("project_days_minimum", 15);
     $maxDays = $params->get("project_days_maximum");
     // If there is an ending date, validate the period.
     $fundingEndDate = new ITPrismValidatorDate($table->get("funding_end"));
     if ($fundingEndDate->isValid()) {
         $fundingStartDate = new CrowdFundingDate($table->get("funding_start"));
         if (!$fundingStartDate->isValidPeriod($table->get("funding_end"), $minDays, $maxDays)) {
             if (!empty($maxDays)) {
                 throw new RuntimeException(JText::sprintf("COM_CROWDFUNDING_ERROR_INVALID_ENDING_DATE_MIN_MAX_DAYS", $minDays, $maxDays));
             } else {
                 throw new RuntimeException(JText::sprintf("COM_CROWDFUNDING_ERROR_INVALID_ENDING_DATE_MIN_DAYS", $minDays));
             }
         }
     }
 }