Framework  3.9
Object-Relational Mapping

Classes

class  DataItemException
 
class  DataNotFoundException
 
class  ExclusionFilter
 Used to place a filter on the contents of a DataItem-derived object. More...
 
class  InclusionFilter
 Used to place a filter on the contents of a DataItem-derived object. More...
 
class  AbstractDataItem
 Abstract base class for all DataItem implementations. More...
 
class  CompositeDataItem
 
class  DataItem
 DataItem is the generic base class for database mapped classes. More...
 
class  DataItemFieldComparator
 Simple field comparator to support sorting arrays of DataItems by the values in a specified field. More...
 
class  GroupedQuery
 
class  IndexedQuery
 
class  DataItemIterator
 DataItemIterator is a memory-efficient iterator class that can be used when rendering large data sets. More...
 
class  IteratedQuery
 IteratedQuery provides a memory-efficient way to query and return large data sets. More...
 
class  JoinResult
 JoinResult is an empty placeholder class. More...
 
class  JoinResultIterator
 
class  AbstractJoin
 AbstractJoin is the abstract base class from which concrete join classes can be derived in order to provide support for different styles of relational join. More...
 
class  InnerJoin
 This class is used to programmatically perform inner join queries across multiple objects. More...
 
class  LeftOuterJoin
 
class  JSONQuery
 
class  AbstractPivotQuery
 AbstractPivotQuery provides the common base class for the shaped pivot query classes PivotQuery, IndexexPivotQuery and GroupedPivotQuery. More...
 
class  PivotQuery
 Standard Pivot Query, with support for paging. More...
 
class  IndexedPivotQuery
 Run a pivot query and return the results indexed by a selected field. More...
 
class  GroupedPivotQuery
 Performs a pivot query against the database, returning an array of arrays of PivotItems, grouped by a particular field. More...
 
class  PivotItem
 PivotItems are dynamically constructed DataItems that map the results of PivotQueries. More...
 
class  PivotTableHelper
 The PivotTableHelper class provides support for configuring display tables (DataListViews and GroupedDataListViews) dynamically, based upon the structure of a pivot query. More...
 
class  AbstractQuery
 
class  Query
 Query provides an object-oriented interface for database queries. More...
 
class  DataTransaction
 The DataTransaction class wraps the underlying database's transaction model. More...
 

Functions

 querySingle ($class)
 Performs a query against the database and returns a matching singleton object. More...
 
 queryValue ($class, $func)
 Query the database to calculate an aggregate value. More...
 
 reindexList ($list, $field, $autoPromote=true)
 Reindex an indexed or grouped query result by a different field. More...
 
 regroupList ($list, $field)
 Regroup an indexed or grouped query result by a different field. More...
 
 removeDuplicates ($list, $field="")
 Remove duplicate DataItems from a list, based on the value of a field. More...
 
 sortList (&$list, $field)
 Sorts an array of DataItems based on the values in the specified field. More...
 
 updateSortOrder ($class, $field="sort_order", $params=null)
 Utility method to update sort order for the selected class of objects based on an array that maps primary keys to sort order values. More...
 
 toXML ($tag, $objects, $header=null)
 
 toJSON ($items)
 
 toJSONGrouped ($items)
 
 toJSONIndexed ($items)
 
 fromJSON ($class, $json)
 
 displayFieldAsList ($items, $field, $separator=", ")
 
 formatItems ($items, $template, $separator="")
 Format a list of DataItems using the specified templated. More...
 
 extractItems ($items, $indexFormat, $valueFormat)
 
 extractFieldValues ($items, $field)
 Extract the field values for the specified field from a list of DataItems. More...
 
 extractIndexedFieldValues ($items, $field)
 Extract the field values for the specified field from a list of DataItems and return them in an array indexed by the primary key values of the source DataItems. More...
 
 itemExists ($class, $key)
 Utility method to test for the existence of a DataItem record in the database. More...
 
 findItem ($items, $field, $value)
 Find the first item in the array that matches the supplied value for the specified field. More...
 
 findItemIndex ($items, $field, $value)
 Find the index of the first item in the array that matches the supplied value for the specified field. More...
 
 restoreHTML ($text)
 
 dumpCSV ($class, $items, $filepath, $filter=null, $append=false)
 Dump a raw representation of a list of DataItems to CSV (one column per field, default format only) More...
 
 groupedQuery ($class)
 Performs a query against the database, returning an array of arrays of DataItem objects of the specified class, grouped by a particular field. More...
 
 indexedQuery ($class)
 Performs a query against the database, returning an array of DataItem objects of the specified class, indexed by a particular field. More...
 
 iteratedQuery ($class)
 iteratedQuery() provides a memory-efficient way to query and return large data sets. More...
 
 extractJoinResults ($class, $results)
 Extracts the specified object from the combined join results, returning an array of the specified objects n the same order they were returned by the join query. More...
 
 extractGroupedJoinResults ($class, $results)
 
 query ($class)
 Performs a query against the database, returning an array of DataItem objects of the specified class. More...
 

Variables

const SerializeRelations 1
 
const SerializeDirectRelations 2
 
const ProtectHTML 4
 

Detailed Description

Function Documentation

◆ displayFieldAsList()

displayFieldAsList (   $items,
  $field,
  $separator = ", " 
)

Definition at line 2163 of file data_item.inc.

2164 {
2165  return formatItems($items, "{".$field."}", $separator);
2166 }
formatItems($items, $template, $separator="")
Format a list of DataItems using the specified templated.
Definition: data_item.inc:2176

◆ dumpCSV()

dumpCSV (   $class,
  $items,
  $filepath,
  $filter = null,
  $append = false 
)

Dump a raw representation of a list of DataItems to CSV (one column per field, default format only)

Parameters
$classclass name of the items to be dumped
$itemsthe items to dump
$filepaththe output file path

Definition at line 2304 of file data_item.inc.

2305 {
2306  $obj = new $class;
2307  $obj->filter = $filter;
2308 
2309  $fields = $obj->getFieldArray();
2310 
2311  if ($append)
2312  {
2313  $fp = fopen($filepath, "a");
2314  }
2315  else
2316  {
2317  $fp = fopen($filepath, "w");
2318  fputcsv($fp, $fields);
2319  }
2320 
2321  foreach($items as $item)
2322  {
2323  $vals = array();
2324  foreach($fields as $field)
2325  {
2326  $vals[] = $item->get($field);
2327  }
2328  fputcsv($fp, $vals);
2329  }
2330  fclose($fp);
2331 }

◆ extractFieldValues()

extractFieldValues (   $items,
  $field 
)

Extract the field values for the specified field from a list of DataItems.

Parameters
$itemsthe DataItems on which to perform the extraction
$fieldthe name of the field to extract
Returns
array an array of the field values in the same order as the presented DataItem list.

Definition at line 2209 of file data_item.inc.

2210 {
2211  $out = array();
2212  foreach($items as $item)
2213  {
2214  $out[] = $item->get($field);
2215  }
2216  return $out;
2217 }

◆ extractGroupedJoinResults()

extractGroupedJoinResults (   $class,
  $results 
)

Definition at line 1098 of file join.inc.

1099 {
1100  $arr = array();
1101 
1102  if (!$results) return $arr;
1103 
1104  foreach(array_keys($results) as $key)
1105  {
1106  $arr[$key] = extractJoinResults($class, $results[$key]);
1107  }
1108 
1109  return $arr;
1110 }
extractJoinResults($class, $results)
Extracts the specified object from the combined join results, returning an array of the specified obj...
Definition: join.inc:1084

◆ extractIndexedFieldValues()

extractIndexedFieldValues (   $items,
  $field 
)

Extract the field values for the specified field from a list of DataItems and return them in an array indexed by the primary key values of the source DataItems.

Parameters
$itemsthe DataItems on which to perform the extraction
$fieldthe name of the field to extract
Returns
array an array of the field values indexed by the primary key values from the DataItem list.

Definition at line 2226 of file data_item.inc.

2227 {
2228  $out = array();
2229  foreach($items as $item)
2230  {
2231  $out[$item->get($item->getPrimaryKey())] = $item->get($field);
2232  }
2233 
2234  return $out;
2235 }

◆ extractItems()

extractItems (   $items,
  $indexFormat,
  $valueFormat 
)

Definition at line 2192 of file data_item.inc.

2193 {
2194  $list = array();
2195  foreach($items as $item)
2196  {
2197  $list[$item->format($indexFormat)] = $item->format($valueFormat);
2198  }
2199 
2200  return $list;
2201 }

◆ extractJoinResults()

extractJoinResults (   $class,
  $results 
)

Extracts the specified object from the combined join results, returning an array of the specified objects n the same order they were returned by the join query.

Parameters
unknown_type$classthe class of objects to extract
unknown_type$resultsan array containing the results of a join query.
Returns
unknown an array of the specified objects extracted from the join query results array.

Definition at line 1084 of file join.inc.

1085 {
1086  $arr = array();
1087 
1088  if (!$results) return $arr;
1089 
1090  foreach($results as $result)
1091  {
1092  $arr[] = $result->$class;
1093  }
1094 
1095  return $arr;
1096 }

◆ findItem()

findItem (   $items,
  $field,
  $value 
)

Find the first item in the array that matches the supplied value for the specified field.

Parameters
array$itemsthe items to search
string$fieldthe name of the field to match
mixed$valuethe value that must be matched
Returns
DataItem the first matching object, or null if no match is found

Definition at line 2261 of file data_item.inc.

2262 {
2263  foreach($items as $item)
2264  {
2265  if ($item->get($field) == $value) return $item;
2266  }
2267 
2268  return null;
2269 }

◆ findItemIndex()

findItemIndex (   $items,
  $field,
  $value 
)

Find the index of the first item in the array that matches the supplied value for the specified field.

Parameters
array$itemsthe items to search
string$fieldthe name of the field to match
mixed$valuethe value that must be matched
Returns
mixed the index of the first matching object, or false if no match was found

Definition at line 2279 of file data_item.inc.

2280 {
2281  $idx = 0;
2282 
2283  foreach($items as $item)
2284  {
2285  if ($item->get($field) == $value) return $idx;
2286  ++$idx;
2287  }
2288 
2289  return false;
2290 }

◆ formatItems()

formatItems (   $items,
  $template,
  $separator = "" 
)

Format a list of DataItems using the specified templated.

The list is returned as a string with the specifed separator between records.

Parameters
array$itemsthe DataItems to format
string$templatethe format template
string$separatorthe separator to use between records
Returns
string

Definition at line 2176 of file data_item.inc.

2177 {
2178  $list = "";
2179  $first = true;
2180 
2181  foreach($items as $item)
2182  {
2183  if (!$item) continue;
2184  if (!$first) $list .= $separator;
2185  $list .= $item->format($template);
2186  $first = false;
2187  }
2188 
2189  return $list;
2190 }

◆ fromJSON()

fromJSON (   $class,
  $json 
)

Definition at line 2138 of file data_item.inc.

2139 {
2140  $data = json_decode($json);
2141 
2142  if (is_object($data))
2143  {
2144  $obj = new $class;
2145  $obj->copy($data);
2146  return $obj;
2147  }
2148  else if (is_array($data))
2149  {
2150  foreach($data as $datum)
2151  {
2152  $obj = new $class;
2153  $obj->copy($datum);
2154  $out[] = $obj;
2155  }
2156 
2157  return $out;
2158  }
2159 
2160  return null;
2161 }

◆ groupedQuery()

groupedQuery (   $class)

Performs a query against the database, returning an array of arrays of DataItem objects of the specified class, grouped by a particular field.

If the indexing field has unique values, indexedQuery() might be more appropriate.

Parameters
string$classthe name of the class of objects to query
string$constraintsoptional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]"
string$fieldoptional the name of the field by which to group the results
object$filteroptional filter used to select subset of the database fields for the result (See InclusionFilter and ExclusionFilter)

Definition at line 175 of file grouped_query.inc.

176 {
177  $field = $prototype->primary_key;
178 
179  $filter = null;
180 
181  $query = new GroupedQuery($class);
182 
183  if (func_num_args() > 1)
184  {
185  $query->constraints(func_get_arg(1));
186 
187  if (func_num_args() > 2)
188  {
189  $query->groupBy(func_get_arg(2));
190 
191  if (func_num_args() > 3)
192  {
193  $query->filter(func_get_arg(3));
194  }
195  }
196  }
197 
198  return $query->execute();
199 }

◆ indexedQuery()

indexedQuery (   $class)

Performs a query against the database, returning an array of DataItem objects of the specified class, indexed by a particular field.

If more than one item is found that matches the same value of the indexing field, the results entry is promoted to an array automatically. However, in cases where this is common, using groupedQuery() might simplify your calling code.

Parameters
string$classthe name of the class of objects to query
string$constraintsoptional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]"
string$fieldoptional the name of the field by which to index the results
object$filteroptional filter used to select subset of the database fields for the result (See InclusionFilter and ExclusionFilter)

Definition at line 145 of file indexed_query.inc.

146 {
147  $field = $prototype->primary_key;
148  $filter = null;
149 
150  $query = new IndexedQuery($class);
151 
152  if (func_num_args() > 1)
153  {
154  $query->constraints(func_get_arg(1));
155 
156  if (func_num_args() > 2)
157  {
158  $query->indexBy(func_get_arg(2));
159 
160  if (func_num_args() > 3)
161  {
162  $query->filter(func_get_arg(3));
163  }
164  }
165  }
166 
167  return $query->execute();
168 }

◆ itemExists()

itemExists (   $class,
  $key 
)

Utility method to test for the existence of a DataItem record in the database.

Parameters
string$classthe class of the DataItem
integer$keythe primary key value for the DataItem
Returns
boolean true if a record for the object exists in the database, false otherwise

Definition at line 2243 of file data_item.inc.

2244 {
2245  $obj = new $class;
2246  if (!$obj instanceof DataItem)
2247  {
2248  return false;
2249  }
2250  $obj->set($obj->getPrimaryKey(), $key);
2251  return $obj->exists();
2252 }
DataItem is the generic base class for database mapped classes.
Definition: data_item.inc:62

◆ iteratedQuery()

iteratedQuery (   $class)

iteratedQuery() provides a memory-efficient way to query and return large data sets.

Whereas the default query() function and the indexedQuery() and groupedQuery() functions all pull the full result set into memory when the query is executed, iteratedQuery() leaves the connection to the database open and retrieves the results one row at a time. The results are returned wrapped in a DataItemIterator, allowing them to be used in foreach(...) statements, etc.

One limitation of the returned resultset is that count() will not return an accurate count of the number of items, since this cannot be determined reliably until all items have been read. In general it is recommend that iteratedQuery() only be used in situations where the result would take up too much memory to be processed using a standard Query object.

Parameters
string$classthe name of the class of objects to query
string$constraintsoptional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]"
object$filteroptional filter used to select subset of the database fields for the result (See InclusionFilter and ExclusionFilter)

Definition at line 239 of file iterated_query.inc.

240 {
241  $query = new IteratedQuery($class);
242 
243  if (func_num_args() > 1)
244  {
245  $query->constraints(func_get_arg(1));
246 
247  if (func_num_args() > 2)
248  {
249  $query->filter(func_get_arg(3));
250  }
251  }
252 
253  return $query->execute();
254 }
IteratedQuery provides a memory-efficient way to query and return large data sets.

◆ query()

query (   $class)

Performs a query against the database, returning an array of DataItem objects of the specified class.

Parameters
string$classthe name of the class of objects to query
$constraintsoptional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]"
$filteroptional filter to apply to the query
$pageoptional page number to retrieve
$sizeoptional size of pages

Definition at line 373 of file query.inc.

374 {
375  $query = new Query($class);
376 
377  if (func_num_args() > 1)
378  {
379  $idx = 1;
380 
381  if (is_object(func_get_arg(1)))
382  {
383  $query->filter($filter);
384  ++$idx;
385  }
386 
387  if (is_array(func_get_arg($idx)))
388  {
389  $query->params(func_get_arg($idx++));
390  }
391 
392  if (func_num_args() > $idx)
393  {
394  $query->constraints(func_get_arg($idx));
395 
396  if (func_num_args() == $idx + 3)
397  {
398  $query->page(func_get_arg($idx + 1), func_get_arg($idx + 2));
399  }
400  }
401  }
402 
403  return $query->execute();
404 }
Query provides an object-oriented interface for database queries.
Definition: query.inc:126

◆ querySingle()

querySingle (   $class)

Performs a query against the database and returns a matching singleton object.

If the query returns more than one object, an error is thrown.

Parameters
string$classthe class name of the object to query
string$constraintsoptional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]"

Definition at line 1810 of file data_item.inc.

1811 {
1812  $constraints = "";
1813 
1814  if (func_num_args() > 1)
1815  {
1816  $constraints = func_get_arg(1);
1817  }
1818 
1819  $result = query($class, $constraints);
1820 
1821  if (count($result) > 1)
1822  {
1823  throw new DataItemException("Ambiguous singleton query");
1824  }
1825 
1826  if (count($result) == 1)
1827  {
1828  return $result[0];
1829  }
1830 
1831  return null;
1832 }
query($class)
Performs a query against the database, returning an array of DataItem objects of the specified class.
Definition: query.inc:373

◆ queryValue()

queryValue (   $class,
  $func 
)

Query the database to calculate an aggregate value.

The database table associated with the specified class is used as the source for the data.

Parameters
string$classthe class name of the object to query
string$functhe value or function to retrieve
string$constraintsoptional constraint clause to apply to the query

Definition at line 1842 of file data_item.inc.

1843 {
1844  $constraints = "";
1845  $value = null;
1846 
1847  if (func_num_args() > 2)
1848  {
1849  $constraints = func_get_arg(2);
1850 
1851  if (func_num_args() > 3)
1852  {
1853  $value = func_get_arg(3);
1854  }
1855  }
1856 
1857  $prototype = new $class;
1858 
1859  if ($constraints == "") $constraints = "WHERE 1=1"; //TODO - tidy this up some day
1860  $constraints .= " ".$prototype->getIdentityConstraint();
1861 
1862  $query = "SELECT $func as result FROM {$prototype->table} $constraints";
1863 
1864  trace($query, 3);
1865 
1866  try
1867  {
1869 
1870  $result = $db->prepare($query);
1871  $result->execute();
1872 
1873  if ($row = $result->fetch())
1874  {
1875  $value = $row['result'];
1876  }
1877 
1878  unset($result);
1879  }
1880  catch(PDOException $e)
1881  {
1882  $err = "queryValue() failed - " . $e->getMessage();
1883  trace($err, 2);
1884  throw new DataItemException($err);
1885  }
1886 
1887  return $value;
1888 }
static getConnection()
Retrieves a reference to the global database connection.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ regroupList()

regroupList (   $list,
  $field 
)

Regroup an indexed or grouped query result by a different field.

Parameters
array$listan array of DataItem-derived objects, as returned by query(), indexedQuery() or groupedQuery()
string$fieldthe field by which to regroup the list

Definition at line 1948 of file data_item.inc.

1949 {
1950  $result = array();
1951 
1952  foreach($list as $elt)
1953  {
1954  if (is_array($elt))
1955  {
1956  foreach ($elt as $e)
1957  {
1958  $result[$e->$field][] = $e;
1959  }
1960  }
1961  else
1962  {
1963  $result[$elt->$field][] = $elt;
1964  }
1965  }
1966 
1967  return $result;
1968 }

◆ reindexList()

reindexList (   $list,
  $field,
  $autoPromote = true 
)

Reindex an indexed or grouped query result by a different field.

Parameters
array$listan array of DataItem-derived objects, as returned by query(), indexedQuery() or groupedQuery()
string$fieldthe field by which to reindex the list

Definition at line 1898 of file data_item.inc.

1899 {
1900  $result = array();
1901 
1902  foreach($list as $elt)
1903  {
1904  if (is_array($elt))
1905  {
1906  foreach($elt as $e)
1907  {
1908  if (array_key_exists($e->$field, $result))
1909  {
1910  if (!is_array($result[$e->$field]))
1911  {
1912  $result[$e->$field] = array($result[$e->$field]);
1913  }
1914  $result[$e->$field][] = $e;
1915  }
1916  else
1917  {
1918  $result[$e->$field] = $e;
1919  }
1920  }
1921  }
1922  else
1923  {
1924  if (array_key_exists($elt->$field, $result) && $autoPromote)
1925  {
1926  if (!is_array($result[$elt->$field]))
1927  {
1928  $result[$elt->$field] = array($result[$elt->$field]);
1929  }
1930  $result[$elt->$field][] = $elt;
1931  }
1932  else
1933  {
1934  $result[$elt->$field] = $elt;
1935  }
1936  }
1937  }
1938 
1939  return $result;
1940 }

◆ removeDuplicates()

removeDuplicates (   $list,
  $field = "" 
)

Remove duplicate DataItems from a list, based on the value of a field.

If no field is specified, the items' primary key is used. It is assumed that all the objects in the list are of the same class. A filtered copy of the list is returned. The original list is left unchanged.

Parameters
array$listthe list of DataItems from which duplicates are to be removed
string$fieldthe name of the field to use to determine duplicity.
Returns
a filtered list containing no duplicates.

Definition at line 1981 of file data_item.inc.

1982 {
1983  if (count($list) == 0) return $list;
1984 
1985  if ($field == "")
1986  {
1987  $field = $list[0]->primary_key;
1988  }
1989 
1990  $found = array();
1991  $filtered = array();
1992  foreach($list as $item)
1993  {
1994  if (!array_key_exists($item->$field, $found))
1995  {
1996  $filtered[] = $item;
1997  }
1998 
1999  $found[$item->$field] = true;
2000  }
2001 
2002  return $filtered;
2003 }

◆ restoreHTML()

restoreHTML (   $text)

Definition at line 2292 of file data_item.inc.

2293 {
2294  $v = str_replace( array("[_[OPENTAG]_]", "[_[CLOSETAG]_]", "[_[AMPERSAND]_]"), array("<", ">", "&"), $text);
2295  return $v;
2296 }

◆ sortList()

sortList ( $list,
  $field 
)

Sorts an array of DataItems based on the values in the specified field.

Parameters
array$listan array of DataItems
string$fieldthe field to sort by
Returns
the sorted list

Definition at line 2030 of file data_item.inc.

2031 {
2032  $cmp = new DataItemFieldComparator($field);
2033 
2034  usort($list, array($cmp, "compare"));
2035 
2036  return $list;
2037 }
Simple field comparator to support sorting arrays of DataItems by the values in a specified field.
Definition: data_item.inc:2010

◆ toJSON()

toJSON (   $items)

Definition at line 2102 of file data_item.inc.

2103 {
2104  $out = array();
2105 
2106  foreach($items as $item)
2107  {
2108  $out[] = $item->toJSON();
2109  }
2110 
2111  return "[".implode(", ", $out)."]";
2112 }

◆ toJSONGrouped()

toJSONGrouped (   $items)

Definition at line 2114 of file data_item.inc.

2115 {
2116  $out = array();
2117 
2118  foreach($items as $key => $group)
2119  {
2120  $out[] = "\"$key\": ".toJSON($group);
2121  }
2122 
2123  return "{".implode(", ", $out)."}";
2124 }

◆ toJSONIndexed()

toJSONIndexed (   $items)

Definition at line 2126 of file data_item.inc.

2127 {
2128  $out = array();
2129 
2130  foreach($items as $key => $item)
2131  {
2132  $out[] = "\"$key\": ".$item->toJSON();
2133  }
2134 
2135  return "{".implode(", ", $out)."}";
2136 }

◆ toXML()

toXML (   $tag,
  $objects,
  $header = null 
)

Definition at line 2080 of file data_item.inc.

2081 {
2082  global $config;
2083 
2084  if ($header === null)
2085  {
2086  $default_charset = $config["default_charset"];
2087  if (!$default_charset) $default_charset = "iso-8859-1";
2088  $header = "<?xml version=\"1.0\" encoding=\"{$default_charset}\"?>";
2089  }
2090 
2091  $xml = "$header\n<$tag>\n";
2092 
2093  foreach($objects as $obj)
2094  {
2095  $xml .= $obj->toXML(1);
2096  }
2097  $xml .= "</$tag>\n";
2098 
2099  return $xml;
2100 }

◆ updateSortOrder()

updateSortOrder (   $class,
  $field = "sort_order",
  $params = null 
)

Utility method to update sort order for the selected class of objects based on an array that maps primary keys to sort order values.

This method is designed to make drag and drop sorting easier to implement.

Parameters
string$classthe class of DataItem that is being resorted
string$fieldthe field that contains the sort order value

Definition at line 2046 of file data_item.inc.

2047 {
2048  if (!$params) $params = $_GET;
2049  $obj = new $class;
2050  $pk = $obj->getPrimaryKey();
2051 
2052  $tx = new DataTransaction();
2053 
2054  try
2055  {
2056  foreach($params[$pk] as $id => $sort_order)
2057  {
2058  checkNumeric($id);
2059  checkNumeric($sort_order);
2060 
2061  $item = new $class();
2062  $item->joinTransaction($tx);
2063 
2064  $item->filter = new InclusionFilter($pk, $field);
2065 
2066  $item->load($id);
2067  $item->set($field, $sort_order);
2068  $item->save();
2069  }
2070 
2071  $tx->commit();
2072  }
2073  catch(Exception $e)
2074  {
2075  $tx->rollback();
2076  throw $e;
2077  }
2078 }
The DataTransaction class wraps the underlying database's transaction model.
Definition: transaction.inc:48
Used to place a filter on the contents of a DataItem-derived object.
checkNumeric($p)
Security helper function.
Definition: functions.inc:630

Variable Documentation

◆ ProtectHTML

const ProtectHTML 4

Definition at line 153 of file abstract_data_item.inc.

◆ SerializeDirectRelations

const SerializeDirectRelations 2

Definition at line 152 of file abstract_data_item.inc.

◆ SerializeRelations

const SerializeRelations 1

Definition at line 151 of file abstract_data_item.inc.