Exemplo n.º 1
0
 /**
  * This method calculates 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 Prism\Validator\Date($table->get('funding_start'));
     if (!$fundingStartDate->isValid()) {
         $app = JFactory::getApplication();
         /** @var $app JApplicationSite */
         $fundingStart = new JDate('now', $app->get('offset'));
         $table->set('funding_start', $fundingStart->toSql());
         // If funding type is 'days', calculate end date.
         if ($table->get('funding_days')) {
             $fundingStartDate = new Crowdfunding\Date($table->get('funding_start'));
             $endDate = $fundingStartDate->calculateEndDate($table->get('funding_days'));
             $table->set('funding_end', $endDate->toSql());
         }
     }
     // Get parameters
     $params = JComponentHelper::getParams('com_crowdfunding');
     /** @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 Prism\Validator\Date($table->get('funding_end'));
     if ($fundingEndDate->isValid()) {
         $validatorPeriod = new Crowdfunding\Validator\Project\Period($table->get('funding_start'), $table->get('funding_end'), $minDays, $maxDays);
         if (!$validatorPeriod->isValid()) {
             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));
             }
         }
     }
 }
Exemplo n.º 2
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 = Joomla\Utilities\ArrayHelper::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 RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_DURING_PROJECT_CREATING_PROCESS"));
     }
 }
Exemplo n.º 3
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @param  CrowdfundingTableProject $table
  *
  * @throws Exception
  *
  * @since    1.6
  */
 protected function prepareTable($table)
 {
     $userId = (int) JFactory::getUser()->get('id');
     if (!$table->get('id')) {
         // Get maximum order number
         // Set ordering to the last item if not set
         if (!$table->get('ordering')) {
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             $query->select('MAX(ordering)')->from($db->quoteName('#__crowdf_projects'));
             $db->setQuery($query, 0, 1);
             $max = $db->loadResult();
             $table->set('ordering', $max + 1);
         }
         // Set state to unpublished.
         $table->set('published', Prism\Constants::UNPUBLISHED);
         // Set user ID
         $table->set('user_id', $userId);
     } else {
         if ($userId !== (int) $table->get('user_id')) {
             throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_INVALID_USER'));
         }
     }
     // If an alias does not exist, I will generate the new one using the title.
     if (!$table->get('alias')) {
         $table->set('alias', $table->get('title'));
     }
     $table->set('alias', JApplicationHelper::stringURLSafe($table->get('alias')));
 }
Exemplo n.º 4
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 Prism\Validator\Date($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 Crowdfunding\Date($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 Prism\Validator\Date($table->get("funding_end"));
     if ($fundingEndDate->isValid()) {
         $validatorPeriod = new Crowdfunding\Validator\Project\Period($table->get("funding_start"), $table->get("funding_end"), $minDays, $maxDays);
         if (!$validatorPeriod->isValid()) {
             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));
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * A protected method to get a set of ordering conditions.
  *
  * @param    CrowdfundingTableProject $table A record object.
  *
  * @return    array    An array of conditions to add to add to ordering queries.
  * @since    1.6
  */
 protected function getReorderConditions($table)
 {
     $condition = array();
     $condition[] = 'catid = ' . (int) $table->get('catid');
     return $condition;
 }
Exemplo n.º 6
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @param CrowdfundingTableProject $table
  * @param array $data
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  *
  * @since    1.6
  */
 protected function prepareTableData($table, $data)
 {
     $durationType = Joomla\Utilities\ArrayHelper::getValue($data, 'duration_type');
     $fundingEnd = Joomla\Utilities\ArrayHelper::getValue($data, 'funding_end');
     $fundingDays = Joomla\Utilities\ArrayHelper::getValue($data, 'funding_days', 0, 'int');
     switch ($durationType) {
         case 'days':
             $fundingDays = $fundingDays < 0 ? 0 : (int) $fundingDays;
             $table->set('funding_days', $fundingDays);
             // Calculate end date
             $startingDateValidator = new Prism\Validator\Date($table->get('funding_start'));
             if ($startingDateValidator->isValid()) {
                 $fundingStartDate = new Crowdfunding\Date($table->get('funding_start'));
                 $fundingEndDate = $fundingStartDate->calculateEndDate($table->get('funding_days'));
                 $table->set('funding_end', $fundingEndDate->format(Prism\Constants::DATE_FORMAT_SQL_DATE));
             } else {
                 $table->set('funding_end', Prism\Constants::DATE_DEFAULT_SQL_DATE);
             }
             break;
         case 'date':
             $fundingEnd = CrowdfundingHelper::convertToSql($fundingEnd);
             $dateValidator = new Prism\Validator\Date($fundingEnd);
             if (!$dateValidator->isValid()) {
                 throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_DATE'));
             }
             $date = new JDate($fundingEnd);
             $table->set('funding_days', 0);
             $table->set('funding_end', $date->toSql());
             break;
         default:
             $table->set('funding_days', 0);
             $table->set('funding_end', Prism\Constants::DATE_DEFAULT_SQL_DATE);
             break;
     }
 }
 /**
  * This method calculates 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 Prism\Validator\Date($table->get('funding_start'));
     if (!$fundingStartDate->isValid()) {
         $app = JFactory::getApplication();
         /** @var $app JApplicationSite */
         $fundingStart = new JDate('now', $app->get('offset'));
         $table->set('funding_start', $fundingStart->toSql());
         // If funding type is 'days', calculate end date.
         if ($table->get('funding_days')) {
             $fundingStartDate = new Crowdfunding\Date($table->get('funding_start'));
             $endDate = $fundingStartDate->calculateEndDate($table->get('funding_days'));
             $table->set('funding_end', $endDate->toSql());
         }
     }
 }