本文整理汇总了PHP中eZContentLanguage::fetchByLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP eZContentLanguage::fetchByLocale方法的具体用法?PHP eZContentLanguage::fetchByLocale怎么用?PHP eZContentLanguage::fetchByLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZContentLanguage
的用法示例。
在下文中一共展示了eZContentLanguage::fetchByLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFetchByContentObjectIDList
/**
* Test FetchByContentObjectList
*/
public function testFetchByContentObjectIDList()
{
$language = eZContentLanguage::fetchByLocale('eng-GB');
$languageID = $language->attribute('id');
$time = time();
$comment1 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time, 'modified' => $time, 'text' => 'comment1', 'user_id' => 15);
$comment2 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time + 1, 'modified' => $time + 1, 'text' => 'comment2', 'user_id' => 15);
$comment3 = array('contentobject_id' => 15, 'language_id' => $languageID, 'created' => $time + 2, 'modified' => $time + 2, 'text' => 'comment3', 'user_id' => 15);
$comment4 = array('contentobject_id' => 14, 'language_id' => $languageID, 'created' => $time + 3, 'modified' => $time + 3, 'text' => 'comment4', 'user_id' => 14);
$comment = ezcomComment::create($comment1);
$comment->store();
$comment = ezcomComment::create($comment2);
$comment->store();
$comment = ezcomComment::create($comment3);
$comment->store();
$comment = ezcomComment::create($comment4);
$comment->store();
// test null contentobject id and user id
$result = ezcomComment::fetchByContentObjectIDList(null, 15, 'eng-GB', null, array('modified' => 'desc'), 0);
$this->assertEquals('comment3', $result[0]->attribute('text'));
$this->assertEquals('comment1', $result[2]->attribute('text'));
// test null contentobject id array and empty user_id
$result = ezcomComment::fetchByContentObjectIDList(null, null, 'eng-GB', null, array('modified' => 'desc'), 0);
$this->assertEquals('comment1', $result[3]->attribute('text'));
// test one contentobject id array
$result = ezcomComment::fetchByContentObjectIDList(array(14), null, 'eng-GB', null, array('modified' => 'desc'), 0);
$this->assertEquals('comment4', $result[0]->attribute('text'));
// test many contentobjects array and sort
$result = ezcomComment::fetchByContentObjectIDList(array(14, 15), null, 'eng-GB', null, array('modified' => 'asc'), 0);
$this->assertEquals('comment3', $result[2]->attribute('text'));
// test length with all null
$result = ezcomComment::fetchByContentObjectIDList(null, null, null, null, null, null, 3);
$this->assertEquals(3, count($result));
}
示例2: testMapLanguage
/**
* Test that fetching the language listing, works after languages
* have been altered in database, and then later refetched.
*
* @link http://issues.ez.no/15484
*/
public function testMapLanguage()
{
$db = eZDB::instance();
eZContentLanguage::addLanguage('nno-NO', 'Nynorsk');
$localeToChangeInto = 'dan-DK';
$languageNameToChangeInto = 'Danish';
$langObject = eZContentLanguage::fetchByLocale('nno-NO');
$langId = (int) $langObject->attribute('id');
$updateSql = <<<END
UPDATE ezcontent_language
SET
locale='{$localeToChangeInto}',
name='{$languageNameToChangeInto}'
WHERE
id={$langId}
END;
$db->query($updateSql);
eZContentLanguage::expireCache();
$newLangObject = eZContentLanguage::fetchByLocale($localeToChangeInto);
if (!$newLangObject instanceof eZContentLanguage) {
self::fail("Language object not returned. Old version provided by cache?");
}
$newLangId = (int) $newLangObject->attribute('id');
self::assertEquals($langId, $newLangId, "New language not mapped to existing language");
}
示例3: __construct
/**
* Initialize ezpClass object
*
* @param string $name
* @param string $identifier
* @param string $contentObjectName
* @param int $creatorID
* @param string $language
* @param int $groupID
* @param string $groupName
*/
public function __construct($name = 'Test class', $identifier = 'test_class', $contentObjectName = '<test_attribute>', $creatorID = 14, $language = 'eng-GB', $groupID = 1, $groupName = 'Content')
{
if (eZContentLanguage::fetchByLocale($language) === false) {
$topPriorityLanguage = eZContentLanguage::topPriorityLanguage();
if ($topPriorityLanguage) {
$language = $topPriorityLanguage->attribute('locale');
}
}
$this->language = $language;
$this->class = eZContentClass::create($creatorID, array(), $this->language);
$this->class->setName($name, $this->language);
$this->class->setAttribute('contentobject_name', $contentObjectName);
$this->class->setAttribute('identifier', $identifier);
$this->class->store();
$languageID = eZContentLanguage::idByLocale($this->language);
$this->class->setAlwaysAvailableLanguageID($languageID);
$this->classGroup = eZContentClassClassGroup::create($this->id, $this->version, $groupID, $groupName);
$this->classGroup->store();
}
示例4: checkContentRequirements
public static function checkContentRequirements($module, $http)
{
// Check that the object params are 'ok'
if (!$http->hasPostVariable('ContentObjectID')) {
eZDebug::writeError('No content object id is provided', 'ezcomments');
return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
$contentObjectId = (int) $http->postVariable('ContentObjectID');
// Either use provided language code, or fallback on siteaccess default
if ($http->hasPostVariable('CommentLanguageCode')) {
$languageCode = $http->postVariable('CommentLanguageCode');
$language = eZContentLanguage::fetchByLocale($languageCode);
if ($language === false) {
eZDebug::writeError("The language code [{$languageCode}] given is not valid in the system.", 'ezcomments');
return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
} else {
$defaultLanguage = eZContentLanguage::topPriorityLanguage();
$languageCode = $defaultLanguage->attribute('locale');
}
// Check that our object is actually a valid holder of comments
$contentObject = eZContentObject::fetch($contentObjectId);
if (!$contentObject instanceof eZContentObject) {
eZDebug::writeError('No content object exists for the given id.', 'ezcomments');
return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
$dataMap = $contentObject->fetchDataMap(false, $languageCode);
$foundCommentAttribute = false;
foreach ($dataMap as $attr) {
if ($attr->attribute('data_type_string') === 'ezcomcomments') {
$foundCommentAttribute = $attr;
break;
}
}
// if there is no ezcomcomments attribute inside the content, return
if (!$foundCommentAttribute) {
eZDebug::writeError("Content object with id [{$contentObjectId}], does not contain an ezcomments attribute.", 'ezcomments');
return $module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
return compact('contentObjectId', 'languageCode', 'contentObject', 'foundCommentAttribute');
}
示例5: setParameters
function setParameters($parm_array)
{
if (!isset($parm_array['original_locale'])) {
return 'Missing locale identifier of original';
}
if (!isset($parm_array['new_locale'])) {
return 'Missing new locale identifier';
}
$this->orgLocale = $parm_array['original_locale'];
$language = eZContentLanguage::fetchByLocale($this->orgLocale);
if ($language) {
$this->orgLangID = $language->attribute('id');
} else {
return 'Missing original locale to be copied in database';
}
$this->newLocale = $parm_array['new_locale'];
$language = eZContentLanguage::fetchByLocale($this->newLocale);
if ($language) {
$this->newLangID = $language->attribute('id');
} else {
return 'Missing alternative locale in database';
}
return true;
}
示例6: setParameters
function setParameters($parm_array)
{
if (!isset($parm_array['remove_locale'])) {
return 'Missing locale identifier to be removed';
}
if (!isset($parm_array['alternative_locale'])) {
return 'Missing alternative locale identifier';
}
$this->remLocale = $parm_array['remove_locale'];
$language = eZContentLanguage::fetchByLocale($this->remLocale);
if ($language) {
$this->remLangID = $language->attribute('id');
} else {
return 'Missing locale to be removed in database';
}
$this->altLocale = $parm_array['alternative_locale'];
$language = eZContentLanguage::fetchByLocale($this->altLocale);
if ($language) {
$this->altLangID = $language->attribute('id');
} else {
return 'Missing alternative locale in database';
}
return true;
}
示例7: array
#!/usr/bin/env php
<?php
require 'autoload.php';
$cli = eZCLI::instance();
$script = eZScript::instance(array('description' => '\\nInitializes tag translations for upgrade to eZ Tags 2.0.\\n', 'use-session' => false, 'use-modules' => false, 'use-extensions' => true));
$script->startup();
$options = $script->getOptions('[locale:]', '', array('locale' => 'Locale to initialize tag translations with'));
$script->initialize();
if (!isset($options['locale'])) {
$cli->error("Locale parameter is needed by the script but wasn't specified.");
$script->shutdown(1);
}
/** @var eZContentLanguage $language */
$language = eZContentLanguage::fetchByLocale($options['locale']);
if (!$language instanceof eZContentLanguage) {
$cli->error("Invalid locale specified.");
$script->shutdown(1);
}
$db = eZDB::instance();
$db->begin();
$languageID = (int) $language->attribute('id');
$locale = $db->escapeString($language->attribute('locale'));
$ini = eZINI::instance('eztags.ini');
$alwaysAvailable = $ini->variable('GeneralSettings', 'DefaultAlwaysAvailable');
$alwaysAvailable = $alwaysAvailable === 'true' ? 1 : 0;
$db->query("UPDATE eztags SET main_language_id = {$languageID}, language_mask = {$languageID} + {$alwaysAvailable}");
$db->query("INSERT INTO eztags_keyword\n SELECT id, {$languageID} + {$alwaysAvailable}, keyword, '{$locale}', 1 FROM eztags");
$db->commit();
$script->shutdown();
示例8: array
eZDebug::writeDebug($translationName, 'translationName');
eZDebug::writeDebug($translationLocale, 'translationLocale');
}
// Make sure the locale string is valid, if not we try to extract a valid part of it
if (!preg_match("/^" . eZLocale::localeRegexp(false, false) . "\$/", $translationLocale)) {
if (preg_match("/(" . eZLocale::localeRegexp(false, false) . ")/", $translationLocale, $matches)) {
$translationLocale = $matches[1];
} else {
// The locale cannot be used so we show the edit page again.
$tpl->setVariable('is_edit', $Module->isCurrentAction('Edit'));
$Result['content'] = $tpl->fetch('design:content/translationnew.tpl');
$Result['path'] = array(array('text' => ezpI18n::tr('kernel/content', 'Translation'), 'url' => false), array('text' => 'New', 'url' => false));
return;
}
}
if (!eZContentLanguage::fetchByLocale($translationLocale)) {
$locale = eZLocale::instance($translationLocale);
if ($locale->isValid()) {
$translation = eZContentLanguage::addLanguage($locale->localeCode(), $translationName);
ezpEvent::getInstance()->notify('content/translations/cache', array($translation->attribute('id')));
} else {
// The locale cannot be used so we show the edit page again.
$tpl->setVariable('is_edit', $Module->isCurrentAction('Edit'));
$Result['content'] = $tpl->fetch('design:content/translationnew.tpl');
$Result['path'] = array(array('text' => ezpI18n::tr('kernel/content', 'Translation'), 'url' => false), array('text' => 'New', 'url' => false));
return;
}
}
}
if ($Module->isCurrentAction('Remove')) {
$seletedIDList = $Module->actionParameter('SelectedTranslationList');
示例9: elseif
{
$thisUrl .= '/' . $object->attribute( 'id' );
$tpl->setVariable( 'elevatedObject', $object );
// check language
$languageFilter = false;
if ( $http->hasPostVariable( 'ezfind-elevationdetail-filter-language' ) )
$languageFilter = $http->postVariable( 'ezfind-elevationdetail-filter-language' );
elseif ( $Params['Language'] !== false and $Params['Language'] != '' )
$languageFilter = $Params['Language'];
if ( $languageFilter and $languageFilter != $wildcard )
{
$viewParameters = array_merge( $viewParameters, array( 'language' => htmlspecialchars( $languageFilter, ENT_QUOTES ) ) );
$tpl->setVariable( 'selectedLocale', eZContentLanguage::fetchByLocale( $languageFilter ) );
}
// check fuzzy filter
$fuzzyFilter = false;
if ( $http->hasPostVariable( 'ezfind-elevationdetail-filter-fuzzy' ) )
$fuzzyFilter = true;
elseif ( $Params['FuzzyFilter'] !== false )
$fuzzyFilter = true;
if ( $fuzzyFilter )
{
$viewParameters = array_merge( $viewParameters, array( 'fuzzy_filter' => $fuzzyFilter ) );
}
示例10: addTranslation
/**
* Adds a new translation and creates a new dedicated fieldset.
* If $lang is an invalid locale (ie. malformed or not declared in site.ini/RegionalSettings.Locale), will throw a SQLIContentException
* @param string $lang Translation code to add, as a locale (xxx-XX)
* @throws SQLIContentException
*/
public function addTranslation($lang)
{
$language = eZContentLanguage::fetchByLocale($lang, true);
if (!$language instanceof eZContentLanguage) {
throw new SQLIContentException("Invalid language '{$lang}'. Must be a valid locale declared in site.ini, RegionalSettings.Locale !");
}
$db = eZDB::instance();
$db->begin();
$version = $this->getCurrentDraft($lang);
$versionNumber = $version->attribute('version');
$objectID = $this->contentObject->attribute('id');
$translatedDataMap = $this->contentObject->fetchDataMap($versionNumber, $lang);
// Check if data map exists for this language in the current draft
// Indeed, several translations can be created for only one publication of an object
if (!$translatedDataMap) {
$classAttributes = $this->contentObject->fetchClassAttributes();
foreach ($classAttributes as $classAttribute) {
// TODO : Check if attribute is translatable
$classAttribute->instantiate($objectID, $lang, $versionNumber);
}
// Now clears in-memory cache for this datamap (it was fetched once above)
// Then re-fetch the newly created translated data map
global $eZContentObjectDataMapCache;
unset($eZContentObjectDataMapCache[$objectID][$versionNumber][$lang]);
unset($this->contentObject->ContentObjectAttributes[$versionNumber][$lang]);
unset($this->contentObject->DataMap[$versionNumber][$lang]);
$translatedDataMap = $this->contentObject->fetchDataMap($versionNumber, $lang);
}
$version->setAttribute('initial_language_id', $language->attribute('id'));
$version->updateLanguageMask();
$version->store();
$db->commit();
$set = SQLIContentFieldset::fromDataMap($translatedDataMap);
$set->setLanguage($lang);
$this->fieldsets[$lang] = $set;
$this->initIterator();
}
示例11: languageInfo
function languageInfo($withLanguageNames = false)
{
$langaugeInfo = array();
$classHandler = eZPackage::packageHandler('ezcontentclass');
$objectHandler = eZPackage::packageHandler('ezcontentobject');
$explainClassInfo = array('language_info');
$packageItems = $this->installItemsList();
foreach ($packageItems as $item) {
$itemLanguageInfo = array();
if ($item['type'] == 'ezcontentclass') {
$classInfo = $classHandler->explainInstallItem($this, $item, $explainClassInfo);
$itemLanguageInfo = isset($classInfo['language_info']) ? $classInfo['language_info'] : array();
} else {
if ($item['type'] == 'ezcontentobject') {
$objectsInfo = $objectHandler->explainInstallItem($this, $item);
// merge objects info
foreach ($objectsInfo as $objectInfo) {
$objectLanguages = isset($objectInfo['language_info']) ? $objectInfo['language_info'] : array();
foreach ($objectLanguages as $objectLanguage) {
if (!in_array($objectLanguage, $itemLanguageInfo)) {
$itemLanguageInfo[] = $objectLanguage;
}
}
}
}
}
// merge class and objects infos
foreach ($itemLanguageInfo as $languageLocale) {
if (!in_array($languageLocale, $langaugeInfo)) {
$langaugeInfo[] = $languageLocale;
}
}
}
if ($withLanguageNames) {
$langaugeInfoWithNames = array();
foreach ($langaugeInfo as $languageLocale) {
$language = eZContentLanguage::fetchByLocale($languageLocale);
$languageName = $language->attribute('name');
$langaugeInfoWithNames[$languageLocale] = $languageName;
}
$langaugeInfo = $langaugeInfoWithNames;
}
return $langaugeInfo;
}
示例12: testChoosePrioritizedRow
public function testChoosePrioritizedRow()
{
// Make sure we can see all languages
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'ShowUntranslatedObjects', 'enabled');
$action = "eznode:" . mt_rand();
$name = __FUNCTION__ . mt_rand();
$engGB = eZContentLanguage::fetchByLocale('eng-GB');
$norNO = eZContentLanguage::fetchByLocale('nor-NO');
// Create an english entry
$url1 = eZURLAliasML::create($name . " en", $action, 0, $engGB->attribute('id'));
$url1->store();
// Create a norwegian entry
$url2 = eZURLAliasML::create($name . " no", $action, 0, $norNO->attribute('id'));
$url2->store();
// Fetch the created entries. choosePrioritizedRow() wants rows from the
// database so our eZURLAliasML objects wont work.
$db = eZDB::instance();
$rows = $db->arrayQuery("SELECT * FROM ezurlalias_ml where action = '{$action}'");
// -------------------------------------------------------------------
// TEST PART 1 - NORMAL PRIORITIZATION -------------------------------
// The order of the language array also determines the prioritization.
// In this case 'eng-GB' should be prioritized before 'nor-NO'.
$languageList = array("eng-GB", "nor-NO");
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', $languageList);
eZContentLanguage::clearPrioritizedLanguages();
$row = eZURLAliasML::choosePrioritizedRow($rows);
// The prioritzed language should be 'eng-GB'
self::assertEquals($engGB->attribute('id'), $row["lang_mask"]);
// -------------------------------------------------------------------
// TEST PART 2 - REVERSED PRIORITIZATION -----------------------------
// Reverse the order of the specified languages, this will also
// reverse the priority.
$languageList = array_reverse($languageList);
ezpINIHelper::setINISetting('site.ini', 'RegionalSettings', 'SiteLanguageList', $languageList);
eZContentLanguage::clearPrioritizedLanguages();
$row = eZURLAliasML::choosePrioritizedRow($rows);
// The prioritzed language should be 'nor-NO'
self::assertEquals($norNO->attribute('id'), $row["lang_mask"]);
// -------------------------------------------------------------------
// TEST TEAR DOWN ----------------------------------------------------
ezpINIHelper::restoreINISettings();
// -------------------------------------------------------------------
}
示例13: unserialize
static function unserialize( $domNode, $contentObject, $ownerID, $sectionID, $activeVersion, $firstVersion, &$nodeList, &$options, $package, $handlerType = 'ezcontentobject' )
{
$oldVersion = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'version' );
$status = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'status' );
$languageNodeArray = $domNode->getElementsByTagName( 'object-translation' );
$initialLanguage = false;
$importedLanguages = $options['language_array'];
$currentLanguages = array();
foreach( $languageNodeArray as $languageNode )
{
$language = eZContentObjectVersion::mapLanguage( $languageNode->getAttribute( 'language' ), $options );
if ( in_array( $language, $importedLanguages ) )
{
$currentLanguages[] = $language;
}
}
foreach ( eZContentLanguage::prioritizedLanguages() as $language )
{
if ( in_array( $language->attribute( 'locale' ), $currentLanguages ) )
{
$initialLanguage = $language->attribute( 'locale' );
break;
}
}
if ( !$initialLanguage )
{
$initialLanguage = $currentLanguages[0];
}
if ( $firstVersion )
{
$contentObjectVersion = $contentObject->version( 1 );
}
else
{
// Create new version in specific language but with empty data.
$contentObjectVersion = $contentObject->createNewVersionIn( $initialLanguage );
}
$created = eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'created' ) );
$modified = eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) );
$contentObjectVersion->setAttribute( 'created', $created );
$contentObjectVersion->setAttribute( 'modified', $modified );
$contentObjectVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
$contentObjectVersion->store();
$db = eZDB::instance();
$db->begin();
foreach( $languageNodeArray as $languageNode )
{
$language = eZContentObjectVersion::mapLanguage( $languageNode->getAttribute( 'language' ), $options );
// Only import allowed languages.
if ( !in_array( $language, $importedLanguages ) )
{
continue;
}
$attributeArray = $contentObjectVersion->contentObjectAttributes( $language );
if ( count( $attributeArray ) == 0)
{
$hasTranslation = eZContentLanguage::fetchByLocale( $language );
if ( !$hasTranslation )
{
// if there is no needed translation in system then add it
$locale = eZLocale::instance( $language );
if ( $locale->isValid() )
{
eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );
$hasTranslation = true;
}
else
$hasTranslation = false;
}
if ( $hasTranslation )
{
// Add translated attributes for the translation
$originalContentAttributes = $contentObjectVersion->contentObjectAttributes( $initialLanguage );
foreach ( $originalContentAttributes as $originalContentAttribute )
{
$contentAttribute = $originalContentAttribute->translateTo( $language );
$contentAttribute->sync();
$attributeArray[] = $contentAttribute;
}
}
// unserialize object name in current version-translation
$objectName = $languageNode->getAttribute( 'object_name' );
if ( $objectName )
$contentObject->setName( $objectName, $contentObjectVersion->attribute( 'version' ), $language );
}
$xpath = new DOMXPath( $domNode->ownerDocument );
$xpath->registerNamespace( 'ezobject', 'http://ez.no/object/' );
$xpath->registerNamespace( 'ezremote', 'http://ez.no/ezobject' );
//.........这里部分代码省略.........
示例14: validate
function validate($param = true)
{
$languageMap = is_array($param) && count($param) > 0 ? $param : false;
$createLanguageIfNotExist = $param === true ? true : false;
$nameList = $this->nameList();
foreach ($nameList as $nameLanguageLocale => $name) {
if ($nameLanguageLocale != eZSerializedObjectNameList::ALWAYS_AVAILABLE_STR) {
$language = false;
if ($createLanguageIfNotExist) {
$language = eZContentLanguage::fetchByLocale($nameLanguageLocale, true);
} else {
if (is_array($languageMap)) {
$languageLocale = isset($languageMap[$nameLanguageLocale]) ? $languageMap[$nameLanguageLocale] : false;
if ($languageLocale && $languageLocale != 'skip') {
$language = eZContentLanguage::fetchByLocale($languageLocale, true);
}
} else {
// just check '$nameLanguageLocale' language if '$languageMap' is not specified.
$language = eZContentLanguage::fetchByLocale($nameLanguageLocale, false);
}
}
$languageLocale = is_object($language) ? $language->attribute('locale') : false;
if ($languageLocale != $nameLanguageLocale) {
if ($languageLocale) {
// map name's language.
$this->removeName($nameLanguageLocale);
$this->setName($name, $languageLocale);
} else {
$this->removeName($nameLanguageLocale);
}
}
}
}
// update always-available(probably original 'always-available' was skiped)
$this->updateAlwaysAvailable();
}
示例15: languageName
/**
* Returns array with language name and locale for this instance
*
* @return array
*/
public function languageName()
{
/** @var eZContentLanguage $language */
$language = eZContentLanguage::fetchByLocale($this->attribute('locale'));
if ($language instanceof eZContentLanguage) {
return array('locale' => $language->attribute('locale'), 'name' => $language->attribute('name'));
}
return false;
}