data = $data;
$this->sm_settings = $sm_settings;
$this->api = $api;
}
function set_affiliate_data($aff_kwid, $aff_track){
$this->affiliate['aff_kwid'] = $aff_kwid;
$this->affiliate['aff_track'] = $aff_track;
}
function getIterator(){
return new ArrayIterator($this->data);
}
function get_api(){
return $this->api;
}
function get_data($name = null, $default = null){
if (is_null($name)) return $this->data;
elseif (isset($this->data[$name])) return $this->data[$name];
elseif (! is_null($default)) return $default;
throw new Exception ("No data exists for \"$name\"");
}
function has_errors(){
return isset($this->data['errors']);
}
function get_errors($formatted = false){
if (isset($this->data['errors']) AND count($this->data['errors'])){
return $this->data['errors'];
} else {
return array();
}
}
function get_formatted_errors($format="html"){
$errors = $this->data['errors'];
if (!empty($this->data['errors'])){
foreach($errors as $error_name => $error_item){
$errors[$error_name] = implode("", $error_item);
}
if ($format=="html"){
foreach($errors as $error_name => $error_item){
$errors[$error_name] = "
$error_item";
}
return "- " . implode("
\n- ", $errors) . "
";
}
elseif ($format=="text"){
foreach($errors as $error_name => $error_item){
$errors[$error_name] = "$error_name : $error_item; \n";
}
return "Errors :\n" . implode("\n", $errors);
} else {
throw new Exception("unknown error format : $format");
}
} else throw new Exception("Currently no errors, call method \"has_errors\" first");
}
function set_parameter($name, $data){
$this->parameters[$name] = $data;
}
function get_parameter($name, $default=null){
if (isset($this->parameters[$name])) return $this->parameters[$name];
elseif (!is_null($default)) return $default;
throw new Exception ("No parameter exists for \"$name\"");
}
function has_parameter($name){
return isset($this->parameters[$name]);
}
function render(){
//get renderable object
$renderable = $this->get_renderable();
//process it
return $renderable->render($this);
}
function get_renderable(){
//if renderable already exists
if (!is_null($this->renderable)) return $this->renderable;
//otherwise generate renderable
//make a class that will render the data
$renderable_class_name = get_class($this) . '__' . $this->get_parameter("view", "basic");
$this->renderable = new $renderable_class_name($this);
//merge the parameters and save them to this object
$this->parameters = array_merge($this->renderable->get_parameters(), $this->parameters);
return $this->renderable;
}
}