diff --git a/main/admin/skill_badge_create.php b/main/admin/skill_badge_create.php index 0252eb5990..b15442d7f9 100644 --- a/main/admin/skill_badge_create.php +++ b/main/admin/skill_badge_create.php @@ -45,13 +45,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($existsBadgesDirectory) { - /*if (!empty($skill['icon'])) { + if (!empty($skill['icon'])) { $iconFileAbsolutePath = $badgePath . $skill['icon']; if (Security::check_abs_path($iconFileAbsolutePath, $badgePath)) { unlink($badgePath . $skill['icon']); } - }*/ + } $skillImagePath = sprintf("%s%s.png", $badgePath, $fileName); diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php index 2638fa0fbc..86afea0266 100755 --- a/main/inc/lib/skill.lib.php +++ b/main/inc/lib/skill.lib.php @@ -534,6 +534,20 @@ class Skill extends Model $this->sessionTable = Database::get_main_table(TABLE_MAIN_SESSION); } + /** + * Gets an element + * @param int $id + * + * @return array|mixed + */ + public function get($id) + { + $result = parent::get($id); + $result['web_icon_path'] = api_get_path(WEB_UPLOAD_PATH).'badges/'.$result['icon']; + + return $result; + } + /** * @param int $id * @return array @@ -589,7 +603,14 @@ class Skill extends Model } } - $sql = "SELECT s.id, s.name, s.description, ss.parent_id, ss.relation_type, s.icon, s.short_code + $sql = "SELECT + s.id, + s.name, + s.description, + ss.parent_id, + ss.relation_type, + s.icon, + s.short_code FROM {$this->table} s INNER JOIN {$this->table_skill_rel_skill} ss ON (s.id = ss.skill_id) $id_condition @@ -597,18 +618,19 @@ class Skill extends Model $result = Database::query($sql); $skills = array(); - + $webPath = api_get_path(WEB_UPLOAD_PATH); if (Database::num_rows($result)) { while ($row = Database::fetch_array($result, 'ASSOC')) { - $skill_rel_skill = new SkillRelSkill(); - $a = $skill_rel_skill->get_skill_parents($row['id']); - $row['level'] = count($a) - 1; - $row['gradebooks'] = self::get_gradebooks_by_skill($row['id']); + $skill_rel_skill = new SkillRelSkill(); + $parents = $skill_rel_skill->get_skill_parents($row['id']); + $row['level'] = count($parents) - 1; + $row['gradebooks'] = self::get_gradebooks_by_skill($row['id']); + $row['web_icon_path'] = $webPath.'badges/'.$row['icon']; $skills[$row['id']] = $row; } } - //Load all children of the parent_id + // Load all children of the parent_id if (!empty($skills) && !empty($parent_id)) { foreach ($skills as $skill) { $children = self::get_all($load_user_data, $user_id, $id, $skill['id']); @@ -848,6 +870,7 @@ class Skill extends Model * Get user's skills * * @param int $userId User's id + * @param bool $get_skill_data */ public function get_user_skills($user_id, $get_skill_data = false) { @@ -860,23 +883,30 @@ class Skill extends Model $result = Database::query($sql); $skills = Database::store_result($result, 'ASSOC'); - + $uploadPath = api_get_path(WEB_UPLOAD_PATH); $clean_skill = array(); if (!empty($skills)) { foreach ($skills as $skill) { if ($get_skill_data) { $iconThumb = null; + $iconPath = null; if (!empty($skill['icon'])) { $iconThumb = sprintf( "badges/%s-small.png", sha1($skill['name']) ); + + $iconPath = sprintf( + "badges/%s.png", + sha1($skill['name']) + ); } $clean_skill[$skill['id']] = array_merge( $skill, array( - 'iconThumb' => $iconThumb + 'web_icon_thumb_path' => $uploadPath.$iconThumb, + 'web_icon_path' => $uploadPath.$iconPath ) ); } else { @@ -884,6 +914,7 @@ class Skill extends Model } } } + return $clean_skill; } diff --git a/main/social/home.php b/main/social/home.php index 47913e4d11..717b53c52e 100755 --- a/main/social/home.php +++ b/main/social/home.php @@ -11,7 +11,6 @@ $cidReset = true; require_once '../inc/global.inc.php'; -require_once api_get_path(LIBRARY_PATH) . 'skill.lib.php'; $user_id = api_get_user_id(); $show_full_profile = true; @@ -25,7 +24,6 @@ if (api_get_setting('allow_social_tool') != 'true') { $url = api_get_path(WEB_CODE_PATH) . 'auth/profile.php'; header('Location: ' . $url); exit; - api_not_allowed(); } //fast upload image @@ -98,8 +96,6 @@ if (api_get_setting('allow_skills_tool') == 'true') { $ranking = $skill->get_user_skill_ranking(api_get_user_id()); $skills = $skill->get_user_skills(api_get_user_id(), true); - //$social_skill_block = '