PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/ThreadList.class.php

https://github.com/timfong888/AF-upload
PHP | 149 lines | 96 code | 18 blank | 35 comment | 13 complexity | 9d58ade82e863d0540106f9923c307bb MD5 | raw file
  1. <?php
  2. //require_once(__DATA_CLASSES__.'/Thread.class.php');
  3. class ThreadListForm extends QForm {
  4. // Declare the DataGrid
  5. protected $dtgThreads;
  6. // Private variables
  7. private $_user;
  8. private $_threadsList;
  9. protected function Form_Create() {
  10. /* grab user object from SESSION */
  11. $this->_user = unserialize($_SESSION['User']);
  12. /* Define datagrid with "From", "Date", "Subjest" and "Action" columns */
  13. $this->dtgThreads = new QDataGrid($this);
  14. $this->dtgThreads->CellPadding = 5;
  15. $this->dtgThreads->CellSpacing = 0;
  16. $this->dtgThreads->AddColumn(new QDataGridColumn(QApplication::Translate('Date'), '<?= $_FORM->RenderDateTime($_ITEM) ?>', 'HtmlEntities=false'));
  17. $this->dtgThreads->AddColumn(new QDataGridColumn(QApplication::Translate('Ally'), '<?= $_FORM->RenderAlly($_ITEM) ?>', 'HtmlEntities=false'));
  18. $this->dtgThreads->AddColumn(new QDataGridColumn(QApplication::Translate('Subject'), '<?= $_FORM->RenderSubject($_ITEM) ?>', 'HtmlEntities=false'));
  19. $this->dtgThreads->AddColumn(new QDataGridColumn(QApplication::Translate('Action'), '<?= $_FORM->Action_Render($_ITEM) ?>', 'HtmlEntities=false'));
  20. /* Obtain all threads with current user */
  21. $aid = isset($_GET['aid']) ? intval($_GET['aid']) : null;
  22. if ($aid) {
  23. $condition = QQ::OrCondition(
  24. QQ::AndCondition(
  25. QQ::Equal(QQN::Thread()->SenderUserId, $this->_user->Id),
  26. QQ::Equal(QQN::Thread()->ReceiverUserId, $aid)
  27. ),
  28. QQ::AndCondition(
  29. QQ::Equal(QQN::Thread()->SenderUserId, $aid),
  30. QQ::Equal(QQN::Thread()->ReceiverUserId, $this->_user->Id)
  31. )
  32. );
  33. } else {
  34. $condition = QQ::OrCondition(
  35. QQ::Equal(QQN::Thread()->SenderUserId, $this->_user->Id),
  36. QQ::Equal(QQN::Thread()->ReceiverUserId, $this->_user->Id)
  37. );
  38. }
  39. $this->_threadsList = Thread::QueryArray(
  40. $condition,
  41. QQ::Clause(
  42. QQ::Expand(QQN::Thread()->SenderUser),
  43. QQ::Expand(QQN::Thread()->ReceiverUser),
  44. QQ::Expand(QQN::Thread()->LastUser),
  45. QQ::OrderBy(QQN::Thread()->DateTime, false)
  46. )
  47. );
  48. /* Display threads list */
  49. $this->dtgThreads->SetDataBinder('dtgThreads_Bind');
  50. // Update the styles of all the rows, or for just specific rows
  51. // (e.g. you can specify a specific style for the header row or for alternating rows)
  52. // Note that styles are hierarchical and inherit from each other. For example, the default RowStyle
  53. // sets the FontSize as 12px, and because that attribute is not overridden in AlternateRowStyle
  54. // or HeaderRowStyle, both those styles will use the 12px Font Size.
  55. $objStyle = $this->dtgThreads->RowStyle;
  56. //$objStyle->BackColor = '#ffffff';
  57. //$objStyle->FontSize = 12;
  58. $objStyle = $this->dtgThreads->AlternateRowStyle;
  59. //$objStyle->BackColor = '#eeeeee';
  60. $objStyle = $this->dtgThreads->HeaderRowStyle;
  61. //$objStyle->ForeColor = '#ffffff';
  62. //$objStyle->BackColor = '#9900cc';
  63. $objStyle = $this->dtgThreads->GetColumn(0);
  64. $objStyle->CssClass = "col1";
  65. }
  66. public function RenderDateTime(Thread $objThread) {
  67. return $objThread->DateTime->__toString('MMMM D, YYYY') . '<br />' . $objThread->DateTime->__toString('hh:mm zz');
  68. }
  69. /* Assign an action to User profile link */
  70. public function RenderAlly(Thread $objThread) {
  71. $ally = ($this->_user->Id == $objThread->ReceiverUserId) ? $objThread->SenderUser : $objThread->ReceiverUser;
  72. $hash = md5( strtolower($ally->Username));
  73. $cssClass = $objThread->LastUser->Id != $this->_user->Id ? 'messagereceive' : '';
  74. $link = sprintf('<img src="http://www.gravatar.com/avatar?size=30&d=monsterid&gravatar_id=%s" /><a href="profile_activity.php?aid=%s" class="%s">%s</a>',$hash, $ally->Id, $cssClass, $ally->FullName);
  75. return $link;
  76. }
  77. /* Assign an action to thread link */
  78. public function RenderSubject(Thread $objThread) {
  79. $cssClass = $objThread->LastUser->Id != $this->_user->Id ? 'messagereceive' : '';
  80. if($this->_user->Id == $objThread->ReceiverUserId) {
  81. $linkUrl = 'message_send.php';
  82. $messageType = MessageType::Reply;
  83. }
  84. else {
  85. $linkUrl = ($objThread->MessageTypeId == MessageType::Send) ? 'message_send.php' : 'message_request.php';
  86. $messageType = $objThread->MessageTypeId;
  87. }
  88. // echo $objThread->MessageTypeId . ': ' . $linkUrl;
  89. // echo $objThread->MessageTypeId . ': ' . $this->_user->Id .': '. $objThread->ReceiverUserId .':' . $linkUrl. '<br>';
  90. // $messageType = $objThread->ReceiverUser->Id != $this->_user->Id ? 3 : 1;
  91. $ally = ($this->_user->Id == $objThread->ReceiverUserId) ? $objThread->SenderUser : $objThread->ReceiverUser;
  92. // $aId =
  93. $link = sprintf('<a href="%s?type=%s&aid=%s&acid=%s" class="%s">%s</a>', $linkUrl, $messageType, $ally->Id, $objThread->AccountId, $cssClass, $objThread->Subject);
  94. return $link;
  95. }
  96. /* Assign an action to "x" link */
  97. public function Action_Render(Thread $objThread) {
  98. // In order to keep track whether or not a Thread's Action has been rendered,
  99. // we will use explicitly defined control ids.
  100. $strControlId = 'actionLink' . $objThread->Id;
  101. // Let's see if the Link exists already
  102. $actionLink = $this->GetControl($strControlId);
  103. if (!$actionLink) {
  104. // Define the Link -- it's parent is the Datagrid (b/c the datagrid is the one calling
  105. // this method which is responsible for rendering the Link. Also, we must
  106. // explicitly specify the control ID
  107. $actionLink = new QLinkButton($this->dtgThreads, $strControlId);
  108. $actionLink->Text = 'X';
  109. // We'll use Control Parameters to help us identify the Thread ID
  110. $actionLink->ActionParameter = $objThread->Id;
  111. // Let's assign a server action on click
  112. $actionLink->AddAction(new QClickEvent(), new QAjaxAction('actionLink_Click'));
  113. }
  114. // Render the link. We want to *return* the contents of the rendered Link,
  115. // not display it. (The datagrid is responsible for the rendering of this column).
  116. // Therefore, we must specify "false" for the optional blnDisplayOutput parameter.
  117. return $actionLink->Render(false);
  118. }
  119. protected function dtgThreads_Bind() {
  120. $this->dtgThreads->DataSource = $this->_threadsList;
  121. }
  122. protected function actionLink_Click($strFormId, $strControlId, $strParameter) {
  123. foreach ($this->_threadsList as $key => $objThread) {
  124. if ($objThread->Id == $strParameter) {
  125. unset($this->_threadsList[$key]);
  126. }
  127. }
  128. $this->dtgThreads_Bind();
  129. }
  130. }
  131. ?>