示例#1
0
 /**
  * This method executes the event onContentAfterSave.
  *
  * @param CrowdFundingTableProject $table
  * @param string $step
  * @param bool $isNew
  *
  * @throws Exception
  */
 protected function triggerEventAfterSave($table, $step, $isNew = false)
 {
     // Get properties
     $project = $table->getProperties();
     $project = JArrayHelper::toObject($project);
     // Generate context
     $context = $this->option . '.' . $step;
     // Include the content plugins for the change of state event.
     $dispatcher = JEventDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     // Trigger the onContentAfterSave event.
     $results = $dispatcher->trigger("onContentAfterSave", array($context, &$project, $isNew));
     if (in_array(false, $results, true)) {
         throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_DURING_PROJECT_CREATING_PROCESS"));
     }
 }
示例#2
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));
             }
         }
     }
 }