本文整理汇总了PHP中Pimcore_Tool::getValidLanguages方法的典型用法代码示例。如果您正苦于以下问题:PHP Pimcore_Tool::getValidLanguages方法的具体用法?PHP Pimcore_Tool::getValidLanguages怎么用?PHP Pimcore_Tool::getValidLanguages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore_Tool
的用法示例。
在下文中一共展示了Pimcore_Tool::getValidLanguages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getByKey
/**
* @static
* @param $id - translation key
* @param bool $create - creates an empty translation entry if the key doesn't exists
* @param bool $returnIdIfEmpty - returns $id if no translation is available
* @return Translation_Website
*/
public static function getByKey($id, $create = false, $returnIdIfEmpty = false)
{
$translation = new self();
try {
$translation->getResource()->getByKey($id);
} catch (Exception $e) {
if (!$create) {
throw new Exception($e->getMessage());
} else {
$translation->setKey($id);
$translation->setDate(time());
$translations = array();
foreach (Pimcore_Tool::getValidLanguages() as $lang) {
$translations[$lang] = "";
}
$translation->setTranslations($translations);
$translation->save();
}
}
if ($returnIdIfEmpty) {
$translations = $translation->getTranslations();
foreach ($translations as $key => $value) {
$translations[$key] = $value ?: $id;
}
$translation->setTranslations($translations);
}
return $translation;
}
示例2: update
/**
* @return void
*/
public function update()
{
foreach ($this->fieldsToSave as $field) {
if (in_array($field, $this->validColumns)) {
$getter = 'get' . ucfirst($field);
if (in_array($field, $this->localizedFields)) {
// handle localized Fields
$localizedValues = array();
foreach (Pimcore_Tool::getValidLanguages() as $lang) {
$localizedValues[$lang] = $value = $this->model->{$getter}($lang);
}
$value = $localizedValues;
} else {
// normal case
$value = $this->model->{$getter}();
}
if (is_array($value) || is_object($value)) {
$value = serialize($value);
} else {
if (is_bool($value)) {
$value = (int) $value;
}
}
$data[$field] = $value;
}
}
$this->db->update(self::TABLE_NAME, $data, 'id=' . $this->db->quote($this->model->getId()));
}
示例3: getLanguages
protected function getLanguages()
{
if ($this->languages == null) {
$languages = Pimcore_Tool::getValidLanguages();
$this->languages = $languages;
}
return $this->languages;
}
示例4: configureOptions
public function configureOptions()
{
$validLanguages = (array) Pimcore_Tool::getValidLanguages();
$languages = Zend_Locale::getTranslationList('language');
asort($languages);
$options = array();
foreach ($languages as $short => $translation) {
if ($this->getOnlySystemLanguages()) {
if (!in_array($short, $validLanguages)) {
continue;
}
}
if (strlen($short) == 2 or strlen($short) == 5 and strpos($short, "_") == 2) {
$options[] = array("key" => $translation, "value" => $short);
}
}
$this->setOptions($options);
}
示例5: walk_path
private function walk_path($folder, $options = null, $path = "")
{
if (is_null($options)) {
$options = array();
}
if ($folder) {
$source = $this->_getParam("source_methodname");
if (Pimcore_Version::getRevision() > 3303) {
$object_name = "Pimcore\\Model\\Object\\" . ucfirst($this->_getParam("source_classname"));
} else {
$object_name = "Object_" . ucfirst($this->_getParam("source_classname"));
}
$children = $folder->getChilds();
$usesI18n = sizeof($children) > 0 && $this->isUsingI18n($children[0], $source);
$current_lang = $this->_getParam("current_language");
if (!Pimcore_Tool::isValidLanguage($current_lang)) {
$languages = Pimcore_Tool::getValidLanguages();
$current_lang = $languages[0];
// TODO: Is this sensible?
}
foreach ($children as $child) {
$class = get_class($child);
switch ($class) {
case "Object_Folder":
/**
* @var Object_Folder $child
*/
$key = $child->getProperty("Taglabel") != "" ? $child->getProperty("Taglabel") : $child->getKey();
if ($this->_getParam("source_recursive") == "true") {
$options = $this->walk_path($child, $options, $path . $this->separator . $key);
}
break;
case $object_name:
$key = $usesI18n ? $child->{$source}($current_lang) : $child->{$source}();
$options[] = array("value" => $child->getId(), "key" => ltrim($path . $this->separator . $key, $this->separator));
if ($this->_getParam("source_recursive") == "true") {
$options = $this->walk_path($child, $options, $path . $this->separator . $key);
}
break;
}
}
}
return $options;
}
示例6: _loadTranslationData
protected function _loadTranslationData($data = null, $locale, array $options = array())
{
$list = new Translation_Website_List();
$list->load();
foreach ($list->getTranslations() as $translation) {
if ($translation instanceof Translation_Abstract) {
foreach ($translation->getTranslations() as $language => $text) {
$this->_translate[$language][$translation->getKey()] = Pimcore_Tool_Text::removeLineBreaks($text);
}
}
}
$availableLanguages = (array) Pimcore_Tool::getValidLanguages();
foreach ($availableLanguages as $language) {
if (!array_key_exists($language, $this->_translate) || empty($this->_translate[$language])) {
$this->_translate[$language] = array("__pimcore_dummy" => "only_a_dummy");
}
}
return $this->_translate;
}
示例7: initTranslation
protected function initTranslation()
{
$translate = null;
if (Zend_Registry::isRegistered("Zend_Translate")) {
$t = Zend_Registry::get("Zend_Translate");
// this check is necessary for the case that a document is rendered within an admin request
// example: send test newsletter
if ($t instanceof Pimcore_Translate) {
$translate = $t;
}
}
if (!$translate) {
// setup Zend_Translate
try {
$locale = Zend_Registry::get("Zend_Locale");
$translate = new Pimcore_Translate_Website($locale);
if (Pimcore_Tool::isValidLanguage($locale)) {
$translate->setLocale($locale);
} else {
Logger::error("You want to use an invalid language which is not defined in the system settings: " . $locale);
// fall back to the first (default) language defined
$languages = Pimcore_Tool::getValidLanguages();
if ($languages[0]) {
Logger::error("Using '" . $languages[0] . "' as a fallback, because the language '" . $locale . "' is not defined in system settings");
$translate = new Pimcore_Translate_Website($languages[0]);
// reinit with new locale
$translate->setLocale($languages[0]);
} else {
throw new Exception("You have not defined a language in the system settings (Website -> Frontend-Languages), please add at least one language.");
}
}
// register the translator in Zend_Registry with the key "Zend_Translate" to use the translate helper for Zend_View
Zend_Registry::set("Zend_Translate", $translate);
} catch (Exception $e) {
Logger::error("initialization of Pimcore_Translate failed");
Logger::error($e);
}
}
return $translate;
}
示例8: initTranslation
public function initTranslation()
{
if (Zend_Registry::isRegistered("Zend_Translate")) {
$translator = Zend_Registry::get("Zend_Translate");
} else {
// setup Zend_Translate
try {
$locale = Zend_Registry::get("Zend_Locale");
$cacheKey = "translator_website";
if (!($translate = Pimcore_Model_Cache::load($cacheKey))) {
$translate = new Pimcore_Translate_Website($locale);
Pimcore_Model_Cache::save($translate, $cacheKey, array("translator", "translator_website", "translate"), null, 999);
}
if (Pimcore_Tool::isValidLanguage($locale)) {
$translate->setLocale($locale);
} else {
Logger::error("You want to use an invalid language which is not defined in the system settings: " . $locale);
// fall back to the first (default) language defined
$languages = Pimcore_Tool::getValidLanguages();
if ($languages[0]) {
Logger::error("Using '" . $languages[0] . "' as a fallback, because the language '" . $locale . "' is not defined in system settings");
$translate->setLocale($languages[0]);
} else {
throw new Exception("You have not defined a language in the system settings (Website -> Frontend-Languages), please add at least one language.");
}
}
// register the translator in Zend_Registry with the key "Zend_Translate" to use the translate helper for Zend_View
Zend_Registry::set("Zend_Translate", $translate);
} catch (Exception $e) {
Logger::error("initialization of Pimcore_Translate failed");
Logger::error($e);
}
}
return $translator;
}
示例9: getAvailableLanguagesAction
public function getAvailableLanguagesAction()
{
if ($languages = Pimcore_Tool::getValidLanguages()) {
$this->_helper->json($languages);
}
$t = new Translation_Website();
$this->_helper->json($t->getAvailableLanguages());
}
示例10: setFieldData
/**
* @param $fd
* @return void
*/
protected function setFieldData($object, $fd, $refDocument, $refAsset, $minAmountLazyRelations)
{
foreach ($fd as $field) {
$name = $field->getName();
$type = $field->getFieldType();
$class = "Object_Class_Data_" . ucfirst($type);
$this->assertTrue(class_exists($class));
$data = new $class();
$setter = "set" . ucfirst($name);
if (!$field->isRelationType() or !$field->isRemoteOwner()) {
$this->assertTrue(method_exists($object, $setter));
}
if ($data instanceof Object_Class_Data_Checkbox) {
$object->{$setter}(true);
} else {
if ($data instanceof Object_Class_Data_Time) {
$object->{$setter}("18:00");
} else {
if ($data instanceof Object_Class_Data_Password) {
$object->{$setter}("verySecret");
} else {
if ($data instanceof Object_Class_Data_Input) {
$object->{$setter}("simple input");
} else {
if ($data instanceof Object_Class_Data_Date) {
$object->{$setter}(new Zend_Date());
} else {
if ($data instanceof Object_Class_Data_Datetime) {
$object->{$setter}(new Zend_Date());
} else {
if ($data instanceof Object_Class_Data_Href) {
$object->{$setter}(Object_Abstract::getById($object->getId() - 1));
} else {
if ($data instanceof Object_Class_Data_Objects and !$data->isRemoteOwner()) {
$data = array();
$o = Object_Abstract::getById($object->getId() - 1);
if (!$o instanceof Object_Folder) {
$data[] = $o;
}
$data[] = Object_Abstract::getById($object->getId());
$object->{$setter}($data);
} else {
if ($data instanceof Object_Class_Data_Fieldcollections) {
$items = new Object_Fieldcollection();
$collectionA = Object_Fieldcollection_Definition::getByKey("collectionA");
$itemDefinitions = $collectionA->getFieldDefinitions();
$item = new Object_Fieldcollection_Data_CollectionA();
$this->setFieldData($item, $itemDefinitions, $refDocument, $refAsset, $minAmountLazyRelations);
$items->add($item);
$object->{$setter}($items);
} else {
if ($data instanceof Object_Class_Data_Localizedfields) {
$getter = "get" . ucfirst($name);
$data = $object->getO_class()->getFieldDefinition("localizedfields");
$localizedData = array();
$validLanguages = Pimcore_Tool::getValidLanguages();
foreach ($validLanguages as $language) {
foreach ($data->getFieldDefinitions() as $fd) {
$fieldData = $this->getLocalizedFieldDataFor($fd, $language, $refAsset);
$localizedData[$language][$fd->getName()] = $fieldData;
}
}
$object->{$setter}(new Object_Localizedfield($localizedData));
} else {
if ($data instanceof Object_Class_Data_Multihref) {
$data = array();
$data[] = Object_Abstract::getById($object->getId() - 1);
$data[] = $refAsset;
//dummy for checking if relation is saved twice
$data[] = Asset::getById($refAsset->getId());
$data[] = $refDocument;
$fd = $object->geto_Class()->getFieldDefinition($name);
if ($fd->getLazyLoading()) {
for ($i = 1; $i <= $minAmountLazyRelations; $i++) {
$data[] = $this->createRandomObject("unittest");
}
}
$object->{$setter}($data);
} else {
if ($data instanceof Object_Class_Data_Languagemultiselect) {
$object->{$setter}(array("de", "en"));
} else {
if ($data instanceof Object_Class_Data_Countrymultiselect) {
$object->{$setter}(array("AT", "AU"));
} else {
if ($data instanceof Object_Class_Data_Multiselect) {
$object->{$setter}(array("cat", "cow"));
} else {
if ($data instanceof Object_Class_Data_User) {
//create a user to set
$user = new User();
$user->setUsername(uniqid());
$user->setParentId(0);
$user->setHasCredentials(true);
$user->setPassword(md5("unitTestUser"));
$user->save();
//.........这里部分代码省略.........
示例11: getFromWebserviceImport
/**
* @param mixed $value
* @return mixed
*/
public function getFromWebserviceImport($value)
{
if (is_array($value)) {
$validLanguages = Pimcore_Tool::getValidLanguages();
foreach ($value as $v) {
if (!in_array($v->language, $validLanguages)) {
throw new Exception("Invalid language in localized fields");
}
}
$data = array();
foreach ($value as $field) {
if (!$field instanceof Webservice_Data_Object_Element) {
throw new Exception("Invalid import data in field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ]");
}
$fd = $this->getFielddefinition($field->name);
if (!$fd instanceof Object_Class_Data) {
throw new Exception("Unknnown field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ] ");
} else {
if ($fd->getFieldtype() != $field->type) {
throw new Exception("Type mismatch for field [ {$field->name} ] for language [ {$field->language} ] in localized fields [ " . $this->getName() . " ]. Should be [ " . $fd->getFieldtype() . " ], but is [ " . $field->type . " ] ");
}
}
$data[$field->language][$field->name] = $this->getFielddefinition($field->name)->getFromWebserviceImport($field->value);
}
$localizedFields = new Object_Localizedfield($data);
return $localizedFields;
} else {
if (!empty($value)) {
throw new Exception("Invalid data in localized fields");
} else {
return null;
}
}
}
示例12: foreach
<?php
// get db connection
$db = Pimcore_Resource::get();
$languages = Pimcore_Tool::getValidLanguages();
$list = new Object_Class_List();
$classes = $list->load();
if (!empty($classes)) {
foreach ($classes as $class) {
if ($class->getFielddefinition("localizedfields")) {
$tableName = "object_localized_data_" . $class->getId();
$cols = $db->fetchRow("SELECT * FROM " . $tableName . " LIMIT 1");
if (is_array($cols)) {
$cols = array_keys($cols);
foreach ($cols as &$col) {
$col = $db->quoteIdentifier($col);
}
foreach ($languages as $language) {
$tableQueryName = "object_localized_query_" . $class->getId() . "_" . $language;
try {
$db->query("INSERT INTO " . $tableQueryName . " (" . implode(",", $cols) . ") SELECT * FROM " . $tableName . " WHERE language = '" . $language . "'");
} catch (\Exception $e) {
echo $e->getMessage() . "<br />";
}
}
}
}
}
}
示例13: setLocale
/**
* Try to set the locale from different sources
*
* @param $locale
* @return void
*/
public function setLocale($locale = null)
{
if ($locale instanceof Zend_Locale) {
$this->locale = $locale;
} elseif (is_string($locale)) {
$this->locale = new Zend_Locale($locale);
} elseif ($this->getParam('locale') || $this->getParam('language')) {
$this->setLocale($this->getParam('locale') ? $this->getParam('locale') : $this->getParam('language'));
} else {
$document = $this->getDocument();
if ($document instanceof Document && $document->getProperty("language")) {
$this->setLocale($document->getProperty("language"));
}
if (is_null($this->locale)) {
//last chance -> get it from registry or use the first Language defined in the system settings
if (Zend_Registry::isRegistered("Zend_Locale")) {
$this->locale = Zend_Registry::get("Zend_Locale");
} else {
list($language) = Pimcore_Tool::getValidLanguages();
$this->locale = new Zend_Locale($language);
}
}
}
}
示例14: reindex_documents
private function reindex_documents(Document $document)
{
if (!$document instanceof Document_Page) {
return;
}
$config = SphinxSearch_Config::getInstance();
switch (SphinxSearch_Config_Plugin::getValue("indexer", "onchange")) {
case "immediately":
$documents_config = $config->getDocumentsAsArray();
$languages = array("all");
if ($this->config->documents->use_i18n == "true") {
$languages = Pimcore_Tool::getValidLanguages();
}
$controller = $document->getController();
$action = $document->getAction();
$template = $document->getTemplate();
$config_name = $controller . "_" . $action;
if ($template != "") {
$config_name . "_" . $template;
}
$indexes = array();
foreach ($languages as $lang) {
foreach ($documents_config as $document_name => $document_properties) {
if ($config_name == $document_name) {
$indexes[] = "idx_document_" . $document_name . "_" . $lang;
}
}
}
if (sizeof($indexes) > 0) {
$indexes = implode(" ", $indexes);
$this->runIndexer($indexes);
}
break;
case "reschedule":
SphinxSearch_Config_Plugin::setValue("indexer", "lastrun", 0);
break;
default:
// Do nothing
break;
}
}
示例15: writeSphinxConfig
public function writeSphinxConfig()
{
$pimcore_config = Pimcore_Config::getSystemConfig();
$params = $pimcore_config->database->params;
$db_host = $params->host;
$db_user = $params->username;
$db_password = $params->password;
$db_name = $params->dbname;
$db_port = $params->port;
$index_path = SPHINX_VAR . DIRECTORY_SEPARATOR . "index";
$cli_path = PIMCORE_PLUGINS_PATH . DIRECTORY_SEPARATOR . "SphinxSearch" . DIRECTORY_SEPARATOR . "cli";
$pid_path = SphinxSearch_Config_Plugin::getValue("path", "pid");
$logfile_path = SphinxSearch_Config_Plugin::getValue("path", "log");
$querylog_path = SphinxSearch_Config_Plugin::getValue("path", "querylog");
$port = SphinxSearch_Config_Plugin::getValue("searchd", "port");
if (substr($pid_path, 0, 1) != DIRECTORY_SEPARATOR) {
$pid_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $pid_path;
}
if (substr($logfile_path, 0, 1) != DIRECTORY_SEPARATOR) {
$logfile_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $logfile_path;
}
if (substr($querylog_path, 0, 1) != DIRECTORY_SEPARATOR) {
$querylog_path = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . $querylog_path;
}
$config = <<<EOL
indexer
{
mem_limit = 32M
}
searchd
{
port = {$port}
log = {$logfile_path}
query_log = {$querylog_path}
read_timeout = 5
max_children = 30
pid_file = {$pid_path}
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
}
EOL;
$indexer = SphinxSearch_Config_Plugin::getValue("path", "phpcli") . " " . $cli_path . DIRECTORY_SEPARATOR . "index_documents.php";
$documents_config = $this->getDocumentsAsArray();
$languages = array("all");
if (SphinxSearch_Config_Plugin::getValue("documents", "use_i18n") == "true") {
$languages = Pimcore_Tool::getValidLanguages();
}
foreach ($languages as $lang) {
foreach ($documents_config as $document_name => $document_properties) {
$source_name = "document_" . $document_name . "_" . $lang;
$index_name = "idx_document_" . $document_name . "_" . $lang;
$document_index_path = $index_path . DIRECTORY_SEPARATOR . "document_" . $document_name . "_" . $lang;
$config .= <<<EOL
source {$source_name} {
type = xmlpipe2
xmlpipe_command = {$indexer} -d {$document_name} -l {$lang}
}
index {$index_name} {
source = {$source_name}
path = {$document_index_path}
charset_type = utf-8
}
EOL;
}
}
foreach ($this->getClasses()->children() as $class) {
/**
* @var $class SimpleXMLElement
*/
$class_name = $class->getName();
$object_class = Object_Class::getByName($class_name);
$fields = array("oo_id", "o_creationDate", "o_modificationDate", "o_published", "o_type");
$attributes = array("o_creationDate" => "sql_attr_timestamp", "o_modificationDate" => "sql_attr_timestamp", "o_published" => "sql_field_string", "o_type" => "sql_field_string");
foreach ($class->children() as $field) {
$fields[] = $field->attributes()->name;
if ($field->attributes()->field_type) {
$attributes[$field->attributes()->name->__toString()] = $field->attributes()->field_type;
}
}
$fields = "`" . implode("`,`", $fields) . "`";
$attributes_definition = "";
foreach ($attributes as $key => $value) {
$attributes_definition .= " {$value} = {$key}\n";
// Yes, really $value first
}
// Do we have localized fields?
if ($object_class->getFieldDefinition("localizedfields")) {
$pimcore_languages = Pimcore_Tool::getValidLanguages();
foreach ($pimcore_languages as $lang) {
$source_class_name = $class_name . "_" . $lang;
$table = "object_localized_" . $object_class->getId() . "_" . $lang;
$config .= <<<EOL
//.........这里部分代码省略.........