sugarwidgetfielddatetime.php

来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 907 行 · 第 1/3 页

PHP
907
字号
        $en = $begin_parts[0] . ' 23:59:59';        if($this->getAssignedUser()) {            $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);            $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $this->assigned_user);        }        else{        	$begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $current_user);            $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $current_user);        }		if ($this->reporter->db->dbType == 'oci8') {		} else {			return $this->_get_column_select($layout_def).">='".PearDatabase :: quote($begin)."' AND ".$this->_get_column_select($layout_def)."<='".PearDatabase :: quote($end)."'\n";		}	}    /**     * Get assigned or logged in user's current date and time value.     * @param boolean $timestamp Format of return value, if set to true, return unix like timestamp , else a formatted date.     */	function get_users_current_date_time($timestamp=false) {	 	global $current_user;        global $timedate;        $begin = gmdate('Y-m-d H:i:s');        //kbrill bug #13884       	//$begin = $timedate->to_display_date_time($begin,true,true,$this->assigned_user);		$begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);        if (!$timestamp) {        	return $begin;        } else {        	$begin_parts = explode(' ', $begin);        	$date_parts=explode('-', $begin_parts[0]);        	$time_parts=explode(':', $begin_parts[1]);        	$curr_timestamp=mktime($time_parts[0],$time_parts[1],0,$date_parts[1], $date_parts[2],$date_parts[0]);        	return $curr_timestamp;        }	}	/**	 * Get specified date and time for a particalur day, in current user's timezone.	 * @param int $days Adjust date by this number of days, negative values are valid.	 * @param time string falg for desired time value, start: minimum time, end: maximum time, default: current time	 */	function get_db_date($days,$time) {        global $timedate;        $begin = date('Y-m-d H:i:s', time()+(86400 * $days));  //gmt date with day adjustment applied.        //kbrill bug #13884        //$begin = $timedate->to_display_date_time($begin,true,true,$this->assigned_user);		$begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);                if ($time=='start') {            $begin_parts = explode(' ', $begin);            $be = $begin_parts[0] . ' 00:00:00';        }        else if ($time=='end') {            $begin_parts = explode(' ', $begin);            $be = $begin_parts[0] . ' 23:59:59';        } else {            $be=$begin;        }        //convert date to db format without converting to GMT.        $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);        return $begin;	}	/**	 * Get filter string for a date field.	 * @param array layout_def field def for field being filtered	 * @param string $begin start date value.	 * @param string $end End date value.	 */	function get_start_end_date_filter(& $layout_def, $begin,$end) {		if ($this->reporter->db->dbType == 'oci8') {		}elseif($this->reporter->db->dbType == 'mssql'){            if (isset ($layout_def['rel_field'])) {                $field_name = "(".$this->_get_column_select($layout_def)." + ' ' + ".$layout_def['rel_field'].")";            } else {                $field_name = $this->_get_column_select($layout_def);            }            return $field_name.">='".PearDatabase :: quote($begin)."' AND ".$field_name."<='".PearDatabase :: quote($end)."'\n";        } else {			if (isset ($layout_def['rel_field'])) {				$field_name = "CONCAT(".$this->_get_column_select($layout_def).",' ',".$layout_def['rel_field'].")";			} else {				$field_name = $this->_get_column_select($layout_def);			}			return $field_name.">='".PearDatabase :: quote($begin)."' AND ".$field_name."<='".PearDatabase :: quote($end)."'\n";		}	}	function queryFilterTP_last_7_days(& $layout_def) {        $begin=$this->get_db_date(-6,'start');        $end=$this->get_db_date(0,'end');        return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_next_7_days(& $layout_def) {        $begin=$this->get_db_date(0,'start');        $end=$this->get_db_date(6,'end');		return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_last_month(& $layout_def) {		global $timedate;		$curr_timestamp= $this->get_users_current_date_time(true);		//Get year and month from time stamp.		$curr_year=date('Y',$curr_timestamp);		$curr_month=date('m',$curr_timestamp);		//get start date for last month and convert it to gmt and db format.	    $begin=date('Y-m-d H:i:s',strtotime("-1 month",mktime(0,0,0,$curr_month,1,$curr_year)));        $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);	    //get end date for last month  and convert it to gmt and db format.        $end=date('Y-m-d H:i:s',strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));	    $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);		return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_this_month(& $layout_def) {		global $timedate;		$curr_timestamp= $this->get_users_current_date_time(true);		//Get year and month from time stamp.		$curr_year=date('Y',$curr_timestamp);		$curr_month=date('m',$curr_timestamp);		//get start date for this month and convert it to gmt and db format.	    $begin=date('Y-m-d H:i:s',mktime(0,0,0,$curr_month,1,$curr_year));        $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);	    //get end date for this month  and convert it to gmt and db format.	    //first get the first day of next month and move back by one day.		if ($curr_month==12) {			$curr_month=1;			$curr_year+=1;		} else {			$curr_month+=1;		}        $end=date('Y-m-d H:i:s',strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));	    $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);		return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_next_month(& $layout_def) {		global $timedate;		$curr_timestamp= $this->get_users_current_date_time(true);		//Get year and month from time stamp.		$curr_year=date('Y',$curr_timestamp);		$curr_month=date('m',$curr_timestamp);		if ($curr_month==12) {			$curr_month=1;			$curr_year+=1;		} else {			$curr_month+=1;		}		//get start date for next month and convert it to gmt and db format.	    $begin=date('Y-m-d H:i:s',mktime(0,0,0,$curr_month,1,$curr_year));        $begin=$timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);	    //get end date for next month  and convert it to gmt and db format.	    //first get first day of the month after and move back by 1 day.		if ($curr_month==12) {			$curr_month=1;			$curr_year+=1;		} else {			$curr_month+=1;		}        $end=date('Y-m-d H:i:s',strtotime("-1 day",(strtotime("1 month",mktime(23,59,59,$curr_month,1,$curr_year)))));	    $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);		return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_last_30_days(& $layout_def) {        $begin=$this->get_db_date(-29,'start');        $end=$this->get_db_date(0,'end');        return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_next_30_days(& $layout_def) {        $begin=$this->get_db_date(0,'start');        $end=$this->get_db_date(29,'end');        return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_last_quarter(& $layout_def) {//		return "LEFT(".$this->_get_column_select($layout_def).",10) BETWEEN (current_date + interval '1' month) AND current_date";	}	function queryFilterTP_this_quarter(& $layout_def) {	}	function queryFilterTP_last_year(& $layout_def) {		global $timedate;		$curr_timestamp= $this->get_users_current_date_time(true);		//Get year and month from time stamp.		$curr_year=date('Y',$curr_timestamp);		$curr_year-=1;		//get start date for last year and convert it to gmt and db format.	    $begin=date('Y-m-d H:i:s',mktime(0,0,0,1,1,$curr_year));        $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);	    //get end date for last year  and convert it to gmt and db format.        $end=date('Y-m-d H:i:s',mktime(23,59,59,12,31,$curr_year));	    $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);		return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_this_year(& $layout_def) {		global $timedate;		$curr_timestamp= $this->get_users_current_date_time(true);		//Get year and month from time stamp.		$curr_year=date('Y',$curr_timestamp);		//get start date for this year and convert it to gmt and db format.	    $begin=date('Y-m-d H:i:s',mktime(0,0,0,1,1,$curr_year));        $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);	    //get end date for this year  and convert it to gmt and db format.        $end=date('Y-m-d H:i:s',mktime(23,59,59,12,31,$curr_year));	    $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);		return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryFilterTP_next_year(& $layout_def) {		global $timedate;		$curr_timestamp= $this->get_users_current_date_time(true);		//Get year and month from time stamp.		$curr_year=date('Y',$curr_timestamp);		$curr_year+=1;		//get start date for this year and convert it to gmt and db format.	    $begin=date('Y-m-d H:i:s',mktime(0,0,0,1,1,$curr_year));        $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);	    //get end date for this year  and convert it to gmt and db format.        $end=date('Y-m-d H:i:s',mktime(23,59,59,12,31,$curr_year));	    $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);		return $this->get_start_end_date_filter($layout_def,$begin,$end);	}	function queryGroupBy($layout_def) {		// i guess qualifier and column_function are the same..		if (!empty ($layout_def['qualifier'])) {			$func_name = 'queryGroupBy'.$layout_def['qualifier'];			//print_r($layout_def);			//print $func_name;			if (method_exists($this, $func_name)) {				return $this-> $func_name ($layout_def)." \n";			}		}		return parent :: queryGroupBy($layout_def)." \n";	}	function queryOrderBy($layout_def) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?