Exemplo n.º 1
0
 /**
  * Method to load a row from the database by primary key and bind the fields
  * to the JTable instance properties.
  *
  * @param   mixed   $keys  An optional primary key value to load the row by, or an array of fields to match.  If not
  *                         set the instance property value is used.
  * @param   boolean $reset True to reset the default values before loading the new row.
  *
  * @return  boolean  True if successful. False if row not found or on error (internal error state set in that case).
  *
  * @link    http://docs.joomla.org/JTable/load
  * @since   11.1
  */
 public function load($keys = null, $reset = true)
 {
     parent::load($keys, $reset);
     $this->slug = $this->id . "." . $this->alias;
     // Calculate funded percent
     if (!$this->goal) {
         $this->fundedPercent = 0;
     } else {
         $percentage = new ITPrismMath();
         $percentage->calculatePercentage($this->funded, $this->goal, 0);
         $this->fundedPercent = (string) $percentage;
     }
     // Calculate end date
     if (!empty($this->funding_days)) {
         $fundingStartDateValidator = new ITPrismValidatorDate($this->funding_start);
         if (!$fundingStartDateValidator->isValid()) {
             $this->funding_end = "0000-00-00";
         } else {
             $fundingStartDate = new CrowdFundingDate($this->funding_start);
             $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days);
             $this->funding_end = $fundingEndDate->toSql();
         }
     }
     // Calculate days left
     $today = new CrowdFundingDate();
     $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end);
     return true;
 }
Exemplo n.º 2
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Get user ID.
     $this->userId = JFactory::getUser()->get("id");
     // Get reward ID.
     $rewardId = $app->input->getInt("id");
     // Validate reward owner
     jimport("crowdfunding.validator.reward.owner");
     $validator = new CrowdFundingValidatorRewardOwner(JFactory::getDbo(), $rewardId, $this->userId);
     if (!$validator->isValid()) {
         $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REWARD"), "notice");
         $app->redirect(JRoute::_(CrowdFundingHelperRoute::getDiscoverRoute()));
         return;
     }
     $this->items = $this->get('Items');
     $this->state = $this->get('State');
     $this->pagination = $this->get('Pagination');
     // Get params
     /** @var  $params Joomla\Registry\Registry */
     $params = $this->state->get("params");
     $this->params = $params;
     // Prepare an URL where user will be redirected when change the state of a reward.
     $this->redirectUrl = "index.php?option=com_crowdfunding&view=reward&id=" . $rewardId;
     // Prepare filters
     $this->listOrder = $this->escape($this->state->get('list.ordering'));
     $this->listDirn = $this->escape($this->state->get('list.direction'));
     $this->saveOrder = strcmp($this->listOrder, 'a.ordering') != 0 ? false : true;
     // Load reward data.
     jimport("crowdfunding.reward");
     $this->reward = new CrowdFundingReward(JFactory::getDbo());
     $this->reward->load($rewardId);
     // Prepare reward delivery date.
     $dateValidator = new ITPrismValidatorDate($this->reward->getDeliveryDate());
     $this->deliveryDate = $dateValidator->isValid() ? JHtml::_('date', $this->reward->getDeliveryDate(), JText::_('DATE_FORMAT_LC3')) : "--";
     // Get images folder.
     $this->imagesFolder = CrowdFundingHelper::getImagesFolderUri($this->userId);
     // Get social profile
     $socialPlatform = $this->params->get("integration_social_platform");
     if (!empty($socialPlatform)) {
         $this->prepareSocialIntegration($socialPlatform);
     }
     $this->prepareDocument();
     $this->version = new CrowdFundingVersion();
     parent::display($tpl);
 }
Exemplo n.º 3
0
 protected function prepareDefaultLayout()
 {
     jimport("crowdfunding.user.rewards");
     $this->rewards = new CrowdFundingUserRewards(JFactory::getDbo());
     $this->rewards->loadByRewardId($this->item->id);
     $this->rewardOwnerId = CrowdFundingHelper::getUserIdByRewardId($this->item->id);
     $dateValidator = new ITPrismValidatorDate($this->item->delivery);
     $this->deliveryDate = $dateValidator->isValid() ? JHtml::_('date', $this->item->delivery, JText::_('DATE_FORMAT_LC3')) : "--";
     $this->imagesFolder = CrowdFundingHelper::getImagesFolderUri($this->rewardOwnerId);
     // Get social profile
     $socialPlatform = $this->params->get("integration_social_platform");
     if (!empty($socialPlatform)) {
         $options = array("social_platform" => $socialPlatform, "user_id" => $this->rewardOwnerId);
         jimport("itprism.integrate.profile.builder");
         $profileBuilder = new ITPrismIntegrateProfileBuilder($options);
         $profileBuilder->build();
         $this->socialProfile = $profileBuilder->getProfile();
         $this->profileLink = $this->socialProfile->getLink();
     }
     $this->returnUrl = base64_encode("index.php?option=com_crowdfunding&view=reward&id=" . $this->item->id);
 }
Exemplo n.º 4
0
 /**
  * Method to get an object.
  *
  * @param    integer  $id  The id of the object to get.
  *
  * @return    mixed    Object on success, false on failure.
  */
 public function getItem($id = null)
 {
     if (empty($id)) {
         $id = $this->getState($this->context . '.id');
     }
     $storedId = $this->getStoreId($id);
     if (!isset($this->item[$storedId])) {
         $this->item[$storedId] = null;
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select("a.id, a.title, a.short_desc, a.description, a.image, a.location, " . "a.funded, a.goal, a.pitch_video, a.pitch_image, " . "a.funding_start, a.funding_end, a.funding_days, a.funding_type,  " . "a.catid, a.user_id, a.published, a.approved, a.hits, " . $query->concatenate(array("a.id", "a.alias"), "-") . ' AS slug, ' . $query->concatenate(array("b.id", "a.alias"), "-") . ' AS catslug')->from($db->quoteName("#__crowdf_projects", "a"))->innerJoin($db->quoteName("#__categories", "b") . " ON a.catid = b.id")->where("a.id = " . (int) $id);
         $db->setQuery($query, 0, 1);
         $result = $db->loadObject();
         // Attempt to load the row.
         if (!empty($result)) {
             // Calculate end date
             if (!empty($result->funding_days)) {
                 $fundingStartDateValidator = new ITPrismValidatorDate($result->funding_start);
                 if (!$fundingStartDateValidator->isValid()) {
                     $result->funding_end = "0000-00-00";
                 } else {
                     $fundingStartDate = new CrowdFundingDate($result->funding_start);
                     $fundingEndDate = $fundingStartDate->calculateEndDate($result->funding_days);
                     $result->funding_end = $fundingEndDate->format("Y-m-d");
                 }
             }
             // Calculate funded percentage.
             $math = new ITPrismMath();
             $math->calculatePercentage($result->funded, $result->goal, 0);
             $result->funded_percents = (string) $math;
             // Calculate days left.
             $today = new CrowdFundingDate();
             $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end);
             $this->item[$storedId] = $result;
         }
     }
     return $this->item[$storedId];
 }
Exemplo n.º 5
0
 /**
  * Calculate days left.
  *
  * <code>
  * $fundingDays = 30;
  * $fundingStart = "01-06-2014";
  * $fundingEnd   = "30-06-2014";
  *
  * $today    = new CrowdFundingDate();
  * $daysLeft = $today->calculateDaysLeft($fundingDays, $fundingStart, $fundingEnd);
  * </code>
  *
  * @param int    $fundingDays
  * @param string $fundingStart
  * @param string $fundingEnd
  *
  * @return int
  */
 public function calculateDaysLeft($fundingDays, $fundingStart, $fundingEnd)
 {
     // Calculate days left
     $today = clone $this;
     if (!empty($fundingDays)) {
         $validatorDate = new ITPrismValidatorDate($fundingStart);
         // Validate starting date.
         // If there is not starting date, set number of day.
         if (!$validatorDate->isValid($fundingStart)) {
             return (int) $fundingDays;
         }
         $endingDate = new DateTime($fundingStart);
         $endingDate->modify("+" . (int) $fundingDays . " days");
     } else {
         $endingDate = new DateTime($fundingEnd);
     }
     $interval = $today->diff($endingDate);
     $daysLeft = $interval->format("%r%a");
     if ($daysLeft < 0) {
         $daysLeft = 0;
     }
     return abs($daysLeft);
 }
Exemplo n.º 6
0
 /**
  * Method to change the published state of one or more records.
  *
  * @param   array   &$pks  A list of the primary keys to change.
  * @param   integer $value The value of the published state.
  *
  * @throws Exception
  *
  * @return  boolean  True on success.
  *
  * @since   12.2
  */
 public function publish(&$pks, $value = 0)
 {
     $table = $this->getTable();
     /** @var $table CrowdFundingTableProject */
     $pks = (array) $pks;
     // Access checks.
     foreach ($pks as $pk) {
         $table->reset();
         if ($table->load($pk)) {
             if ($value == CrowdFundingConstants::PUBLISHED) {
                 // Publish a project
                 // Validate funding period
                 jimport("itprism.validator.date");
                 $fundingEndValidator = new ITPrismValidatorDate($table->funding_end);
                 if (!$table->funding_days and !$fundingEndValidator->isValid()) {
                     throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_DURATION_PERIOD"));
                 }
                 // Calculate starting date if the user publish a project for first time.
                 $fundingStartValidator = new ITPrismValidatorDate($table->funding_start);
                 if (!$fundingStartValidator->isValid()) {
                     $fundingStart = new JDate();
                     $table->funding_start = $fundingStart->toSql();
                     // If funding type is "days", calculate end date.
                     if (!empty($table->funding_days)) {
                         jimport("crowdfunding.date");
                         $fundingStartDate = new CrowdFundingDate($table->funding_start);
                         $fundingEndDate = $fundingStartDate->calculateEndDate($table->funding_days);
                         $table->funding_end = $fundingEndDate->toSql();
                     }
                 }
                 // Validate the period if the funding type is days
                 $params = JComponentHelper::getParams($this->option);
                 /** @var  $params Joomla\Registry\Registry */
                 $minDays = $params->get("project_days_minimum", 15);
                 $maxDays = $params->get("project_days_maximum");
                 $fundingStartValidator = new ITPrismValidatorDate($table->funding_start);
                 if ($fundingStartValidator->isValid()) {
                     $dateValidator = new CrowdFundingDate($table->funding_start);
                     if (!$dateValidator->isValidPeriod($table->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));
                         }
                     }
                 }
                 $table->set("published", CrowdFundingConstants::PUBLISHED);
                 $table->store();
             } else {
                 // Set other states - unpublished, trash,...
                 $table->publish(array($pk), $value);
             }
         }
     }
     // Trigger change state event
     $context = $this->option . '.' . $this->name;
     // Include the content plugins for the change of state event.
     JPluginHelper::importPlugin('content');
     // Trigger the onContentChangeState event.
     $dispatcher = JEventDispatcher::getInstance();
     $result = $dispatcher->trigger($this->event_change_state, array($context, $pks, $value));
     if (in_array(false, $result, true)) {
         throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_CHANGE_STATE"));
     }
     // Clear the component's cache
     $this->cleanCache();
 }
Exemplo n.º 7
0
<?php

/**
 * @package      CrowdFunding
 * @subpackage   Components
 * @author       Todor Iliev
 * @copyright    Copyright (C) 2014 Todor Iliev <*****@*****.**>. All rights reserved.
 * @license      http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
// no direct access
defined('_JEXEC') or die;
?>

<?php 
foreach ($this->items as $i => $item) {
    $dateValidator = new ITPrismValidatorDate($item->delivery);
    ?>
    <tr class="row<?php 
    echo $i % 2;
    ?>
">
        <td class="center hidden-phone">
            <?php 
    echo JHtml::_('grid.id', $i, $item->id);
    ?>
        </td>
        <td class="center">
            <?php 
    echo JHtml::_('jgrid.published', $item->published, $i, "rewards.");
    ?>
        </td>
Exemplo n.º 8
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @param CrowdFundingTableProject $table
  * @param array $data
  *
  * @throws RuntimeException
  *
  * @since    1.6
  */
 protected function prepareTable(&$table, $data)
 {
     $durationType = JArrayHelper::getValue($data, "duration_type");
     $fundingEnd = JArrayHelper::getValue($data, "funding_end");
     $fundingDays = JArrayHelper::getValue($data, "funding_days");
     switch ($durationType) {
         case "days":
             $table->funding_days = $fundingDays < 0 ? 0 : (int) $fundingDays;
             // Calculate end date
             if (!empty($table->funding_start)) {
                 $fundingStartDate = new CrowdFundingDate($table->funding_start);
                 $fundingEndDate = $fundingStartDate->calculateEndDate($table->funding_days);
                 $table->funding_end = $fundingEndDate->format("Y-m-d");
             } else {
                 $table->funding_end = "0000-00-00";
             }
             break;
         case "date":
             $dateValidator = new ITPrismValidatorDate($fundingEnd);
             if (!$dateValidator->isValid($fundingEnd)) {
                 throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_DATE"));
             }
             $date = new JDate($fundingEnd);
             $table->funding_days = 0;
             $table->funding_end = $date->toSql();
             break;
         default:
             $table->funding_days = 0;
             $table->funding_end = "0000-00-00";
             break;
     }
 }
Exemplo n.º 9
0
 /**
  * @param string       $endDate
  * @param int       $days
  * @param string $format
  *
  * @return string
  */
 public static function duration($endDate, $days, $format = "d F Y")
 {
     $output = "";
     $endDateValidator = new ITPrismValidatorDate($endDate);
     if (!empty($days)) {
         $output .= JText::sprintf("COM_CROWDFUNDING_DURATION_DAYS", (int) $days);
         // Display end date
         if ($endDateValidator->isValid()) {
             $output .= '<div class="info-mini">';
             $output .= JText::sprintf("COM_CROWDFUNDING_DURATION_END_DATE", JHTML::_('date', $endDate, $format));
             $output .= '</div>';
         }
     } elseif ($endDateValidator->isValid()) {
         $output .= JText::sprintf("COM_CROWDFUNDING_DURATION_END_DATE", JHTML::_('date', $endDate, $format));
     } else {
         $output .= "---";
     }
     return $output;
 }
Exemplo n.º 10
0
 protected function prepareFundingDurationType()
 {
     $this->fundingDuration = $this->params->get("project_funding_duration");
     switch ($this->fundingDuration) {
         case "days":
             // Only days type is enabled
             $this->checkedDays = 'checked="checked"';
             break;
         case "date":
             // Only date type is enabled
             $this->checkedDate = 'checked="checked"';
             break;
         default:
             // Both ( days and date ) types are enabled
             $fundingStartDateValidator = new ITPrismValidatorDate($this->item->funding_end);
             $this->checkedDays = 0;
             $this->checkedDate = "";
             if (!empty($this->item->funding_days)) {
                 $this->checkedDays = 'checked="checked"';
                 $this->checkedDate = '';
             } elseif ($fundingStartDateValidator->isValid()) {
                 $this->checkedDays = '';
                 $this->checkedDate = 'checked="checked"';
             }
             // If missing both, select days
             if (!$this->checkedDays and !$this->checkedDate) {
                 $this->checkedDays = 'checked="checked"';
             }
             break;
     }
 }
Exemplo n.º 11
0
 /**
  * Calculate a project amount for full period of the campaign.
  *
  * <code>
  * $projectId    = 1;
  *
  * $statistics   = new CrowdFundingStatisticsProject(JFactory::getDbo(), $projectId);
  * $amount = $statistics->getFullPeriodAmounts();
  * </code>
  *
  * @return int
  */
 public function getFullPeriodAmounts()
 {
     $query = $this->db->getQuery(true);
     $query->select("a.funding_start, a.funding_end")->from($this->db->quoteName("#__crowdf_projects", "a"))->where("a.id = " . (int) $this->id);
     $this->db->setQuery($query);
     $result = $this->db->loadObject();
     // Validate dates
     jimport("itprism.validator.date");
     $fundingStartDate = new ITPrismValidatorDate($result->funding_start);
     $fundingEndDate = new ITPrismValidatorDate($result->funding_end);
     if (!$fundingStartDate->isValid() or !$fundingEndDate->isValid()) {
         return array();
     }
     $dataset = array();
     jimport("itprism.date");
     $date = new ITPrismDate();
     $date1 = new ITPrismDate($result->funding_start);
     $date2 = new ITPrismDate($result->funding_end);
     $period = $date->getDaysPeriod($date1, $date2);
     $query = $this->db->getQuery(true);
     $query->select("a.txn_date as date, SUM(a.txn_amount) as amount")->from($this->db->quoteName("#__crowdf_transactions", "a"))->where("a.project_id = " . (int) $this->id)->group("DATE(a.txn_date)");
     $this->db->setQuery($query);
     $results = $this->db->loadAssocList();
     if (!$results) {
         $results = array();
     }
     // Prepare data
     $data = array();
     foreach ($results as $result) {
         $date = new JDate($result["date"]);
         $index = $date->format("d.m");
         $data[$index] = $result;
     }
     /** @var $day JDate */
     foreach ($period as $day) {
         $dayMonth = $day->format("d.m");
         if (isset($data[$dayMonth])) {
             $amount = $data[$dayMonth]["amount"];
         } else {
             $amount = 0;
         }
         $dataset[] = array("date" => $dayMonth, "amount" => $amount);
     }
     return $dataset;
 }
Exemplo n.º 12
0
 /**
  * Load project data from database.
  *
  * <code>
  * $projectId = 1;
  *
  * $project   = CrowdFundingProject::getInstance(JFactory::getDbo());
  * $project->load($projectId);
  * </code>
  *
  * @param int $id
  *
  * @throws UnexpectedValueException
  */
 public function load($id)
 {
     if (!$id) {
         throw new UnexpectedValueException(JText::_("LIB_CROWDFUNDING_INVALID_PROJECT"));
     }
     $query = $this->db->getQuery(true);
     $query->select("a.id, a.title, a.alias, a.short_desc, a.description, a.image, a.image_square, a.image_small, " . "a.location, a.goal, a.funded, a.funding_type, a.funding_start, a.funding_end, a.funding_days, " . "a.pitch_video, a.pitch_image, a.hits, a.created, a.featured, a.published, a.approved, " . "a.ordering, a.catid, a.type_id, a.user_id, " . $query->concatenate(array("a.id", "a.alias"), "-") . " AS slug, " . $query->concatenate(array("b.id", "b.alias"), "-") . " AS catslug")->from($this->db->quoteName("#__crowdf_projects", "a"))->leftJoin($this->db->quoteName("#__categories", "b") . " ON a.catid = b.id")->where("a.id = " . (int) $id);
     $this->db->setQuery($query);
     $result = $this->db->loadAssoc();
     if (!$result) {
         $result = array();
     }
     $this->bind($result);
     // Calculate funded percent
     if (!$this->goal) {
         $this->fundedPercent = 0;
     } else {
         $math = new ITPrismMath();
         $math->calculatePercentage($this->funded, $this->goal, 0);
         $this->fundedPercent = (string) $math;
     }
     // Calculate end date
     if (!empty($this->funding_days)) {
         $fundingStartDateValidator = new ITPrismValidatorDate($this->funding_start);
         if (!$fundingStartDateValidator->isValid()) {
             $this->funding_end = "0000-00-00";
         } else {
             $fundingStartDate = new CrowdFundingDate($this->funding_start);
             $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days);
             $this->funding_end = $fundingEndDate->format("Y-m-d");
         }
     }
     // Calculate days left
     $today = new CrowdFundingDate();
     $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end);
 }
 /**
  * Validate user data that comes from step "Funding".
  *
  * @param array $data
  * @param Joomla\Registry\Registry $params
  *
  * @return array
  */
 protected function validateStepFunding(&$data, &$params)
 {
     $result = array("success" => false, "message" => "");
     // Validate minimum and maximum amount.
     if ($this->params->get("validate_amount", 1)) {
         $goal = JArrayHelper::getValue($data, "goal", 0, "float");
         $minAmount = $params->get("project_amount_minimum", 100);
         $maxAmount = $params->get("project_amount_maximum");
         // Verify minimum amount
         if ($goal < $minAmount) {
             $result["message"] = JText::_('PLG_CONTENT_CROWDFUNDINGVALIDATOR_ERROR_INVALID_GOAL');
             return $result;
         }
         // Verify maximum amount
         if (!empty($maxAmount) and $goal > $maxAmount) {
             $result["message"] = JText::_('PLG_CONTENT_CROWDFUNDINGVALIDATOR_ERROR_INVALID_GOAL');
             return $result;
         }
     }
     // Validate funding duration - days or date.
     if ($this->params->get("validate_funding_duration", 1)) {
         $minDays = (int) $params->get("project_days_minimum", 15);
         $maxDays = (int) $params->get("project_days_maximum", 0);
         $fundingType = JArrayHelper::getValue($data, "funding_duration_type");
         // Validate funding type "days"
         if (strcmp("days", $fundingType) == 0) {
             $days = JArrayHelper::getValue($data, "funding_days", 0, "integer");
             if ($days < $minDays) {
                 $result["message"] = JText::_('PLG_CONTENT_CROWDFUNDINGVALIDATOR_ERROR_INVALID_DAYS');
                 return $result;
             }
             if (!empty($maxDays) and $days > $maxDays) {
                 $result["message"] = JText::_('PLG_CONTENT_CROWDFUNDINGVALIDATOR_ERROR_INVALID_DAYS');
                 return $result;
             }
         } else {
             // Validate funding type "date"
             $fundingEndDate = JArrayHelper::getValue($data, "funding_end");
             $dateValidator = new ITPrismValidatorDate($fundingEndDate);
             if (!$dateValidator->isValid()) {
                 $result["message"] = JText::_('PLG_CONTENT_CROWDFUNDINGVALIDATOR_ERROR_INVALID_DATE');
                 return $result;
             }
         }
     }
     // Validate funding duration when the projects is published and approved.
     if ($this->params->get("validate_funding_duration_approved", 1)) {
         // Get item and check it for active state ( published and approved ).
         $itemId = JArrayHelper::getValue($data, "id");
         $userId = JFactory::getUser()->get("id");
         $item = $this->getItem($itemId, $userId);
         // Validate date if user want to edit date, while the project is published.
         if ($item->published and $item->approved) {
             $minDays = (int) $params->get("project_days_minimum", 15);
             $maxDays = (int) $params->get("project_days_maximum", 0);
             $fundingType = JArrayHelper::getValue($data, "funding_duration_type");
             // Generate funding end date from days.
             if (strcmp("days", $fundingType) == 0) {
                 // Get funding days.
                 $days = JArrayHelper::getValue($data, "funding_days", 0, "integer");
                 $fundingStartDate = new CrowdFundingDate($item->funding_start);
                 $endDate = $fundingStartDate->calculateEndDate($days);
                 $fundingEndDate = $endDate->format("Y-m-d");
             } else {
                 // Get funding end date from request
                 $fundingEndDate = JArrayHelper::getValue($data, "funding_end");
             }
             // Validate the period.
             $dateValidator = new CrowdFundingDate($item->funding_start);
             if (!$dateValidator->isValidPeriod($fundingEndDate, $minDays, $maxDays)) {
                 $result["message"] = !empty($maxDays) ? JText::sprintf("PLG_CONTENT_CROWDFUNDINGVALIDATOR_ERROR_INVALID_ENDING_DATE_MIN_MAX_DAYS", $minDays, $maxDays) : JText::sprintf("PLG_CONTENT_CROWDFUNDINGVALIDATOR_ERROR_INVALID_ENDING_DATE_MIN_DAYS", $minDays);
                 return $result;
             }
         }
     }
     // Validations completed successfully.
     $result = array("success" => true);
     return $result;
 }
Exemplo n.º 14
0
 * @subpackage   Components
 * @author       Todor Iliev
 * @copyright    Copyright (C) 2014 Todor Iliev <*****@*****.**>. All rights reserved.
 * @license      http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
// no direct access
defined('_JEXEC') or die;
// Prepare availability number
$availability = JArrayHelper::getValue($this->formItem, "number", 0);
if (!$availability) {
    $availability = "";
}
// Prepare delivery date
$deliveryDate = JArrayHelper::getValue($this->formItem, "delivery", null);
if (!empty($deliveryDate)) {
    $dateValidator = new ITPrismValidatorDate($deliveryDate);
    if (!$dateValidator->isValid()) {
        $deliveryDate = null;
    } else {
        // Formatting date
        $date = new JDate($deliveryDate);
        $deliveryDate = $date->format($this->dateFormat);
    }
}
?>
<div class="row-fluid reward-form" id="reward_box_<?php 
echo $this->formIndex;
?>
">
    <div class="span2 reward-form-help"><?php 
echo JText::_("COM_CROWDFUNDING_REWARDS_REWARD");
Exemplo n.º 15
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));
             }
         }
     }
 }