static function &stateInit($name = 'default', $defaults = array(), $source = array())
{
if (empty(Pommo::$_session['state'][$name])) {
Pommo::$_session['state'][$name] =& $defaults;
}
$state =& Pommo::$_session['state'][$name];
if (empty($defaults)) {
return $state;
}
//Add support for passing multi select options
if (is_array($source)) {
foreach ($source as $k => $v) {
if (is_array($source[$k])) {
$source[$k] = implode(',', $source[$k]);
}
}
}
foreach (array_keys($state) as $key) {
if (array_key_exists($key, $source)) {
$state[$key] = $source[$key];
}
}
// normalize the page state
if (count($state) > count($defaults)) {
$state = Pommo_Helper::arrayIntersect($state, $defaults);
}
return $state;
}