コード例 #1
0
 /**
  * Prepare the statuses of the items.
  *
  * @param array $data
  * @param array $options
  */
 public function handle(&$data, array $options = array())
 {
     foreach ($data as $key => $item) {
         // Calculate funding end date
         if (is_numeric($item->funding_days) and $item->funding_days > 0) {
             $fundingStartDate = new Crowdfunding\Date($item->funding_start);
             $endDate = $fundingStartDate->calculateEndDate($item->funding_days);
             $item->funding_end = $endDate->format(Prism\Constants::DATE_FORMAT_SQL_DATE);
         }
         // Calculate funded percentage.
         $item->funded_percents = (string) MathHelper::calculatePercentage($item->funded, $item->goal, 0);
         // Calculate days left
         $today = new Crowdfunding\Date();
         $item->days_left = $today->calculateDaysLeft($item->funding_days, $item->funding_start, $item->funding_end);
         // Decode parameters.
         if ($item->params === null) {
             $item->params = '{}';
         }
         if (is_string($item->params) and $item->params !== '') {
             $params = new Registry();
             $params->loadString($item->params);
             $item->params = $params;
         }
     }
 }
コード例 #2
0
 /**
  * Prepare the statuses of the items.
  *
  * @param array $data
  * @param array $options
  */
 public function handle(&$data, array $options = array())
 {
     foreach ($data as $key => $item) {
         // Calculate funding end date
         if (is_numeric($item->funding_days) and $item->funding_days > 0) {
             $fundingStartDate = new Crowdfunding\Date($item->funding_start);
             $endDate = $fundingStartDate->calculateEndDate($item->funding_days);
             $item->funding_end = $endDate->format('Y-m-d');
         }
         // Calculate funded percentage.
         $item->funded_percents = (string) MathHelper::calculatePercentage($item->funded, $item->goal, 0);
         // Calculate days left
         $today = new Crowdfunding\Date();
         $item->days_left = $today->calculateDaysLeft($item->funding_days, $item->funding_start, $item->funding_end);
     }
 }
コード例 #3
0
 /**
  * Load project data from database.
  *
  * <code>
  * $projectId = 1;
  *
  * $project   = new Crowdfunding\Project(\JFactory::getDbo());
  * $project->load($projectId);
  * </code>
  *
  * @param array|int $keys
  * @param array $options
  *
  * @throws \UnexpectedValueException
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  */
 public function load($keys, array $options = array())
 {
     if (!$keys) {
         throw new \InvalidArgumentException(\JText::_('LIB_CROWDFUNDING_INVALID_KEYS'));
     }
     $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_id, 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');
     if (is_array($keys)) {
         foreach ($keys as $key => $value) {
             $query->where($this->db->quoteName('a.' . $key) . ' = ' . $this->db->quote($value));
         }
     } else {
         $query->where('a.id = ' . (int) $keys);
     }
     // Filter by state.
     $filter = ArrayHelper::getValue($options, 'state');
     if ($filter !== null and is_numeric($filter)) {
         $query->where('a.published = ' . (int) $filter);
     }
     // Filter by approved state.
     $filter = ArrayHelper::getValue($options, 'approved');
     if ($filter !== null and is_numeric($filter)) {
         $query->where('a.approved = ' . (int) $filter);
     }
     $this->db->setQuery($query);
     $result = (array) $this->db->loadAssoc();
     $this->bind($result);
     // Calculate funded percent
     if (!$this->goal) {
         $this->fundedPercent = 0;
     } else {
         $this->fundedPercent = MathHelper::calculatePercentage($this->funded, $this->goal, 0);
     }
     // Calculate end date
     if ($this->funding_days > 0) {
         $fundingStartDateValidator = new Prism\Validator\Date($this->funding_start);
         if (!$fundingStartDateValidator->isValid()) {
             $this->funding_end = Prism\Constants::DATE_DEFAULT_SQL_DATE;
         } else {
             $fundingStartDate = new Date($this->funding_start);
             $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days);
             $this->funding_end = $fundingEndDate->format('Y-m-d');
         }
     }
     // Calculate days left
     $today = new Date();
     $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end);
 }
コード例 #4
0
ファイル: Project.php プロジェクト: pashakiz/crowdf
 /**
  * Load project data from database.
  *
  * <code>
  * $projectId = 1;
  *
  * $project   = new Crowdfunding\Project(\JFactory::getDbo());
  * $project->load($projectId);
  * </code>
  *
  * @param int $keys
  * @param array $options
  *
  * @throws \UnexpectedValueException
  */
 public function load($keys, $options = array())
 {
     if (!$keys) {
         throw new \UnexpectedValueException(\JText::_("LIB_CROWDFUNDING_INVALID_PROJECT_ID"));
     }
     $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_id, 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) $keys);
     $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 Prism\Math();
         $math->calculatePercentage($this->funded, $this->goal, 0);
         $this->fundedPercent = (string) $math;
     }
     // Calculate end date
     if (!empty($this->funding_days)) {
         $fundingStartDateValidator = new Prism\Validator\Date($this->funding_start);
         if (!$fundingStartDateValidator->isValid()) {
             $this->funding_end = "0000-00-00";
         } else {
             $fundingStartDate = new Date($this->funding_start);
             $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days);
             $this->funding_end = $fundingEndDate->format("Y-m-d");
         }
     }
     // Calculate days left
     $today = new Date();
     $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end);
 }
コード例 #5
0
ファイル: Project.php プロジェクト: bellodox/CrowdFunding
 /**
  * Load project data from database.
  *
  * <code>
  * $projectId = 1;
  *
  * $project   = new Crowdfunding\Project(\JFactory::getDbo());
  * $project->load($projectId);
  * </code>
  *
  * @param int $keys
  * @param array $options
  *
  * @throws \UnexpectedValueException
  */
 public function load($keys, $options = array())
 {
     if (!$keys) {
         throw new \UnexpectedValueException(\JText::_('LIB_CROWDFUNDING_INVALID_PROJECT_ID'));
     }
     $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_id, 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) $keys);
     $this->db->setQuery($query);
     $result = (array) $this->db->loadAssoc();
     $this->bind($result);
     // Calculate funded percent
     if (!$this->goal) {
         $this->fundedPercent = 0;
     } else {
         $this->fundedPercent = MathHelper::calculatePercentage($this->funded, $this->goal, 0);
     }
     // Calculate end date
     if ($this->funding_days > 0) {
         $fundingStartDateValidator = new Validator\Date($this->funding_start);
         if (!$fundingStartDateValidator->isValid()) {
             $this->funding_end = '0000-00-00';
         } else {
             $fundingStartDate = new Date($this->funding_start);
             $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days);
             $this->funding_end = $fundingEndDate->format('Y-m-d');
         }
     }
     // Calculate days left
     $today = new Date();
     $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end);
 }