本文整理汇总了PHP中Backend\Core\Engine\Language::getWorkingLanguages方法的典型用法代码示例。如果您正苦于以下问题:PHP Language::getWorkingLanguages方法的具体用法?PHP Language::getWorkingLanguages怎么用?PHP Language::getWorkingLanguages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Backend\Core\Engine\Language
的用法示例。
在下文中一共展示了Language::getWorkingLanguages方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadForm
/**
* Load the form
*/
private function loadForm()
{
if ($this->getParameter('id') != null) {
// get the translation
$translation = BackendLocaleModel::get($this->getParameter('id', 'int'));
// if not empty, set the filter
if (!empty($translation)) {
// we are copying the given translation
$isCopy = true;
} else {
$this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing' . $this->filterQuery);
}
} else {
$isCopy = false;
}
// create form
$this->frm = new BackendForm('add', BackendModel::createURLForAction() . $this->filterQuery);
// create and add elements
$this->frm->addDropdown('application', array('Backend' => 'Backend', 'Frontend' => 'Frontend'), $isCopy ? $translation['application'] : $this->filter['application']);
$this->frm->addDropdown('module', BackendModel::getModulesForDropDown(), $isCopy ? $translation['module'] : $this->filter['module']);
$this->frm->addDropdown('type', BackendLocaleModel::getTypesForDropDown(), $isCopy ? $translation['type'] : $this->filter['type'][0]);
$this->frm->addText('name', $isCopy ? $translation['name'] : $this->filter['name']);
$this->frm->addTextarea('value', $isCopy ? $translation['value'] : $this->filter['value'], null, null, true);
$this->frm->addDropdown('language', BL::getWorkingLanguages(), $isCopy ? $translation['language'] : $this->filter['language'][0]);
}
示例2: execute
/**
* Execute the action
* We will build the classname, require the class and call the execute method.
*/
public function execute()
{
$this->loadConfig();
// is the requested action possible? If not we throw an exception.
// We don't redirect because that could trigger a redirect loop
if (!in_array($this->getAction(), $this->config->getPossibleActions())) {
throw new Exception('This is an invalid action (' . $this->getAction() . ').');
}
// build action-class
$actionClass = 'Backend\\Modules\\' . $this->getModule() . '\\Actions\\' . $this->getAction();
if ($this->getModule() == 'Core') {
$actionClass = 'Backend\\Core\\Actions\\' . $this->getAction();
}
if (!class_exists($actionClass)) {
throw new Exception('The class ' . $actionClass . ' could not be found.');
}
// get working languages
$languages = Language::getWorkingLanguages();
$workingLanguages = array();
// loop languages and build an array that we can assign
foreach ($languages as $abbreviation => $label) {
$workingLanguages[] = array('abbr' => $abbreviation, 'label' => $label, 'selected' => $abbreviation == Language::getWorkingLanguage());
}
// assign the languages
$this->tpl->assign('workingLanguages', $workingLanguages);
// create action-object
/** @var $object BackendBaseAction */
$object = new $actionClass($this->getKernel());
$this->getContainer()->get('logger')->info("Executing backend action '{$object->getAction()}' for module '{$object->getModule()}'.");
$object->execute();
return $object->getContent();
}
示例3: loadForm
/**
* Load the form
*/
private function loadForm()
{
$this->frm = new BackendForm('edit', BackendModel::createURLForAction(null, null, null, array('id' => $this->id)) . $this->filterQuery);
$this->frm->addDropdown('application', array('Backend' => 'Backend', 'Frontend' => 'Frontend'), $this->record['application']);
$this->frm->addDropdown('module', BackendModel::getModulesForDropDown(), $this->record['module']);
$this->frm->addDropdown('type', BackendLocaleModel::getTypesForDropDown(), $this->record['type']);
$this->frm->addText('name', $this->record['name']);
$this->frm->addTextarea('value', $this->record['value'], null, 'inputText', 'inputTextError', true);
$this->frm->addDropdown('language', BL::getWorkingLanguages(), $this->record['language']);
}
示例4: setLanguage
/**
* @param string $language
* @throws Exception If the provided language is not valid
*/
public function setLanguage($language)
{
// get the possible languages
$possibleLanguages = Language::getWorkingLanguages();
// validate
if (!in_array($language, array_keys($possibleLanguages))) {
throw new Exception('Language invalid.');
}
// set working language
Language::setWorkingLanguage($language);
}
示例5: execute
/**
* Execute the action
*/
public function execute()
{
parent::execute();
$isGod = BackendAuthentication::getUser()->isGod();
// get possible languages
if ($isGod) {
$possibleLanguages = array_unique(array_merge(BL::getWorkingLanguages(), BL::getInterfaceLanguages()));
} else {
$possibleLanguages = BL::getWorkingLanguages();
}
// get parameters
$language = \SpoonFilter::getPostValue('language', array_keys($possibleLanguages), null, 'string');
$module = \SpoonFilter::getPostValue('module', BackendModel::getModules(), null, 'string');
$name = \SpoonFilter::getPostValue('name', null, null, 'string');
$type = \SpoonFilter::getPostValue('type', BackendModel::getContainer()->get('database')->getEnumValues('locale', 'type'), null, 'string');
$application = \SpoonFilter::getPostValue('application', array('Backend', 'Frontend'), null, 'string');
$value = \SpoonFilter::getPostValue('value', null, null, 'string');
// validate values
if (trim($value) == '' || $language == '' || $module == '' || $type == '' || $application == '' || $application == 'Frontend' && $module != 'Core') {
$error = BL::err('InvalidValue');
}
// in case this is a 'act' type, there are special rules concerning possible values
if ($type == 'act' && !isset($error)) {
if (urlencode($value) != CommonUri::getUrl($value)) {
$error = BL::err('InvalidActionValue', $this->getModule());
}
}
// no error?
if (!isset($error)) {
// build item
$item['language'] = $language;
$item['module'] = $module;
$item['name'] = $name;
$item['type'] = $type;
$item['application'] = $application;
$item['value'] = $value;
$item['edited_on'] = BackendModel::getUTCDate();
$item['user_id'] = BackendAuthentication::getUser()->getUserId();
// does the translation exist?
if (BackendLocaleModel::existsByName($name, $type, $module, $language, $application)) {
// add the id to the item
$item['id'] = (int) BackendLocaleModel::getByName($name, $type, $module, $language, $application);
// update in db
BackendLocaleModel::update($item);
} else {
// insert in db
BackendLocaleModel::insert($item);
}
// output OK
$this->output(self::OK);
} else {
$this->output(self::ERROR, null, $error);
}
}
示例6: loadForm
/**
* Load the form
*/
private function loadForm()
{
// create form
$this->frm = new BackendForm('edit');
// add "no default group" option for radiobuttons
$chkDefaultForLanguageValues[] = array('label' => BL::msg('NoDefault'), 'value' => '0');
// set default for language radiobutton values
foreach (BL::getWorkingLanguages() as $key => $value) {
$chkDefaultForLanguageValues[] = array('label' => $value, 'value' => $key);
}
// create elements
$this->frm->addText('name', $this->record['name']);
$this->frm->addRadiobutton('default', $chkDefaultForLanguageValues, $this->record['language']);
}
示例7: loadForm
/**
* Load the form
*/
private function loadForm()
{
//--Create form
$this->frm = new BackendForm('import');
//--Create file
$this->frm->addFile('csv');
//--Dropdown for languages
$this->frm->addDropdown('languages', BL::getWorkingLanguages(), BL::getWorkingLanguage());
//--Get all the users
$groups = BackendMailengineModel::getAllGroups();
//--Loop all the groups
$groupCheckboxes = array();
foreach ($groups as &$group) {
$groupCheckboxes[] = array("label" => $group["title"], "value" => $group["id"]);
}
//--Add multicheckboxes to form
$this->frm->addMultiCheckbox("groups", $groupCheckboxes);
$this->frm->parse($this->tpl);
}
示例8: checkDefaultGroups
/**
* Returns true if every working language has a default group set, false if at least one is missing.
*
* @return bool
*/
public static function checkDefaultGroups()
{
// check if the defaults were set already, and return true if they were
if (BackendModel::get('fork.settings')->get('Mailmotor', 'cm_groups_defaults_set')) {
return true;
}
// get all default groups
$defaults = self::getDefaultGroups();
// if the total amount of working languages do not add up to
// the total amount of default groups not all default groups were set.
if (count(BL::getWorkingLanguages()) === count($defaults)) {
// cm_groups_defaults_set status is now true
BackendModel::get('fork.settings')->set('Mailmotor', 'cm_groups_defaults_set', true);
// return true
return true;
}
// if we made it here, not all default groups were set; return false
return false;
}
示例9: setLanguage
/**
* Set language
*
* @param string $value The language to load.
*/
public function setLanguage($value)
{
// get the possible languages
$possibleLanguages = Language::getWorkingLanguages();
// validate
if (!in_array($value, array_keys($possibleLanguages))) {
throw new Exception('Invalid language.');
}
// set property
$this->language = $value;
// set the locale (we need this for the labels)
Language::setLocale($this->language);
// set working language
Language::setWorkingLanguage($this->language);
}
示例10: processQueryString
/**
* Process the querystring
*/
private function processQueryString()
{
// store the querystring local, so we don't alter it.
$queryString = $this->getQueryString();
// find the position of ? (which separates real URL and GET-parameters)
$positionQuestionMark = strpos($queryString, '?');
// separate the GET-chunk from the parameters
$getParameters = '';
if ($positionQuestionMark === false) {
$processedQueryString = $queryString;
} else {
$processedQueryString = substr($queryString, 0, $positionQuestionMark);
$getParameters = substr($queryString, $positionQuestionMark);
}
// split into chunks, a Backend URL will always look like /<lang>/<module>/<action>(?GET)
$chunks = (array) explode('/', trim($processedQueryString, '/'));
// check if this is a request for a AJAX-file
$isAJAX = isset($chunks[1]) && $chunks[1] == 'ajax';
// get the language, this will always be in front
$language = '';
if (isset($chunks[1]) && $chunks[1] != '') {
$language = \SpoonFilter::getValue($chunks[1], array_keys(Language::getWorkingLanguages()), '');
}
// no language provided?
if ($language == '' && !$isAJAX) {
// remove first element
array_shift($chunks);
// redirect to login
$this->redirect('/' . NAMED_APPLICATION . '/' . SITE_DEFAULT_LANGUAGE . (empty($chunks) ? '' : '/') . implode('/', $chunks) . $getParameters);
}
// get the module, null will be the default
$module = isset($chunks[2]) && $chunks[2] != '' ? $chunks[2] : 'Dashboard';
$module = \SpoonFilter::toCamelCase($module);
// get the requested action, if it is passed
if (isset($chunks[3]) && $chunks[3] != '') {
$action = \SpoonFilter::toCamelCase($chunks[3]);
} elseif (!$isAJAX) {
// Check if we can load the config file
$configClass = 'Backend\\Modules\\' . $module . '\\Config';
if ($module == 'Core') {
$configClass = 'Backend\\Core\\Config';
}
try {
// when loading a backend url for a module that doesn't exist, without
// providing an action, a FatalErrorException occurs, because the config
// class we're trying to load doesn't exist. Let's just throw instead,
// and catch it immediately.
if (!class_exists($configClass)) {
throw new Exception('The config class does not exist');
}
/** @var BackendBaseConfig $config */
$config = new $configClass($this->getKernel(), $module);
// set action
$action = $config->getDefaultAction() !== null ? $config->getDefaultAction() : 'Index';
} catch (Exception $ex) {
if (BackendModel::getContainer()->getParameter('kernel.debug')) {
throw new Exception('The config file for the module (' . $module . ') can\'t be found.');
} else {
// @todo don't use redirects for error, we should have something like an invoke method.
// build the url
$errorUrl = '/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed';
// add the querystring, it will be processed by the error-handler
$errorUrl .= '&querystring=' . urlencode('/' . $this->getQueryString());
// redirect to the error page
$this->redirect($errorUrl, 307);
}
}
}
// AJAX parameters are passed via GET or POST
if ($isAJAX) {
$module = isset($_GET['fork']['module']) ? $_GET['fork']['module'] : '';
$action = isset($_GET['fork']['action']) ? $_GET['fork']['action'] : '';
$language = isset($_GET['fork']['language']) ? $_GET['fork']['language'] : SITE_DEFAULT_LANGUAGE;
$module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : $module;
$action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : $action;
$language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : $language;
$this->setModule($module);
$this->setAction($action);
Language::setWorkingLanguage($language);
} else {
$this->processRegularRequest($module, $action, $language);
}
}
示例11: importXML
/**
* Import a locale XML file.
*
* @param \SimpleXMLElement $xml The locale XML.
* @param bool $overwriteConflicts Should we overwrite when there is a conflict?
* @param array $frontendLanguages The frontend languages to install locale for.
* @param array $backendLanguages The backend languages to install locale for.
* @param int $userId Id of the user these translations should be inserted for.
* @param int $date The date the translation has been inserted.
* @return array The import statistics
*/
public static function importXML(\SimpleXMLElement $xml, $overwriteConflicts = false, $frontendLanguages = null, $backendLanguages = null, $userId = null, $date = null)
{
$overwriteConflicts = (bool) $overwriteConflicts;
$statistics = array('total' => 0, 'imported' => 0);
// set defaults if necessary
// we can't simply use these right away, because this function is also calls by the installer,
// which does not have Backend-functions
if ($frontendLanguages === null) {
$frontendLanguages = array_keys(BL::getWorkingLanguages());
}
if ($backendLanguages === null) {
$backendLanguages = array_keys(BL::getInterfaceLanguages());
}
if ($userId === null) {
$userId = BackendAuthentication::getUser()->getUserId();
}
if ($date === null) {
$date = BackendModel::getUTCDate();
}
// get database instance
$db = BackendModel::getContainer()->get('database');
// possible values
$possibleApplications = array('Frontend', 'Backend');
$possibleModules = (array) $db->getColumn('SELECT m.name FROM modules AS m');
// types
$typesShort = (array) $db->getEnumValues('locale', 'type');
foreach ($typesShort as $type) {
$possibleTypes[$type] = self::getTypeName($type);
}
// install English translations anyhow, they're fallback
$possibleLanguages = array('Frontend' => array_unique(array_merge(array('en'), $frontendLanguages)), 'Backend' => array_unique(array_merge(array('en'), $backendLanguages)));
// current locale items (used to check for conflicts)
$currentLocale = (array) $db->getColumn('SELECT CONCAT(application, module, type, language, name)
FROM locale');
// applications
foreach ($xml as $application => $modules) {
// application does not exist
if (!in_array($application, $possibleApplications)) {
continue;
}
// modules
foreach ($modules as $module => $items) {
// module does not exist
if (!in_array($module, $possibleModules)) {
continue;
}
// items
foreach ($items as $item) {
// attributes
$attributes = $item->attributes();
$type = \SpoonFilter::getValue($attributes['type'], $possibleTypes, '');
$name = \SpoonFilter::getValue($attributes['name'], null, '');
// missing attributes
if ($type == '' || $name == '') {
continue;
}
// real type (shortened)
$type = array_search($type, $possibleTypes);
// translations
foreach ($item->translation as $translation) {
// statistics
$statistics['total']++;
// attributes
$attributes = $translation->attributes();
$language = \SpoonFilter::getValue($attributes['language'], $possibleLanguages[$application], '');
// language does not exist
if ($language == '') {
continue;
}
// the actual translation
$translation = (string) $translation;
// locale item
$locale['user_id'] = $userId;
$locale['language'] = $language;
$locale['application'] = $application;
$locale['module'] = $module;
$locale['type'] = $type;
$locale['name'] = $name;
$locale['value'] = $translation;
$locale['edited_on'] = $date;
// check if translation does not yet exist, or if the translation can be overridden
if (!in_array($application . $module . $type . $language . $name, $currentLocale) || $overwriteConflicts) {
$db->execute('INSERT INTO locale (user_id, language, application, module, type, name, value, edited_on)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE user_id = ?, value = ?, edited_on = ?', array($locale['user_id'], $locale['language'], $locale['application'], $locale['module'], $locale['type'], $locale['name'], $locale['value'], $locale['edited_on'], $locale['user_id'], $locale['value'], $locale['edited_on']));
// statistics
$statistics['imported']++;
}
}
//.........这里部分代码省略.........
示例12: loadForm
/**
* Load the form
*/
private function loadForm()
{
// create form
$this->frm = new BackendForm('import');
// create elements
$this->frm->addFile('csv');
// dropdown for languages
$this->frm->addDropdown('languages', BL::getWorkingLanguages(), BL::getWorkingLanguage());
// fetch groups
$groups = BackendMailmotorModel::getGroupsForCheckboxes();
// if no groups are found, redirect to overview
if (empty($groups)) {
$this->redirect(BackendModel::createURLForAction('Addresses') . '&error=no-groups');
}
// add radiobuttons for groups
$this->frm->addRadiobutton('groups', $groups, empty($this->groupId) ? null : $this->groupId);
// show the form
$this->tpl->assign('import', true);
}