| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 | 
							- <?php
 
- /**
 
-  * Define a planning event.
 
-  * @author Julien NARBONI
 
-  * @category Plugin
 
-  * @license copyright
 
-  */
 
- class PlanningEvent extends Entity{
 
- 	public $id,$label,$type,$startDate,$endDate,$description,$street,$city,$zip,$planning,$notificationNumber,$notificationUnity,$notificationState,
 
- 		$repeatType,
 
- 		$repeatDailyNumber,
 
- 		$repeatWeeklyDay,
 
- 		$repeatMonthlyNumber,
 
- 		$repeatMonthlyDay, 
 
- 		$repeatYearlyNumber, 
 
- 		$repeatYearlyMonth, 
 
- 		$repeatUntil, 
 
- 		$repeatOccurence;
 
- 	protected $TABLE_NAME = 'planning_event';
 
- 	public $links = array(
 
- 		'planning' => 'Planning',
 
- 		'type' => 'PlanningEventType',
 
- 	);
 
- 	public $fields =
 
- 	array(
 
- 		'id' => 'key',
 
- 		'label' => 'string',
 
- 		'type' => 'int',
 
- 		'startDate' => 'date',
 
- 		'endDate' => 'date',
 
- 		'description' => 'longstring',
 
- 		'street' => 'string',
 
- 		'city' => 'string',
 
- 		'zip' => 'string',
 
- 		'planning' => 'int',
 
- 		'notificationNumber' => 'int',
 
- 		'notificationState' => 'string',
 
- 		'notificationUnity' => 'string',
 
- 		'repeatType' => 'string',
 
- 		'repeatDailyNumber' => 'int',
 
- 		'repeatWeeklyDay' => 'string',
 
- 		'repeatMonthlyNumber' => 'int',
 
- 		'repeatMonthlyDay' => 'int',
 
- 		'repeatYearlyNumber' => 'int',
 
- 		'repeatYearlyMonth' => 'int',
 
- 		'repeatUntil' => 'string',
 
- 		'repeatOccurence' => 'int'
 
- 	);
 
- 	const NOTIFIED = 'notified';
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 		$this->notificationNumber = 0;
 
- 	}
 
- 	public static function getAll($user,$ranks,$plannings,$start = null,$end = null){
 
- 		require_once(__DIR__.SLASH.'Planning.class.php');
 
- 		require_once(__DIR__.SLASH.'PlanningShare.class.php');
 
- 		require_once(__DIR__.SLASH.'PlanningEventType.class.php');
 
- 		if(!isset($start)) $start = strtotime('-1month');
 
- 		if(!isset($end)) $end = strtotime('+1month');
 
- 		$types = array();
 
- 		foreach(PlanningEventType::getAll() as $type){
 
- 			$types[$type->id] = $type;
 
- 		}
 
- 		$rankIds = array();
 
- 		foreach ($ranks as $rank) {
 
- 			if($rank->id==0) continue;
 
- 			$rankIds[] = $rank->id;
 
- 		}
 
- 		$allowedPlannings = array();
 
- 		$sql = 'SELECT * FROM {{table}} p WHERE p.owner = ? OR p.id IN(SELECT s.planning FROM '.PlanningShare::tableName().' s WHERE (recipient = ? AND recipientEntity="user") ';
 
- 		
 
- 		if(count($rankIds)>0) $sql .= ' OR (recipient IN('.implode(',',$rankIds).') AND recipientEntity="rank" )';
 
- 		
 
- 		$sql .= ')';
 
- 		foreach(Planning::staticQuery($sql,array($user,$user)) as $row){
 
- 			$allowedPlannings[] = $row['id'];
 
- 		}
 
- 		$originalPlannings = $plannings;
 
- 		foreach ($plannings as $key=>$id) {
 
- 			if(!in_array($id, $allowedPlannings)) unset($plannings[$key]);
 
- 		}
 
- 		$query = 'SELECT e.*,p.id AS '.Planning::tableName().'_join_id,p.color AS '.Planning::tableName().'_join_color FROM {{table}} e LEFT JOIN '.Planning::tableName().' p ON e.planning=p.id WHERE ((startDate BETWEEN ? AND ?) OR (endDate BETWEEN ? AND ?) OR (startDate<? && endDate>?)) AND planning IN('.implode(',',$plannings).')';
 
- 		$events = array();
 
- 		foreach(self::staticQuery($query,array($start,$end,$start,$end,$start,$end),true,1) as $event){
 
- 			$event->type = isset($types[$event->type]) ? $types[$event->type] : new PlanningEventType();
 
- 			$event->planning = $event->join('planning');
 
- 			$events[] = $event;
 
- 		}
 
- 		Plugin::callHook('planning_event_search',array(&$events,$originalPlannings,$start,$end));
 
- 		return $events;
 
- 	}
 
- 	public static function removeAll($user,$events){
 
- 		
 
- 	
 
- 		
 
- 		require_once(__DIR__.SLASH.'PlanningShare.class.php');
 
- 		require_once(__DIR__.SLASH.'Planning.class.php');
 
- 		
 
- 		$events = self::staticQuery('SELECT e.*,p.id AS '.Planning::tableName().'_join_id,p.owner AS '.Planning::tableName().'_join_owner FROM {{table}} e LEFT JOIN '.Planning::tableName().' p ON p.id=e.planning  WHERE e.id IN ('.implode(',',$events).')',array(),true,1);
 
- 		$errors = array();
 
- 		foreach ($events as $event) {
 
- 			$planning = $event->join('planning');
 
- 			if($planning->owner != $user){
 
- 				if(PlanningShare::rowCount(array('planning'=>$planning->id,'edit'=>1,'recipient'=>$user))==0) {
 
- 					$errors[] = $event->id;
 
- 					continue;
 
- 				}
 
- 			}
 
- 			self::deleteById($event->id);
 
- 		}
 
- 		return $errors;
 
- 	}
 
- 	public function address(){
 
- 		if($this->street=='') return '';
 
- 		return $this->street.', '.$this->zip.' '.$this->city;
 
- 	}
 
- }
 
- ?>
 
 
  |