2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
|
2008-01-08 07:37:50 +01:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage view
|
|
|
|
*/
|
|
|
|
|
2007-07-19 12:40:28 +02: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.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* new ArrayData(array(
|
|
|
|
* "ClassName" => "Page",
|
|
|
|
* "AddAction" => "Add a new Page page",
|
|
|
|
* ));
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage view
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
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) {
|
|
|
|
$this->array = $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
?>
|