ar\store

This module contains methods to access the ariadne store and run templates on other objects. These methods are all also directly available in the root ar module. e.g. ar_store::ls() or ar('store')->ls() can also be written as ar::ls().

methods

(void) configure Allows you to change the default behaviour or the ar_store module through some configurable settings.
(mixed) exists Returns false if the given path is not found or the object id if it is.
(string) currentProject Returns the path to the nearest project.
(string) currentSection Returns the path to the nearest section.
(string) currentSite Returns the path to the nearest site.
(object) find Returns an ar_storeFind object with the given query.
(object) get Returns an ar_storeGet object with the given path.
(object) ls Returns an ar_storeList object with the given path
(string) makePath Returns an absolute path from a given path that may contain relative parts.
(string) makeRealPath Returns the real (resolved) path from a given path that may be virtual and/or contain relative parts.
(object) parents

Returns an ar_storeParents object with the given path.

(string) parentProject Returns the path to the nearest parent project.
(string) parentSection Returns the path to the nearest parent section.
(string) parentSite Returns the path to the nearest parent site.

configure

(void) ar('store')->configure( $option, $value )

(string) $option The name of the option to configure.
(mixed) $value The value for the option.

The ar_store module supports the following options:

(bool) rememberShortcuts Default: true. When true, all methods will remember shortcuts with KeepURL set to true. Any path generated by passing through such a shortcut in the current session will be kept intact — a virtual path. If false, all paths are automatically turned into real or resolved store paths.

currentProject

(string) ar('store')->currentProject( $path = '' )

(string) $path The path to start searching from.

Returns the path to the nearest project. Nearest in this case means the nearest parent or if the given path argument is a project it will return this. 

currentSection

(string) ar('store')->currentSection( $path = '' )

(string) $path The path to start searching from.

Returns the path to the nearest section. Nearest in this case means the nearest parent or if the given path argument is a section it will return this.

currentSite

(string) ar('store')->currentSite( $path = '' )

(string) $path The path to start searching from.

Returns the path to the nearest site. Nearest in this case means the nearest parent or if the given path argument is a site it will return this.

exists

(mixed) ar('store')->exists( $path )
(mixed) ar::exists( $path )

(string) $path The path of the Ariadne object to check.

If the given path exists, this method will return its id. If not it will return false. 

Warning: ar::exists is broken in Ariadne 2.7.3 and 2.7.4, either use exists() instead or update the file lib/modules/mod_keepurl.php from svn.

find

(object) ar('store')->find( $query )
(object) ar::find( $query )

(string) $query The search query to use for matching objects.

This method returns a new ar_storeFind object with the given query set. The ar_storeFind object has the following methods:

(array) call Calls the givent template on each of the objects found.
(int) count Returns the number of objects found.
(object) limit Limits the result set to the given number.
(object) offset Skips the first number of results found.
(object) order Orders the result set.

(mixed) $storeFind->call( $template, $args=null )

Calls the given template with the given arguments on the Ariadne objects that match the query $query. The results returned by the template will be collected and returned in an array. The key of the array is the path of the object which returned that result. See ar::call() for more information. 

In addition to the options of ar::call(), you can also specify a listPattern as $template. In that case the listPattern will be automatically converted to a listExpression with the number of objects found as the length. e.g.:

<pinp>
ar::find( "object.implements = 'pdir'")->call(
ar::listPattern(
'show.single.html | ' .
'show.first.html ( show.odd.html show.even.html? )* show.last.html'
)
);
</pinp>

This will call the following templates in order on the objects found:

For five objects:

show.first.html
show.odd.html
show.even.html
show.odd.html
show.last.html

For three objects:

show.first.html
show.odd.html
show.last.html

For a single object:

show.single.html

(int) $storeFind->count()

Returns the number of objects that match the given query.

(object) $storeFind->limit($limit)

Returns a clone of itself with the result limit set to $limit.

(object) $storeFind->offset($offset)

Returns a clone of itself with the result offset set to $offset

(object) $storeFind->order($order)

Returns a clone of itself with the result order set to $order.

Examples:

ar('store')->find("name.value ~= 'A%' and name.nls='en')
->order('name.value ASC')
->limit(10)
->offset(10)
->call('show.html');

The example above finds all objects with a name starting with A, in english. Orders the results alfabetically by name, skips the first 10 results and then calls the template 'show.html' and the next 10 results.

Query Format

( propertyName.valueName compare $value ( and | or )? )+

The query string format is a bit like SQL, but geared only to data retrieval. You can search on any Ariadne property, a short list is presented below. The valid compare methods are:

< smaller "time.ctime < ".(time()-7*24*60*60))
<= smaller or equal "article.start <= ".time()
!= not equal "object.path != '".$path."'"
> larger "article.end > ".time()
>= larger or equal "object.priority >= 0"
= or == equal "object.parent = '".$path."'"
=~ or ~= like "name.value ~= 'A%'"
!~ not like "object.path !~ '".$path."%'"
Case sensitive or binary 'like' searches (MySQL only)
=~~ like binary "my.customvalue =~~ 'Case Sensitive %' "
!~~ not like binary "name.value =~~ 'A%'"
Full text search (MySQL only)
=* contains text "fulltext.value =* 'search text'"
=** contains words "fulltext.value =** '+search -text'"
!* does not contain text "fulltext.value !* 'search text'"
!** does not contain words "fulltext.value !** '+search -text'"
Regular expressions (MySQL only)
=/ like "my.customvalue =/ '^[a-z0-9]*'"
=// like binary "my.customvalue =/ '^[a-zA-Z0-9]*'"
!/ not like "my.customvalue !/ 'new .*'"
!// not like binary "my.customvalue !// 'New .*'"

For like (~=) and not like (!~) the '%' character is used as a wildcard, it will match any string. The fulltext search will only work on the fulltext property and is currently only supported in MySQL.

List of most used properties in Ariadne.

object implements Matches if the type matches any of the parent classes of the object.
parent Path of the parent object.
path Path of the object itself.
priority The priority of the object.
type The type (class) of the object, e.g. pobject or ppage.
name value The name of the object, $nlsdata->name.
nls The language code of this name, e.g. 'en'.
text value Any text in the object, the name, summary or page.
nls The language code of this text.
fulltext value Contains all words in the objects text fields with 4 or more characters.
nls The language code of the text.
time ctime The unix timestamp of the creation of the object.
mtime The last time the object was changed.
muser The login of the user that last changed the object.
custom name The name of a custom property.
value The value of that custom property.
nls The language code of that custom property, or 'none'.
referencespathThe path to an object referenced either in page content or directly.
statevalueA string indicating the state of an object.
groupA string indicating the grouped state of an object.
operatorA string indicating who or what should operate on the object next.
valuevalueThe value of a pobject or pbookmark.
loginvalueThe login name of a user, profile or group.
ownervalueThe login name of the user that owns an object.
articlestartThe startdate and time of a particle display.
endThe enddate and time of a particle display.
displayThe name of this display of articles.
timeframestartThe startdate and time of a pcalitem.
endThe enddate and time of pcalitem.
publishedvalueA timestamp.

You can combine multiple properties, or multiple values of a property, in a single query, e.g.:

  $query = "name.value ~='A%' and name.nls = 'en'";

This query matches any object whose name starts with 'A' in english.

  $query = "object.implements = 'ppage' and time.ctime > ".$lastweek;

Will match any object whose class is a subclass of ppage and which is created within the last week.

You can use both AND and OR to combine properties. Use parentheses, ( and ), to make clear how these properties should be combined. e.g.:

  $query = "object.implements = 'ppage' or ".
"( object.type = 'pphoto' and time.ctime > $lastweek )";

This will match all page objects, or subclasses thereof, and all pphoto objects created in the last week.

Custom properties

You can query a custom property (a property defined via the custom fields wizard) by prefixing the name of the property with 'my.' e.g.:

  $query = "my.price >= 90";

If the property is language dependant, you can define the language like this:

  $query = "my.description ~= '%" . AddSlashes( $keyword ) . "%'" .
           " and my.nls = '" . $nls . "'"; 

Multiple checks on a single property

For some properties multiple values are stored for a single object. In some cases you may need to check more than one of these values based on different criteria. You can do this via the following query syntax:

  $query =
    "( my.keyword:a.value = '" . AddSlashes( $keyword1 ) . "'" .
    " and my.keyword:a.nls = '" . $nls . "' )" .
    " and ( my.keyword:b.value = '" . AddSlashes( $keyword2 ) . "'" .
    " and my.keyword:b.nls = '" . $nls . "')";

The ':a ' and ':b ' define 'tags' for that specific match, so that firstly the query engine knows that keyword1 and keyword2 do not need to match both with the same property record, just as long as there is a matching record for both of them, and secondly it also knows which nls field must match with which record, although in this case they're both the same.

fulltext searches

Ariadne supports MySQL's full text search options. However for historical reasons the words are stored in an encoded format. All non-ascii characters are replaced with their hexadecimal value. So if you want to search for words containing special characters, you'll need to include code similar to this:

  $allowedchars  = "_'-";
  $searchFTI     = array("%[\\x80-\\xFF$allowedchars]%es", "%\\s+%s");
  $replaceFTI = array("'_'.dechex(ord('\\0'))", " ");
  $searchTextFTI = preg_replace( $searchFTI, $replaceFTI, $searchText);  

And then use the $searchTextFTI in your query instead of $searchText.

MySQL has support for searches in 'natural language' mode and 'boolean search' mode. In natural language mode MySQL searches for the complete phrase given. It is triggered by the '=*' and '!*' operators. In boolean search mode, you can specify AND, NOT and OR for each word, like this:

word1 and word2 +word1 +word2
either word1 or word2 word1 word2
word1 and not word2 +word1 -word2

get

(object) ar('store')->get( $path )
(object) ar::get( $path )

(string) $path The path of the Ariadne object to get.

This method returns a new ar_storeGet object, with the given path set. The ar_storeGet object has the following methods:

(array) call Calls a template on each object found.
(object) find Searches the store for objects matching the query.
(object) ls Lists all the immediate children of the given path.
(object) parents Lists all parents upto the given top parent for this path.

(array) $storeGet->call( $template, $args=null )

Calls the given template with the given arguments on the Ariadne object with path $path. The results returned by the template will be returned in an array. The key of the array is the path of the object. See ar::call() for more information.

(object) $storeGet->parents()

Return a new ar_storeParents object for the given path. See the ar_store::parents() method for more information.

(object) $storeGet->find( $query )

Returns an ar_storeFind object with the given query and the given path. See the ar_store::find() method for more information.

(object) $storeGet->ls()

Returns an ar_storeList object with the given path. See the ar_store::ls() method for further information.

Examples:

ar('store')->get('/system/')->call('view.html');

ls

(object) ar('store')->ls()
(object) ar::ls()

This method returns a new ar_storeList object. This object implements the ar_storeFind class. The only change is that it automatically sets a search query to list only the immediate children of the current path. See find() for more information on the results.

Example:

ar('store')->ls()
->order('name.value ASC')
->call('show.html');

makePath

(string) ar('store')->makePath( $path = '' )

(string) $path The path to parse and turn into an absolute path.

Returns an absolute path, which may still be virtual, depending on the rememberShortcuts setting. If this setting is set to true, the returned path may contain shortcut redirects.

makeRealPath

(string) ar('store')->makeRealPath( $path = '' )

(string) $path The path to parse and turn into a resolved path.

Returns an absolute and resolved path. There is no guarantee that an object with this path exists, but if it doesn't than the original path was invalid.

parents

(object) ar('store')->parents()
(object) ar::parents() 

This method returns a new ar_storeParents object. This object implements the following methods:

(array) call Calls a template on each object found.
(int) count Returns the number of objects found.
(object) top Sets the top most object to call.

(mixed) $storeParents->call( $template, $args=null )

Calls the given template with the given arguments on the Ariadne object with path $path. The results returned by the template will be returned in an array. The key of the array is the path of the object. See ar::call() and ar_store::find()->call() for more information.

(int) $storeParents->count()

Returns the number of parent objects found.

(object) $storeParents->top()

Returns a clone of itself with the top most parent to find set.

Example:

ar('store')->parents()
->top( ar('store')->currentSite() )
->call('show.html');

This example shows a crumb trail of the current object starting with the site root.

parentProject

(string) ar('store')->parentProject( $path = '' )

(string) $path The path to start searching from.

Returns the path to the nearest parent project.

parentSection

(string) ar('store')->parentSection( $path = '' )

(string) $path The path to start searching from.

Returns the path to the nearest parent section.

parentSite

(string) ar('store')->parentSite( $path = '' )

(string) $path The path to start searching from.

Returns the path to the nearest parent site.