Folder.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /*
  3. @nom: Folder
  4. @auteur: Idleman (http://blog.idleman.fr)
  5. @description: Classe de gestion des dossiers/catégories contenant les flux
  6. */
  7. class Folder extends MysqlEntity{
  8. protected $id,$name,$parent,$isopen;
  9. protected $TABLE_NAME = 'folder';
  10. protected $object_fields =
  11. array(
  12. 'id'=>'key',
  13. 'name'=>'string',
  14. 'parent'=>'integer',
  15. 'isopen'=>'integer'
  16. );
  17. function unreadCount(){
  18. $results = $this->customQuery('SELECT COUNT(`'.MYSQL_PREFIX.'event`.`id`) 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`.`folder` = '.$this->getId());
  19. $number = $results->fetch_array();
  20. return $number[0];
  21. }
  22. function getEvents($start=0,$limit=10000,$order,$columns='*',$filter=false){
  23. if(!isset($filter['unread'])) {
  24. $filter['unread'] = 1;
  25. }
  26. $filter['folder'] = $this->getId();
  27. $whereClause = $this->getWhereClause($filter,'=');
  28. $objects = array();
  29. $query =
  30. 'SELECT '.$columns.' '.
  31. 'FROM `'.MYSQL_PREFIX.'event` '.
  32. 'INNER JOIN `'.MYSQL_PREFIX.'feed` '.
  33. 'ON (`'.MYSQL_PREFIX.'event`.`feed` = `'.MYSQL_PREFIX.'feed`.`id`) '.
  34. $whereClause.' '.
  35. 'ORDER BY '.$order.' '.
  36. 'LIMIT '.$start.','.$limit;
  37. $results = $this->customQuery($query);
  38. if($results!=false){
  39. while($item = $results->fetch_array()){
  40. $object = new Event();
  41. foreach($object->getObject_fields() as $field=>$type){
  42. $setter = 'set'.ucFirst($field);
  43. if(isset($item[$field])) $object->$setter($item[$field]);
  44. }
  45. $objects[] = $object;
  46. unset($object);
  47. }
  48. }
  49. return $objects;
  50. }
  51. function __construct(){
  52. parent::__construct();
  53. }
  54. function setId($id){
  55. $this->id = $id;
  56. }
  57. function getFeeds(){
  58. $feedManager = new Feed();
  59. return $feedManager->loadAll(array('folder'=>$this->getId()),'name');
  60. }
  61. function getFolders(){
  62. $folderManager = new Folder();
  63. return $folderManager->loadAll(array('parent'=>$this->getId()));
  64. }
  65. function getId(){
  66. return $this->id;
  67. }
  68. function getName(){
  69. return $this->name;
  70. }
  71. function setName($name){
  72. $this->name = $name;
  73. }
  74. function getParent(){
  75. return $this->parent;
  76. }
  77. function setParent($parent){
  78. $this->parent = $parent;
  79. }
  80. function getIsopen(){
  81. return $this->isopen;
  82. }
  83. function setIsopen($isopen){
  84. $this->isopen = $isopen;
  85. }
  86. }
  87. ?>