/** * Get the number of started soon projects. * * <code> * $options = array( * "interval" => 7, // The number of last days when the campaigns have been started. * "state" => 1, // The state of the campaign - published or unpublished. * "approved" => 1, // The approved state - approved or not approved. * ); * * $statistics = new Crowdfunding\Statistics\Basic(\JFactory::getDbo()); * $numberOfProjects = $statistics->getStartedSoonProjects(); * </code> * * @param array $options Options used to be aggregated data. * * @return int */ public function getStartedSoonProjects($options = array()) { $query = $this->db->getQuery(true); $query->select('COUNT(*)')->from($this->db->quoteName('#__crowdf_projects', 'a')); // Filter by date interval. if (array_key_exists('interval', $options)) { $days = (int) $options['interval']; if ($days > 0) { jimport('joomla.date.date'); $date = new \JDate(); $today = $date->toSql(); $date->sub(new \DateInterval('P' . $days . 'D')); $query->where('a.funding_start >= ' . $this->db->quote($date->toSql()) . ' AND a.funding_start <= ' . $this->db->quote($today)); } } // Prepare filters. $this->prepareFilters($query, $options); $this->db->setQuery($query); return (int) $this->db->loadResult(); }
/** * Prepare filter by date. * * @param JDatabaseQuery $query */ protected function prepareFilterDate(&$query) { $db = $this->getDbo(); // Filter by date. $filter = (int) $this->getState($this->context . '.filter_date'); switch ($filter) { case 1: // Starting soon jimport('joomla.date.date'); $date = new JDate(); $today = $date->toSql(); $date->sub(new DateInterval('P7D')); $query->where('a.funding_start >= ' . $db->quote($date->toSql()) . ' AND a.funding_start <= ' . $db->quote($today)); break; case 2: // Ending soon jimport('joomla.date.date'); $date = new JDate(); $today = $date->toSql(); $date->add(new DateInterval('P7D')); $query->where('a.funding_end >= ' . $db->quote($today) . ' AND a.funding_start <= ' . $db->quote($date->toSql())); break; } }
/** * Get the number of started soon projects. * * <code> * $options = array( * "interval" => 7, // The number of last days when the campaigns have been started. * "state" => 1, // The state of the campaign - published or unpublished. * "approved" => 1, // The approved state - approved or not approved. * ); * * $statistics = new Crowdfunding\Statistics\Basic(\JFactory::getDbo()); * $numberOfProjects = $statistics->getStartedSoonProjects(); * </code> * * @param array $options Options used to be aggregated data. * * @return int */ public function getStartedSoonProjects($options = array()) { $query = $this->db->getQuery(true); $query->select("COUNT(*)")->from($this->db->quoteName("#__crowdf_projects", "a")); // Filter by date interval. if (isset($options["interval"])) { $days = (int) $options["interval"]; if ($days > 0) { jimport("joomla.date.date"); $date = new \JDate(); $today = $date->toSql(); $date->sub(new \DateInterval("P" . $days . "D")); $query->where("a.funding_start >= " . $this->db->quote($date->toSql()) . " AND a.funding_start <= " . $this->db->quote($today)); } } // Prepare filters. $this->prepareFilters($query, $options); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { $result = 0; } return $result; }