/
IPSTimerEvent.class.php
135 lines (122 loc) · 2.79 KB
/
IPSTimerEvent.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?
/**
* IPS Timer Event class
*
* This configures ips timer events and manages them
* This is just a simple capsulation allowing recurring cyclic events every x seconds.
*
* !!Other features are not implemented yet!!
*
* @link https://github.com/florianprobst/ips-library project website
*
* @author Florian Probst <florian.probst@gmx.de>
*
* @license GNU
* GNU General Public License, version 3
*/
/**
* class IPSTimerEvent
*/
class IPSTimerEvent{
/**
* ips id of the event
*
* @var int
* @access private
*/
protected $id;
/**
* name of the event
*
* @var string
* @access private
*/
protected $name;
/**
* id of the events parent
* this defines where the event will be created
*
* @var int
* @access private
*/
protected $parentId;
/**
* event cycle in seconds
* this defines in which interval this event occurs (currently only a simple second interval is supported!)
*
* @var int
* @access private
*/
protected $cycle;
/**
* debug information
* enables debug information for this class
*
* @var boolean
* @access private
*/
private $debug;
/**
* constructor
*
* @throws Exception if $type is not valid
* @access public
*/
public function __construct($parentId, $name, $cycle, $debug = false){
$this->parentId = $parentId;
$this->name = $name;
$this->cycle = $cycle;
$this->debug = $debug;
$this->id = @IPS_GetEventIDByName($this->name, $this->parentId);
//check if event does already exist
if($this->id == false){
if($this->debug) echo "INFO - create IPS event $name\n";
$this->id = IPS_CreateEvent(1); //create trigger event and store id
IPS_SetName($this->id, $this->name); //set event name
IPS_SetParent($this->id, $this->parentId); //move event to parent (this will be called when trigger occurs)
IPS_SetEventCyclic($this->id, 0, 1, 0, 0, 1, $cycle); //every $cycle seconds
IPS_SetInfo($this->id, "this event was created by script " . $_IPS['SELF'] . " which is part of the ips-library (https://github.com/florianprobst/ips-library)");
$this->activate();
}
}
/**
* getName
*
* @return $string event name
* @access public
*/
public function getName(){
return $this->name;
}
/**
* activate
* enables this event
*
* @access public
*/
public function activate(){
$time = time();
IPS_SetEventCyclicTimeFrom($this->id, intval(date('H', $time)), intval (date('i', $time)), intval(date('s', $time)));
//IPS_SetEventCyclicTimeFrom($this->id, 16, 06, 32);
return IPS_SetEventActive($this->id, true);
}
/**
* disable
* disables this event
*
* @access public
*/
public function disable(){
return IPS_SetEventActive($this->id, false);
}
/**
* delete
* deletes this event
*
* @access public
*/
public function delete(){
return IPS_DeleteEvent($this->id);
}
}
?>