5.2. Data Symbols

Here are some of the generic objects available in this package.

5.2.1. Xyster_Data_Aggregate

This class is an extension of Xyster_Enum and provides the different ways to aggregate a group of data. SQL developers will recognize these function names.

  1. Xyster_Data_Aggregate::Average() – A mathematical mean of a group of numbers

  2. Xyster_Data_Aggregate::Count() – A simple count of rows

  3. Xyster_Data_Aggregate::Maximum() – Finds the greatest value in a set of data

  4. Xyster_Data_Aggregate::Minimum() – Finds the smallest value in a set of data

  5. Xyster_Data_Aggregate::Sum() – The addition of a group of numbers

5.2.2. Xyster_Data_Field

This object is used to refer to a column in a database table, an attribute in an XML tag, a property on an object, a method call on an object, an attribute in an LDAP record, etc. It can be aliased (given a nickname), it can be associated with an Aggregate, and it can be used to represent data grouped by a certain field.

<?php
Xyster_Data_Field::named("myColumn", "nickName");
Xyster_Data_Field::group("myColumn");
Xyster_Data_Field::count("myId");
Xyster_Data_Field::aggregate(Xyster_Data_Aggregate::Average(), "myColumn");

                

5.2.3. Xyster_Data_Sort

A sort consists of a Xyster_Data_Field and a direction (either ascending or descending).

<?php
$column = Xyster_Data_Field::named("email");
Xyster_Data_Sort::asc( $column );
Xyster_Data_Sort::desc( $column );

                

Xyster_Data_Comparator is an instance of Xyster_Collection's Xyster_Collection_Comparator interface. It can be used to sort a Xyster_Collection_Set_Sortable containing arrays or objects using one or more Xyster_Data_Sort objects.

<?php
// example will sort a set by last name and salary 
$sorts = array(Xyster_Data_Sort::asc("lastName"),
    Xyster_Data_Sort::desc("salary"));
$comparator = new Xyster_Data_Comparator($sorts);
// assuming $sortableSet is a Xyster_Collection_Set_Sortable containing objects or associative arrays
$sortableSet->sort($comparator);

                

5.2.4. Xyster_Data_Criterion

This is an abstract class that overshadows two other classes: the Expression and the Junction. A Criterion is a boolean expression, such as a SQL where clause, a PHP if statement, or an LDAP query filter. An Expression is just one statement, with two terms and an operator between (this is commonly called an infix operator). A Junction is a joining of two or more Criterion objects with either an AND or an OR operator between.

Equality: A Field must be equal to a value (==) or not equal to a value (!=, <>)

<?php
Xyster_Data_Expression::eq("myColumn","some value");
Xyster_Data_Expression::neq("myColumn","some other value");

                

Value comparisons: A Field must be greater than (>), less than (<), greater than or equal to (>=), or less than or equal to (<=) a value.

<?php
Xyster_Data_Expression::gt("myColumn",10);
Xyster_Data_Expression::gte("myColumn",11);
Xyster_Data_Expression::lt("myColumn",30);
Xyster_Data_Expression::lte("myColumn",29);

                

(Not) Between: A Field must be between or not be between two values

<?php
Xyster_Data_Expression::between("myColumn",10,20);
Xyster_Data_Expression::notBetween("myColumn",1,9);

                

Like: A Field must start with, end with, or contain a value (or not)

<?php
Xyster_Data_Expression::like("myColumn","peanut%");
Xyster_Data_Expression::notLike("myColumn","%butter");

                

In: A Field must be one of or not be one of a set of values

<?php
Xyster_Data_Expression::in("myColumn",array(1,2,3,4,5));
Xyster_Data_Expression::notIn("myColumn",array(1,2,3,4,5));

                

A Junction is a group of two or more Expression objects, and must either be "and" statements (conjunctions), or "or" statements (disjunctions). For instance:

<?php
$junction1 = Xyster_Data_Junction::any(Xyster_Data_Expression::eq("myColumn", 100), Xyster_Data_Expression::eq("otherColumn", "text"));
$junction2 = Xyster_Data_Junction::any(Xyster_Data_Expression::eq("name", "Smith"), Xyster_Data_Expression::like("city", "D%"));
Xyster_Data_Junction::all($junction1, $junction2);

                

These objects can be used to abstractly represent a query for data, or manipulate data returned from such a query. The Xyster framework wanted to provide a universal way to work with this kind of data that can easily be reused.