1<?php
2
3/**
4 * Copyright Intermesh
5 *
6 * This file is part of Group-Office. You should have received a copy of the
7 * Group-Office license along with Group-Office. See the file /LICENSE.TXT
8 *
9 * If you have questions write an e-mail to info@intermesh.nl
10 *
11 * @version $Id: Exception.php 7607 2011-09-16 11:24:50Z <<USERNAME>> $
12 * @copyright Copyright Intermesh
13 * @author <<FIRST_NAME>> <<LAST_NAME>> <<EMAIL>>@intermesh.nl
14 */
15
16/**
17 * The Exception model
18 *
19 * @property int $id
20 * @property int $event_id
21 * @property int $time The time of the day of the exception. Use getStartTime() for the acurate time.
22 * @property int $exception_event_id
23 */
24
25namespace GO\Calendar\Model;
26
27
28class Exception extends \GO\Base\Db\ActiveRecord {
29
30
31
32	protected function init() {
33		parent::init();
34
35		$this->columns['time']['required'] = true;
36	}
37
38	/**
39	 * Enable this function if you want this model to check the acl's automatically.
40	 */
41	// public function aclField(){
42	//	 return 'acl_id';
43	// }
44
45	/**
46	 * Returns the table name
47	 */
48	public function tableName() {
49		return 'cal_exceptions';
50	}
51
52	/**
53	 * Here you can define the relations of this model with other models.
54	 * See the parent class for a more detailed description of the relations.
55	 */
56	public function relations() {
57		return array(
58				'event' => array('type' => self::BELONGS_TO, 'model' => 'GO\Calendar\Model\Event', 'field' => 'exception_event_id'),
59				'mainevent' => array('type' => self::BELONGS_TO, 'model' => 'GO\Calendar\Model\Event', 'field' => 'event_id')
60		);
61	}
62
63	protected function afterSave($wasNew) {
64
65		if ($this->mainevent){
66			$this->mainevent->touch();
67			$this->mainevent->setReminder();
68		}
69
70		return parent::afterSave($wasNew);
71	}
72
73	/**
74	 * Get's the start time of the exception based on the actual master event
75	 * start time. The time entry just contains the date.
76	 *
77	 * @return int
78	 */
79	public function getStartTime(){
80		return \GO\Base\Util\Date::clear_time($this->time, date('H',$this->mainevent->start_time), date('i',$this->mainevent->start_time));
81	}
82
83}
84