Event.class.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /*
  3. @nom: Event
  4. @auteur: Idleman (http://blog.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 $object_fields =
  11. array(
  12. 'id'=>'key',
  13. 'guid'=>'longstring',
  14. 'title'=>'string',
  15. 'creator'=>'string',
  16. 'content'=>'extralongstring',
  17. 'description'=>'longstring',
  18. 'link'=>'longstring',
  19. 'unread'=>'integer',
  20. 'feed'=>'integer',
  21. 'unread'=>'integer',
  22. 'favorite'=>'integer',
  23. 'pubdate'=>'integer',
  24. 'syncId'=>'integer',
  25. );
  26. protected $object_fields_index =
  27. array(
  28. 'feed'=>'index',
  29. 'unread'=>'index',
  30. 'favorite'=>'index'
  31. );
  32. function __construct($guid=null,$title=null,$description=null,$content=null,$pubdate=null,$link=null,$category=null,$creator=null){
  33. $this->guid = $guid;
  34. $this->title = $title;
  35. $this->creator = $creator;
  36. $this->content = $content;
  37. $this->description = $description;
  38. $this->pubdate = $pubdate;
  39. $this->link = $link;
  40. $this->category = $category;
  41. parent::__construct();
  42. }
  43. function getEventCountPerFolder(){
  44. $events = array();
  45. $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`');
  46. while($item = $results->fetch_array()){
  47. $events[$item[1]] = intval($item[0]);
  48. }
  49. return $events;
  50. }
  51. function getEventCountNotVerboseFeed(){
  52. $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');
  53. while($item = $results->fetch_array()){
  54. $nbitem = $item[0];
  55. }
  56. return $nbitem;
  57. }
  58. function getEventsNotVerboseFeed($start=0,$limit=10000,$order,$columns='*'){
  59. $eventManager = new Event();
  60. $objects = array();
  61. $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);
  62. if($results!=false){
  63. while($item = $results->fetch_array()){
  64. $object = new Event();
  65. foreach($object->getObject_fields() as $field=>$type){
  66. $setter = 'set'.ucFirst($field);
  67. if(isset($item[$field])) $object->$setter($item[$field]);
  68. }
  69. $objects[] = $object;
  70. unset($object);
  71. }
  72. }
  73. return $objects;
  74. }
  75. function setId($id){
  76. $this->id = $id;
  77. }
  78. function getCreator(){
  79. return $this->creator;
  80. }
  81. function setCreator($creator){
  82. $this->creator = $creator;
  83. }
  84. function getCategory(){
  85. return $this->category;
  86. }
  87. function setCategory($category){
  88. $this->category = $category;
  89. }
  90. function getDescription(){
  91. return $this->description;
  92. }
  93. function setDescription($description,$encoding = true){
  94. $this->description = $description;
  95. }
  96. function getPubdate($format=false){
  97. if($this->pubdate!=0){
  98. return ($format!=false?date($format,$this->pubdate):$this->pubdate);
  99. }else{
  100. return '';
  101. }
  102. }
  103. function getPubdateWithInstant($instant){
  104. if (empty($this->pubdate)) return '';
  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. if ($hour!=0) {
  111. return _t('PUBDATE_WITHINSTANT_LOWERH24',array($hour,$minuts));
  112. } else {
  113. return _t('PUBDATE_WITHINSTANT_LOWERH1',array($minuts));
  114. }
  115. }else{
  116. $date=$this->getPubdate(_t('FORMAT_DATE_HOURS'));
  117. return _t('PUBDATE_WITHINSTANT',array($date));
  118. }
  119. }
  120. function setPubdate($pubdate){
  121. $this->pubdate = (is_numeric($pubdate)?$pubdate:strtotime($pubdate));
  122. }
  123. function getLink(){
  124. return $this->link;
  125. }
  126. function setLink($link){
  127. $this->link = $link;
  128. }
  129. function getId(){
  130. return $this->id;
  131. }
  132. function getTitle(){
  133. return $this->title;
  134. }
  135. function setTitle($title){
  136. $this->title = $title;
  137. }
  138. function getContent(){
  139. return $this->content;
  140. }
  141. function setContent($content,$encoding=true){
  142. $this->content = $content;
  143. }
  144. function getGuid(){
  145. return $this->guid;
  146. }
  147. function setGuid($guid){
  148. $this->guid = $guid;
  149. }
  150. function getSyncId(){
  151. return $this->syncId;
  152. }
  153. function setSyncId($syncId){
  154. $this->syncId = $syncId;
  155. }
  156. function getUnread(){
  157. return $this->unread;
  158. }
  159. function setUnread($unread){
  160. $this->unread = $unread;
  161. }
  162. function setFeed($feed){
  163. $this->feed = $feed;
  164. }
  165. function getFeed(){
  166. return $this->feed;
  167. }
  168. function setFavorite($favorite){
  169. $this->favorite = $favorite;
  170. }
  171. function getFavorite(){
  172. return $this->favorite;
  173. }
  174. }
  175. ?>