当前位置: 首页>>代码示例>>PHP>>正文


PHP JDate::subDays方法代码示例

本文整理汇总了PHP中JDate::subDays方法的典型用法代码示例。如果您正苦于以下问题:PHP JDate::subDays方法的具体用法?PHP JDate::subDays怎么用?PHP JDate::subDays使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JDate的用法示例。


在下文中一共展示了JDate::subDays方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveAndEndForetagsTavling

 /**
  * This function ends and saves a competition. 
  * The sql will only find ended competitions on tuesdays, it is supposed to run as a cron.  
  * The competitions and all the calculated data are saved in tables: mm_tavling_save, mm_tavling, mm_lag_save
  * A tavling_id is created for each competition.
  * Actions are logged to /motiomera/log/motiomera.log
  *
  * All members will have some extra days added, see the FORETAGSMEDLEMS_EXTRA_DAYS
  *  
  * @author krillo 
  * 
  * krillo 091026 changed the sql to only get the records that have a competition thats ending.
  * krillo 100420 changed to only save the competition to mm_tavling_save, mm_tavling, mm_lag_save
  * krillo 110511 changed to add extra days after closed competition FORETAGSMEDLEMS_EXTRA_DAYS
  * krillo 110817 changed to take a date parameter to be bale to run from admin. Please use only Tuesdays after finished competition
  */
 public static function saveAndEndForetagsTavling($date = false)
 {
     Misc::logMotiomera("Start foretag::saveAndEndForetagsTavling() ", 'info');
     global $db;
     $jDate = new JDate($date);
     $subDays = $jDate->subDays(3)->getDate(true);
     // today - 3 days in unixtime
     $sql = 'SELECT c.id as foretag_id, namn as foretag_namn,  a.id, a.aNamn as user_anamn, a.epost as user_epost, c.startDatum, c.slutDatum FROM mm_medlem a, mm_foretagsnycklar b, mm_foretag c
         WHERE a.id = b.medlem_id
         AND b.foretag_id = c.id
         AND a.epostBekraftad = 1
         AND UNIX_TIMESTAMP(c.slutDatum) BETWEEN ' . $subDays . ' AND ' . $jDate->getOrigDate(true);
     $users = $db->allValuesAsArray($sql);
     $tavling = new Tavling('0000-00-00', '0000-00-00');
     $save = array();
     $i = 1;
     if (count($users) == 0) {
         Misc::logMotiomera("No tavling ended this last sunday", 'info');
     } else {
         //commence saving
         Misc::logMotiomera("End of tavling, saving data for " . count($users) . " members", 'info');
         foreach ($users as $user) {
             $medlem = Medlem::loadById($user['id']);
             if (isset($medlem)) {
                 $startDatum = $user['startDatum'];
                 //$medlem->getForetag()->getStartDatum();
                 $slutDatum = $user['slutDatum'];
                 //$medlem->getForetag()->getSlutdatum();
                 if ($tavling->getStartDatum() == '0000-00-00') {
                     $tavling->setStartDatum($startDatum);
                     // give the Tavling object a correct startdate as soon as we've got one (we only do this once)
                     $tavling->setSlutDatum($slutDatum);
                     $tavling->commit();
                 }
                 if ($medlem->getForetag()) {
                     if ($medlem->getLag()) {
                         //members that are not in a lag, want also to be in the toplists  set lagId to -1
                         $lagId = $medlem->getLag()->getId();
                     } else {
                         $lagId = 0;
                     }
                     $steg = $medlem->getStegTotal($startDatum, $slutDatum);
                     $antal_dagar = $medlem->getForetag()->getAntalTavlingsDagar();
                     if ($steg > 0) {
                         //only save data for members who have more than 0 steg
                         try {
                             $save[] = array('medlem_id' => $medlem->getId(), 'foretag_id' => $medlem->getForetag()->getId(), 'lag_id' => $lagId, 'foretagsnyckel' => $medlem->getForetagsnyckel(), 'tavlings_id' => $tavling->getId(), 'steg' => $steg, 'start_datum' => $startDatum, 'stop_datum' => $slutDatum, 'antal_dagar' => $antal_dagar);
                             Misc::logMotiomera(" " . $i++ . " tavling_id: " . $tavling->getId() . " | " . $medlem->getForetag()->getNamn() . ' | id: ' . $medlem->getId() . ' | ' . $medlem->getAnamn() . " | steg: {$steg}" . " | email: " . $medlem->getEpost(), 'ok');
                             $medlem->addPaidUntil(self::FORETAGSMEDLEMS_EXTRA_DAYS);
                             //add some extra days after finished competition
                             $medlem->commit();
                         } catch (Exception $e) {
                             Misc::logMotiomera(" " . $i++ . " | something went wrong", 'error');
                         }
                     } else {
                         Misc::logMotiomera(" " . $i++ . " | Member is omitted due to 0 steps |" . $medlem->getForetag()->getNamn() . ' | id: ' . $medlem->getId() . ' | ' . $medlem->getAnamn() . " | steg: {$steg}" . " | email: " . $medlem->getEpost(), 'warning');
                     }
                 } else {
                     Misc::logMotiomera(" " . $i++ . " | Member is omitted due to member not in foretag | id: " . $medlem->getId() . ' | ' . $medlem->getAnamn() . " | email: " . $medlem->getEpost(), 'warning');
                 }
             }
         }
         $lag_save = array();
         foreach ($save as $m) {
             //print_r($m);
             $i = 0;
             if (!isset($lag_save[$m['lag_id']]) and $m['lag_id'] > 0) {
                 $lag_save[$m['lag_id']] = Lag::loadById($m['lag_id']);
             }
             $sql = "INSERT INTO " . Tavling::RELATION_TABLE . " SET ";
             foreach ($m as $field => $value) {
                 $i++;
                 if ($i == 9) {
                     $sql .= $field . " = '" . $value . "'";
                 } else {
                     $sql .= $field . " = '" . $value . "', ";
                 }
             }
             //echo "<br />$sql";
             $db->query($sql);
         }
         if (count($lag_save) != 0) {
             Tavling::saveLagList($lag_save);
         }
//.........这里部分代码省略.........
开发者ID:krillo,项目名称:motiomera,代码行数:101,代码来源:Foretag.php


注:本文中的JDate::subDays方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。