本文整理汇总了PHP中Widgets::retrieveAvalaibleLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP Widgets::retrieveAvalaibleLanguage方法的具体用法?PHP Widgets::retrieveAvalaibleLanguage怎么用?PHP Widgets::retrieveAvalaibleLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Widgets
的用法示例。
在下文中一共展示了Widgets::retrieveAvalaibleLanguage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: retrieveWidgetManifest
/**
* Retrieves the XML manifest of a widget for a given user. Be carefull, the returned
* manifest will not be exactly the same as the manifest deployed on the application server.
* Actually, the return manifest will be provided with the preferences relevant with a given user,
* and not the default values of the preferences as expected.
*
* @param integer $userId The user's identifier.
* @param string $widgetInstanceId The widget's instance identifier.
* @return string The requested manifest as a character stream.
*/
public static function retrieveWidgetManifest($userId, $widgetInstanceId)
{
$instanceIsRequested = is_numeric($widgetInstanceId);
# Get the widget associated with the instance
if ($instanceIsRequested) {
$widgetId = WidgetInstances::getWidgetIdByInstanceId($widgetInstanceId);
if (!$widgetId) {
throw new MwwException(MwwException::MODEL, 'Unable to find the any widget instance [' . $widgetInstanceId . ']');
}
} else {
$widgetId = $widgetInstanceId;
}
// We load the document wich must be in the widgets direcory.
try {
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->load('widgets/' . $widgetId . '/config.xml');
// Try to determine if l10n module is activate
$l10nModule = $doc->getElementsByTagNameNS('http://palette.ercim.org/ns/', 'active_l10n_module');
if ($l10nModule->length == 1 && $l10nModule->item(0)->nodeValue == 'true') {
# Now inject avalaible language into manifest
$doc->createElementNS('http://palette.ercim.org/ns/', 'l10n_avalaible_language');
$l = Widgets::retrieveAvalaibleLanguage($widgetId);
if (!empty($l)) {
$l10nAvalaibleLanguageNode = $doc->createElementNS('http://palette.ercim.org/ns/', 'l10n_avalaible_language');
# Process All Avalaible language
foreach ($l as $l10n_code => $l10n_label) {
$langageNode = $doc->createElementNS('http://palette.ercim.org/ns/', 'l10n_langage');
$langageCodeNode = $doc->createAttribute('code');
$l10n_code = trim($l10n_code);
$l10n_label = trim($l10n_label);
$langageAttCodeValueNode = $doc->createTextNode($l10n_code);
$langageLabelValueNode = $doc->createTextNode($l10n_label);
$langageNode->appendChild($langageCodeNode);
$langageCodeNode->appendChild($langageAttCodeValueNode);
$langageNode->appendChild($langageLabelValueNode);
$l10nAvalaibleLanguageNode->appendChild($langageNode);
}
$widget = $doc->getElementsByTagName('widget')->item(0);
$widget->appendChild($l10nAvalaibleLanguageNode);
}
}
if (VALIDATE_XML_FILE && !$doc->schemaValidate(XML_SCHEMA_FILE)) {
throw new XMLValidationException(MwwException::MODEL, XML_SCHEMA_FILE);
} else {
if ($instanceIsRequested) {
// Manifest loaded and validated.
// Now we add it dynamic values relevant to the user preferences.
$db = DbUtil::accessFactory();
$userId = $db->escape($userId);
$widgetInstanceId = $db->escape($widgetInstanceId);
$prefs = $doc->getElementsByTagNameNS('http://palette.ercim.org/ns/', 'preference');
foreach ($prefs as $pref) {
$name = $pref->attributes->getNamedItem('name')->value;
$rs = $db->select("SELECT `value` FROM `interface_preferences` WHERE `widgetInstanceId` = '{$widgetInstanceId}' AND `userid` = {$userId} AND `preference` = '{$name}'");
/* Read the the result set into an associative array */
if ($rs->count() == 1) {
$pref->setAttribute('value', $rs->value);
} else {
if ($pref->attributes->getNamedItem('default_value')) {
$pref->setAttribute('value', $pref->attributes->getNamedItem('default_value')->value);
} else {
$pref->setAttribute('value', '');
}
}
}
}
return $doc->saveXML();
}
} catch (DOMException $e) {
throw new FileException(MwwException::MODEL, 'Unable to load the manifest for widget ' . $widgetId);
}
}