[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery { 4 5 private $ids; 6 private $blogPHIDs; 7 private $bloggerPHIDs; 8 private $phameTitles; 9 private $visibility; 10 private $publishedAfter; 11 private $phids; 12 13 public function withIDs(array $ids) { 14 $this->ids = $ids; 15 return $this; 16 } 17 18 public function withPHIDs(array $phids) { 19 $this->phids = $phids; 20 return $this; 21 } 22 23 public function withBloggerPHIDs(array $blogger_phids) { 24 $this->bloggerPHIDs = $blogger_phids; 25 return $this; 26 } 27 28 public function withBlogPHIDs(array $blog_phids) { 29 $this->blogPHIDs = $blog_phids; 30 return $this; 31 } 32 33 public function withPhameTitles(array $phame_titles) { 34 $this->phameTitles = $phame_titles; 35 return $this; 36 } 37 38 public function withVisibility($visibility) { 39 $this->visibility = $visibility; 40 return $this; 41 } 42 43 public function withPublishedAfter($time) { 44 $this->publishedAfter = $time; 45 return $this; 46 } 47 48 protected function loadPage() { 49 $table = new PhamePost(); 50 $conn_r = $table->establishConnection('r'); 51 52 $where_clause = $this->buildWhereClause($conn_r); 53 $order_clause = $this->buildOrderClause($conn_r); 54 $limit_clause = $this->buildLimitClause($conn_r); 55 56 $data = queryfx_all( 57 $conn_r, 58 'SELECT * FROM %T p %Q %Q %Q', 59 $table->getTableName(), 60 $where_clause, 61 $order_clause, 62 $limit_clause); 63 64 $posts = $table->loadAllFromArray($data); 65 66 if ($posts) { 67 // We require these to do visibility checks, so load them unconditionally. 68 $blog_phids = mpull($posts, 'getBlogPHID'); 69 $blogs = id(new PhameBlogQuery()) 70 ->setViewer($this->getViewer()) 71 ->withPHIDs($blog_phids) 72 ->execute(); 73 $blogs = mpull($blogs, null, 'getPHID'); 74 foreach ($posts as $post) { 75 if (isset($blogs[$post->getBlogPHID()])) { 76 $post->setBlog($blogs[$post->getBlogPHID()]); 77 } 78 } 79 } 80 81 return $posts; 82 } 83 84 private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 85 $where = array(); 86 87 if ($this->ids) { 88 $where[] = qsprintf( 89 $conn_r, 90 'p.id IN (%Ld)', 91 $this->ids); 92 } 93 94 if ($this->phids) { 95 $where[] = qsprintf( 96 $conn_r, 97 'p.phid IN (%Ls)', 98 $this->phids); 99 } 100 101 if ($this->bloggerPHIDs) { 102 $where[] = qsprintf( 103 $conn_r, 104 'p.bloggerPHID IN (%Ls)', 105 $this->bloggerPHIDs); 106 } 107 108 if ($this->phameTitles) { 109 $where[] = qsprintf( 110 $conn_r, 111 'p.phameTitle IN (%Ls)', 112 $this->phameTitles); 113 } 114 115 if ($this->visibility !== null) { 116 $where[] = qsprintf( 117 $conn_r, 118 'p.visibility = %d', 119 $this->visibility); 120 } 121 122 if ($this->publishedAfter !== null) { 123 $where[] = qsprintf( 124 $conn_r, 125 'p.datePublished > %d', 126 $this->publishedAfter); 127 } 128 129 if ($this->blogPHIDs) { 130 $where[] = qsprintf( 131 $conn_r, 132 'p.blogPHID in (%Ls)', 133 $this->blogPHIDs); 134 } 135 136 $where[] = $this->buildPagingClause($conn_r); 137 138 return $this->formatWhereClause($where); 139 } 140 141 public function getQueryApplicationClass() { 142 // TODO: Does setting this break public blogs? 143 return null; 144 } 145 146 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |