本文整理汇总了PHP中eZContentLanguage::store方法的典型用法代码示例。如果您正苦于以下问题:PHP eZContentLanguage::store方法的具体用法?PHP eZContentLanguage::store怎么用?PHP eZContentLanguage::store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZContentLanguage
的用法示例。
在下文中一共展示了eZContentLanguage::store方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addLanguage
/**
* Adds new language to the site.
*
* \param locale Locale code (e.g. 'slk-SK') of language to add.
* \param name Optional. Name of the language. If not specified, the international language name for the $locale locale
* will be used.
* \return eZContentLanguage object of the added language (or the existing one if specified language has been already used)
* or false in case of any error (invalid locale code or already reached eZContentLanguage::maxCount() languages).
* \static
*/
static function addLanguage($locale, $name = null)
{
$localeObject = eZLocale::instance($locale);
if (!$localeObject) {
eZDebug::writeError("No such locale {$locale}!", __METHOD__);
return false;
}
if ($name === null) {
$name = $localeObject->attribute('intl_language_name');
}
$db = eZDB::instance();
$languages = eZContentLanguage::fetchList(true);
if ($existingLanguage = eZContentLanguage::fetchByLocale($locale)) {
eZDebug::writeWarning("Language '{$locale}' already exists!", __METHOD__);
return $existingLanguage;
}
if (count($languages) >= self::maxCount()) {
eZDebug::writeError('Too many languages, cannot add more!', __METHOD__);
return false;
}
$db->lock('ezcontent_language');
$idSum = 0;
foreach ($languages as $language) {
$idSum += $language->attribute('id');
}
// ID 1 is reserved
$candidateId = 2;
while ($idSum & $candidateId) {
$candidateId *= 2;
}
$newLanguage = new eZContentLanguage(array('id' => $candidateId, 'locale' => $locale, 'name' => $name, 'disabled' => 0));
$newLanguage->store();
$db->unlock();
eZContentLanguage::fetchList(true);
// clear the cache
eZContentCacheManager::clearAllContentCache();
return $newLanguage;
}