class_DateBC.inc.php 7.79 KB
<?php
/**
 * @file	class_DateBC.inc.php
 * @category freeSN
 * @mailto	code [at] netz.coop
 * @version 0.4.200901
 * @link http://netz.coop
 * 
 *  @copyright Copyright by netz.coop e.G. 2015
 *  
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
/**
 *  Klasse realisiert den Kalender für das losp Projekt
 *
 *	@version 		0.2.080319
 *	@author 		dev [at] mensch [dot] coop
 */
class DateBC extends BasisClipboard  {
	protected $Start;
	protected $End;

	protected function &loadObject(Account &$param_HostAccount, iStorable &$param_iStorable, $param_State=null, array $param_ConditionArray=null) {

		if(!array_key_exists('operator',$param_ConditionArray) && !array_key_exists('secConditionArrays',$param_ConditionArray)){
			if(array_key_exists('OrderByDefault',$param_ConditionArray)) {
				$tmp=$param_ConditionArray['OrderByDefault'];
			} else {
				$tmp=CONFIG::getSQL_Data('DateBE', 'OrderByDefault');
			}

			$param_ConditionArray['operator']=$tmp['operator'];
			$param_ConditionArray['column']=$tmp['column'];

			if(!array_key_exists('from', $tmp)){
				$tmp_value=ListCondition::calculateSpecialValue($tmp['special'], null, true);
			} else {
				$tmp_value['Value']=$tmp['from'][0];
			}

			$param_ConditionArray['from']['0']=$tmp_value['Value'];

			if(count($tmp['column'])>1) {
				$param_ConditionArray['from']['1']=ListCondition::calculateSpecialValue($tmp['special'],null,false);
			}

		}
		if(array_key_exists('OrderByDefault',$param_ConditionArray) && array_key_exists('limit',$param_ConditionArray['OrderByDefault'])) {
			$param_ConditionArray['limit']=$param_ConditionArray['OrderByDefault']['limit'];
		} else {
			$param_ConditionArray['limit']=CONFIG::getDisplayLimits('SideDateBC');
		}

		$param_ConditionArray['secConditionArrays'][0]['nexus']='OR';
		$param_ConditionArray['secConditionArrays'][0]['column'][0]='Cycle';
		$param_ConditionArray['secConditionArrays'][0]['operator']='!=';
		$param_ConditionArray['secConditionArrays'][0]['from'][0]='NULL';

		$this->Start = $param_ConditionArray['from']['0'];

		if(is_array($param_ConditionArray['from']) && array_key_exists('1', $param_ConditionArray['from'])) {
			$this->End = $param_ConditionArray['from']['1'];
		}

		return parent::loadObject($param_HostAccount, $param_iStorable, $param_State, $param_ConditionArray);

	}
	/**
	 * static functions return a domelement with all days between the two timestamps
	 *
	 * @param DOMDocument $param_DOMDocument
	 * @param int param_start timestamp
	 * @param int param_end timestamp
	 */
	public static function getCalendarDays(DOMDocument $param_DOMDocument,$param_start,$param_end,$param_dateList = null){
		$DOMElementDays = $param_DOMDocument->createElement('CalendarDays');
		if($param_start < $param_end){
			$var_dayStamp = $param_start;
			$var_day = date('d',$param_start);
			$var_month = date('m',$param_start);
			$var_year = date('y',$param_start);
			$var_hour = date('H',$param_start);
			$var_minute = date('m',$param_start);

			while($var_dayStamp <= $param_end){
				$DOMElementDay = $param_DOMDocument->createElement('Day');
				$DOMElementDay->setAttribute('timestamp',$var_dayStamp);
				$DOMElementDay->setAttribute('day',date('d',$var_dayStamp));
				$DOMElementDay->setAttribute('month',date('m',$var_dayStamp));
				$DOMElementDay->setAttribute('year',date('y',$var_dayStamp));
				$DOMElementDay->setAttribute('hour',date('H',$var_dayStamp));
				$DOMElementDay->setAttribute('minute',date('i',$var_dayStamp));
				$DOMElementDay->setAttribute('weekday',date('N',$var_dayStamp));

				foreach($param_dateList as $key => $value){
					if($value[1]<$var_dayStamp+86400 && $value[2]>$var_dayStamp){
						$DOMElementDateHit = $param_DOMDocument->createElement('DateHit',$value[0]);
						$DOMElementDateHit->setAttribute('entryNr',$key+1);
						$DOMElementDay->appendChild($DOMElementDateHit);
					}
				}

				$DOMElementDays->appendChild($DOMElementDay);
				$var_day += 1;
				$var_dayStamp = mktime($var_hour, $var_minute, 0, $var_month, $var_day, $var_year);
			}
		}
		return $DOMElementDays;
	}
	public function getObjDOMElementSpecial(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf=null, array $param_DOMElemente=null, $param_CallbackFnc=null, $param_LastFormular=false, $param_edit = false, &$param_XMLElement) {

		$var_dateList = array();
		$var_idList = array();
		$var_startList = array();
		$var_endList = array();
		foreach($this->AttachIDList as $key => $value){
			foreach($this->get($param_HostAccount,$param_iStorable,$key)->getCycleDateArray($this->Start,$this->End) as $single_array){
				array_push($var_dateList,$single_array);
				array_push($var_idList,$single_array[0]);
				array_push($var_startList,$single_array[1]);
				array_push($var_endList,$single_array[2]);
			}
		}

		array_multisort($var_startList, SORT_ASC, $var_endList, SORT_ASC, $var_dateList);


		$DOMElementCalendar = $param_DOMDocument->createElement('Calendar');
		$DOMElementEntrys = $param_DOMDocument->createElement('Entrys');

		$DOMElementCalendar->setAttribute('today',time());



		$DOMElementCalendar->setAttribute('month',date('m',$this->Start + (($this->End - $this->Start)*1/2)));
		$DOMElementCalendar->setAttribute('year',date('Y',$this->Start + (($this->End - $this->Start)*1/2)));
		//D::show($var_dateList,'$var_dateList');
		foreach($var_dateList as $entry){
			$DOMElementEntry = $param_DOMDocument->createElement('Entry',$entry[0]);
			$DOMElementEntry->setAttribute('be_id',$entry[0]);
			$DOMElementEntry->setAttribute('start',$entry[1]);
			$DOMElementEntry->setAttribute('end',$entry[2]);

			$DOMElementEntry->setAttribute('startDay',date('d',$entry[1]));
			$DOMElementEntry->setAttribute('startMonth',date('m',$entry[1]));
			$DOMElementEntry->setAttribute('startYear',date('y',$entry[1]));
			$DOMElementEntry->setAttribute('startHour',date('H',$entry[1]));
			$DOMElementEntry->setAttribute('startMinute',date('i',$entry[1]));
			$DOMElementEntry->setAttribute('startWeekday',date('N',$entry[1]));

			if($entry[1] != $entry[2]){
				$DOMElementEntry->setAttribute('endDay',date('d',$entry[2]));
				$DOMElementEntry->setAttribute('endMonth',date('m',$entry[2]));
				$DOMElementEntry->setAttribute('endYear',date('y',$entry[2]));
				$DOMElementEntry->setAttribute('endHour',date('H',$entry[2]));
				$DOMElementEntry->setAttribute('endMinute',date('i',$entry[2]));
				$DOMElementEntry->setAttribute('endWeekday',date('N',$entry[2]));
			}
			$DOMElementEntrys->appendChild($DOMElementEntry);
		}
		$DOMElementCalendar->appendChild($DOMElementEntrys);
		$DOMElementCalendar->appendChild(self::getCalendarDays($param_DOMDocument,$this->Start,$this->End,$var_dateList));

		$param_XMLElement->appendChild($DOMElementCalendar);
	}
	public function getObjDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf=null, array $param_DOMElemente=null, $param_CallbackFnc=null, $param_LastFormular=false, $param_edit = false) {


		$DOMElement = parent::getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf, $param_DOMElemente, $param_CallbackFnc, $param_LastFormular,$param_edit);


		$DOMElement->setAttribute('start', $this->Start);
		$DOMElement->setAttribute('end', $this->End);

		return $DOMElement;
	}
}
?>