本文整理汇总了PHP中XMLDAO::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLDAO::parse方法的具体用法?PHP XMLDAO::parse怎么用?PHP XMLDAO::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLDAO
的用法示例。
在下文中一共展示了XMLDAO::parse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: installEmailTemplateData
/**
* Install email template localized data from an XML file.
* NOTE: Uses qstr instead of ? bindings so that SQL can be fetched
* rather than executed.
* @param $templateDataFile string Filename to install
* @param $returnSql boolean Whether or not to return SQL rather than
* executing it
* @param $emailKey string If specified, the key of the single template
* to install (otherwise all are installed)
* @return array
*/
function installEmailTemplateData($templateDataFile, $returnSql = false, $emailKey = null)
{
$xmlDao = new XMLDAO();
$sql = array();
$data = $xmlDao->parse($templateDataFile, array('email_texts', 'email_text', 'subject', 'body', 'description'));
if (!$data) {
return false;
}
$locale = $data->getAttribute('locale');
foreach ($data->getChildren() as $emailNode) {
if ($emailKey && $emailKey != $emailNode->getAttribute('key')) {
continue;
}
$sql[] = 'DELETE FROM email_templates_default_data WHERE email_key = ' . $this->_dataSource->qstr($emailNode->getAttribute('key')) . ' AND locale = ' . $this->_dataSource->qstr($locale);
if (!$returnSql) {
$this->update(array_shift($sql));
}
$sql[] = 'INSERT INTO email_templates_default_data
(email_key, locale, subject, body, description)
VALUES
(' . $this->_dataSource->qstr($emailNode->getAttribute('key')) . ', ' . $this->_dataSource->qstr($locale) . ', ' . $this->_dataSource->qstr($emailNode->getChildValue('subject')) . ', ' . $this->_dataSource->qstr($emailNode->getChildValue('body')) . ', ' . $this->_dataSource->qstr($emailNode->getChildValue('description')) . ")";
if (!$returnSql) {
$this->update(array_shift($sql));
}
}
if ($returnSql) {
return $sql;
}
return true;
}
示例2: foreach
/**
* Update or install review objects
* @param $journal Journal
* @param $reviewObjects array of review object types keys or ids
* @param $locales array of locales
* @param $action string (install or update)
*/
function _updateOrInstallReviewObjectTypes($journal, $reviewObjects, $locales, $action)
{
$plugin =& $this->_getObjectsForReviewPlugin();
if (!isset($journal) || !isset($reviewObjects) || !isset($locales) || !isset($action)) {
return false;
}
$journalId = $journal->getId();
$plugin->import('classes.ReviewObjectType');
$plugin->import('classes.ReviewObjectMetadata');
$reviewObjectTypeDao =& DAORegistry::getDAO('ReviewObjectTypeDAO');
$reviewObjectMetadataDao =& DAORegistry::getDAO('ReviewObjectMetadataDAO');
$onlyCommonMetadata = false;
foreach ($reviewObjects as $keyOrId) {
if ($action == 'install') {
// Create a new review object type
$reviewObjectType = $reviewObjectTypeDao->newDataObject();
$reviewObjectType->setContextId($journalId);
$reviewObjectType->setActive(0);
$reviewObjectType->setKey($keyOrId);
} elseif ($action == 'update') {
// Get the review object type
$reviewObjectType =& $reviewObjectTypeDao->getById($keyOrId, $journalId);
if (!isset($reviewObjectType)) {
return false;
}
// If the type was created by the user, update only the common metadata
if ($reviewObjectType->getKey() == NULL) {
$onlyCommonMetadata = true;
}
}
// Callect the metadata in the array
$reviewObjectMetadataArray = array();
// For all languages
foreach ($locales as $locale) {
// Register the locale/translation file
$localePath = $plugin->getPluginPath() . '/locale/' . $locale . '/locale.xml';
AppLocale::registerLocaleFile($locale, $localePath, true);
$xmlDao = new XMLDAO();
// Get common metadata
$commonDataPath = $plugin->getPluginPath() . '/xml/commonMetadata.xml';
$commonData = $xmlDao->parse($commonDataPath);
$commonMetadata = $commonData->getChildByName('objectMetadata');
$allMetadataChildren = $commonMetadata->getChildren();
// Get the object metadata
if (!$onlyCommonMetadata) {
// Parse the review object XML file
$itemPath = $plugin->getPluginPath() . '/xml/reviewObjects/' . $reviewObjectType->getKey() . '.xml';
$data = $xmlDao->parse($itemPath);
if (!$data) {
return false;
}
// Set the review object name
$itemTypeName = __($data->getChildValue('objectType'), array(), $locale);
$reviewObjectType->setName($itemTypeName, $locale);
// $reviewObjectType->setDescription($itemTypeNameDescription, $locale);
// Get the review object role selection options
$roleSelectionOptions = $data->getChildByName('roleSelectionOptions');
// Handle Metadata
// Get multiple options metadata types
$multipleOptionsTypes = ReviewObjectMetadata::getMultipleOptionsTypes();
// Get metadata types defined in DTD
$dtdTypes = ReviewObjectMetadata::getMetadataDTDTypes();
// Get the review object metadata
$itemMetadata = $data->getChildByName('objectMetadata');
// Merge all (common + review objec) metadata
$allMetadataChildren = array_merge($commonMetadata->getChildren(), $itemMetadata->getChildren());
}
// Go through the metadata
foreach ($allMetadataChildren as $metadataNode) {
$key = $metadataNode->getAttribute('key');
// If we have already went througt, collected/considered the metadata
if (array_key_exists($key, $reviewObjectMetadataArray)) {
$reviewObjectMetadata = $reviewObjectMetadataArray[$key];
} else {
if ($action == 'update') {
// Get the metadata
$reviewObjectMetadata = $reviewObjectMetadataDao->getByKey($key, $reviewObjectType->getId());
}
if ($action == 'install' || !isset($reviewObjectMetadata)) {
// Create a new metadata
$reviewObjectMetadata = $reviewObjectMetadataDao->newDataObject();
$reviewObjectMetadata->setSequence(REALLY_BIG_NUMBER);
$metadataType = $dtdTypes[$metadataNode->getAttribute('type')];
$reviewObjectMetadata->setMetadataType($metadataType);
$required = $metadataNode->getAttribute('required');
$reviewObjectMetadata->setRequired($required == 'true' ? 1 : 0);
$display = $metadataNode->getAttribute('display');
$reviewObjectMetadata->setDisplay($display == 'true' ? 1 : 0);
}
}
// Set metadata name
$name = __($metadataNode->getChildValue('name'), array(), $locale);
$reviewObjectMetadata->setName($name, $locale);
//.........这里部分代码省略.........
示例3: execute
/**
* @see Form::execute()
*/
function execute()
{
$ofrPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
$journal =& Request::getJournal();
$journalId = $journal->getId();
$ofrPlugin->import('classes.ReviewObjectType');
$reviewObjectTypeDao =& DAORegistry::getDAO('ReviewObjectTypeDAO');
if ($this->reviewObjectType == null) {
$reviewObjectType = $reviewObjectTypeDao->newDataObject();
$reviewObjectType->setContextId($journalId);
$reviewObjectType->setActive(0);
} else {
$reviewObjectType =& $this->reviewObjectType;
}
$reviewObjectType->setName($this->getData('name'), null);
// Localized
$reviewObjectType->setDescription($this->getData('description'), null);
// Localized
if ($reviewObjectType->getId() != null) {
$reviewObjectTypeDao->updateObject($reviewObjectType);
} else {
//install common metadata
$ofrPlugin->import('classes.ReviewObjectMetadata');
$multipleOptionsTypes = ReviewObjectMetadata::getMultipleOptionsTypes();
$dtdTypes = ReviewObjectMetadata::getMetadataDTDTypes();
$reviewObjectMetadataDao =& DAORegistry::getDAO('ReviewObjectMetadataDAO');
$reviewObjectMetadataArray = array();
$availableLocales = $journal->getSupportedLocaleNames();
foreach ($availableLocales as $locale => $localeName) {
$xmlDao = new XMLDAO();
$commonDataPath = $ofrPlugin->getPluginPath() . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'commonMetadata.xml';
$commonData = $xmlDao->parse($commonDataPath);
$commonMetadata = $commonData->getChildByName('objectMetadata');
foreach ($commonMetadata->getChildren() as $metadataNode) {
$key = $metadataNode->getAttribute('key');
if (array_key_exists($key, $reviewObjectMetadataArray)) {
$reviewObjectMetadata = $reviewObjectMetadataArray[$key];
} else {
$reviewObjectMetadata = $reviewObjectMetadataDao->newDataObject();
$reviewObjectMetadata->setSequence(REALLY_BIG_NUMBER);
$metadataType = $dtdTypes[$metadataNode->getAttribute('type')];
$reviewObjectMetadata->setMetadataType($metadataType);
$required = $metadataNode->getAttribute('required');
$reviewObjectMetadata->setRequired($required == 'true' ? 1 : 0);
$display = $metadataNode->getAttribute('display');
$reviewObjectMetadata->setDisplay($display == 'true' ? 1 : 0);
}
$name = __($metadataNode->getChildValue('name'), array(), $locale);
$reviewObjectMetadata->setName($name, $locale);
if ($key == 'role') {
$reviewObjectMetadata->setPossibleOptions($this->getData('possibleOptions'), null);
// Localized
} else {
if (in_array($reviewObjectMetadata->getMetadataType(), $multipleOptionsTypes)) {
$selectionOptions = $metadataNode->getChildByName('selectionOptions');
$possibleOptions = array();
$index = 1;
foreach ($selectionOptions->getChildren() as $selectionOptionNode) {
$possibleOptions[] = array('order' => $index, 'content' => __($selectionOptionNode->getValue(), array(), $locale));
$index++;
}
$reviewObjectMetadata->setPossibleOptions($possibleOptions, $locale);
} else {
$reviewObjectMetadata->setPossibleOptions(null, null);
}
}
$reviewObjectMetadataArray[$key] = $reviewObjectMetadata;
}
}
$reviewObjectTypeId = $reviewObjectTypeDao->insertObject($reviewObjectType);
// insert review object metadata
foreach ($reviewObjectMetadataArray as $key => $reviewObjectMetadata) {
$reviewObjectMetadata->setReviewObjectTypeId($reviewObjectTypeId);
$reviewObjectMetadata->setKey($key);
$reviewObjectMetadataDao->insertObject($reviewObjectMetadata);
$reviewObjectMetadataDao->resequence($reviewObjectTypeId);
}
}
}
示例4: installDefaultBaseData
/**
* Install setting type localized data from an XML file.
* @param $locale string
* @param $pressId int
* @param $skipLoad bool
* @param $localInstall bool
* @return boolean
*/
function installDefaultBaseData($locale, $pressId, $skipLoad = true, $localeInstall = false)
{
$xmlDao = new XMLDAO();
$data = $xmlDao->parse($this->getDefaultBaseFilename());
if (!$data) {
return false;
}
$defaultIds = $this->getDefaultSettingIds($pressId);
Locale::requireComponents(array(LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS), $locale);
foreach ($data->getChildren() as $formatNode) {
$settings =& $this->getSettingAttributes($formatNode, $locale);
if (empty($defaultIds[$formatNode->getAttribute('key')])) {
// ignore keys not associated with this press
continue;
} else {
// prepare a list of attributes not defined in the current settings xml file
unset($defaultIds[$formatNode->getAttribute('key')]);
}
foreach ($settings as $settingName => $settingValue) {
$this->update('INSERT INTO press_defaults
(press_id, assoc_type, entry_key, locale, setting_name, setting_value, setting_type)
VALUES
(?, ?, ?, ?, ?, ?, ?)', array($pressId, $this->getDefaultType(), $formatNode->getAttribute('key'), $locale, $settingName, $settingValue, 'string'));
}
}
$attributeNames =& $this->getSettingAttributes();
// install defaults for keys not defined in the xml
foreach ($defaultIds as $key => $id) {
foreach ($attributeNames as $setting) {
$this->update('INSERT INTO press_defaults
(press_id, assoc_type, entry_key, locale, setting_name, setting_value, setting_type)
VALUES
(?, ?, ?, ?, ?, ?, ?)', array($pressId, $this->getDefaultType(), $key, $locale, $setting, '##', 'string'));
}
}
if ($skipLoad) {
return true;
}
if ($localeInstall) {
$this->restoreByPressId($pressId, $locale);
} else {
$this->restoreByPressId($pressId);
}
return true;
}