diff --git a/main/inc/ajax/skill.ajax.php b/main/inc/ajax/skill.ajax.php index c6f0b925ed..422f3a8296 100755 --- a/main/inc/ajax/skill.ajax.php +++ b/main/inc/ajax/skill.ajax.php @@ -138,6 +138,7 @@ switch ($action) { echo $html; break; case 'get_skills_tree_json': + header('Content-Type: application/json'); $userId = isset($_REQUEST['load_user']) && $_REQUEST['load_user'] == 1 ? api_get_user_id() : 0; $skill_id = isset($_REQUEST['skill_id']) ? intval($_REQUEST['skill_id']) : 0; $depth = isset($_REQUEST['main_depth']) ? intval($_REQUEST['main_depth']) : 2; diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php index 3c13640f80..125da41ccb 100755 --- a/main/inc/lib/skill.lib.php +++ b/main/inc/lib/skill.lib.php @@ -619,8 +619,8 @@ class Skill extends Model { $result = parent::get($id); $result['web_icon_path'] = api_get_path(WEB_UPLOAD_PATH).'badges/'.$result['icon']; - $result['name'] = self::translate($result['name']); - $result['short_code'] = self::translate($result['short_code']); + $result['name'] = self::translateName($result['name']); + $result['short_code'] = self::translateCode($result['short_code']); return $result; } @@ -664,8 +664,8 @@ class Skill extends Model "badges/%s-small.png", sha1($skill['name']) ); - $skill['name'] = self::translate($skill['name']); - $skill['short_code'] = self::translate($skill['short_code']); + $skill['name'] = self::translateName($skill['name']); + $skill['short_code'] = self::translateCode($skill['short_code']); } return $skills; @@ -718,8 +718,8 @@ class Skill extends Model $webPath = api_get_path(WEB_UPLOAD_PATH); if (Database::num_rows($result)) { while ($row = Database::fetch_array($result, 'ASSOC')) { - $row['name'] = self::translate($row['name']); - $row['short_code'] = self::translate($row['short_code']); + $row['name'] = self::translateName($row['name']); + $row['short_code'] = self::translateCode($row['short_code']); $skill_rel_skill = new SkillRelSkill(); $parents = $skill_rel_skill->get_skill_parents($row['id']); $row['level'] = count($parents) - 1; @@ -1015,7 +1015,7 @@ class Skill extends Model sha1($skill['name']) ); } - $skill['name'] = self::translate($skill['name']); + $skill['name'] = self::translateName($skill['name']); $clean_skill[$skill['id']] = array_merge( $skill, array( @@ -1506,7 +1506,7 @@ class Skill extends Model $result = Database::query($sql); while ($row = Database::fetch_assoc($result)) { - $row['skill_name'] = self::translate($row['skill_name']); + $row['skill_name'] = self::translateName($row['skill_name']); $list[] = $row; } @@ -1551,7 +1551,7 @@ class Skill extends Model $result = Database::query($sql); while ($row = Database::fetch_assoc($result)) { - $row['skill_name'] = self::translate($row['skill_name']); + $row['skill_name'] = self::translateName($row['skill_name']); $list[] = $row; } @@ -1740,7 +1740,7 @@ class Skill extends Model foreach ($result as $item) { $skills[] = [ - 'name' => self::translate($item['name']), + 'name' => self::translateName($item['name']), 'acquired_skill_at' => $item['acquired_skill_at'] ]; } @@ -1752,7 +1752,7 @@ class Skill extends Model * @param string $name * @return string */ - public static function translate($name) + public static function translateName($name) { $camelCase = 'Skill'.api_underscore_to_camel_case( str_replace(' ', '_', $name) @@ -1760,4 +1760,17 @@ class Skill extends Model return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $name; } + + public static function translateCode($code) + { + if (empty($code)) { + return ''; + } + + $camelCase = 'SkillCode'.api_underscore_to_camel_case( + str_replace(' ', '_', $code) + ); + + return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : ''; + } } diff --git a/main/social/my_skills_report.php b/main/social/my_skills_report.php index e114d3585f..7328777246 100644 --- a/main/social/my_skills_report.php +++ b/main/social/my_skills_report.php @@ -50,7 +50,7 @@ if ($isStudent) { $result = Database::query($sql); while ($resultData = Database::fetch_assoc($result)) { $tableRow = array( - 'skillName' => Skill::translate($resultData['name']), + 'skillName' => Skill::translateName($resultData['name']), 'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER), 'courseImage' => Display::return_icon( 'course.png', @@ -104,7 +104,7 @@ if ($isStudent) { while ($resultData = Database::fetch_assoc($result)) { $tableRow = array( 'completeName' => $followedStudents[$selectedStudent]['completeName'], - 'skillName' => Skill::translate($resultData['name']), + 'skillName' => Skill::translateName($resultData['name']), 'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER), 'courseImage' => Display::return_icon( 'course.png', diff --git a/src/Chamilo/CoreBundle/Entity/Skill.php b/src/Chamilo/CoreBundle/Entity/Skill.php index 9d3997cddd..329efe47c6 100644 --- a/src/Chamilo/CoreBundle/Entity/Skill.php +++ b/src/Chamilo/CoreBundle/Entity/Skill.php @@ -155,7 +155,7 @@ class Skill */ public function getShortCode($translated = true) { - if ($translated) { + if ($translated && !empty($this->shortCode)) { $camelCase = 'SkillCode'.api_underscore_to_camel_case( str_replace(' ', '_', $this->shortCode) );