當前位置: 首頁>>代碼示例>>PHP>>正文


PHP JDate::sub方法代碼示例

本文整理匯總了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();
 }
開發者ID:sis-direct,項目名稱:CrowdFunding,代碼行數:38,代碼來源:Basic.php

示例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;
     }
 }
開發者ID:ITPrism,項目名稱:CrowdfundingDistribution,代碼行數:29,代碼來源:category.php

示例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;
 }
開發者ID:Eautentik,項目名稱:CrowdFunding,代碼行數:42,代碼來源:Basic.php


注:本文中的JDate::sub方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。