PHP code example of aplia / query

1. Go to this page and download the library: Download aplia/query library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aplia / query example snippets



$set = new QuerySet();
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$newSet = $set->depth(1)->sortByField('a-z');
// $set and $newSet are the same instance


$set = new QuerySet(array('useClone' => true));
$newSet = $set->depth(1)->sortByField('a-z');
// $set and $newSet are different instances


$set = new QuerySet();
$newSet = $set->copy()->depth(1)->sortByField('a-z');
// $set and $newSet are different instances


$set = new QuerySet();
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set->classes('article');
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}
// or
$set = new QuerySet(array('classes' => array('article')));
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set->depth(false)->parentNode(42);
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}
// or
$set = new QuerySet(array('depth' => false, 'parentNodeId' => 42));
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set->depth(2, '>=');
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}
// or
$set = new QuerySet(array('depth' => false, 'depthOperator' => '>='));
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set->sortByField('a-z');
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set->sortChoices(array('age' => 'created'))->sortByField('-age');
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set->sortByArray(array(
    array('published', 1),
));
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set->pageLimit(50)->page(5);
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set
  ->defineFilter('title', 'string', 'article/title')
  ->filter('title', 'My title');
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set
  ->defineFilter('title', 'string', 'article/title:first_letter:=')
  ->filter('title', 'M');
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set
  ->classes('article')
  ->loadFilters()
  ->filter('article/title', 'My title');
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set
  ->classes('article')
  ->addFilter(
  array('article/title', 'My title', '=')
)
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$result = $set->result();


$set = new QuerySet();
foreach ($set->items() as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set
  ->visibilty(false);
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}
// or
$set = new QuerySet(array('useVisibility' => false));
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}



$set = new QuerySet();
$set = $set
  ->filter('visible', false);
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set
  ->onlyMainNodes();
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}
// or
$set = new QuerySet(array('mainNodeOnly' => true));
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$set = new QuerySet();
$set = $set
  ->policies(false);
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}
// or
$set = new QuerySet(array('useRoles' => false));
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}


$policies = array(/*...*/);
$set = new QuerySet();
$set = $set
  ->policies($policies);
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}
// or
$policies = array(/*...*/);
$set = new QuerySet(array('policies' => $policies));
foreach ($set as $node) {
    echo $node->attribute('name'), "\n";
}