<?php /** * @package Neno * @subpackage Helpers * * @author Jensen Technologies S.L. <*****@*****.**> * @copyright Copyright (C) 2014 Jensen Technologies S.L. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; $document = JFactory::getDocument(); $document->addStyleSheet(JUri::root() . '/media/neno/css/languageconfiguration.css'); $item = (array) $displayData; $translationMethods = NenoHelper::loadTranslationMethods(); $n = 0; ?> <div class="language-wrapper language-<?php echo $item['placement']; ?> "> <?php if (!empty($item['errors'])) { ?> <div class="alert alert-error"> <button type="button" class="close" data-dismiss="alert">×</button> <?php foreach ($item['errors'] as $itemError) { ?>
/** * Get translation method selector * * @return void */ public function getTranslationMethodSelector() { $input = $this->input; $n = $input->getInt('n', 0); $selected_methods = $input->get('selected_methods', array(), 'ARRAY'); $placement = $input->getString('placement', 'general'); $translationMethods = NenoHelper::loadTranslationMethods(); $app = JFactory::getApplication(); // Ensure that we know what was selected for the previous selector if ($n > 0 && !isset($selected_methods[$n - 1]) || $n > 0 && $selected_methods[$n - 1] == 0) { $app->close(); } // As a safety measure prevent more than 5 selectors and always allow only one more selector than already selected if ($n > 4 || $n > count($selected_methods) + 1) { $app->close(); } // Reduce the translation methods offered depending on the parents if ($n > 0 && !empty($selected_methods)) { $parent_method = $selected_methods[$n - 1]; $acceptable_follow_up_method_ids = $translationMethods[$parent_method]->acceptable_follow_up_method_ids; $acceptable_follow_up_methods = explode(',', $acceptable_follow_up_method_ids); foreach ($translationMethods as $k => $translation_method) { if (!in_array($k, $acceptable_follow_up_methods)) { unset($translationMethods[$k]); } } } // If there are no translation methods left then return nothing if (!count($translationMethods)) { JFactory::getApplication()->close(); } // Prepare display data $displayData = array(); $displayData['translation_methods'] = $translationMethods; $displayData['n'] = $n; if ($placement == 'general') { $displayData['assigned_translation_methods'] = NenoHelper::getTranslationMethods('dropdown'); } else { $lang = $input->getString('language'); $displayData['assigned_translation_methods'] = NenoHelper::getLanguageDefault($lang, $n); } $selectorHTML = JLayoutHelper::render('translationmethodselector', $displayData, JPATH_NENO_LAYOUTS); echo $selectorHTML; $app->close(); }
public function getTranslationMethodSelector() { $app = JFactory::getApplication(); $input = $this->input; $n = $input->getInt('n', 0); $groupId = $input->getInt('group_id'); $selectedMethods = $input->get('selected_methods', array(), 'ARRAY'); $translationMethods = NenoHelper::loadTranslationMethods(); if (!empty($groupId)) { $group = NenoContentElementGroup::load($groupId)->prepareDataForView(); } else { $group = new stdClass(); $group->assigned_translation_methods = array(); } // Ensure that we know what was selected for the previous selector if ($n > 0 && !isset($selectedMethods[$n - 1]) || $n > 0 && $selectedMethods[$n - 1] == 0) { JFactory::getApplication()->close(); } // As a safety measure prevent more than 5 selectors and always allow only one more selector than already selected if ($n > 4 || $n > count($selectedMethods) + 1) { $app->close(); } // Reduce the translation methods offered depending on the parents if ($n > 0 && !empty($selectedMethods)) { $parentMethod = $selectedMethods[$n - 1]; $acceptableFollowUpMethodIds = $translationMethods[$parentMethod]->acceptable_follow_up_method_ids; $acceptableFollowUpMethods = explode(',', $acceptableFollowUpMethodIds); foreach ($translationMethods as $k => $translationMethod) { if (!in_array($k, $acceptableFollowUpMethods)) { unset($translationMethods[$k]); } } } // If there are no translation methods left then return nothing if (!count($translationMethods)) { $app->close(); } // Prepare display data $displayData = array(); $displayData['translation_methods'] = $translationMethods; $displayData['assigned_translation_methods'] = $group->assigned_translation_methods; $displayData['n'] = $n; $selectorHTML = JLayoutHelper::render('translationmethodselector', $displayData, JPATH_NENO_LAYOUTS); echo $selectorHTML; $app->close(); }