Пример #1
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;
 }
Пример #2
0
 /**
  * Prepare some specific CSS styles of the projects.
  *
  * @param object $item
  * @param Joomla\Registry\Registry $params
  *
  * @return string
  */
 public static function styles($item, $params)
 {
     $classes = array();
     // Prepare class Featured
     if (!empty($item->featured)) {
         $classes[] = $params->get("style_featured");
     }
     // Check dates
     $today = new JDate();
     $fundingEnd = new ITPrismDate($item->funding_end);
     $fundingStart = new ITPrismDate($item->funding_start);
     // Prepare completed campaign classes.
     if ($today > $fundingEnd) {
         if ($item->goal <= $item->funded) {
             $classes[] = $params->get("style_completed_successfully");
         } else {
             $classes[] = $params->get("style_completed_unsuccessfully");
         }
     }
     // Prepare class for a new campaign.
     if ($today < $fundingEnd and $fundingStart->isCurrentWeekDay()) {
         $classes[] = $params->get("style_new");
     }
     // Prepare class for a ending soon campaign.
     if ($today < $fundingEnd and $fundingEnd->isCurrentWeekDay()) {
         $classes[] = $params->get("style_ending_soon");
     }
     $classes = array_filter($classes);
     return implode(" ", $classes);
 }
Пример #3
0
 /**
  * Check whether the date is part of the current week.
  *
  * <code>
  * $date   = new ITPrismDate("05-06-2014");
  *
  * if ($date->isCurrentWeekDay()) {
  * ...
  * }
  * </code>
  *
  * @return bool
  */
 public function isCurrentWeekDay()
 {
     $today = new ITPrismDate();
     $startOfWeek = $today->getBeginOfWeek();
     $endOfWeek = $today->getEndOfWeek();
     if ($startOfWeek <= $this and $this <= $endOfWeek) {
         return true;
     } else {
         return false;
     }
 }