/**
  * construct a swiss swiss factory and create it if it doesn't exist.
  * @param I2CE_MagicDataNode $storage.  The root of the magic data we will be operating on
  * @param string  $type.  The  type of the root swiwss.  Defaults to 'Swiss'
  * @throws Exception
  */
 public function __construct($page, $init_options = array())
 {
     if (array_key_exists('root_url_postfix', $init_options) && $init_options['root_url_postfix']) {
         $this->root_url_postfix = $init_options['root_url_postfix'];
     } else {
         $this->root_url_postfix = false;
     }
     if (array_key_exists('root_type', $init_options) && $init_options['root_type']) {
         $this->root_type = $init_options['root_type'];
     } else {
         $this->root_type = false;
     }
     if (array_key_exists('root_url', $init_options) && $init_options['root_url']) {
         $this->root_url = $init_options['root_url'];
     } else {
         $this->root_url = false;
     }
     if (array_key_exists('root_path', $init_options) && $init_options['root_path']) {
         $this->root_path = $init_options['root_path'];
     } else {
         $this->root_path = false;
     }
     if (array_key_exists('root_path_create', $init_options) && $init_options['root_path_create']) {
         $this->root_path_create = true;
     } else {
         $this->root_path_create = false;
     }
     parent::__construct($page, $init_options);
     if (array_key_exists('status', $init_options) && is_array($init_options['status'])) {
         $this->status = $init_options['status'];
     } else {
         $this->status = array('showIndex' => false, 'visible' => true, 'advanced' => true);
     }
 }
 /**
  * construct a swiss swiss factory and create it if it doesn't exist.
  * @param I2CE_MagicDataNode $storage.  The root of the magic data we will be operating on
  * @param string  $swissName.  The classname for the root swiss object.
  * @throws Exception
  */
 public function __construct($page, $options = array())
 {
     $this->child_node_cache = array();
     $this->child_node_cache_index = array();
     parent::__construct($page);
     if (!array_key_exists('module', $options) || !$options['module']) {
         throw new Exception("No modules specified");
     }
     $this->module = $options['module'];
     $config_file = null;
     if (!I2CE::getConfig()->setIfIsSet($config_file, "/config/data/{$options['module']}/file")) {
         throw new Exception("No magic data template found for {$options['module']}");
     }
     $this->configTemplate = new I2CE_MagicDataTemplate();
     if (!$this->configTemplate->loadRootFile($config_file)) {
         throw new Exception("Invalid magic data template found for {$options['module']}");
     }
     $this->xpath = new DOMXPath($this->configTemplate->getDoc());
     $this->configNodes = array();
     $nodes = $this->xpath->query('/I2CEConfiguration/configurationGroup');
     if ($nodes->length != 1) {
         throw new Exception("No or invalid configuration data for {$options['module']}");
     }
     $this->configNodes['/'] = $nodes->item(0);
     $this->statii['/'] = $this->configTemplate->getDefaultStatus();
     if (!array_key_exists('version', $this->statii['/'])) {
         if (array_key_exists('version', $options)) {
             $this->statii['/']['version'] = $options['version'];
         } else {
             $this->statii['/']['version'] = 0;
         }
     }
     $file_search = new I2CE_FileSearch();
     $mod_factory = I2CE_ModuleFactory::instance();
     $mod_factory->loadPaths($this->module, 'CONFIGS', true, $file_search);
     $translated = $file_search->search('CONFIGS', $config_file, true);
     $translated_locales = $file_search->getLocaleOfLastSearch();
     $preferred_locales = I2CE_Locales::getPreferredLocales();
     $this->translatedConfigs = array();
     foreach ($preferred_locales as $locale) {
         if (($index = array_search($locale, $translated_locales)) === false) {
             continue;
         }
         $trans_file = $translated[$index];
         $trans_template = new I2CE_MagicDataTemplate();
         if (!$trans_template->loadRootFile($trans_file)) {
             continue;
         }
         $this->translatedConfigs[$locale] = $trans_template;
     }
 }