Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

remotes/angel/1.11.x
Yannick Warnier 9 years ago
commit 1eb0462d28
  1. 46
      app/Migrations/Schema/V111/Version20160603113100.php
  2. 6
      main/admin/settings.lib.php
  3. 80
      main/admin/sub_language.php
  4. 16
      main/admin/sub_language_ajax.inc.php
  5. 11
      main/inc/ajax/model.ajax.php
  6. 27
      main/inc/lib/api.lib.php
  7. 161
      main/inc/lib/extra_field.lib.php
  8. 86
      main/inc/lib/extra_field_option.lib.php
  9. 49
      src/Chamilo/CoreBundle/Entity/Language.php

@ -0,0 +1,46 @@
<?php
/* For licensing terms, see /license.txt */
namespace Application\Migrations\Schema\V111;
use Application\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Type;
/**
* Class Version20160603113100
* Add association mapping for Language class
* @package Application\Migrations\Schema\V111
*/
class Version20160603113100 extends AbstractMigrationChamilo
{
/**
* @param Schema $schema
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function up(Schema $schema)
{
$languageTable = $schema->getTable('language');
$languageTable
->getColumn('parent_id')
->setType(Type::getType(Type::INTEGER))
->setNotnull(false);
$languageTable->addForeignKeyConstraint('language', ['parent_id'], ['id'], [], 'language_parent');
}
/**
* @param Schema $schema
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function down(Schema $schema)
{
$languageTable = $schema->getTable('language');
$languageTable->removeForeignKey('language_parent');
$languageTable
->getColumn('parent_id')
->setType(Type::getType(Type::BOOLEAN))
->setNotnull(false);
}
}

@ -752,7 +752,7 @@ function handle_search()
$group = array ();
if (is_array($values)) {
foreach ($values as $key => $value) {
$element = & $form->createElement('radio', 'search_enabled', '', get_lang($value['display_text']), $value['value']);
$element = & $form->createElement('radio', 'search_enabled', '', $value['display_text'], $value['value']);
$group[] = $element;
}
}
@ -777,7 +777,7 @@ function handle_search()
$values = api_get_settings_options('search_show_unlinked_results');
$group = array ();
foreach ($values as $key => $value) {
$element = & $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']);
$element = & $form->createElement('radio', 'search_show_unlinked_results', '', $value['display_text'], $value['value']);
$group[] = $element;
}
$form->addGroup($group, 'search_show_unlinked_results', array(get_lang('SearchShowUnlinkedResultsTitle'),get_lang('SearchShowUnlinkedResultsComment')), '', false);
@ -1461,7 +1461,7 @@ function generate_settings_form($settings, $settings_by_access_list)
'radio',
$row['variable'],
'',
get_lang($value['display_text']),
$value['display_text'],
$value['value']
);
if ($hide_element) {

@ -14,13 +14,13 @@ api_protect_admin_script();
$htmlHeadXtra[] ='<script type="text/javascript">
$(document).ready(function() {
$(".save").click(function() {
button_name=$(this).attr("name");
button_array=button_name.split("|");
button_name=button_array[1];
file_id=button_array[2];
is_variable_language="$"+button_name;
var button_name=$(this).attr("name");
var button_array=button_name.split("|");
var button_name=button_array[1];
var file_id=button_array[2];
var is_variable_language="$"+button_name;
is_new_language = $("#txtid_"+file_id+"_"+button_name).val();
var is_new_language = $("#txtid_"+file_id+"_"+button_name).val();
if (is_new_language == undefined) {
is_new_language="_";
}
@ -28,21 +28,28 @@ $htmlHeadXtra[] ='<script type="text/javascript">
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {
$("#div_message_information_id").html("<div class=\"normal-message\"><img src=\'../inc/lib/javascript/indicator.gif\' /></div>");
$("#div_message_information_id").html("<div class=\"alert alert-info\"><img src=\'../inc/lib/javascript/indicator.gif\' /></div>");
},
type: "POST",
url: "../admin/sub_language_ajax.inc.php",
data: "new_language="+is_new_language+"&variable_language="+is_variable_language+"&file_id="+file_id+"&id="+'.intval($_REQUEST['id']).'+"&sub="+'.intval($_REQUEST['sub_language_id']).',
data: {
\'new_language\': is_new_language,
\'variable_language\': is_variable_language,
\'file_id\': file_id,
\'id\': ' . intval($_REQUEST['id']) . ',
\'sub\': ' . intval($_REQUEST['sub_language_id']) . ',
\'sub_language_id\': ' . intval($_REQUEST['sub_language_id']) . '
},
success: function(datos) {
if (datos == "1") {
$("#div_message_information_id").html("<div class=\"confirmation-message\">'.get_lang('TheNewWordHasBeenAdded').'</div>");
$("#div_message_information_id").html(\'' . Display::return_message(get_lang('TheNewWordHasBeenAdded'), 'success') . '\');
} else {
$("#div_message_information_id").html("<div class=\"warning-message\">" + datos +"</div>");
$("#div_message_information_id").html("<div class=\"alert alert-warning\">" + datos +"</div>");
}
}
});
} else {
$("#div_message_information_id").html("<div class=\"error-message\">'.get_lang('FormHasErrorsPleaseComplete').'</div>");
$("#div_message_information_id").html(\'' . Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error') . '\');
}
});
});
@ -120,14 +127,13 @@ if (!empty($sublanguage_folder_error)) {
echo '<div id="div_message_information_id">&nbsp;</div>';
/**
* Search a term in the language
* @param string $term the term to search
* @param bool $search_in_variable the search will include the variable definition of the term
* @param bool $search_in_english the search will include the english language variables
* @param bool $search_in_parent the search will include the parent language variables of the sub language
* @param bool $search_in_sub_language the search will include the sub language variables
* @param $term The term to search
* @param bool $search_in_variable The search will include the variable definition of the term
* @param bool $search_in_english The search will include the english language variables
* @param bool $search_in_parent The search will include the parent language variables of the sub language
* @param bool $search_in_sub_language The search will include the sub language variables
* @author Julio Montoya
*
* @return array
*/
function search_language_term(
$term,
@ -302,6 +308,44 @@ if (isset($_REQUEST['txt_search_word'])) {
}
}
if (
(isset($_GET['extra_field']) && !empty($_GET['extra_field'])) ||
(isset($_GET['extra_field_option']) && !empty($_GET['extra_field_option']))
) {
if (isset($_GET['extra_field'])) {
$extraFieldInfo = ExtraField::getInfoById($_GET['extra_field'], false);
$variable_language = '$' . api_underscore_to_camel_case($extraFieldInfo['variable']);
$original_name = $extraFieldInfo['display_text'];
} elseif (isset($_GET['extra_field_option'])) {
$extraFieldOptionInfo = ExtraFieldOption::getInfoById($_GET['extra_field_option'], false);
$variable_language = '$' . api_underscore_to_camel_case($extraFieldOptionInfo['display_text']);
$original_name = $extraFieldOptionInfo['display_text'];
}
$platformLanguage = api_get_setting('platformLanguage');
$languageId = api_get_language_id($platformLanguage);
$languageInfo = api_get_language_info($languageId);
$translateUrl = api_get_path(WEB_CODE_PATH) . 'admin/sub_language_ajax.inc.php';
$form = new FormValidator('new_lang_variable', 'POST', $translateUrl);
$form->addHeader(get_lang('AddWordForTheSubLanguage'));
$form->addText('variable_language', get_lang('LanguageVariable'), false);
$form->addText('original_name', get_lang('OriginalName'), false);
$form->addText('new_language', get_lang('SubLanguage'));
$form->addHidden('file_id', 0);
$form->addHidden('id', $languageInfo['parent_id']);
$form->addHidden('sub', $languageInfo['id']);
$form->addHidden('sub_language_id', $languageInfo['id']);
$form->addHidden('redirect', true);
$form->addButtonSave(get_lang('Save'));
$form->setDefaults([
'variable_language' => $variable_language,
'original_name' => $original_name
]);
$form->freeze(['variable_language', 'original_name']);
$form->display();
}
$parameters = array(
'id' => intval($_GET['id']),
'sub_language_id' => intval($_GET['sub_language_id']),

@ -44,10 +44,24 @@ if (isset($new_language) && isset($language_variable) && isset($file_id)) {
}
}
}
if (isset($_REQUEST['redirect'])) {
Display::addFlash(
Display::return_message(get_lang('TheNewWordHasBeenAdded'), 'success')
);
header('Location: ' . api_get_path(WEB_CODE_PATH) . 'admin/sub_language.php?' . http_build_query([
'id' => $id_language,
'sub_language_id' => $sub_language_id,
'txt_search_word' => ltrim($language_variable, '$')
]));
exit;
}
if (!empty($variables_with_problems)) {
echo $path_folder.' '.get_lang('IsNotWritable').'<br /> '.api_ucwords(get_lang('ErrorsFound')).': <br />'.$variables_with_problems;
} else {
echo get_lang('Saved');
echo 1;
}
}

@ -1421,11 +1421,14 @@ switch ($action) {
$new_result = array();
if (!empty($result)) {
foreach ($result as $item) {
$item['display_text'] = $item['displayText'];
$checkIcon = Display::return_icon('check-circle.png', get_lang('Yes'));
$timesIcon = Display::return_icon('closed-circle.png', get_lang('No'));
$item['display_text'] = ExtraField::translateDisplayName($item['variable'], $item['displayText']);
$item['field_type'] = $obj->get_field_type_by_id($item['fieldType']);
$item['changeable'] = $item['changeable'] ? Display::return_icon('check-circle.png', get_lang('Invisible')) : Display::return_icon('closed-circle.png', get_lang('Visible'), null, ICON_SIZE_SMALL);
$item['visible'] = $item['visible'] ? Display::return_icon('check-circle.png', get_lang('Invisible')) : Display::return_icon('closed-circle.png', get_lang('Visible'), null, ICON_SIZE_SMALL);
$item['filter'] = $item['filter'] ? Display::return_icon('check-circle.png', get_lang('Invisible')) : Display::return_icon('closed-circle.png', get_lang('Visible'), null, ICON_SIZE_SMALL);
$item['changeable'] = $item['changeable'] ? $checkIcon : $timesIcon;
$item['visible'] = $item['visible'] ? $checkIcon : $timesIcon;
$item['filter'] = $item['filter'] ? $checkIcon : $timesIcon;
$new_result[] = $item;
}
$result = $new_result;

@ -4255,15 +4255,24 @@ function api_get_language_from_type($lang_type)
return $return;
}
function api_get_language_info($language_id) {
$tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
$sql = 'SELECT * FROM '.$tbl_admin_languages.' WHERE id = "'.intval($language_id).'"';
$rs = Database::query($sql);
$language_info = array();
if (Database::num_rows($rs)) {
$language_info = Database::fetch_array($rs,'ASSOC');
}
return $language_info;
/**
* Get the language information by its id
* @param int $languageId
* @return array
*/
function api_get_language_info($languageId) {
$language = Database::getManager()
->find('ChamiloCoreBundle:Language', intval($languageId));
return [
'id' => $language->getId(),
'original_name' => $language->getOriginalName(),
'english_name' => $language->getEnglishName(),
'isocode' => $language->getIsocode(),
'dokeos_folder' => $language->getDokeosFolder(),
'available' => $language->getAvailable(),
'parent_id' => $language->getParent() ? $language->getParent()->getId() : null
];
}
/**

@ -223,6 +223,10 @@ class ExtraField extends Model
$option = new ExtraFieldOption($this->type);
if (!empty($extraFields)) {
foreach ($extraFields as &$extraField) {
$extraField['display_text'] = self::translateDisplayName(
$extraField['variable'],
$extraField['display_text']
);
$extraField['options'] = $option->get_field_options_by_field(
$extraField['id'],
false,
@ -249,6 +253,7 @@ class ExtraField extends Model
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result, 'ASSOC');
$row['display_text'] = ExtraField::translateDisplayName($row['variable'], $row['display_text']);
// All the options of the field
$sql = "SELECT * FROM $this->table_field_options
@ -907,7 +912,7 @@ class ExtraField extends Model
foreach ($field_details['options'] as $option_details) {
$optionList[$option_details['id']] = $option_details;
if ($get_lang_variables) {
$options[$option_details['option_value']] = get_lang($option_details['display_text']);
$options[$option_details['option_value']] = $option_details['display_text'];
} else {
if ($optionsExists) {
// Adding always the default value
@ -960,10 +965,6 @@ class ExtraField extends Model
}
}
if ($get_lang_variables) {
$field_details['display_text'] = get_lang($field_details['display_text']);
}
// chzn-select doesn't work for sessions??
$form->addElement(
'select',
@ -1169,16 +1170,6 @@ class ExtraField extends Model
$variable = $field_details['variable'];
$field_id = $field_details['id'];
//Added for correctly translate the extra_field
$get_lang_variables = false;
if (in_array($variable, ['tags'])) {
$get_lang_variables = true;
}
if ($get_lang_variables) {
$field_details['display_text'] = get_lang($field_details['display_text']);
}
$tagsSelect = $form->addSelect(
"extra_{$field_details['variable']}",
$field_details['display_text']
@ -1473,16 +1464,6 @@ EOF;
}
break;
case ExtraField::FIELD_TYPE_VIDEO_URL:
//Added for correctly translate the extra_field
$get_lang_variables = false;
if (in_array($field_details['variable'], ['video_url'])) {
$get_lang_variables = true;
}
if ($get_lang_variables) {
$field_details['display_text'] = get_lang($field_details['display_text']);
}
$form->addUrl(
"extra_{$field_details['variable']}",
$field_details['display_text'],
@ -1702,11 +1683,30 @@ EOF;
if ($action == 'edit') {
$header = get_lang('Modify');
// Setting the defaults
$defaults = $this->get($id);
$defaults = $this->get($id, false);
}
$form->addElement('header', $header);
$form->addElement('text', 'display_text', get_lang('Name'), array('class' => 'span5'));
if ($action === 'edit') {
$platformLanguage = api_get_setting('platformLanguage');
$languageId = api_get_language_id($platformLanguage);
$languageInfo = api_get_language_info($languageId);
$translateUrl = api_get_path(WEB_CODE_PATH) . 'admin/sub_language.php?' . http_build_query([
'id' => $languageInfo['parent_id'],
'action' => 'registersublanguage',
'sub_language_id' => $languageInfo['id'],
'extra_field' => $id
]);
$translateButton = Display::toolbarButton(get_lang('TranslateThisTerm'), $translateUrl, 'language', 'link');
$form->addText(
'display_text',
[get_lang('Name'), $translateButton]
);
} else {
$form->addText('display_text', get_lang('Name'));
}
// Field type
$types = self::get_field_types();
@ -1808,36 +1808,43 @@ EOF;
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('display_text', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('field_type', get_lang('ThisFieldIsRequired'), 'required');
return $form;
}
/**
* @param $token
* With this function we can add actions to the jgrid (edit, delete, etc)
* @param string $token
* @return string
*/
public function getJqgridActionLinks($token)
{
//With this function we can add actions to the jgrid (edit, delete, etc)
return 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="?action=edit&type='.$this->type.'&id=\'+options.rowId+\'">'.Display::return_icon(
'edit.png',
get_lang('Edit'),
'',
ICON_SIZE_SMALL
).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(
$editIcon = Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL);
$deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
$confirmMessage = addslashes(
api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES)
)."\'".')) return false;" href="?sec_token='.$token.'&type='.$this->type.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon(
'delete.png',
get_lang('Delete'),
'',
ICON_SIZE_SMALL
).'</a>'.
'\';
}';
);
$editButton = <<<JAVASCRIPT
<a href="?action=edit&type={$this->type}&id=' + options.rowId + '" class="btn btn-link btn-xs">\
$editIcon\
</a>
JAVASCRIPT;
$deleteButton = <<<JAVASCRIPT
<a \
onclick="if (!confirm(\'$confirmMessage\')) {return false;}" \
href="?sec_token=$token&type={$this->type}&id=' + options.rowId + '&action=delete" \
class="btn btn-link btn-xs">\
$deleteIcon\
</a>
JAVASCRIPT;
return "function action_formatter(cellvalue, options, rowObject) {
console.log(options);
return '$editButton $deleteButton';
}";
}
/**
@ -2278,4 +2285,68 @@ EOF;
return $valuesData;
}
/**
* Gets an element
* @param int $id
* @param bool $translateDisplayText Optional
* @return array
*/
public function get($id, $translateDisplayText = true)
{
$info = parent::get($id);
if ($translateDisplayText) {
$info['display_text'] = self::translateDisplayName($info['variable'], $info['display_text']);
}
return $info;
}
/**
* Translate the display text for a extra field
* @param string $variable
* @param string $defaultDisplayText
* @return string
*/
public static function translateDisplayName($variable, $defaultDisplayText)
{
$camelCase = api_underscore_to_camel_case($variable);
return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $defaultDisplayText;
}
/**
* Get the info from an extra field by its id
* @param int $id
* @param bool $translateDisplayText
* @return array
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
*/
public static function getInfoById($id, $translateDisplayText = true)
{
$extraField = Database::getManager()
->find('ChamiloCoreBundle:ExtraField', $id);
$objExtraField = null;
switch ($extraField->getExtraFieldType()) {
case \Chamilo\CoreBundle\Entity\ExtraField::USER_FIELD_TYPE:
$objExtraField = new self('user');
break;
case \Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE:
$objExtraField = new self('course');
break;
case \Chamilo\CoreBundle\Entity\ExtraField::SESSION_FIELD_TYPE:
$objExtraField = new self('session');
break;
}
if (!$objExtraField) {
return [];
}
return $objExtraField->get($extraField->getId(), $translateDisplayText);
}
}

@ -615,7 +615,23 @@ class ExtraFieldOption extends Model
$form->addElement('hidden', 'type', $this->type);
$form->addElement('hidden', 'field_id', $this->field_id);
$form->addElement('text', 'display_text', get_lang('Name'));
if ($action == 'edit') {
$platformLanguage = api_get_setting('platformLanguage');
$languageId = api_get_language_id($platformLanguage);
$languageInfo = api_get_language_info($languageId);
$translateUrl = api_get_path(WEB_CODE_PATH) . 'admin/sub_language.php?' . http_build_query([
'id' => $languageInfo['parent_id'],
'action' => 'registersublanguage',
'sub_language_id' => $languageInfo['id'],
'extra_field_option' => $id
]);
$translateButton = Display::toolbarButton(get_lang('TranslateThisTerm'), $translateUrl, 'language', 'link');
$form->addElement('text', 'display_text', [get_lang('Name'), $translateButton]);
} else {
$form->addElement('text', 'display_text', get_lang('Name'));
}
$form->addElement('text', 'option_value', get_lang('Value'));
$form->addElement('text', 'option_order', get_lang('Order'));
$form->addElement('select', 'priority', get_lang('Priority'), $this->getPriorityOptions());
@ -625,7 +641,7 @@ class ExtraFieldOption extends Model
if ($action == 'edit') {
// Setting the defaults
$defaults = $this->get($id);
$defaults = $this->get($id, false);
$form->freeze('option_value');
$form->addButtonUpdate(get_lang('Modify'));
} else {
@ -693,4 +709,70 @@ class ExtraFieldOption extends Model
return $json;
}
/**
* Gets an element
* @param int $id
* @param bool $translateDisplayText Optional
* @return array
*/
public function get($id, $translateDisplayText = true)
{
$info = parent::get($id);
if ($translateDisplayText) {
$info['display_text'] = self::translateDisplayName($info['display_text']);
}
return $info;
}
/**
* Translate the display text for a extra field option
* @param string $defaultDisplayText
* @return string
*/
public static function translateDisplayName($defaultDisplayText)
{
$camelCase = api_underscore_to_camel_case($defaultDisplayText);
$camelCase = ucwords($camelCase);
$camelCase = str_replace(' ', '', $camelCase);
return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $defaultDisplayText;
}
/**
* Get the info from an extra field option by its id
* @param int $id
* @param bool $translateDisplayText
* @return array
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
*/
public static function getInfoById($id, $translateDisplayText = true)
{
$extraField = Database::getManager()
->find('ChamiloCoreBundle:ExtraFieldOptions', $id);
$objExtraField = null;
switch ($extraField->getField()->getExtraFieldType()) {
case \Chamilo\CoreBundle\Entity\ExtraField::USER_FIELD_TYPE:
$objExtraField = new self('user');
break;
case \Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE:
$objExtraField = new self('course');
break;
case \Chamilo\CoreBundle\Entity\ExtraField::SESSION_FIELD_TYPE:
$objExtraField = new self('session');
break;
}
if (!$objExtraField) {
return [];
}
return $objExtraField->get($extraField->getId(), $translateDisplayText);
}
}

@ -2,7 +2,9 @@
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\ChamiloCoreBundle;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Language
@ -57,12 +59,25 @@ class Language
private $available;
/**
* @var integer
*
* @ORM\Column(name="parent_id", type="integer", nullable=true)
* @var \Chamilo\CoreBundle\Entity\Language
* @ORM\ManyToOne(targetEntity="Language", inversedBy="subLanguages")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true)
*/
private $parent;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="Language", mappedBy="parent")
*/
private $parentId;
private $subLanguages;
/**
* Language constructor
*/
public function __construct()
{
$this->children = new ArrayCollection();
}
/**
* Set originalName
@ -180,26 +195,36 @@ class Language
}
/**
* Set parentId
* Set parent
*
* @param boolean $parentId
* @param Language $parent
* @return Language
*/
public function setParentId($parentId)
public function setParent(Language $parent)
{
$this->parentId = $parentId;
$this->parent = $parent;
return $this;
}
/**
* Get parentId
* Get parent
*
* @return boolean
* @return Language
*/
public function getParent()
{
return $this->parent;
}
/**
* Get subLanguages
*
* @return ArrayCollection
*/
public function getParentId()
public function getSubLanguages()
{
return $this->parentId;
return $this->subLanguages;
}
/**

Loading…
Cancel
Save