2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
|
2008-01-08 07:37:50 +01:00
|
|
|
/**
|
2008-02-25 02:06:39 +01:00
|
|
|
* Lets you wrap a bunch of array data into a ViewableData object.
|
|
|
|
* This is useful when you want to pass data to a template in the "SilverStripe 1" way of giving a
|
|
|
|
* big data array.
|
2007-07-19 12:40:28 +02:00
|
|
|
*
|
2008-02-25 02:06:39 +01:00
|
|
|
* Usage:
|
2007-07-19 12:40:28 +02:00
|
|
|
* new ArrayData(array(
|
|
|
|
* "ClassName" => "Page",
|
|
|
|
* "AddAction" => "Add a new Page page",
|
|
|
|
* ));
|
|
|
|
*/
|
|
|
|
class ArrayData extends ViewableData {
|
2007-10-20 10:36:47 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $array;
|
|
|
|
|
|
|
|
public function __construct($array) {
|
2008-02-25 02:06:39 +01:00
|
|
|
$this->array = $array;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getField($f) {
|
2007-10-20 10:36:47 +02:00
|
|
|
if(is_array($this->array[$f])) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return new ArrayData($this->array[$f]);
|
2007-10-20 10:36:47 +02:00
|
|
|
} else {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->array[$f];
|
2007-10-20 10:36:47 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-10-20 10:36:47 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
public function hasField($f) {
|
|
|
|
return isset($this->array[$f]);
|
|
|
|
}
|
2007-10-20 10:36:47 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|