コード例 #1
0
ファイル: DocTest.php プロジェクト: lamenath/fbp
 public function testAllPredicates()
 {
     // startgist:7a6da96d9e6f94269057:prismic-allPredicates.php
     // "at" predicate: equality of a fragment to a value.
     $at = Predicates::at("document.type", "article");
     // "any" predicate: equality of a fragment to a value.
     $any = Predicates::any("document.type", array("article", "blog-post"));
     // "fulltext" predicate: fulltext search in a fragment.
     $fulltext = Predicates::fulltext("my.article.body", "sausage");
     // "similar" predicate, with a document id as reference
     $similar = Predicates::similar("UXasdFwe42D", 10);
     // endgist
 }
コード例 #2
0
    render($app, 'search', array('posts' => $posts, 'skin' => $skin));
});
// Category
$app->get('/category/:uid', function ($uid) use($app, $prismic) {
    $cat = $prismic->by_uid('category', $uid);
    if (!$cat) {
        not_found($app);
        return;
    }
    $posts = $prismic->form()->query(Predicates::at('document.type', 'post'), Predicates::any('my.post.categories.link', array($cat->getId())))->fetchLinks('post.date', 'category.name', 'author.full_name', 'author.first_name', 'author.surname', 'author.company')->orderings('my.post.date desc')->page(current_page($app))->submit();
    $skin = $prismic->get_skin();
    render($app, 'category', array('category' => $cat, 'posts' => $posts, 'skin' => $skin));
});
// Tag
$app->get('/tag/:tag', function ($tag) use($app, $prismic) {
    $posts = $prismic->form()->query(Predicates::at('document.type', 'post'), Predicates::any('document.tags', array($tag)))->fetchLinks('post.date', 'category.name', 'author.full_name', 'author.first_name', 'author.surname', 'author.company')->orderings('my.post.date desc')->page(current_page($app))->submit();
    $skin = $prismic->get_skin();
    render($app, 'tag', array('posts' => $posts, 'tag' => $tag, 'skin' => $skin));
});
// Blog
$app->get('/blog', function () use($app, $prismic) {
    $homeId = $prismic->get_api()->bookmark('home');
    $blogHomeId = $prismic->get_api()->bookmark('bloghome');
    if ($blogHomeId == null) {
        not_found($app);
    } else {
        if ($blogHomeId == $homeId) {
            redirect('/');
            return;
        }
    }
コード例 #3
0
 public function testLinkedDocuments()
 {
     $api = Api::get("https://micro.prismic.io/api");
     $results = $api->query(Predicates::any('document.type', array("doc", "docchapter")))->getResults();
     $linkedDocuments = $results[0]->getLinkedDocuments();
     $this->assertEquals(1, count($linkedDocuments));
     $this->assertEquals("U0w8OwEAACoAQEvB", $linkedDocuments[0]->getId());
 }
コード例 #4
0
 /**
  * Return the prismic response containing the documents in the given page
  * @param  int      $page
  * @return Response
  */
 protected function retrieveDocumentsByPage($page)
 {
     $api = $this->getPrismicApi();
     $ref = $this->getContext()->getRef();
     $predicates = array(Predicates::any("document.type", $this->documentTypes));
     $form = $api->forms()->everything->ref($ref)->pageSize($this->pageSize)->page($page)->query($predicates);
     return $form->submit();
 }
コード例 #5
0
 public function testAnyPredicate()
 {
     $p = Predicates::any("document.tags", array("Macaron", "Cupcakes"));
     $this->assertEquals('[:d = any(document.tags, ["Macaron", "Cupcakes"])]', $p->q());
 }
コード例 #6
0
ファイル: PrismicHelper.php プロジェクト: lamenath/fbp
 public function get_all_pages()
 {
     if ($this->allPages == null) {
         $has_more = true;
         $this->allPages = array();
         $p = 0;
         while ($has_more) {
             $response = $this->form(20)->query(Predicates::any('document.type', array('page', 'bloghome')))->page($p++)->submit();
             foreach ($response->getResults() as $page) {
                 $this->allPages[$page->getId()] = $page;
             }
             $has_more = $response->getNextPage() != null;
         }
     }
     return $this->allPages;
 }