人人人妻人人人妻人人人,99精品国产综合久久久久五月天 ,欧美白人最猛性XXXXX,日韩AV无码免费播放

News新聞

業(yè)界新聞動態(tài)、技術(shù)前沿
Who are we?

您的位置:首頁      樂道系統(tǒng)FAQ      基于ThinkPHP實現(xiàn)的日歷功能實例詳解

基于ThinkPHP實現(xiàn)的日歷功能實例詳解

標簽: 發(fā)布日期:2017-04-15 00:00:00 260
【CLI】利用Curl下載文件實時進度條顯示的實現(xiàn)

本文實例講述了基于ThinkPHP實現(xiàn)的日歷功能。分享給大家供大家參考,具體如下:

開發(fā)環(huán)境介紹

最新,閑來沒事,便開發(fā)了一款簡單的日歷,來統(tǒng)計工作情況。為了開發(fā)便捷,使用ThinkPHP架構(gòu)。界面如下圖

備注:每頁包含上一個月,當(dāng)前月,下一個月的日期,并用不同的顏色區(qū)分,如果某天工作了,便圈出來。
主要是以下兩個文件

重要文件描述

功能文件

CalenDar.class.php主要負責(zé),獲取日歷詳細信息的,不涉及用戶數(shù)據(jù)操作。

代碼如下:

<?php
namespace Util;
class CalenDar{
  //上一個月信息
  private $lastYear=null;
  private $lastMonth=null;
  //當(dāng)前月信息
  private $curYear=null;
  private $curMonth=null;
  private $curWek=null;
  private $curDay=null;
  private $curDaySum=0;
  //下一個月月信息
  private $nextYear=null; //下一個月是哪一年
  private $nextMonth=null;//下一個月
  private $calendar=null;
  public function __construct($dateTime=null){
    if(isset($_get['yeal']) && is_numeric($_get['yeal'])){
      $this->curYear=$_get['yeal'];
    }else{
      $this->curYear=date('Y');
    }
    if(isset($_get['month']) && is_numeric($_get['month'])){
      $this->curMonth=$_get['month'];
    }else{
      $this->curMonth=date('n');
    }
    if(isset($_get['day']) && is_numeric($_get['day'])){
      $this->curDay=$_get['day'];
    }else{
      $this->curDay=date('j');
    }
    $this->init($dateTime);
    $this->createCalendar();
  }
  /**
  *初始化
  */
  public function init($dateTime=null){
    if(!empty($dateTime)){ //當(dāng)月
      $this->curYear=date('Y',strtotime($dateTime));
      $this->curMonth=date('n',strtotime($dateTime));
      $this->curDay=date('j',strtotime($dateTime));
    }
    $this->curWek=date('w',strtotime($this->curYear.'-'.$this->curMonth.'-1'));
    //上一個月
    $this->lastMonth=$this->curMonth-1; //上一個月
    $this->lastYear=$this->curYear; //上一個月屬于哪一年
    if($this->lastMonth<0){
      $this->lastMonth=12;
      $this->lastYear-=1;
    }
    //下一個月
    $this->nextMonth=$this->curMonth+1;//下一個月
    $this->nextYear=$this->curYear; //下一個月屬于哪一年
    if($this->nextMonth > 12){
      $this->nextMonth=1;
      $this->nextYear+=1;
    }
  }
  public function getCalendar(){
    return $this->calendar;
  }
  /**
  *創(chuàng)建日歷從周日 周一 周二 周三 周四 周五 周六,7*5方格,前面補上月后幾天,后面補下月開始幾天
  **/
  public function createCalendar(){
    //判斷當(dāng)月共計多少天
    $nextStr=$this->nextYear.'-'.$this->nextMonth.'-1 -1 days';
    $curDaySum=date('j',strtotime($nextStr));
    //判斷上一個月最后一天是多少號
    $lastStr=$this->curYear.'-'.$this->curMonth.'-1 -1 days';
    $lastDaySum=date('j',strtotime($lastStr));
    $prefixLId=$this->lastYear.'-'.$this->lastMonth;
    $prefixCId=$this->curYear.'-'.$this->curMonth;
    $prefixNId=$this->nextYear.'-'.$this->nextMonth;
    if($this->curWek == 0){
      $lastMonthSum=7; //需要添加上個月的$lastMonthSum天
    }else{
      $lastMonthSum=$this->curWek;
    }
    $lastMonthStart=$lastDaySum - $lastMonthSum+1;
    for($i=0,$j=1,$k=1;$i<42;$i++){
      $dateInfo=array();
      if($i<$lastMonthSum){ //上一個月
        $dateInfo['day']=$lastMonthStart + $i;
        $dateInfo['type']=1;
        $id=$prefixLId.'-'.$dateInfo['day'];
        $this->calendar[]=array('id'=>$id,
                    'info'=>$dateInfo);
      }else if($j > $curDaySum){//下一個月
        $id=$prefixNId.'-'.$k;
        $dateInfo['day']=$k;
        $dateInfo['type']=3;
        $this->calendar[]=array('id'=>$id,
                    'info'=>$dateInfo);
        $k++;
      }else{//本月
        $dateInfo['day']=$j;
        $dateInfo['type']=2;
        $this->calendar[]=array('id'=>($prefixCId.'-'.$j),
                    'info'=>$dateInfo);
        $j++;
        $this->curDaySum+=1;
      }
    }
  }
  public function getDayTime(){
    return $this->curYear.'-'.$this->curMonth.'-'.$this->curDay;
  }
  /**
  *獲取當(dāng)前月屬于哪個月
  **/
  public function getCurMonth(){
    return $this->curYear.'-'.$this->curMonth;
  }
  /**
  *獲取上一個月屬于哪個月
  **/
  public function getLastMonth(){
    return $this->lastYear.'-'.$this->lastMonth;
  }
  /**
  *獲取下一個月屬于哪個月
  **/
  public function getNextMonth(){
    return $this->nextYear.'-'.$this->nextMonth;
  }
  /**
  *判斷當(dāng)前月有多少天
  **/
  public function getCurDaySum(){
    return $this->curDaySum;
  }
}