public function execute($request)
 {
     $this->form = new sfForm();
     if (!$this->context->user->hasCredential('administrator')) {
         QubitAcl::forwardUnauthorized();
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'plugins');
     if (1 == count($query = QubitSetting::get($criteria))) {
         $setting = $query[0];
         $this->form->setDefault('enabled', unserialize($setting->__get('value', array('sourceCulture' => true))));
     }
     $configuration = ProjectConfiguration::getActive();
     $pluginPaths = $configuration->getAllPluginPaths();
     foreach (sfPluginAdminPluginConfiguration::$pluginNames as $name) {
         unset($pluginPaths[$name]);
     }
     $this->plugins = array();
     foreach ($pluginPaths as $name => $path) {
         $className = $name . 'Configuration';
         if (sfConfig::get('sf_plugins_dir') == substr($path, 0, strlen(sfConfig::get('sf_plugins_dir'))) && is_readable($classPath = $path . '/config/' . $className . '.class.php')) {
             $this->installPluginAssets($name, $path);
             require_once $classPath;
             $class = new $className($configuration);
             // Build a list of themes
             if (isset($class::$summary) && 1 === preg_match('/theme/i', $class::$summary)) {
                 $this->plugins[$name] = $class;
             }
         }
     }
     if ($request->isMethod('post')) {
         $this->form->setValidators(array('enabled' => new sfValidatorChoice(array('choices' => array_keys($this->plugins), 'empty_value' => array(), 'multiple' => true))));
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             if (1 != count($query)) {
                 $setting = new QubitSetting();
                 $setting->name = 'plugins';
             }
             $settings = unserialize($setting->__get('value', array('sourceCulture' => true)));
             foreach (array_keys($this->plugins) as $item) {
                 if (in_array($item, (array) $this->form->getValue('enabled'))) {
                     $settings[] = $item;
                 } else {
                     if (false !== ($key = array_search($item, $settings))) {
                         unset($settings[$key]);
                     }
                 }
             }
             $setting->__set('value', serialize(array_unique($settings)));
             $setting->save();
             // Clear cache
             $cacheClear = new sfCacheClearTask(sfContext::getInstance()->getEventDispatcher(), new sfFormatter());
             $cacheClear->run();
             $this->redirect(array('module' => 'sfPluginAdminPlugin', 'action' => 'themes'));
         }
     }
 }
 public function execute($request)
 {
     $this->form = new sfForm();
     $this->form->setWidgets(array('toggleDescription' => new sfWidgetFormInputCheckbox(), 'toggleLogo' => new sfWidgetFormInputCheckbox(), 'toggleTitle' => new sfWidgetFormInputCheckbox()));
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleDescription');
     if (1 == count($toggleDescriptionQuery = QubitSetting::get($criteria))) {
         $toggleDescriptionSetting = $toggleDescriptionQuery[0];
         $this->form->setDefault('toggleDescription', $toggleDescriptionSetting->__get('value', array('sourceCulture' => true)));
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleLogo');
     if (1 == count($toggleLogoQuery = QubitSetting::get($criteria))) {
         $toggleLogoSetting = $toggleLogoQuery[0];
         $this->form->setDefault('toggleLogo', $toggleLogoSetting->__get('value', array('sourceCulture' => true)));
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleTitle');
     if (1 == count($toggleTitleQuery = QubitSetting::get($criteria))) {
         $toggleTitleSetting = $toggleTitleQuery[0];
         $this->form->setDefault('toggleTitle', $toggleTitleSetting->__get('value', array('sourceCulture' => true)));
     }
     if ($request->isMethod('post')) {
         $this->form->setValidators(array('toggleDescription' => new sfValidatorBoolean(), 'toggleLogo' => new sfValidatorBoolean(), 'toggleTitle' => new sfValidatorBoolean()));
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             if (1 != count($toggleDescriptionQuery)) {
                 $toggleDescriptionSetting = new QubitSetting();
                 $toggleDescriptionSetting->name = 'toggleDescription';
             }
             $toggleDescriptionSetting->__set('value', $this->form->getValue('toggleDescription'), array('sourceCulture' => true));
             $toggleDescriptionSetting->save();
             if (1 != count($toggleLogoQuery)) {
                 $toggleLogoSetting = new QubitSetting();
                 $toggleLogoSetting->name = 'toggleLogo';
             }
             $toggleLogoSetting->__set('value', $this->form->getValue('toggleLogo'), array('sourceCulture' => true));
             $toggleLogoSetting->save();
             if (1 != count($toggleTitleQuery)) {
                 $toggleTitleSetting = new QubitSetting();
                 $toggleTitleSetting->name = 'toggleTitle';
             }
             $toggleTitleSetting->__set('value', $this->form->getValue('toggleTitle'), array('sourceCulture' => true));
             $toggleTitleSetting->save();
             $this->redirect(array('module' => 'settings', 'action' => 'list'));
         }
     }
 }
 protected function addField($name)
 {
     switch ($name) {
         case 'username':
             $this->form->setDefault('username', $this->resource->username);
             $this->form->setValidator('username', new sfValidatorString(array('required' => true)));
             $this->form->setWidget('username', new sfWidgetFormInput());
             break;
         case 'email':
             $this->form->setDefault('email', $this->resource->email);
             $this->form->setValidator('email', new sfValidatorEmail(array('required' => true)));
             $this->form->setWidget('email', new sfWidgetFormInput());
             break;
         case 'password':
         case 'confirmPassword':
             $this->form->setDefault($name, null);
             // Required field only if a new user is being created
             $this->form->setValidator($name, new sfValidatorString(array('required' => !isset($this->getRoute()->resource))));
             $this->form->setWidget($name, new sfWidgetFormInputPassword());
             break;
         case 'groups':
             $values = array();
             $criteria = new Criteria();
             $criteria->add(QubitAclUserGroup::USER_ID, $this->resource->id);
             foreach (QubitAclUserGroup::get($criteria) as $item) {
                 $values[] = $item->groupId;
             }
             $choices = array();
             $criteria = new Criteria();
             $criteria->add(QubitAclGroup::ID, 99, Criteria::GREATER_THAN);
             foreach (QubitAclGroup::get($criteria) as $item) {
                 $choices[$item->id] = $item->getName(array('cultureFallback' => true));
             }
             $this->form->setDefault('groups', $values);
             $this->form->setValidator('groups', new sfValidatorPass());
             $this->form->setWidget('groups', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
         case 'translate':
             $c = sfCultureInfo::getInstance($this->context->user->getCulture());
             $languages = $c->getLanguages();
             $choices = array();
             if (0 < count($langSettings = QubitSetting::getByScope('i18n_languages'))) {
                 foreach ($langSettings as $item) {
                     $choices[$item->name] = $languages[$item->name];
                 }
             }
             // Find existing translate permissions
             $criteria = new Criteria();
             $criteria->add(QubitAclPermission::USER_ID, $this->resource->id);
             $criteria->add(QubitAclPermission::ACTION, 'translate');
             $defaults = null;
             if (null !== ($permission = QubitAclPermission::getOne($criteria))) {
                 $defaults = $permission->getConstants(array('name' => 'languages'));
             }
             $this->form->setDefault('translate', $defaults);
             $this->form->setValidator('translate', new sfValidatorPass());
             $this->form->setWidget('translate', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
             break;
     }
 }
 public static function getAccessionNumber($incrementCounter)
 {
     $setting = QubitSetting::getSettingByName('accession_counter');
     if ($incrementCounter) {
         $setting->value = $setting->getValue(array('sourceCulture' => true)) + 1;
         $setting->save();
         return $setting->getValue(array('sourceCulture' => true));
     }
     return $setting->getValue(array('sourceCulture' => true)) + 1;
 }
 public function execute($request)
 {
     $setting = QubitSetting::getById($this->request->id);
     $this->forward404Unless($setting);
     // check that the setting is deleteable
     if ($setting->isDeleteable()) {
         $setting->delete();
     }
     // TODO: else populate an error?
     $this->refreshSettings();
     $this->redirect('settings/list');
 }
 public function execute($request)
 {
     $this->form = new sfForm();
     $this->form->setValidator('confirmPassword', new sfValidatorString(array('required' => true)));
     $this->form->setWidget('confirmPassword', new sfWidgetFormInputPassword());
     $this->form->setValidator('email', new sfValidatorEmail(array('required' => true)));
     $this->form->setWidget('email', new sfWidgetFormInput());
     $this->form->setValidator('password', new sfValidatorString(array('required' => true)));
     $this->form->setWidget('password', new sfWidgetFormInputPassword());
     $this->form->setValidator('siteDescription', new sfValidatorString());
     $this->form->setWidget('siteDescription', new sfWidgetFormInput());
     $this->form->setValidator('siteTitle', new sfValidatorString(array('required' => true)));
     $this->form->setWidget('siteTitle', new sfWidgetFormInput());
     $this->form->setValidator('username', new sfValidatorString(array('required' => true)));
     $this->form->setWidget('username', new sfWidgetFormInput());
     $this->form->getValidatorSchema()->setPostValidator(new sfValidatorSchemaCompare('password', '==', 'confirmPassword'));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             $setting = new QubitSetting();
             $setting->name = 'siteTitle';
             $setting->value = $this->form->getValue('siteTitle');
             $setting->save();
             $setting = new QubitSetting();
             $setting->name = 'siteDescription';
             $setting->value = $this->form->getValue('siteDescription');
             $setting->save();
             $user = new QubitUser();
             $user->username = $this->form->getValue('username');
             $user->email = $this->form->getValue('email');
             $user->setPassword($this->form->getValue('password'));
             $user->save();
             $aclUserGroup = new QubitAclUserGroup();
             $aclUserGroup->userId = $user->id;
             $aclUserGroup->groupId = QubitAclGroup::ADMINISTRATOR_ID;
             $aclUserGroup->save();
             $this->redirect(array('module' => 'sfInstallPlugin', 'action' => 'clearCache'));
         }
     }
 }
 /**
  * @see sfPluginConfiguration
  */
 public function initialize()
 {
     // Project classes, e.g. QubitSetting, not loaded unless
     // sfApplicationConfiguration,
     // http://qubit-toolkit.org/wiki/index.php?title=Autoload#Plugins
     if (!$this->configuration instanceof sfApplicationConfiguration) {
         return;
     }
     $enabledModules = sfConfig::get('sf_enabled_modules');
     $enabledModules[] = 'sfPluginAdminPlugin';
     sfConfig::set('sf_enabled_modules', $enabledModules);
     // Stash plugin names enabled in ProjectConfiguration.class.php for
     // sfPluginAdminPluginIndexAction. Where is the best place to stash it?
     // This is probably not the best place : P
     sfPluginAdminPluginConfiguration::$pluginNames = $this->configuration->getPlugins();
     new sfDatabaseManager($this->configuration);
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'plugins');
     try {
         if (1 == count($query = QubitSetting::get($criteria))) {
             // http://qubit-toolkit.org/wiki/index.php?title=Autoload
             $this->dispatcher->disconnect('autoload.filter_config', array($this->configuration, 'filterAutoloadConfig'));
             $pluginNames = unserialize($query[0]->__get('value', array('sourceCulture' => true)));
             $this->configuration->enablePlugins($pluginNames);
             $pluginPaths = $this->configuration->getAllPluginPaths();
             foreach ($pluginNames as $name) {
                 if (!isset($pluginPaths[$name])) {
                     throw new InvalidArgumentException('The plugin "' . $name . '" does not exist.');
                 }
                 // Copied from sfProjectConfiguration::loadPlugins()
                 $className = $name . 'Configuration';
                 if (!is_readable($path = $pluginPaths[$name] . '/config/' . $className . '.class.php')) {
                     $configuration = new sfPluginConfigurationGeneric($this->configuration, $pluginPaths[$name], $name);
                 } else {
                     require_once $path;
                     $configuration = new $className($this->configuration, $pluginPaths[$name], $name);
                 }
                 // Is this cached?
                 $configuration->initializeAutoload();
                 $configuration->initialize();
                 $this->configuration->pluginConfigurations[$name] = $configuration;
             }
             $this->dispatcher->connect('autoload.filter_config', array($this->configuration, 'filterAutoloadConfig'));
         }
     } catch (PropelException $e) {
         // Silently swallow PropelException because we can't tell at this point
         // if we are in install, and install plugin can't listen for an exception
         // thrown at this point, is this the best solution?
     }
 }
 public function execute($filterChain)
 {
     // Create a function cache object for the QubitSettings method call
     $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir') . '/settings'));
     // Get settings (from cache if exists)
     if ($cache->has('settings')) {
         $settings = unserialize($cache->get('settings'));
     } else {
         $settings = QubitSetting::getSettingsArray();
         $cache->set('settings', serialize($settings));
     }
     // Overwrite/populate settings into sfConfig object
     sfConfig::add($settings);
     // Execute next filter
     $filterChain->execute();
 }
 public function contextLoadFactories(sfEvent $event)
 {
     $context = $event->getSubject();
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'siteTitle');
     try {
         if (1 == count($query = QubitSetting::get($criteria))) {
             $context->response->addMeta('title', $query[0]->__get('value', array('cultureFallback' => true)));
         }
     } catch (PropelException $e) {
         // Silently swallow PropelException in install
         if ('sfInstallPlugin' != $context->request->module) {
             throw $e;
         }
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'siteDescription');
     try {
         if (1 == count($query = QubitSetting::get($criteria))) {
             $context->response->addMeta('description', $query[0]->__get('value', array('cultureFallback' => true)));
         }
     } catch (PropelException $e) {
         // Silently swallow PropelException in install
         if ('sfInstallPlugin' != $context->request->module) {
             throw $e;
         }
     }
     foreach (array('actor_template', 'informationobject_template', 'repository_template') as $name) {
         if (isset($context->request[$name])) {
             $context->routing->setDefaultParameter($name, $context->request[$name]);
         } else {
             $criteria = new Criteria();
             $criteria->add(QubitSetting::NAME, substr($name, 0, -9));
             $criteria->add(QubitSetting::SCOPE, 'default_template');
             try {
                 if (1 == count($query = QubitSetting::get($criteria))) {
                     $context->routing->setDefaultParameter($name, $query[0]->__get('value', array('sourceCulture' => true)));
                 }
             } catch (PropelException $e) {
                 // Silently swallow PropelException in install
                 if ('sfInstallPlugin' != $context->request->module) {
                     throw $e;
                 }
             }
         }
     }
 }
 protected function initializeDefaultPageElementsForm()
 {
     $this->defaultPageElementsForm = new sfForm();
     $this->defaultPageElementsForm->setWidgets(array('toggleDescription' => new sfWidgetFormInputCheckbox(), 'toggleLogo' => new sfWidgetFormInputCheckbox(), 'toggleTitle' => new sfWidgetFormInputCheckbox()));
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleDescription');
     if (1 == count($toggleDescriptionQuery = QubitSetting::get($criteria))) {
         $toggleDescriptionSetting = $toggleDescriptionQuery[0];
         $this->defaultPageElementsForm->setDefault('toggleDescription', $toggleDescriptionSetting->__get('value', array('sourceCulture' => true)));
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleLogo');
     if (1 == count($toggleLogoQuery = QubitSetting::get($criteria))) {
         $toggleLogoSetting = $toggleLogoQuery[0];
         $this->defaultPageElementsForm->setDefault('toggleLogo', $toggleLogoSetting->__get('value', array('sourceCulture' => true)));
     }
     $criteria = new Criteria();
     $criteria->add(QubitSetting::NAME, 'toggleTitle');
     if (1 == count($toggleTitleQuery = QubitSetting::get($criteria))) {
         $toggleTitleSetting = $toggleTitleQuery[0];
         $this->defaultPageElementsForm->setDefault('toggleTitle', $toggleTitleSetting->__get('value', array('sourceCulture' => true)));
     }
     return $this;
 }
<?php

echo get_component('default', 'updateCheck');
?>

<?php 
if ($sf_user->isAdministrator() && (string) QubitSetting::getByName('siteBaseUrl') === '') {
    ?>
    <div id="update-check">
        <?php 
    echo link_to('Please configure your site base URL', 'settings/siteInformation', array('rel' => 'home', 'title' => __('Home')));
    ?>
    </div>
<?php 
}
?>

<header>
    <div class="row" id="top-bar">
        <div id="account-controls-container">
            <?php 
echo get_component('menu', 'userMenu');
?>
        </div>
        <div id="logo-container">
            <?php 
echo link_to(image_tag('/plugins/sfCendariThemePlugin/images/cendari_logo.png'), '@homepage', array('id' => 'logo', 'rel' => 'home'));
?>
        </div>
        <div id="search-controls-container">
            <div id="search-bar">
 public function import($xmlFile, $options = array())
 {
     // load the XML document into a DOMXML object
     $importDOM = $this->loadXML($xmlFile, $options);
     // if we were unable to parse the XML file at all
     if (empty($importDOM->documentElement)) {
         $errorMsg = sfContext::getInstance()->i18n->__('Unable to parse XML file: malformed or unresolvable entities');
         throw new Exception($errorMsg);
     }
     // if libxml threw errors, populate them to show in the template
     if ($importDOM->libxmlerrors) {
         // warning condition, XML file has errors (perhaps not well-formed or invalid?)
         foreach ($importDOM->libxmlerrors as $libxmlerror) {
             $xmlerrors[] = sfContext::getInstance()->i18n->__('libxml error %code% on line %line% in input file: %message%', array('%code%' => $libxmlerror->code, '%message%' => $libxmlerror->message, '%line%' => $libxmlerror->line));
         }
         $this->errors = array_merge((array) $this->errors, $xmlerrors);
     }
     if ('eac-cpf' == $importDOM->documentElement->tagName) {
         $this->rootObject = new QubitActor();
         $this->rootObject->parentId = QubitActor::ROOT_ID;
         $eac = new sfEacPlugin($this->rootObject);
         $eac->parse($importDOM);
         $this->rootObject->save();
         return $this;
     }
     // FIXME hardcoded until we decide how these will be developed
     $validSchemas = array('+//ISBN 1-931666-00-8//DTD ead.dtd Encoded Archival Description (EAD) Version 2002//EN' => 'ead', '-//Society of American Archivists//DTD ead.dtd (Encoded Archival Description (EAD) Version 1.0)//EN' => 'ead1', 'http://www.loc.gov/METS/' => 'mets', 'http://www.loc.gov/mods/' => 'mods', 'http://www.loc.gov/MARC21/slim' => 'marc', 'record' => 'oai_dc_record', 'dc' => 'dc', 'oai_dc:dc' => 'dc', 'dublinCore' => 'dc', 'metadata' => 'dc', 'ead' => 'ead', 'add' => 'alouette', 'http://www.w3.org/2004/02/skos/core#' => 'skos');
     // determine what kind of schema we're trying to import
     $schemaDescriptors = array($importDOM->documentElement->tagName);
     if (!empty($importDOM->namespaces)) {
         krsort($importDOM->namespaces);
         $schemaDescriptors = array_merge($schemaDescriptors, $importDOM->namespaces);
     }
     if (!empty($importDOM->doctype)) {
         $schemaDescriptors = array_merge($schemaDescriptors, array($importDOM->doctype->name, $importDOM->doctype->systemId, $importDOM->doctype->publicId));
     }
     foreach ($schemaDescriptors as $descriptor) {
         if (array_key_exists($descriptor, $validSchemas)) {
             $importSchema = $validSchemas[$descriptor];
         }
     }
     switch ($importSchema) {
         case 'ead':
             // just validate EAD import for now until we can get StrictXMLParsing working for all schemas in the self::LoadXML function. Having problems right now loading schemas.
             $importDOM->validate();
             // if libxml threw errors, populate them to show in the template
             foreach (libxml_get_errors() as $libxmlerror) {
                 $this->errors[] = sfContext::getInstance()->i18n->__('libxml error %code% on line %line% in input file: %message%', array('%code%' => $libxmlerror->code, '%message%' => $libxmlerror->message, '%line%' => $libxmlerror->line));
             }
             break;
         case 'skos':
             $criteria = new Criteria();
             $criteria->add(QubitSetting::NAME, 'plugins');
             $setting = QubitSetting::getOne($criteria);
             if (null === $setting || !in_array('sfSkosPlugin', unserialize($setting->getValue(array('sourceCulture' => true))))) {
                 throw new sfException(sfContext::getInstance()->i18n->__('The SKOS plugin is not enabled'));
             }
             $importTerms = sfSkosPlugin::parse($importDOM);
             $this->rootObject = QubitTaxonomy::getById(QubitTaxonomy::SUBJECT_ID);
             $this->count = count($importTerms);
             return $this;
             break;
     }
     $importMap = sfConfig::get('sf_app_module_dir') . DIRECTORY_SEPARATOR . 'object' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'import' . DIRECTORY_SEPARATOR . $importSchema . '.yml';
     if (!file_exists($importMap)) {
         // error condition, unknown schema or no import filter
         $errorMsg = sfContext::getInstance()->i18n->__('Unknown schema or import format: "%format%"', array('%format%' => $importSchema));
         throw new Exception($errorMsg);
     }
     $this->schemaMap = sfYaml::load($importMap);
     // if XSLs are specified in the mapping, process them
     if (!empty($this->schemaMap['processXSLT'])) {
         // pre-filter through XSLs in order
         foreach ((array) $this->schemaMap['processXSLT'] as $importXSL) {
             $importXSL = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'xslt' . DIRECTORY_SEPARATOR . $importXSL;
             if (file_exists($importXSL)) {
                 // instantiate an XSLT parser
                 $xslDOM = new DOMDocument();
                 $xslDOM->load($importXSL);
                 // Configure the transformer
                 $xsltProc = new XSLTProcessor();
                 $xsltProc->registerPHPFunctions();
                 $xsltProc->importStyleSheet($xslDOM);
                 $importDOM->loadXML($xsltProc->transformToXML($importDOM));
                 unset($xslDOM);
                 unset($xsltProc);
             } else {
                 $this->errors[] = sfContext::getInstance()->i18n->__('Unable to load import XSL filter: "%importXSL%"', array('%importXSL%' => $importXSL));
             }
         }
         // re-initialize xpath on the new XML
         $importDOM->xpath = new DOMXPath($importDOM);
     }
     // switch source culture if langusage is set in an EAD document
     if ($importSchema == 'ead') {
         if (is_object($langusage = $importDOM->xpath->query('//eadheader/profiledesc/langusage/language/@langcode'))) {
             $sf_user = sfContext::getInstance()->user;
             $currentCulture = $sf_user->getCulture();
             $langCodeConvertor = new fbISO639_Map();
             foreach ($langusage as $language) {
                 $isocode = trim(preg_replace('/[\\n\\r\\s]+/', ' ', $language->nodeValue));
                 // convert to Symfony culture code
                 if (!($twoCharCode = strtolower($langCodeConvertor->getID2($isocode)))) {
                     $twoCharCode = $isocode;
                 }
                 // Check to make sure that the selected language is supported with a Symfony i18n data file.
                 // If not it will cause a fatal error in the Language List component on every response.
                 ProjectConfiguration::getActive()->loadHelpers('I18N');
                 try {
                     format_language($twoCharCode, $twoCharCode);
                 } catch (Exception $e) {
                     $this->errors[] = sfContext::getInstance()->i18n->__('EAD "langmaterial" is set to') . ': "' . $isocode . '". ' . sfContext::getInstance()->i18n->__('This language is currently not supported.');
                     continue;
                 }
                 if ($currentCulture !== $twoCharCode) {
                     $this->errors[] = sfContext::getInstance()->i18n->__('EAD "langmaterial" is set to') . ': "' . $isocode . '" (' . format_language($twoCharCode, 'en') . '). ' . sfContext::getInstance()->i18n->__('Your XML document has been saved in this language and your user interface has just been switched to this language.');
                 }
                 $sf_user->setCulture($twoCharCode);
                 // can only set to one language, so have to break once the first valid language is encountered
                 break;
             }
         }
     }
     unset($this->schemaMap['processXSLT']);
     // go through schema map and populate objects/properties
     foreach ($this->schemaMap as $name => $mapping) {
         // if object is not defined or a valid class, we can't process this mapping
         if (empty($mapping['Object']) || !class_exists('Qubit' . $mapping['Object'])) {
             $this->errors[] = sfContext::getInstance()->i18n->__('Non-existent class defined in import mapping: "%class%"', array('%class%' => 'Qubit' . $mapping['Object']));
             continue;
         }
         // get a list of XML nodes to process
         $nodeList = $importDOM->xpath->query($mapping['XPath']);
         foreach ($nodeList as $domNode) {
             // create a new object
             $class = 'Qubit' . $mapping['Object'];
             $currentObject = new $class();
             // set the rootObject to use for initial display in successful import
             if (!$this->rootObject) {
                 $this->rootObject = $currentObject;
             }
             // if a parent path is specified, try to parent the node
             if (empty($mapping['Parent'])) {
                 $parentNodes = new DOMNodeList();
             } else {
                 $parentNodes = $importDOM->xpath->query('(' . $mapping['Parent'] . ')', $domNode);
             }
             if ($parentNodes->length > 0) {
                 // parent ID comes from last node in the list because XPath forces forward document order
                 $parentId = $parentNodes->item($parentNodes->length - 1)->getAttribute('xml:id');
                 unset($parentNodes);
                 if (!empty($parentId) && is_callable(array($currentObject, 'setParentId'))) {
                     $currentObject->parentId = $parentId;
                 }
             } else {
                 // orphaned object, set root if possible
                 if (is_callable(array($currentObject, 'setRoot'))) {
                     $currentObject->setRoot();
                 }
             }
             // go through methods and populate properties
             foreach ($mapping['Methods'] as $name => $methodMap) {
                 // if method is not defined, we can't process this mapping
                 if (empty($methodMap['Method']) || !is_callable(array($currentObject, $methodMap['Method']))) {
                     $this->errors[] = sfContext::getInstance()->i18n->__('Non-existent method defined in import mapping: "%method%"', array('%method%' => $methodMap['Method']));
                     continue;
                 }
                 // get a list of XML nodes to process
                 $nodeList2 = $importDOM->xpath->query($methodMap['XPath'], $domNode);
                 if (is_object($nodeList2)) {
                     switch ($name) {
                         // hack: some multi-value elements (e.g. 'languages') need to get passed as one array instead of individual nodes values
                         case 'languages':
                             $langCodeConvertor = new fbISO639_Map();
                             $value = array();
                             foreach ($nodeList2 as $nodeee) {
                                 if ($twoCharCode = $langCodeConvertor->getID2($nodeee->nodeValue)) {
                                     $value[] = strtolower($twoCharCode);
                                 } else {
                                     $value[] = $nodeee->nodeValue;
                                 }
                             }
                             $currentObject->language = $value;
                             break;
                         case 'flocat':
                             $resources = array();
                             foreach ($nodeList2 as $nodeee) {
                                 $resources[] = $nodeee->nodeValue;
                             }
                             if (0 < count($resources)) {
                                 $currentObject->importDigitalObjectFromUri($resources);
                             }
                             break;
                         default:
                             foreach ($nodeList2 as $domNode2) {
                                 // normalize the node text (trim whitespace manually); NB: this will strip any child elements, eg. HTML tags
                                 $nodeValue = trim(preg_replace('/[\\n\\r\\s]+/', ' ', $domNode2->nodeValue));
                                 // if you want the full XML from the node, use this
                                 $nodeXML = $domNode2->ownerDocument->saveXML($domNode2);
                                 // set the parameters for the method call
                                 if (empty($methodMap['Parameters'])) {
                                     $parameters = array($nodeValue);
                                 } else {
                                     $parameters = array();
                                     foreach ((array) $methodMap['Parameters'] as $parameter) {
                                         // if the parameter begins with %, evaluate it as an XPath expression relative to the current node
                                         if ('%' == substr($parameter, 0, 1)) {
                                             // evaluate the XPath expression
                                             $xPath = substr($parameter, 1);
                                             $result = $importDOM->xpath->query($xPath, $domNode2);
                                             if ($result->length > 1) {
                                                 // convert nodelist into an array
                                                 foreach ($result as $element) {
                                                     $resultArray[] = $element->nodeValue;
                                                 }
                                                 $parameters[] = $resultArray;
                                             } else {
                                                 // pass the node value unaltered; this provides an alternative to $nodeValue above
                                                 $parameters[] = $result->item(0)->nodeValue;
                                             }
                                         } else {
                                             // Confirm DOMXML node exists to avoid warnings at run-time
                                             if (false !== preg_match_all('/\\$importDOM->xpath->query\\(\'@\\w+\', \\$domNode2\\)->item\\(0\\)->nodeValue/', $parameter, $matches)) {
                                                 foreach ($matches[0] as $match) {
                                                     $str = str_replace('->nodeValue', '', $match);
                                                     if (null !== ($node = eval('return ' . $str . ';'))) {
                                                         // Substitute node value for search string
                                                         $parameter = str_replace($match, '\'' . $node->nodeValue . '\'', $parameter);
                                                     } else {
                                                         // Replace empty nodes with null in parameter string
                                                         $parameter = str_replace($match, 'null', $parameter);
                                                     }
                                                 }
                                             }
                                             eval('$parameters[] = ' . $parameter . ';');
                                         }
                                     }
                                 }
                                 // invoke the object and method defined in the schema map
                                 call_user_func_array(array(&$currentObject, $methodMap['Method']), $parameters);
                             }
                     }
                     unset($nodeList2);
                 }
             }
             // make sure we have a publication status set before indexing
             if ($currentObject instanceof QubitInformationObject && count($currentObject->statuss) == 0) {
                 $currentObject->setPublicationStatus(sfConfig::get('app_defaultPubStatus', QubitTerm::PUBLICATION_STATUS_DRAFT_ID));
             }
             // save the object after it's fully-populated
             $currentObject->save();
             // write the ID onto the current XML node for tracking
             $domNode->setAttribute('xml:id', $currentObject->id);
         }
     }
     return $this;
 }
 public static function loadData()
 {
     $object = new QubitInformationObject();
     $object->id = QubitInformationObject::ROOT_ID;
     $object->save();
     $object = new QubitActor();
     $object->id = QubitActor::ROOT_ID;
     $object->save();
     $object = new QubitSetting();
     $object->name = 'plugins';
     $object->value = serialize(array('sfCaribouPlugin', 'sfEhriThemePlugin', 'sfDcPlugin', 'sfEacPlugin', 'sfEadPlugin', 'sfIsaarPlugin', 'sfIsadPlugin', 'sfEhriIsadPlugin', 'sfIsdfPlugin', 'sfIsdiahPlugin', 'sfEhriIsdiahPlugin', 'sfModsPlugin', 'sfRadPlugin', 'sfSkosPlugin'));
     $object->save();
     $dispatcher = sfContext::getInstance()->getEventDispatcher();
     $formatter = new sfAnsiColorFormatter();
     chdir(sfConfig::get('sf_root_dir'));
     $loadData = new sfPropelDataLoadTask($dispatcher, $formatter);
     $loadData->run();
 }
 /**
  * Get Oai identifier
  * @param
  * @return String containing OAI-compliant Identifier
  */
 public function getOaiIdentifier()
 {
     $domain = sfContext::getInstance()->request->getHost();
     $oaiRepositoryCode = QubitSetting::getSettingByName('oai_repository_code')->getValue(array('sourceCulture' => true));
     $oaiIdentifier = 'oai:' . $domain . ':' . $oaiRepositoryCode . '_' . $this->getOaiLocalIdentifier();
     return $oaiIdentifier;
 }
 /**
  * Create a new setting object with some default properties
  *
  * @param string $name object name
  * @param string $value object value
  * @param array  $options array of options
  */
 public static function createNewSetting($name, $value, $options = array())
 {
     $setting = new QubitSetting();
     $setting->setName($name);
     $setting->setValue($value);
     if (isset($options['scope'])) {
         $setting->setScope($options['scope']);
     }
     // Default "editable" to true, unless forced to false
     $setting->setEditable(1);
     if (isset($options['editable']) && $options['editable'] == false) {
         $setting->setEditable(0);
     }
     // Default "deleteable" to true, unless forced to false
     $setting->setDeleteable(1);
     if (isset($options['deleteable']) && $options['deleteable'] == false) {
         $setting->setDeleteable(0);
     }
     // Set the source culture option
     if (isset($options['sourceCulture'])) {
         $setting->setSourceCulture($options['sourceCulture']);
     }
     // Set the culture option
     if (isset($options['culture'])) {
         $setting->setCulture($options['culture']);
     }
     return $setting;
 }