Translate secondary options for extrafield options - refs BT#11015

ofaj
Angel Fernando Quiroz Campos 9 years ago
parent f04cf03eb6
commit 3310cfa2d7
  1. 2
      main/extrafield/translate.php
  2. 1
      main/inc/ajax/extra_field.ajax.php
  3. 73
      main/inc/lib/extra_field_option.lib.php
  4. 2
      src/Chamilo/CoreBundle/Entity/ExtraFieldOptions.php
  5. 36
      src/Chamilo/CoreBundle/Entity/Repository/ExtraFieldOptionsRepository.php

@ -20,7 +20,7 @@ if (isset($_GET['extra_field'])) {
$originalName = $extraFieldInfo['display_text'];
} elseif (isset($_GET['extra_field_option'])) {
$extraFieldOptionInfo = ExtraFieldOption::getInfoById($_GET['extra_field_option'], false);
$variableLanguage = '$' . api_underscore_to_camel_case($extraFieldOptionInfo['display_text']);
$variableLanguage = '$' . ExtraFieldOption::getLanguageVariable($extraFieldOptionInfo['display_text']);
$originalName = $extraFieldOptionInfo['display_text'];
}

@ -16,7 +16,6 @@ switch ($action) {
if (!empty($type) && !empty($field_id) && !empty($option_value_id)) {
$field_options = new ExtraFieldOption($type);
echo $field_options->get_second_select_field_options_by_field(
$field_id,
$option_value_id,
true
);

@ -480,38 +480,48 @@ class ExtraFieldOption extends Model
/**
* Get options for a specific field as array or in JSON format suited for the double-select format
* @param int $field_id
* @param int $option_value_id Option value ID
* @param bool $to_json Return format (whether it should be formatted to JSON or not)
* @return mixed Row/JSON on success
*/
public function get_second_select_field_options_by_field($field_id, $option_value_id, $to_json = false)
public function get_second_select_field_options_by_field($option_value_id, $to_json = false)
{
$field_id = intval($field_id);
$option_value_id = intval($option_value_id);
$options = array();
$sql = "SELECT * FROM {$this->table}
WHERE field_id = $field_id AND option_value = $option_value_id
ORDER BY display_text";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$options = Database::store_result($result, 'ASSOC');
$em = Database::getManager();
$option = $em->find('ChamiloCoreBundle:ExtraFieldOptions', intval($option_value_id));
if (!$option) {
return !$to_json ? [] : '{}';
}
if ($to_json) {
$string = null;
if (!empty($options)) {
$array = array();
foreach ($options as $option) {
$array[$option['id']] = $option['display_text'];
}
$string = json_encode($array);
}
$subOptions = $em
->getRepository('ChamiloCoreBundle:ExtraFieldOptions')
->findSecondaryOptions($option);
$optionsInfo = [];
foreach ($subOptions as $subOption) {
$optionsInfo[] = [
'id' => $subOption->getId(),
'field_id' => $subOption->getField()->getId(),
'option_value' => $subOption->getValue(),
'display_text' => $subOption->getDisplayText(),
'priority' => $subOption->getPriority(),
'priority_message' => $subOption->getPriorityMessage(),
'option_order' => $subOption->getOptionOrder()
];
}
return $string;
if (!$to_json) {
return $optionsInfo;
}
return $options;
$json = [];
foreach ($optionsInfo as $optionInfo) {
$json[$optionInfo['id']] = $optionInfo['display_text'];
}
return json_encode($json);
}
/**
@ -766,11 +776,22 @@ class ExtraFieldOption extends Model
*/
public static function translateDisplayName($defaultDisplayText)
{
$camelCase = api_underscore_to_camel_case($defaultDisplayText);
$camelCase = ucwords($camelCase);
$camelCase = str_replace(' ', '', $camelCase);
$variableLanguage = self::getLanguageVariable($defaultDisplayText);
return isset($GLOBALS[$variableLanguage]) ? $GLOBALS[$variableLanguage] : $defaultDisplayText;
}
/**
* @param $defaultDisplayText
* @return mixed|string
*/
public static function getLanguageVariable($defaultDisplayText)
{
$variableLanguage = api_replace_dangerous_char($defaultDisplayText);
$variableLanguage = str_replace('-', '_', $variableLanguage);
$variableLanguage = api_underscore_to_camel_case($variableLanguage);
return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $defaultDisplayText;
return $variableLanguage;
}
/**

@ -9,7 +9,7 @@ use Gedmo\Mapping\Annotation as Gedmo;
/**
* Class ExtraField
*
* @ORM\Entity
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\ExtraFieldOptionsRepository")
* @ORM\Table(name="extra_field_options")
*
* @ORM\MappedSuperclass

@ -0,0 +1,36 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity\Repository;
use Chamilo\CoreBundle\Entity\ExtraFieldOptions;
use Doctrine\ORM\EntityRepository;
/**
* Class ExtraFieldOptionsRepository
* @package Chamilo\CoreBundle\Entity\Repository
*/
class ExtraFieldOptionsRepository extends EntityRepository
{
/**
* Get the secondary options. For double select extra field
* @param ExtraFieldOptions $option
* @return array
*/
public function findSecondaryOptions(ExtraFieldOptions $option)
{
$qb = $this->createQueryBuilder('so');
$qb
->where(
$qb->expr()->eq('so.field', $option->getField()->getId())
)
->andWhere(
$qb->expr()->eq('so.value', $option->getId())
)
->orderBy('so.displayText', 'ASC');
return $qb
->getQuery()
->getResult();
}
}
Loading…
Cancel
Save