本文整理汇总了PHP中JDate::sub方法的典型用法代码示例。如果您正苦于以下问题:PHP JDate::sub方法的具体用法?PHP JDate::sub怎么用?PHP JDate::sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JDate
的用法示例。
在下文中一共展示了JDate::sub方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getStartedSoonProjects
/**
* 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();
}
示例2: prepareFilterDate
/**
* 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;
}
}
示例3: getStartedSoonProjects
/**
* 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;
}