/plugins/LatestComment/class.latestcommentmodule.php

https://github.com/ru4/arabbnota · PHP · 66 lines · 61 code · 4 blank · 1 comment · 8 complexity · cb2bc9f7fcf0f7900c73e965a8516064 MD5 · raw file

  1. <?php if (!defined('APPLICATION')) exit();
  2. class LatestCommentModule extends Gdn_Module {
  3. protected $_LatestComments;
  4. public function __construct(&$Sender = '') {
  5. parent::__construct($Sender);
  6. }
  7. public function GetAllDiscussion(){
  8. $SQL = Gdn::SQL();
  9. return $SQL->Select('p.DiscussionID, p.CategoryID, p.Name, p.Body, p.DateLastComment, p.LastCommentUserID, p.CountComments')->From('Discussion p')->OrderBy('p.DateLastComment', 'desc')->Get()->ResultArray();
  10. }
  11. public function GetData() {
  12. $SQL = Gdn::SQL();
  13. $Limit = Gdn::Config('LatestComment.Limit');
  14. $LatestOrMost = Gdn::Config('LatestComment.LatestOrMost');
  15. $Limit = (!$Limit || $Limit ==0)?10:$Limit;
  16. $Session = Gdn::Session();
  17. if($LatestOrMost == "YES")
  18. {
  19. $this->_LatestComments = $SQL->Query('SELECT DiscussionID, CategoryID, Name, Body, DateLastComment, LastCommentUserID, CountComments From '.$SQL->Database->DatabasePrefix.'Discussion order by DateLastComment desc LIMIT '.$Limit);
  20. }
  21. else
  22. {
  23. $this->_LatestComments = $SQL->Query('SELECT DiscussionID, CategoryID, Name, Body, DateLastComment, LastCommentUserID, CountComments From '.$SQL->Database->DatabasePrefix.'Discussion order by DateLastComment desc LIMIT '.$Limit);
  24. }
  25. }
  26. public function getLatestComments(){
  27. return $this->_LatestComments;
  28. }
  29. public function AssetTarget() {
  30. return 'Panel';
  31. }
  32. public function ToString() {
  33. $String = '';
  34. $Session = Gdn::Session();
  35. ob_start();
  36. $LatestOrMost = Gdn::Config('LatestComment.Show.LatestComment');
  37. //Hide the top poster box id there's no post greater than 0
  38. if($this->_LatestComments->NumRows() > 0) {
  39. ?>
  40. <div id="LatestComment" class="Box BoxLatestComment">
  41. <h4><?php if($LatestOrMost == "YES") echo Gdn::Translate("Latest Commented"); else echo Gdn::Translate("Most Commented"); ?></h4>
  42. <ul class="PanelInfo PanelLatestComment">
  43. <?php
  44. $i =1;
  45. foreach($this->_LatestComments->Result() as $Discussion) {
  46. ?>
  47. <li><span><strong>
  48. <a href="/Discussion/<?php echo $Discussion->DiscussionID; ?>/<?php echo str_replace(" ", "-",$Discussion->Name); ?>"><?php echo $Discussion->Name; ?></a>
  49. </span></strong></li>
  50. <?php
  51. $i++;
  52. }
  53. ?>
  54. </ul>
  55. </div>
  56. <?php
  57. }
  58. $String = ob_get_contents();
  59. @ob_end_clean();
  60. return $String;
  61. }
  62. }