PageRenderTime 57ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/src/applications/metamta/controller/receivedlist/PhabricatorMetaMTAReceivedListController.php

http://github.com/facebook/phabricator
PHP | 94 lines | 67 code | 12 blank | 15 comment | 0 complexity | b795a55289b89a29760d943b5e68a559 MD5 | raw file
Possible License(s): JSON, MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause, LGPL-2.0, MIT, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /*
  3. * Copyright 2011 Facebook, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. class PhabricatorMetaMTAReceivedListController
  18. extends PhabricatorMetaMTAController {
  19. public function processRequest() {
  20. $request = $this->getRequest();
  21. $user = $request->getUser();
  22. $pager = new AphrontPagerView();
  23. $pager->setOffset($request->getInt('page'));
  24. $pager->setURI($request->getRequestURI(), 'page');
  25. $mails = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere(
  26. '1 = 1 ORDER BY id DESC LIMIT %d, %d',
  27. $pager->getOffset(),
  28. $pager->getPageSize() + 1);
  29. $mails = $pager->sliceResults($mails);
  30. $phids = array_merge(
  31. mpull($mails, 'getAuthorPHID'),
  32. mpull($mails, 'getRelatedPHID')
  33. );
  34. $phids = array_unique(array_filter($phids));
  35. $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
  36. $rows = array();
  37. foreach ($mails as $mail) {
  38. $rows[] = array(
  39. $mail->getID(),
  40. phabricator_date($mail->getDateCreated(), $user),
  41. phabricator_time($mail->getDateCreated(), $user),
  42. $mail->getAuthorPHID()
  43. ? $handles[$mail->getAuthorPHID()]->renderLink()
  44. : '-',
  45. $mail->getRelatedPHID()
  46. ? $handles[$mail->getRelatedPHID()]->renderLink()
  47. : '-',
  48. phutil_escape_html($mail->getMessage()),
  49. );
  50. }
  51. $table = new AphrontTableView($rows);
  52. $table->setHeaders(
  53. array(
  54. 'ID',
  55. 'Date',
  56. 'Time',
  57. 'Author',
  58. 'Object',
  59. 'Message',
  60. ));
  61. $table->setColumnClasses(
  62. array(
  63. null,
  64. null,
  65. 'right',
  66. null,
  67. null,
  68. 'wide',
  69. ));
  70. $panel = new AphrontPanelView();
  71. $panel->setHeader('Received Mail');
  72. $panel->setCreateButton('Test Receiver', '/mail/receive/');
  73. $panel->appendChild($table);
  74. $panel->appendChild($pager);
  75. return $this->buildStandardPageResponse(
  76. $panel,
  77. array(
  78. 'title' => 'Received Mail',
  79. 'tab' => 'received',
  80. ));
  81. }
  82. }