From 8b099b4f73fc74db7d5a2a461e17ed8cdfbc91d4 Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 14 Oct 2015 16:57:13 +0200 Subject: [PATCH 1/6] Fix course document import see #7886 --- .../classes/CourseRestorer.class.php | 85 +++---------------- 1 file changed, 12 insertions(+), 73 deletions(-) diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index 3a11f662c5..76f1fd0c07 100755 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -384,13 +384,13 @@ class CourseRestorer } elseif ($document->file_type == DOCUMENT) { //Checking if folder exists in the database otherwise we created it $dir_to_create = dirname($document->path); + if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') { if (is_dir($path.dirname($document->path))) { $sql = "SELECT id FROM $table WHERE c_id = ".$this->destination_course_id." AND path = '/".self::DBUTF8escapestring(substr(dirname($document->path), 9))."'"; - $res = Database::query($sql); if (Database::num_rows($res) == 0) { //continue; @@ -437,11 +437,13 @@ class CourseRestorer WHERE c_id = ".$this->destination_course_id." AND path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'"; + $res = Database::query($sql); $count = Database::num_rows($res); + if ($count == 0) { $params = [ - 'path' => self::DBUTF8("/".substr($document->path, 9)), + 'path' => "/".self::DBUTF8(substr($document->path, 9)), 'c_id' => $this->destination_course_id, 'comment'=> self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), @@ -449,15 +451,16 @@ class CourseRestorer 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id ]; - $document_id = Database::insert($table, $params); + error_log('1'); + error_log(print_r($params, 1)); + $document_id = Database::insert($table, $params, true); if ($document_id) { $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; Database::query($sql); } - - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; + api_item_property_update( $course_info, TOOL_DOCUMENT, @@ -473,20 +476,8 @@ class CourseRestorer } else { $obj = Database::fetch_object($res); $document_id = $obj->id; - /*$sql = "UPDATE ".$table." SET - path = '/".self::DBUTF8escapestring(substr($document->path, 9))."', - c_id = ".$this->destination_course_id.", - comment = '".self::DBUTF8escapestring($document->comment)."', - title = '".self::DBUTF8escapestring($document->title)."' , - filetype ='".$document->file_type."', - size = '".$document->size."', - session_id = '$my_session_id' - WHERE - c_id = ".$this->destination_course_id." AND - path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'";*/ - $params = [ - 'path' => self::DBUTF8("/".substr($document->path, 9)), + 'path' => "/".self::DBUTF8(substr($document->path, 9)), 'c_id' => $this->destination_course_id, 'comment'=> self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), @@ -494,7 +485,8 @@ class CourseRestorer 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id ]; - + error_log('2'); + error_log(print_r($params, 1)); Database::update( $table, $params, @@ -538,15 +530,6 @@ class CourseRestorer file_put_contents($path.$document->path,$content); } - /*$sql = "UPDATE $table SET - comment = '".self::DBUTF8escapestring($document->comment)."', - title='".self::DBUTF8escapestring($document->title)."', - size='".$document->size."' - WHERE - c_id = ".$this->destination_course_id." AND - id = '".$document_id."'"; - Database::query($sql);*/ - $params = [ 'comment'=> self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), @@ -635,7 +618,6 @@ class CourseRestorer $dest_document_path = $new_base_path.'/'.$document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" - //$dest_filename = basename($dest_document_path); // e.g: "collaborative.png" $base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" $path_title = '/'.$new_base_foldername.'/'.$document_path[2]; @@ -672,15 +654,6 @@ class CourseRestorer } } - /*$sql = "INSERT INTO $table SET - path = '$path_title', - c_id = ".$this->destination_course_id.", - comment = '".self::DBUTF8escapestring($document->comment)."', - title = '".self::DBUTF8escapestring(basename($path_title))."' , - filetype ='".$document->file_type."', - size = '".$document->size."', - session_id = '$my_session_id'";*/ - $params = [ 'path' => self::DBUTF8($path_title), 'c_id' => $this->destination_course_id, @@ -737,17 +710,6 @@ class CourseRestorer } } - /*$sql = "INSERT INTO ".$table." SET - c_id = ".$this->destination_course_id.", - path = '/".self::DBUTF8escapestring(substr($new_file_name, 9))."', - comment = '".self::DBUTF8escapestring($document->comment)."', - title = '".self::DBUTF8escapestring($document->title)."' , - filetype ='".$document->file_type."', - size = '".$document->size."', - session_id = '$my_session_id'"; - Database::query($sql); - $document_id = Database::insert_id();*/ - $params = [ 'path' => "/".self::DBUTF8escapestring(substr($new_file_name, 9)), 'c_id' => $this->destination_course_id, @@ -804,18 +766,6 @@ class CourseRestorer } } - /*$sql = "INSERT INTO ".$table." SET - c_id = ".$this->destination_course_id.", - path = '/".self::DBUTF8escapestring(substr($new_file_name, 9))."', - comment = '".self::DBUTF8escapestring($document->comment)."', - title = '".self::DBUTF8escapestring($document->title)."' , - filetype ='".$document->file_type."', - size = '".$document->size."', - session_id = '$my_session_id'"; - Database::query($sql); - - $document_id = Database::insert_id();*/ - $params = [ 'c_id' => $this->destination_course_id, 'path' => "/".self::DBUTF8escapestring(substr($new_file_name, 9)), @@ -880,20 +830,9 @@ class CourseRestorer } } - /*$sql = "INSERT INTO ".$table." SET - c_id = ".$this->destination_course_id.", - path = '/".substr($document->path, 9)."', - comment = '".self::DBUTF8escapestring($document->comment)."', - title = '".self::DBUTF8escapestring($document->title)."' , - filetype='".$document->file_type."', - size= '".$document->size."', - session_id = '$my_session_id'"; - Database::query($sql); - $document_id = Database::insert_id();*/ - $params = [ 'c_id' => $this->destination_course_id, - 'path' => "/".self::DBUTF8("/".substr($document->path, 9)), + 'path' => "/".self::DBUTF8(substr($document->path, 9)), 'comment'=> self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), From 3aeead0ef40be8ef3903c7f9af471cb84ace5b8b Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 14 Oct 2015 17:03:15 +0200 Subject: [PATCH 2/6] Fix queries + adding intval see #7886 --- main/exercice/TestCategory.php | 35 +++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/main/exercice/TestCategory.php b/main/exercice/TestCategory.php index 4de5d6c207..7b45b05f0f 100644 --- a/main/exercice/TestCategory.php +++ b/main/exercice/TestCategory.php @@ -648,14 +648,16 @@ class TestCategory * * @return int is id of test category */ - public static function get_category_id_for_title($in_title, $in_c_id = 0) + public static function get_category_id_for_title($title, $courseId = 0) { $out_res = 0; - if ($in_c_id == 0) { - $in_c_id = api_get_course_int_id(); + if (empty($courseId)) { + $courseId = api_get_course_int_id(); } + $courseId = intval($courseId); $tbl_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); - $sql = "SELECT id FROM $tbl_cat WHERE c_id=$in_c_id AND title = '".Database::escape_string($in_title)."'"; + $sql = "SELECT id FROM $tbl_cat + WHERE c_id = $courseId AND title = '".Database::escape_string($title)."'"; $res = Database::query($sql); if (Database::num_rows($res) > 0) { $data = Database::fetch_array($res); @@ -666,23 +668,30 @@ class TestCategory /** * Add a relation between question and category in table c_quiz_question_rel_category - * @param int $in_category_id - * @param int $in_question_id - * @param int $in_course_c_id + * @param int $categoryId + * @param int $questionId + * @param int $courseId + * + * @return int */ - public static function add_category_for_question_id($in_category_id, $in_question_id, $in_course_c_id) + public static function add_category_for_question_id($categoryId, $questionId, $courseId) { $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); // if question doesn't have a category // @todo change for 1.10 when a question can have several categories - if (TestCategory::getCategoryForQuestion($in_question_id, $in_course_c_id) == 0 && - $in_question_id > 0 && - $in_course_c_id > 0 + if (TestCategory::getCategoryForQuestion($questionId, $courseId) == 0 && + $questionId > 0 && + $courseId > 0 ) { - $sql = "INSERT INTO $table - VALUES (".intval($in_course_c_id).", ".intval($in_question_id).", ".intval($in_category_id).")"; + $sql = "INSERT INTO $table (c_id, question_id, category_id) + VALUES (".intval($courseId).", ".intval($questionId).", ".intval($categoryId).")"; Database::query($sql); + $id = Database::insert_id(); + + return $id; } + + return false; } /** From df4ae7f9706d85f5c3b939aa1c657c3df4502c60 Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 14 Oct 2015 17:05:52 +0200 Subject: [PATCH 3/6] Minor - format code. --- .../classes/CourseRestorer.class.php | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index 76f1fd0c07..2020993175 100755 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -303,7 +303,6 @@ class CourseRestorer $course_info = api_get_course_info($destination_course_code); if ($this->course->has_resources(RESOURCE_DOCUMENT)) { - $table = Database :: get_course_table(TABLE_DOCUMENT); $resources = $this->course->resources; $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; @@ -319,12 +318,6 @@ class CourseRestorer if ($document->file_type == FOLDER) { $visibility = $document->item_properties[0]['visibility']; - /*if (!empty($document->title)) { - $title = $document->title; - } else { - $title = basename($document->path); - }*/ - $new = substr($document->path, 8); $folderList = explode('/', $new); @@ -451,8 +444,7 @@ class CourseRestorer 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id ]; - error_log('1'); - error_log(print_r($params, 1)); + $document_id = Database::insert($table, $params, true); if ($document_id) { @@ -485,8 +477,7 @@ class CourseRestorer 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id ]; - error_log('2'); - error_log(print_r($params, 1)); + Database::update( $table, $params, @@ -740,8 +731,6 @@ class CourseRestorer $my_session_id ); } - - } } else { @@ -1996,8 +1985,7 @@ class CourseRestorer $course_id = api_get_course_int_id(); // Let's restore the categories $tab_test_category_id_old_new = array(); // used to build the quiz_question_rel_category table - if ($this->course->has_resources(RESOURCE_TEST_CATEGORY)) - { + if ($this->course->has_resources(RESOURCE_TEST_CATEGORY)) { $resources = $this->course->resources; foreach ($resources[RESOURCE_TEST_CATEGORY] as $id => $CourseCopyTestcategory ) { $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $id; @@ -2235,7 +2223,6 @@ class CourseRestorer } } } - } } } @@ -2318,7 +2305,8 @@ class CourseRestorer ]; $answerId = Database::insert($table_ans, $params); if ($answerId) { - $sql = "UPDATE $table_ans SET question_option_id = iid WHERE iid = $answerId"; + $sql = "UPDATE $table_ans SET question_option_id = iid + WHERE iid = $answerId"; Database::query($sql); } } @@ -2488,8 +2476,9 @@ class CourseRestorer // we set the ref code here and then we update in a for loop $ref = $item['ref']; - //Dealing with path the same way as ref as some data has been put into path when it's a local resource - //Only fix the path for no scos + // Dealing with path the same way as ref as some data has + // been put into path when it's a local resource + // Only fix the path for no scos if ($item['item_type'] == 'sco') { $path = $item['path']; } else { @@ -2623,7 +2612,7 @@ class CourseRestorer { $sessionId = intval($sessionId); $work_assignment_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); - $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); + $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); $item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); // Query in student publication From bd77833702505b68f5846caa43f352807e05552b Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 14 Oct 2015 10:23:31 -0500 Subject: [PATCH 4/6] Fix redirect on Badge Criteria page - refs #7881 --- main/badge/criteria.php | 1 + 1 file changed, 1 insertion(+) diff --git a/main/badge/criteria.php b/main/badge/criteria.php index cb87b01985..0c75af30c4 100644 --- a/main/badge/criteria.php +++ b/main/badge/criteria.php @@ -16,6 +16,7 @@ if (!$skill) { ); header('Location: ' . api_get_path(WEB_PATH)); + exit; } $skillInfo = [ From bae16d483614a31da755a1a46859aadf10a2c5ee Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 14 Oct 2015 10:35:42 -0500 Subject: [PATCH 5/6] Fix closing EM tags --- main/admin/course_list.php | 2 +- main/install/install.lib.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/admin/course_list.php b/main/admin/course_list.php index e16f23ddc9..d2651a3889 100755 --- a/main/admin/course_list.php +++ b/main/admin/course_list.php @@ -368,7 +368,7 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') { $form = new FormValidator('search_simple', 'get', '', '', array(), FormValidator::LAYOUT_INLINE); $form->addElement('text', 'keyword', null, array('id' => 'course-search-keyword')); $form->addButtonSearch(get_lang('SearchCourse')); - $advanced = ' '.get_lang('AdvancedSearch').''; + $advanced = ' '.get_lang('AdvancedSearch').''; // Create a filter by session $sessionFilter = new FormValidator('course_filter', 'get', '', '', array(), FormValidator::LAYOUT_INLINE); diff --git a/main/install/install.lib.php b/main/install/install.lib.php index edf5e4a6e8..c6e1fa9763 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -1242,7 +1242,7 @@ function get_contact_registration_form()
 
-
+
 
From 71a8b34000e7a254a6ac0f7a6da30495a2164ecc Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 14 Oct 2015 10:41:05 -0500 Subject: [PATCH 6/6] Add page for Issued Badge Information - refs #7881 --- main/badge/issued.php | 120 ++++++++++++++++++ main/inc/lib/social.lib.php | 1 + main/template/default/skill/issued.tpl | 53 ++++++++ main/template/default/social/skills_block.tpl | 2 +- 4 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 main/badge/issued.php create mode 100644 main/template/default/skill/issued.tpl diff --git a/main/badge/issued.php b/main/badge/issued.php new file mode 100644 index 0000000000..ad34b6d97f --- /dev/null +++ b/main/badge/issued.php @@ -0,0 +1,120 @@ + + * @package chamilo.badge + */ +require_once '../inc/global.inc.php'; + +$userId = isset($_GET['user']) ? intval($_GET['user']) : 0; +$skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0; + +if (!isset($_GET['user'], $_GET['skill'])) { + header('Location: ' . api_get_path(WEB_PATH)); + exit; +} + +$entityManager = Database::getManager(); +$user = $entityManager->find('ChamiloUserBundle:User', $_GET['user']); +$skill = $entityManager->find('ChamiloCoreBundle:Skill', $_GET['skill']); + +if (!$user || !$skill) { + Display::addFlash( + Display::return_message(get_lang('NoResults'), 'error') + ); + + header('Location: ' . api_get_path(WEB_PATH)); + exit; +} + +$skillUserRepo = $entityManager->getRepository('ChamiloCoreBundle:SkillRelUser'); +$userSkills = $skillUserRepo->findBy([ + 'userId' => $user->getId(), + 'skillId' => $skill->getId() +]); + +if (!$userSkills) { + Display::addFlash( + Display::return_message(get_lang('TheUserXNotYetAchievedTheSkillX'), 'error') + ); + + header('Location: ' . api_get_path(WEB_PATH)); + exit; +} + +$userInfo = [ + 'id' => $user->getId(), + 'complete_name' => $user->getCompleteName() +]; + +$skillInfo = [ + 'id' => $skill->getId(), + 'name' => $skill->getName(), + 'short_code' => $skill->getShortCode(), + 'description' => $skill->getDescription(), + 'criteria' => $skill->getCriteria(), + 'badge_image' => $skill->getWebIconPath(), + 'courses' => [] +]; + +$badgeAssertions = []; + +foreach ($userSkills as $userSkill) { + $sessionId = 0; + $course = $entityManager->find('ChamiloCoreBundle:Course', $userSkill->getCourseId()); + $courseName = $course->getTitle(); + + if ($userSkill->getSessionId()) { + $session = $entityManager->find('ChamiloCoreBundle:Session', $userSkill->getSessionId()); + $sessionId = $session->getId(); + $courseName = "[{$session->getName()}] {$course->getTitle()}"; + } + + $userSkillDate = api_get_local_time($userSkill->getAcquiredSkillAt()); + $skillInfo['courses'][] = [ + 'name' => $courseName, + 'date_issued' => api_format_date($userSkillDate, DATE_TIME_FORMAT_LONG) + ]; + + $assertionUrl = api_get_path(WEB_CODE_PATH) . "badge/assertion.php?"; + $assertionUrl .= http_build_query(array( + 'user' => $user->getId(), + 'skill' => $skill->getId(), + 'course' => $userSkill->getCourseId(), + 'session' => $userSkill->getSessionId() + )); + + $badgeAssertions[] = $assertionUrl; +} + +$allowExport = api_get_user_id() == $user->getId(); + +if ($allowExport) { + $backpack = 'https://backpack.openbadges.org/'; + + $configBackpack = api_get_setting('openbadges_backpack'); + + if (strcmp($backpack, $configBackpack) !== 0) { + $backpack = $configBackpack; + } + + $htmlHeadXtra[] = ''; +} + +$template = new Template(''); +$template->assign('skill_info', $skillInfo); +$template->assign('user_info', $userInfo); +$template->assign('allow_export', $allowExport); + +if ($allowExport) { + $template->assign('assertions', $badgeAssertions); +} + +$content = $template->fetch( + $template->get_template('skill/issued.tpl') +); + +$template->assign('header', get_lang('IssuedBadgeInformation')); +$template->assign('content', $content); +$template->display_one_col_template(); diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 37fa2b2c49..1f98d8e0fc 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -1885,6 +1885,7 @@ class SocialManager extends UserManager $template = new Template(null, false, false, false, false, false); $template->assign('ranking', $ranking); $template->assign('skills', $skills); + $template->assign('user_id', $userId); $template->assign( 'show_skills_report_link', api_is_student() || api_is_student_boss() || api_is_drh() diff --git a/main/template/default/skill/issued.tpl b/main/template/default/skill/issued.tpl new file mode 100644 index 0000000000..4bb0d31bad --- /dev/null +++ b/main/template/default/skill/issued.tpl @@ -0,0 +1,53 @@ +
+
+
+ {{ skill_info.name }} +
+

{{ skill_info.name }}

+
+
+

{{ 'SkillAcquiredAt'|get_lang }}

+
    + {% for course in skill_info.courses %} +
  • +

    + {{ 'TimeXThroughCourseY'|get_lang|format(course.date_issued, course.name) }} +

    +
  • + {% endfor %} +
+ {% if allow_export %} +

+ + {{ 'ExportBadge'|get_lang }} + +

+ {% endif %} +
+
+

{{ 'RecipientDetails'|get_lang }}

+

{{ user_info.complete_name }}

+

{{ 'BadgeDetails'|get_lang }}

+

{{ 'Name'|get_lang }}

+

{{ skill_info.name }}

+ {% if skill_info.short_code %} +

{{ 'ShortCode'|get_lang }}

+

{{ skill_info.short_code }}

+ {% endif %} +

{{ 'Description'|get_lang }}

+

{{ skill_info.description }}

+

{{ 'CriteriaToEarnTheBadge'|get_lang }}

+

{{ skill_info.criteria }}

+
+
+{% if allow_export %} + +{% endif %} diff --git a/main/template/default/social/skills_block.tpl b/main/template/default/social/skills_block.tpl index 8dabe94e6a..09741d097d 100644 --- a/main/template/default/social/skills_block.tpl +++ b/main/template/default/social/skills_block.tpl @@ -32,7 +32,7 @@