bloggerPHID = $blogger_phid; return $this; } public function withoutBloggerPHID($blogger_phid) { $this->withoutBloggerPHID = $blogger_phid; return $this; } public function withVisibility($visibility) { $this->visibility = $visibility; return $this; } public function execute() { $table = new PhamePost(); $conn_r = $table->establishConnection('r'); $where_clause = $this->buildWhereClause($conn_r); $order_clause = $this->buildOrderClause($conn_r); $limit_clause = $this->buildLimitClause($conn_r); $data = queryfx_all( $conn_r, 'SELECT * FROM %T e %Q %Q %Q', $table->getTableName(), $where_clause, $order_clause, $limit_clause); $posts = $table->loadAllFromArray($data); return $posts; } private function buildWhereClause($conn_r) { $where = array(); if ($this->bloggerPHID) { $where[] = qsprintf( $conn_r, 'bloggerPHID = %s', $this->bloggerPHID ); } else if ($this->withoutBloggerPHID) { $where[] = qsprintf( $conn_r, 'bloggerPHID != %s', $this->withoutBloggerPHID ); } if ($this->visibility !== null) { $where[] = qsprintf( $conn_r, 'visibility = %d', $this->visibility ); } return $this->formatWhereClause($where); } private function buildOrderClause($conn_r) { return 'ORDER BY datePublished DESC, id DESC'; } }