Changeset View
Changeset View
Standalone View
Standalone View
src/applications/notification/query/PhabricatorNotificationQuery.php
| Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | /* -( Query Execution )---------------------------------------------------- */ | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| $story_table = new PhabricatorFeedStoryData(); | $story_table = new PhabricatorFeedStoryData(); | ||||
| $notification_table = new PhabricatorFeedStoryNotification(); | $notification_table = new PhabricatorFeedStoryNotification(); | ||||
| $conn = $story_table->establishConnection('r'); | $conn = $story_table->establishConnection('r'); | ||||
| $data = queryfx_all( | $data = queryfx_all( | ||||
| $conn, | $conn, | ||||
| 'SELECT story.*, notif.hasViewed FROM %R notif | 'SELECT story.*, notification.hasViewed FROM %R notification | ||||
| JOIN %R story ON notif.chronologicalKey = story.chronologicalKey | JOIN %R story ON notification.chronologicalKey = story.chronologicalKey | ||||
| %Q | %Q | ||||
| ORDER BY notif.chronologicalKey DESC | ORDER BY notification.chronologicalKey DESC | ||||
| %Q', | %Q', | ||||
| $notification_table, | $notification_table, | ||||
| $story_table, | $story_table, | ||||
| $this->buildWhereClause($conn), | $this->buildWhereClause($conn), | ||||
| $this->buildLimitClause($conn)); | $this->buildLimitClause($conn)); | ||||
| $viewed_map = ipull($data, 'hasViewed', 'chronologicalKey'); | $viewed_map = ipull($data, 'hasViewed', 'chronologicalKey'); | ||||
| Show All 9 Lines | /* -( Query Execution )---------------------------------------------------- */ | ||||
| } | } | ||||
| protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->userPHIDs !== null) { | if ($this->userPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'notif.userPHID IN (%Ls)', | 'notification.userPHID IN (%Ls)', | ||||
| $this->userPHIDs); | $this->userPHIDs); | ||||
| } | } | ||||
| if ($this->unread !== null) { | if ($this->unread !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'notif.hasViewed = %d', | 'notification.hasViewed = %d', | ||||
| (int)!$this->unread); | (int)!$this->unread); | ||||
| } | } | ||||
| if ($this->keys !== null) { | if ($this->keys !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'notif.chronologicalKey IN (%Ls)', | 'notification.chronologicalKey IN (%Ls)', | ||||
| $this->keys); | $this->keys); | ||||
| } | } | ||||
| return $where; | return $where; | ||||
| } | } | ||||
| protected function willFilterPage(array $stories) { | protected function willFilterPage(array $stories) { | ||||
| foreach ($stories as $key => $story) { | foreach ($stories as $key => $story) { | ||||
| if (!$story->isVisibleInNotifications()) { | if (!$story->isVisibleInNotifications()) { | ||||
| unset($stories[$key]); | unset($stories[$key]); | ||||
| } | } | ||||
| } | } | ||||
| return $stories; | return $stories; | ||||
| } | } | ||||
| protected function getResultCursor($item) { | protected function getDefaultOrderVector() { | ||||
| return $item->getChronologicalKey(); | return array('key'); | ||||
| } | |||||
| public function getBuiltinOrders() { | |||||
| return array( | |||||
| 'newest' => array( | |||||
| 'vector' => array('key'), | |||||
| 'name' => pht('Creation (Newest First)'), | |||||
| 'aliases' => array('created'), | |||||
| ), | |||||
| 'oldest' => array( | |||||
| 'vector' => array('-key'), | |||||
| 'name' => pht('Creation (Oldest First)'), | |||||
| ), | |||||
| ); | |||||
| } | |||||
| public function getOrderableColumns() { | |||||
| return array( | |||||
| 'key' => array( | |||||
| 'table' => 'notification', | |||||
| 'column' => 'chronologicalKey', | |||||
| 'type' => 'string', | |||||
| 'unique' => true, | |||||
| ), | |||||
| ); | |||||
| } | |||||
| protected function applyExternalCursorConstraintsToQuery( | |||||
| PhabricatorCursorPagedPolicyAwareQuery $subquery, | |||||
| $cursor) { | |||||
| $subquery->withKeys(array($cursor)); | |||||
| } | |||||
| protected function newExternalCursorStringForResult($object) { | |||||
| return $object->getChronologicalKey(); | |||||
| } | |||||
| protected function newPagingMapFromPartialObject($object) { | |||||
| return array( | |||||
| 'key' => $object->getChronologicalKey(), | |||||
| ); | |||||
| } | |||||
| protected function getPrimaryTableAlias() { | |||||
| return 'notification'; | |||||
| } | } | ||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorNotificationsApplication'; | return 'PhabricatorNotificationsApplication'; | ||||
| } | } | ||||
| } | } | ||||