You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.2 KiB

  1. <?php
  2. namespace modl;
  3. class MessageDAO extends ModlSQL {
  4. function set(Message $message) {
  5. $this->_sql = '
  6. insert into message
  7. (
  8. session,
  9. jidto,
  10. jidfrom,
  11. ressource,
  12. type,
  13. subject,
  14. thread,
  15. body,
  16. html,
  17. published,
  18. delivered)
  19. values(
  20. :session,
  21. :jidto,
  22. :jidfrom,
  23. :ressource,
  24. :type,
  25. :subject,
  26. :thread,
  27. :body,
  28. :html,
  29. :published,
  30. :delivered
  31. )';
  32. $this->prepare(
  33. 'Message',
  34. array(
  35. 'session' => $this->_user,
  36. 'jidto' => $message->jidto,
  37. 'jidfrom' => $message->jidfrom,
  38. 'ressource' => $message->ressource,
  39. 'type' => $message->type,
  40. 'subject' => $message->subject,
  41. 'thread' => $message->thread,
  42. 'body' => $message->body,
  43. 'html' => $message->html,
  44. 'published' => $message->published,
  45. 'delivered' => $message->delivered
  46. )
  47. );
  48. return $this->run('Message');
  49. }
  50. function getContact($jid, $limitf = false, $limitr = false) {
  51. $this->_sql = '
  52. select * from message
  53. where session = :session
  54. and (jidfrom = :jidfrom
  55. or jidto = :jidto)
  56. order by published desc';
  57. if($limitr)
  58. $this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf;
  59. $this->prepare(
  60. 'Message',
  61. array(
  62. 'session' => $this->_user,
  63. 'jidfrom' => $jid,
  64. 'jidto' => $jid
  65. )
  66. );
  67. return $this->run('Message');
  68. }
  69. function deleteContact($jid) {
  70. $this->_sql = '
  71. delete from message
  72. where jidfrom = :jidfrom
  73. or jidto = :jidto';
  74. $this->prepare(
  75. 'Message',
  76. array(
  77. 'jidfrom' => $jid,
  78. 'jidto' => $jid
  79. )
  80. );
  81. return $this->run('Message');
  82. }
  83. function clearMessage() {
  84. $this->_sql = '
  85. delete from message
  86. where session = :session';
  87. $this->prepare(
  88. 'Message',
  89. array(
  90. 'session' => $this->_user
  91. )
  92. );
  93. return $this->run('Message');
  94. }
  95. function getStatistics() {
  96. $this->_sql = '
  97. select count(*) as count, extract(month from published) as month, extract(year from published) as year
  98. from message
  99. where session = :session
  100. group by month, year order by year, month';
  101. $this->prepare(
  102. 'Message',
  103. array(
  104. 'session' => $this->_user
  105. )
  106. );
  107. return $this->run(null, 'array');
  108. }
  109. }