[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/notification/query/ -> PhabricatorNotificationQuery.php (source)

   1  <?php
   2  
   3  /**
   4   * @task config Configuring the Query
   5   * @task exec   Query Execution
   6   */
   7  final class PhabricatorNotificationQuery
   8    extends PhabricatorCursorPagedPolicyAwareQuery {
   9  
  10    private $userPHIDs;
  11    private $keys;
  12    private $unread;
  13  
  14  
  15  /* -(  Configuring the Query  )---------------------------------------------- */
  16  
  17  
  18    public function withUserPHIDs(array $user_phids) {
  19      $this->userPHIDs = $user_phids;
  20      return $this;
  21    }
  22  
  23    public function withKeys(array $keys) {
  24      $this->keys = $keys;
  25      return $this;
  26    }
  27  
  28  
  29    /**
  30     * Filter results by read/unread status. Note that `true` means to return
  31     * only unread notifications, while `false` means to return only //read//
  32     * notifications. The default is `null`, which returns both.
  33     *
  34     * @param mixed True or false to filter results by read status. Null to remove
  35     *              the filter.
  36     * @return this
  37     * @task config
  38     */
  39    public function withUnread($unread) {
  40      $this->unread = $unread;
  41      return $this;
  42    }
  43  
  44  
  45  /* -(  Query Execution  )---------------------------------------------------- */
  46  
  47  
  48    protected function loadPage() {
  49      $story_table = new PhabricatorFeedStoryData();
  50      $notification_table = new PhabricatorFeedStoryNotification();
  51  
  52      $conn = $story_table->establishConnection('r');
  53  
  54      $data = queryfx_all(
  55        $conn,
  56        'SELECT story.*, notif.hasViewed FROM %T notif
  57           JOIN %T story ON notif.chronologicalKey = story.chronologicalKey
  58           %Q
  59           ORDER BY notif.chronologicalKey DESC
  60           %Q',
  61        $notification_table->getTableName(),
  62        $story_table->getTableName(),
  63        $this->buildWhereClause($conn),
  64        $this->buildLimitClause($conn));
  65  
  66      $viewed_map = ipull($data, 'hasViewed', 'chronologicalKey');
  67  
  68      $stories = PhabricatorFeedStory::loadAllFromRows(
  69        $data,
  70        $this->getViewer());
  71  
  72      foreach ($stories as $key => $story) {
  73        $story->setHasViewed($viewed_map[$key]);
  74      }
  75  
  76      return $stories;
  77    }
  78  
  79    private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  80      $where = array();
  81  
  82      if ($this->userPHIDs !== null) {
  83        $where[] = qsprintf(
  84          $conn_r,
  85          'notif.userPHID IN (%Ls)',
  86          $this->userPHIDs);
  87      }
  88  
  89      if ($this->unread !== null) {
  90        $where[] = qsprintf(
  91          $conn_r,
  92          'notif.hasViewed = %d',
  93          (int)!$this->unread);
  94      }
  95  
  96      if ($this->keys) {
  97        $where[] = qsprintf(
  98          $conn_r,
  99          'notif.chronologicalKey IN (%Ls)',
 100          $this->keys);
 101      }
 102  
 103      return $this->formatWhereClause($where);
 104    }
 105  
 106    protected function getPagingValue($item) {
 107      return $item->getChronologicalKey();
 108    }
 109  
 110    public function getQueryApplicationClass() {
 111      return 'PhabricatorNotificationsApplication';
 112    }
 113  
 114  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1