Event.class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. // $event = new Event();
  3. // $event->setTime(time());
  4. // $event->setRepeat(2);
  5. // $event->setContent($sayHello);
  6. // $event->save();
  7. class Event extends SQLiteEntity{
  8. protected $id,$name,$content,$year,$month,$day,$hour,$minut,$repeat,$recipients,$state;
  9. protected $TABLE_NAME = 'event';
  10. protected $CLASS_NAME = 'Event';
  11. protected $object_fields =
  12. array(
  13. 'id'=>'key',
  14. 'name'=>'string',
  15. 'content'=>'longstring',
  16. 'year'=>'string',
  17. 'month'=>'string',
  18. 'day'=>'string',
  19. 'hour'=>'string',
  20. 'minut'=>'string',
  21. 'repeat'=>'string',
  22. 'state'=>'int',
  23. 'recipients'=>'longstring'
  24. );
  25. function __construct(){
  26. parent::__construct();
  27. // $this->time = time();
  28. // $this->repeat = '1';
  29. // $this->name = 'Evenement sans titre du '.date('d/m/Y H:i:s');
  30. // $this->setRecipients(array());
  31. }
  32. function setId($id){
  33. $this->id= $id;
  34. }
  35. function getId(){
  36. return $this->id;
  37. }
  38. function setState($state){
  39. $this->state= $state;
  40. }
  41. function getState(){
  42. return $this->state;
  43. }
  44. function setYear($year){
  45. $this->year= $year;
  46. }
  47. function getYear(){
  48. return $this->year;
  49. }
  50. function setMonth($month){
  51. $this->month= $month;
  52. }
  53. function getMonth(){
  54. return $this->month;
  55. }
  56. function setDay($day){
  57. $this->day= $day;
  58. }
  59. function getDay(){
  60. return $this->day;
  61. }
  62. function setHour($hour){
  63. $this->hour= $hour;
  64. }
  65. function getHour(){
  66. return $this->hour;
  67. }
  68. function setMinut($minut){
  69. $this->minut= $minut;
  70. }
  71. function getMinut(){
  72. return $this->minut;
  73. }
  74. function setName($name){
  75. $this->name= $name;
  76. }
  77. function getName(){
  78. return $this->name;
  79. }
  80. function setContent($content){
  81. $this->content= json_encode($content);
  82. }
  83. function getContent(){
  84. return json_decode($this->content,true);
  85. }
  86. function setRepeat($repeat){
  87. $this->repeat= $repeat;
  88. }
  89. function getRepeat(){
  90. return $this->repeat;
  91. }
  92. function addRecipient($recipient){
  93. $recipients = $this->getRecipients();
  94. $recipients[] = $recipient;
  95. $this->setRecipients($recipients);
  96. }
  97. function setRecipients($recipients){
  98. $this->recipients= json_encode($recipients);
  99. }
  100. function getRecipients(){
  101. $rec = json_decode($this->recipients,true);
  102. return is_array($rec)?$rec:array();
  103. }
  104. public static function emit($event, $data) {
  105. if(isset($GLOBALS['events'][$event])) {
  106. foreach($GLOBALS['events'][$event] as $functionName) {
  107. call_user_func_array($functionName, $data);
  108. }
  109. }
  110. }
  111. public static function on($event, $functionName) {
  112. $GLOBALS['events'][$event][] = $functionName;
  113. }
  114. public static function announce($event, $comment,$dataDescription) {
  115. $GLOBALS['eventsDictionnary'][$event]['comment'] = $comment;
  116. $GLOBALS['eventsDictionnary'][$event]['data'] = $dataDescription;
  117. }
  118. public static function availables($event, $comment) {
  119. return $GLOBALS['eventsDictionnary'];
  120. }
  121. }
  122. ?>