Event.class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /*
  3. @nom: Event
  4. @auteur: Idleman (idleman@idleman.fr)
  5. @description: Classe de gestion des évenements/news liés a chaques flux RSS/ATOM
  6. */
  7. class Event extends MysqlEntity{
  8. protected $id,$title,$guid,$content,$description,$pudate,$link,$feed,$category,$creator,$unread,$favorite;
  9. protected $TABLE_NAME = 'event';
  10. protected $CLASS_NAME = 'Event';
  11. protected $object_fields =
  12. array(
  13. 'id'=>'key',
  14. 'guid'=>'longstring',
  15. 'title'=>'string',
  16. 'creator'=>'string',
  17. 'content'=>'extralongstring',
  18. 'description'=>'longstring',
  19. 'link'=>'longstring',
  20. 'unread'=>'integer',
  21. 'feed'=>'integer',
  22. 'unread'=>'integer',
  23. 'favorite'=>'integer',
  24. 'pubdate'=>'integer',
  25. 'syncId'=>'integer',
  26. );
  27. protected $object_fields_index =
  28. array(
  29. 'feed'=>'index',
  30. 'unread'=>'index',
  31. 'favorite'=>'index'
  32. );
  33. function __construct($guid=null,$title=null,$description=null,$content=null,$pubdate=null,$link=null,$category=null,$creator=null){
  34. $this->guid = $guid;
  35. $this->title = $title;
  36. $this->creator = $creator;
  37. $this->content = $content;
  38. $this->description = $description;
  39. $this->pubdate = $pubdate;
  40. $this->link = $link;
  41. $this->category = $category;
  42. parent::__construct();
  43. }
  44. function getEventCountPerFolder(){
  45. $events = array();
  46. $results = $this->customQuery('SELECT COUNT('.MYSQL_PREFIX.$this->TABLE_NAME.'.id),'.MYSQL_PREFIX.'feed.folder FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' INNER JOIN '.MYSQL_PREFIX.'feed ON ('.MYSQL_PREFIX.'event.feed = '.MYSQL_PREFIX.'feed.id) WHERE '.MYSQL_PREFIX.$this->TABLE_NAME.'.unread=1 GROUP BY '.MYSQL_PREFIX.'feed.folder');
  47. while($item = mysql_fetch_array($results)){
  48. $events[$item[1]] = $item[0];
  49. }
  50. return $events;
  51. }
  52. function getEventCountNotVerboseFeed(){
  53. $results = $this->customQuery('SELECT COUNT(1) FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' INNER JOIN '.MYSQL_PREFIX.'feed ON ('.MYSQL_PREFIX.'event.feed = '.MYSQL_PREFIX.'feed.id) WHERE '.MYSQL_PREFIX.$this->TABLE_NAME.'.unread=1 AND '.MYSQL_PREFIX.'feed.isverbose=0');
  54. while($item = mysql_fetch_array($results)){
  55. $nbitem = $item[0];
  56. }
  57. return $nbitem;
  58. }
  59. function getEventsNotVerboseFeed($start=0,$limit=10000,$order,$columns='*'){
  60. $eventManager = new Event();
  61. $objects = array();
  62. $results = $this->customQuery('SELECT '.$columns.' FROM '.MYSQL_PREFIX.'event INNER JOIN '.MYSQL_PREFIX.'feed ON ('.MYSQL_PREFIX.'event.feed = '.MYSQL_PREFIX.'feed.id) WHERE '.MYSQL_PREFIX.'event.unread=1 AND '.MYSQL_PREFIX.'feed.isverbose = 0 ORDER BY '.$order.' LIMIT '.$start.','.$limit);
  63. if($results!=false){
  64. while($item = mysql_fetch_array($results)){
  65. $object = new Event();
  66. foreach($object->getObject_fields() as $field=>$type){
  67. $setter = 'set'.ucFirst($field);
  68. if(isset($item[$field])) $object->$setter($item[$field]);
  69. }
  70. $objects[] = $object;
  71. unset($object);
  72. }
  73. }
  74. return $objects;
  75. }
  76. function setId($id){
  77. $this->id = $id;
  78. }
  79. function getCreator(){
  80. return $this->creator;
  81. }
  82. function setCreator($creator){
  83. $this->creator = $creator;
  84. }
  85. function getCategory(){
  86. return $this->category;
  87. }
  88. function setCategory($category){
  89. $this->category = $category;
  90. }
  91. function getDescription(){
  92. return $this->description;
  93. }
  94. function setDescription($description,$encoding = true){
  95. $this->description = $description;
  96. }
  97. function getPubdate($format=false){
  98. if($this->pubdate!=0){
  99. return ($format!=false?date($format,$this->pubdate):$this->pubdate);
  100. }else{
  101. return '';
  102. }
  103. }
  104. function getPubdateWithInstant($instant){
  105. $alpha = $instant - $this->pubdate;
  106. if ($alpha < 86400 ){
  107. $hour = floor($alpha/3600);
  108. $alpha = ($hour!=0?$alpha-($hour*3600):$alpha);
  109. $minuts = floor($alpha/60);
  110. return 'il y a '.($hour!=0?$hour.'h et':'').' '.$minuts.'min';
  111. }else{
  112. return 'le '.$this->getPubdate('d/m/Y à H:i:s');
  113. }
  114. }
  115. function setPubdate($pubdate){
  116. $this->pubdate = (is_numeric($pubdate)?$pubdate:strtotime($pubdate));
  117. }
  118. function getLink(){
  119. return $this->link;
  120. }
  121. function setLink($link){
  122. $this->link = $link;
  123. }
  124. function getId(){
  125. return $this->id;
  126. }
  127. function getTitle(){
  128. return $this->title;
  129. }
  130. function setTitle($title){
  131. $this->title = $title;
  132. }
  133. function getContent(){
  134. return $this->content;
  135. }
  136. function setContent($content,$encoding=true){
  137. $this->content = $content;
  138. }
  139. function getGuid(){
  140. return $this->guid;
  141. }
  142. function setGuid($guid){
  143. $this->guid = $guid;
  144. }
  145. function getSyncId(){
  146. return $this->syncId;
  147. }
  148. function setSyncId($syncId){
  149. $this->syncId = $syncId;
  150. }
  151. function getUnread(){
  152. return $this->unread;
  153. }
  154. function setUnread($unread){
  155. $this->unread = $unread;
  156. }
  157. function setFeed($feed){
  158. $this->feed = $feed;
  159. }
  160. function getFeed(){
  161. return $this->feed;
  162. }
  163. function setFavorite($favorite){
  164. $this->favorite = $favorite;
  165. }
  166. function getFavorite(){
  167. return $this->favorite;
  168. }
  169. }
  170. ?>