From ade6b5c7106d45d10935ab77c25bee8ae3ba07c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Thu, 13 Oct 2016 18:25:14 -0500 Subject: [PATCH 01/17] Fix update user picture that fails if you set it for the first time --- main/inc/lib/usermanager.lib.php | 74 +++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index ef80a8560f..24a15af5a7 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -1531,6 +1531,73 @@ class UserManager ); } + /** + * *** READ BEFORE REVIEW THIS FUNCTION *** + * This function is a exact copy from get_user_picture_path_by_id() and it was create it to avoid + * a recursive calls for get_user_picture_path_by_id() in another functions when you update a user picture + * in same script, so you can find this function usage in update_user_picture() function. + * + * @param integer $id User ID + * @param string $type Type of path to return (can be 'system', 'web') + * @param array $userInfo user information to avoid query the DB + * returns the /main/img/unknown.jpg image set it at true + * + * @return array Array of 2 elements: 'dir' and 'file' which contain + * the dir and file as the name implies if image does not exist it will + * return the unknow image if anonymous parameter is true if not it returns an empty array + */ + public static function getUserPicturePathById($id, $type = 'web', $userInfo = []) + { + switch ($type) { + case 'system': // Base: absolute system path. + $base = api_get_path(SYS_CODE_PATH); + break; + case 'web': // Base: absolute web path. + default: + $base = api_get_path(WEB_CODE_PATH); + break; + } + + $anonymousPath = array( + 'dir' => $base.'img/', + 'file' => 'unknown.jpg', + 'email' => '' + ); + + if (empty($id) || empty($type)) { + return $anonymousPath; + } + + $id = intval($id); + + if (empty($userInfo)) { + $user_table = Database:: get_main_table(TABLE_MAIN_USER); + $sql = "SELECT email, picture_uri FROM $user_table WHERE id=$id"; + $res = Database::query($sql); + + if (!Database::num_rows($res)) { + return $anonymousPath; + } + $user = Database::fetch_array($res); + + if (empty($user['picture_uri'])) { + return $anonymousPath; + } + } else { + $user = $userInfo; + } + + $pictureFilename = trim($user['picture_uri']); + + $dir = self::getUserPathById($id, $type); + + return array( + 'dir' => $dir, + 'file' => $pictureFilename, + 'email' => $user['email'] + ); + } + /** * Get user path from user ID (returns an array). * The return format is a complete path to a folder ending with "/" @@ -1704,7 +1771,7 @@ class UserManager } // User-reserved directory where photos have to be placed. - $path_info = self::get_user_picture_path_by_id($user_id, 'system'); + $path_info = self::getUserPicturePathById($user_id, 'system'); $path = $path_info['dir']; // If this directory does not exist - we create it. @@ -1767,6 +1834,11 @@ class UserManager // Storing the new photos in 4 versions with various sizes. $userPath = self::getUserPathById($user_id, 'system'); + + // If this path does not exist - we create it. + if (!file_exists($userPath)) { + mkdir($userPath, api_get_permissions_for_new_directories(), true); + } $small = new Image($source_file); $small->resize(32); $small->send_image($userPath.'small_'.$filename); From ed461971360b4d0cf7017bfa1564457f811c269a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Thu, 13 Oct 2016 19:34:00 -0500 Subject: [PATCH 02/17] Change quotes to double quotes in hrefs to avoid language parser error when you share a badge --- main/template/default/skill/issued.tpl | 4 ++-- main/template/default/skill/issued_all.tpl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/main/template/default/skill/issued.tpl b/main/template/default/skill/issued.tpl index 8c5c95a0ee..7071ca6a5e 100644 --- a/main/template/default/skill/issued.tpl +++ b/main/template/default/skill/issued.tpl @@ -39,10 +39,10 @@

{{ 'ShareWithYourFriends' | get_lang }}
- + - +
diff --git a/main/template/default/skill/issued_all.tpl b/main/template/default/skill/issued_all.tpl index a258133aa7..4b906839e2 100644 --- a/main/template/default/skill/issued_all.tpl +++ b/main/template/default/skill/issued_all.tpl @@ -40,10 +40,10 @@

{{ 'ShareWithYourFriends' | get_lang }}
- + - +
From aad0efb57907eacdcc2f49d2197689bc6482eb90 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 08:54:36 +0200 Subject: [PATCH 03/17] Reset question number. --- main/exercise/exercise_submit.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main/exercise/exercise_submit.php b/main/exercise/exercise_submit.php index a5bd54b4a4..bc5acdc9c5 100755 --- a/main/exercise/exercise_submit.php +++ b/main/exercise/exercise_submit.php @@ -489,6 +489,10 @@ if (!empty($questionList)) { $question_count = count($questionList); } +if ($current_question > $question_count) { + $current_question = 0; +} + if ($formSent && isset($_POST)) { if ($debug) { error_log('9. $formSent was set'); } @@ -528,7 +532,7 @@ if ($formSent && isset($_POST)) { //saving each question if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) { $nro_question = $current_question; // - 1; - $questionId = $key; + $questionId = $key; // gets the student choice for this question $choice = $exerciseResult[$questionId]; if (isset($exe_id)) { From 2b5621a0c2c4f676962a95d587b8ddb9c3281d9b Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 09:03:25 +0200 Subject: [PATCH 04/17] Just check track_exercise record to see if user already enter an exercise. --- main/exercise/overview.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/main/exercise/overview.php b/main/exercise/overview.php index 7599caa3e6..95c0dbb87d 100755 --- a/main/exercise/overview.php +++ b/main/exercise/overview.php @@ -1,7 +1,7 @@ expired_time != 0 && !empty($clock_expired_time)) { if ($time_control) { // Get time left for expiring time - $time_left = api_strtotime($clock_expired_time,'UTC') - time(); - + $time_left = api_strtotime($clock_expired_time, 'UTC') - time(); $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css'); $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css'); $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js'); @@ -99,18 +98,18 @@ $exercise_stat_info = $objExercise->get_stat_track_exercise_info( 0 ); -$attempt_list = null; +/*$attempt_list = null; if (isset($exercise_stat_info['exe_id'])) { $attempt_list = Event::getAllExerciseEventByExeId($exercise_stat_info['exe_id']); -} +}*/ //1. Check if this is a new attempt or a previous $label = get_lang('StartTest'); -if ($time_control && !empty($clock_expired_time) || !empty($attempt_list)) { +if ($time_control && !empty($clock_expired_time) || isset($exercise_stat_info['exe_id'])) { $label = get_lang('ContinueTest'); } -if (!empty($attempt_list)) { +if (isset($exercise_stat_info['exe_id'])) { $message = Display::return_message(get_lang('YouTriedToResolveThisExerciseEarlier')); } @@ -177,7 +176,6 @@ if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANS if (!empty($attempts)) { $i = $counter; foreach ($attempts as $attempt_result) { - $score = ExerciseLib::show_score( $attempt_result['exe_result'], $attempt_result['exe_weighting'] From 54ef79d95b71cab995657cea9f922839a6ed5620 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 09:07:18 +0200 Subject: [PATCH 05/17] Minor - format code --- main/exercise/adminhp.php | 1 + main/exercise/exercise_admin.php | 5 +++-- main/exercise/exercise_submit.php | 4 ++-- main/exercise/hotspot_lang_conversion.php | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/main/exercise/adminhp.php b/main/exercise/adminhp.php index 559817ce86..464f8af3ec 100755 --- a/main/exercise/adminhp.php +++ b/main/exercise/adminhp.php @@ -1,5 +1,6 @@ Date: Fri, 14 Oct 2016 09:52:54 +0200 Subject: [PATCH 06/17] Replace default admin user (= 1) to first admin user. --- app/Migrations/Schema/V110/Version20150603181728.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Migrations/Schema/V110/Version20150603181728.php b/app/Migrations/Schema/V110/Version20150603181728.php index 8c44697e93..85a0d8ed47 100644 --- a/app/Migrations/Schema/V110/Version20150603181728.php +++ b/app/Migrations/Schema/V110/Version20150603181728.php @@ -60,8 +60,8 @@ class Version20150603181728 extends AbstractMigrationChamilo $this->addSql("DELETE FROM c_item_property WHERE to_user_id IS NOT NULL AND to_user_id <> 0 AND to_user_id NOT IN (SELECT id FROM user)"); // Sometimes the user was deleted but we need to keep the document. - // Assuming user.id = 1 (admin) - $this->addSql("UPDATE c_item_property SET insert_user_id = 1 WHERE insert_user_id IS NOT NULL AND insert_user_id <> 0 AND insert_user_id NOT IN (SELECT id FROM user)"); + // Taking first admin + $this->addSql("UPDATE c_item_property SET insert_user_id = (SELECT user_id FROM admin LIMIT 1) WHERE insert_user_id IS NOT NULL AND insert_user_id <> 0 AND insert_user_id NOT IN (SELECT id FROM user)"); // Remove inconsistencies about non-existing users $this->addSql("DELETE FROM c_item_property WHERE c_id NOT IN (SELECT id FROM course)"); From 174ba72b31d458c7e4bb6591eb024b56baca3a09 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 10:21:01 +0200 Subject: [PATCH 07/17] Set first real admin instead of admin=1 --- app/Migrations/Schema/V110/Version110.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Migrations/Schema/V110/Version110.php b/app/Migrations/Schema/V110/Version110.php index 57de74ed22..6820e31ddd 100644 --- a/app/Migrations/Schema/V110/Version110.php +++ b/app/Migrations/Schema/V110/Version110.php @@ -24,7 +24,7 @@ class Version110 extends AbstractMigrationChamilo $this->addSql("ALTER TABLE session_rel_course ENGINE=InnoDB"); $this->addSql("ALTER TABLE session_rel_course_rel_user ENGINE=InnoDB"); $this->addSql("ALTER TABLE session_rel_user ENGINE=InnoDB"); - $this->addSql("UPDATE session SET session.id_coach = 1 WHERE id_coach NOT IN ( SELECT user_id FROM user)"); + $this->addSql("UPDATE session SET session.id_coach = (SELECT user_id FROM admin LIMIT 1) WHERE id_coach NOT IN (SELECT user_id FROM user)"); } /** From 841df7793fc436159969791ca35a9ee25d6ba66e Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 10:55:41 +0200 Subject: [PATCH 08/17] Fix migrations --- app/Migrations/Schema/V110/Version110.php | 11 +++++++---- app/Migrations/Schema/V110/Version20150522112023.php | 8 +++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Migrations/Schema/V110/Version110.php b/app/Migrations/Schema/V110/Version110.php index 6820e31ddd..15edf18e81 100644 --- a/app/Migrations/Schema/V110/Version110.php +++ b/app/Migrations/Schema/V110/Version110.php @@ -276,10 +276,13 @@ class Version110 extends AbstractMigrationChamilo } if ($schema->hasTable('c_attendance_calendar_rel_group')) { - $this->addSql("ALTER TABLE c_attendance_calendar_rel_group MODIFY COLUMN id INT NOT NULL"); - $this->addSql("ALTER TABLE c_attendance_calendar_rel_group DROP PRIMARY KEY"); - $this->addSql("ALTER TABLE c_attendance_calendar_rel_group MODIFY COLUMN id INT NULL DEFAULT NULL"); - $this->addSql("ALTER TABLE c_attendance_calendar_rel_group ADD COLUMN iid int NOT NULL PRIMARY KEY AUTO_INCREMENT"); + $table = $schema->getTable('c_attendance_calendar_rel_group'); + if ($table->hasColumn('iid') === false) { + $this->addSql("ALTER TABLE c_attendance_calendar_rel_group MODIFY COLUMN id INT NOT NULL"); + $this->addSql("ALTER TABLE c_attendance_calendar_rel_group DROP PRIMARY KEY"); + $this->addSql("ALTER TABLE c_attendance_calendar_rel_group MODIFY COLUMN id INT NULL DEFAULT NULL"); + $this->addSql("ALTER TABLE c_attendance_calendar_rel_group ADD COLUMN iid int NOT NULL PRIMARY KEY AUTO_INCREMENT"); + } } $this->addSql("ALTER TABLE c_attendance_sheet MODIFY COLUMN c_id INT NOT NULL"); diff --git a/app/Migrations/Schema/V110/Version20150522112023.php b/app/Migrations/Schema/V110/Version20150522112023.php index 7325186fb1..c6ef04b7b8 100644 --- a/app/Migrations/Schema/V110/Version20150522112023.php +++ b/app/Migrations/Schema/V110/Version20150522112023.php @@ -21,7 +21,13 @@ class Version20150522112023 extends AbstractMigrationChamilo $this->addSql('ALTER TABLE usergroup ADD group_type INT NOT NULL, ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL'); $this->addSql('ALTER TABLE usergroup ADD picture VARCHAR(255) DEFAULT NULL, ADD url VARCHAR(255) DEFAULT NULL, ADD visibility VARCHAR(255) NOT NULL, ADD allow_members_leave_group INT NOT NULL, CHANGE description description LONGTEXT'); - $this->addSql('CREATE TABLE usergroup_rel_usergroup (id INT AUTO_INCREMENT NOT NULL, group_id INT NOT NULL, subgroup_id INT NOT NULL, relation_type INT NOT NULL, PRIMARY KEY(id))'); + + if (!$schema->hasTable('usergroup_rel_usergroup')) { + $this->addSql( + 'CREATE TABLE usergroup_rel_usergroup (id INT AUTO_INCREMENT NOT NULL, group_id INT NOT NULL, subgroup_id INT NOT NULL, relation_type INT NOT NULL, PRIMARY KEY(id))' + ); + } + $this->addSql('ALTER TABLE usergroup_rel_user ADD relation_type INT'); if (!$schema->hasTable('access_url_rel_usergroup')) { From 25ce879a212d7b08ae71509e0d2ceec757381b37 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 11:38:55 +0200 Subject: [PATCH 09/17] Fix extra field set visible See 0aecbbeaac87d2e9a5b02e74e477ed2f3ea0d8d0 --- main/install/install.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 756e3436a1..11fb5aadad 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -2558,7 +2558,7 @@ function fixIds(EntityManager $em) ->setDisplayText($field['field_display_text']) ->setDefaultValue($field['field_default_value']) ->setFieldOrder($field['field_order']) - ->setVisible($field['field_visible']) + ->setVisibleToSelf($field['field_visible']) ->setChangeable($field['field_changeable']) ->setFilter($field['field_filter']); From d65675916899cf8b5cc2806979997c85ad7209ec Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 11:41:04 +0200 Subject: [PATCH 10/17] Fix hotspot migration , add c_id, skip if image doesnt exists --- .../Schema/V110/Version20151214170800.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Migrations/Schema/V110/Version20151214170800.php b/app/Migrations/Schema/V110/Version20151214170800.php index 4ec3e2effc..0d999249a0 100644 --- a/app/Migrations/Schema/V110/Version20151214170800.php +++ b/app/Migrations/Schema/V110/Version20151214170800.php @@ -31,15 +31,19 @@ class Version20151214170800 extends AbstractMigrationChamilo SELECT a.iid, a.c_id, a.question_id, a.hotspot_coordinates, a.hotspot_type, q.picture, c.directory FROM c_quiz_answer a INNER JOIN c_quiz_question q - ON a.question_id = q.id + ON (a.question_id = q.id AND a.c_id = q.c_id) INNER JOIN course c - ON (a.c_id = c.id AND q.c_id = c.id) + ON (a.c_id = c.id AND q.c_id = c.id) WHERE a.hotspot_type IN ('square', 'circle', 'poly', 'delineation', 'oar') "); foreach ($answers as $answer) { // Recover the real image size to recalculate coordinates $imagePath = api_get_path(SYS_PATH) . "courses/{$answer['directory']}/document/images/{$answer['picture']}"; + if (!file_exists($imagePath)) { + error_log("Migration: Image does not exists: $imagePath"); + continue; + } $imageSize = getimagesize($imagePath); $widthRatio = $imageSize[0] / 360; $heightRatio = $imageSize[1] / 360; @@ -50,7 +54,6 @@ class Version20151214170800 extends AbstractMigrationChamilo switch ($answer['hotspot_type']) { case 'square': $oldCenter = explode(';', $oldPairedString[0]); - $oldCenterX = intval($oldCenter[0]); $oldCenterY = intval($oldCenter[1]); $oldWidth = intval($oldPairedString[1]); @@ -65,10 +68,8 @@ class Version20151214170800 extends AbstractMigrationChamilo $newPairedString[] = $newWidth; $newPairedString[] = $newHeight; break; - case 'circle': $oldCenter = explode(';', $oldPairedString[0]); - $oldCenterX = intval($oldCenter[0]); $oldCenterY = intval($oldCenter[1]); $oldRadiusX = intval($oldPairedString[1]) / 2; @@ -83,14 +84,12 @@ class Version20151214170800 extends AbstractMigrationChamilo $newPairedString[] = $newRadiusX; $newPairedString[] = $newRadiusY; break; - case 'poly': //no break; case 'delineation': //no break case 'oar': $paired = []; - foreach ($oldPairedString as $pairString) { $pair = explode(';', $pairString); $x = isset($pair[0]) ? intval($pair[0]) : 0; From 12f7921a627cb80b3c7e3368688969083ec2cbda Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 13:25:25 +0200 Subject: [PATCH 11/17] Fix migration errors --- app/Migrations/Schema/V111/Version111.php | 1 - .../Schema/V111/Version20160304151300.php | 2 +- .../Schema/V111/Version20160706182000.php | 2 +- .../Schema/V111/Version20160930144400.php | 2 + main/install/install.lib.php | 55 ++++++++----------- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/app/Migrations/Schema/V111/Version111.php b/app/Migrations/Schema/V111/Version111.php index 13390b28be..a72e9ba243 100644 --- a/app/Migrations/Schema/V111/Version111.php +++ b/app/Migrations/Schema/V111/Version111.php @@ -314,7 +314,6 @@ class Version111 extends AbstractMigrationChamilo $this->addSql('DELETE FROM settings_options WHERE variable = "visio_use_rtmpt"'); $this->addSql('DELETE FROM course_module WHERE name = "conference"'); $this->addSql('ALTER TABLE c_student_publication_assignment CHANGE add_to_calendar add_to_calendar INT NOT NULL;'); - $this->addSql('ALTER TABLE extra_field ADD visible_to_others TINYINT(1) DEFAULT 0, CHANGE visible visible_to_self TINYINT(1) DEFAULT 0'); } /** diff --git a/app/Migrations/Schema/V111/Version20160304151300.php b/app/Migrations/Schema/V111/Version20160304151300.php index 7cf90edf5f..592afe559c 100644 --- a/app/Migrations/Schema/V111/Version20160304151300.php +++ b/app/Migrations/Schema/V111/Version20160304151300.php @@ -26,6 +26,6 @@ class Version20160304151300 extends AbstractMigrationChamilo */ public function down(Schema $schema) { - + } } diff --git a/app/Migrations/Schema/V111/Version20160706182000.php b/app/Migrations/Schema/V111/Version20160706182000.php index 5c1db18a88..836f1df068 100644 --- a/app/Migrations/Schema/V111/Version20160706182000.php +++ b/app/Migrations/Schema/V111/Version20160706182000.php @@ -24,7 +24,7 @@ class Version20160706182000 extends AbstractMigrationChamilo { $this->addSql( 'CREATE TABLE course_rel_user_catalogue (id int NOT NULL AUTO_INCREMENT, user_id int DEFAULT NULL, c_id int DEFAULT NULL, visible int NOT NULL, PRIMARY KEY (id), KEY (user_id), KEY (c_id), CONSTRAINT FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE, CONSTRAINT FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' - ); + ); } /** diff --git a/app/Migrations/Schema/V111/Version20160930144400.php b/app/Migrations/Schema/V111/Version20160930144400.php index 3ff485adb5..ef7886aac6 100644 --- a/app/Migrations/Schema/V111/Version20160930144400.php +++ b/app/Migrations/Schema/V111/Version20160930144400.php @@ -28,6 +28,8 @@ class Version20160930144400 extends AbstractMigrationChamilo h.hotspot_answer_id = qa.id ) '); + + $this->addSql('ALTER TABLE extra_field ADD visible_to_others TINYINT(1) DEFAULT 0, CHANGE visible visible_to_self TINYINT(1) DEFAULT 0'); } /** diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 11fb5aadad..3ab091b070 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -2550,20 +2550,21 @@ function fixIds(EntityManager $em) error_log("Loading field: ".$field['field_variable']); } $originalId = $field['id']; - $extraField = new ExtraField(); - $extraField - ->setExtraFieldType($type) - ->setVariable($field['field_variable']) - ->setFieldType($field['field_type']) - ->setDisplayText($field['field_display_text']) - ->setDefaultValue($field['field_default_value']) - ->setFieldOrder($field['field_order']) - ->setVisibleToSelf($field['field_visible']) - ->setChangeable($field['field_changeable']) - ->setFilter($field['field_filter']); - - $em->persist($extraField); - $em->flush(); + + $params = [ + 'extra_field_type' => $type, + 'variable' => $field['field_variable'], + 'field_type' => $field['field_type'], + 'display_text' => $field['field_display_text'], + 'default_value' => $field['field_default_value'], + 'field_order' => $field['field_order'], + 'visible' => $field['field_visible'], + 'changeable' => $field['field_changeable'], + 'filter' => $field['field_filter'] + ]; + + $connection->insert('extra_field', $params); + $newExtraFieldId = $connection->lastInsertId(); $values = array(); $handlerId = null; @@ -2603,14 +2604,13 @@ function fixIds(EntityManager $em) $options = $result->fetchAll(); foreach ($options as $option) { - $extraFieldOption = new ExtraFieldOptions(); - $extraFieldOption - ->setDisplayText($option['option_display_text']) - ->setField($extraField) - ->setOptionOrder($option['option_order']) - ->setValue($option['option_value']); - $em->persist($extraFieldOption); - $em->flush(); + $params = [ + 'display_text' => $option['option_display_text'], + 'field_id' => $newExtraFieldId, + 'option_order' => $option['option_order'], + 'option_value' => $option['option_value'] + ]; + $connection->insert('extra_field_options', $params); } $sql = "SELECT * FROM $valueTable WHERE field_id = $originalId "; @@ -2628,19 +2628,10 @@ function fixIds(EntityManager $em) $k = 0; foreach ($values as $value) { if (isset($value[$handlerId])) { - /* - $extraFieldValue = new ExtraFieldValues(); - $extraFieldValue - ->setValue($value['field_value']) - ->setField($extraField) - ->setItemId($value[$handlerId]); - $em->persist($extraFieldValue); - $em->flush(); - */ // Insert without the use of the entity as it reduces // speed to 2 records per second (much too slow) $params = [ - 'field_id' => $extraField->getId(), + 'field_id' => $newExtraFieldId, 'value' => $value['field_value'], 'item_id' => $value[$handlerId] ]; From d2f6ad13177549ddbeea40e7d97d094ec3e93f0c Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 13:33:38 +0200 Subject: [PATCH 12/17] Remove error log --- main/exercise/hotspot_answers.as.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/main/exercise/hotspot_answers.as.php b/main/exercise/hotspot_answers.as.php index 947f8a0830..3232154f53 100755 --- a/main/exercise/hotspot_answers.as.php +++ b/main/exercise/hotspot_answers.as.php @@ -57,8 +57,6 @@ $data['image_height'] = $pictureHeight; $data['courseCode'] = $_course['path']; $data['hotspots'] = []; -error_log("\$objExercise->results_disabled: {$objExercise->results_disabled}"); - $showScoreOptions = [ RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES, @@ -89,13 +87,13 @@ if ($showExpectedChoice) { ->getQuery() ->getResult(); - /** @var CQuizAnswer $hotspotAnswer */ - foreach ($result as $hotspotAnswer) { + /** @var CQuizAnswer $hotSpotAnswer */ + foreach ($result as $hotSpotAnswer) { $hotSpot = []; - $hotSpot['id'] = $hotspotAnswer->getIid(); - $hotSpot['answer'] = $hotspotAnswer->getAnswer(); + $hotSpot['id'] = $hotSpotAnswer->getIid(); + $hotSpot['answer'] = $hotSpotAnswer->getAnswer(); - switch ($hotspotAnswer->getHotspotType()) { + switch ($hotSpotAnswer->getHotspotType()) { case 'square': $hotSpot['type'] = 'square'; break; @@ -113,8 +111,7 @@ if ($showExpectedChoice) { break; } - $hotSpot['coord'] = $hotspotAnswer->getHotspotCoordinates(); - + $hotSpot['coord'] = $hotSpotAnswer->getHotspotCoordinates(); $data['hotspots'][] = $hotSpot; } } From 4e1bb0806fe6a98494babfc3bd3fbd3247416222 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 14 Oct 2016 13:56:04 +0200 Subject: [PATCH 13/17] Fix wrong variable name --- main/install/install.lib.php | 2 +- main/install/update-files-1.10.0-1.11.0.inc.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 3ab091b070..c6ce973593 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -3065,7 +3065,7 @@ function migrateSwitch($fromVersion, $manager, $processFiles = true) $sessionId ); $courseInfo = api_get_course_info_by_id($courseId); - if (empty($item_info)) { + if (empty($itemInfo)) { api_item_property_update( $courseInfo, 'work', diff --git a/main/install/update-files-1.10.0-1.11.0.inc.php b/main/install/update-files-1.10.0-1.11.0.inc.php index 08dff1db5c..b1107f8024 100644 --- a/main/install/update-files-1.10.0-1.11.0.inc.php +++ b/main/install/update-files-1.10.0-1.11.0.inc.php @@ -41,7 +41,6 @@ if (defined('SYSTEM_INSTALLATION')) { if ($debug) { error_log('Folders cleaned up'); } - } else { echo 'You are not allowed here !'. __FILE__; } From 62459f9115876ba4087f1ae6d01648045db154f9 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 14 Oct 2016 09:30:03 -0500 Subject: [PATCH 14/17] Allow clear/reset date and datetime pickers in form --- .../lib/formvalidator/Element/DatePicker.php | 51 +++++++++++------ .../formvalidator/Element/DateTimePicker.php | 55 +++++++++++++------ 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/main/inc/lib/formvalidator/Element/DatePicker.php b/main/inc/lib/formvalidator/Element/DatePicker.php index 8aba686b93..a96a730a15 100644 --- a/main/inc/lib/formvalidator/Element/DatePicker.php +++ b/main/inc/lib/formvalidator/Element/DatePicker.php @@ -44,14 +44,20 @@ class DatePicker extends HTML_QuickForm_text $value = api_format_date($value, DATE_TIME_FORMAT_LONG_24H); } - return $this->getElementJS() . ' + return '
_getAttrString($this->_attributes) . '> + + +
- '; + ' . $this->getElementJS(); } /** @@ -76,21 +82,34 @@ class DatePicker extends HTML_QuickForm_text $js = null; $id = $this->getAttribute('id'); - $js .= ""; diff --git a/main/inc/lib/formvalidator/Element/DateTimePicker.php b/main/inc/lib/formvalidator/Element/DateTimePicker.php index 07d18db10a..fb6c3674e9 100755 --- a/main/inc/lib/formvalidator/Element/DateTimePicker.php +++ b/main/inc/lib/formvalidator/Element/DateTimePicker.php @@ -37,14 +37,20 @@ class DateTimePicker extends HTML_QuickForm_text $value = api_format_date($value, DATE_TIME_FORMAT_LONG_24H); } - return $this->getElementJS() . ' + return '
_getAttrString($this->_attributes) . '> + + +
- '; + ' . $this->getElementJS(); } /** @@ -71,22 +77,35 @@ class DateTimePicker extends HTML_QuickForm_text //timeFormat: 'hh:mm' $js .= ""; From 17aca502d1e3c1cb6806f40737fbb4f7edfa19d4 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Fri, 14 Oct 2016 09:56:48 -0500 Subject: [PATCH 15/17] Allow update session dates when these are null --- main/inc/lib/sessionmanager.lib.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 1ede8d89ac..fbfbe11324 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -1461,7 +1461,13 @@ class SessionManager 'description'=> $description, 'show_description' => intval($showDescription), 'visibility' => $visibility, - 'send_subscription_notification' => $sendSubscriptionNotification + 'send_subscription_notification' => $sendSubscriptionNotification, + 'access_start_date' => null, + 'access_end_date' => null, + 'display_start_date' => null, + 'display_end_date' => null, + 'coach_access_start_date' => null, + 'coach_access_end_date' => null ]; if (!empty($sessionAdminId)) { From dff94509a60de3057d2cdef20bbde2bd0cfa09b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Fri, 14 Oct 2016 12:41:16 -0500 Subject: [PATCH 16/17] Fix delete session if exist an assignments inside --- main/inc/lib/sessionmanager.lib.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index fbfbe11324..a3a5cd0844 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -1536,6 +1536,8 @@ class SessionManager $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); $tbl_url_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $tbl_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY); + $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $tbl_student_publication_assignment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $em = Database::getManager(); $userId = api_get_user_id(); @@ -1568,8 +1570,26 @@ class SessionManager foreach ($courses as $courseId) { $courseInfo = api_get_course_info_by_id($courseId); DocumentManager::deleteDocumentsFromSession($courseInfo, $id_checked); + + $works = Database::select( + '*', + $tbl_student_publication, + [ + 'where' => ['session_id = ? AND c_id = ?' => [$id_checked, $courseId]] + ] + ); + + $currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/'; + + foreach ($works as $index => $work) { + if ($work['filetype'] = 'folder') { + Database::query("DELETE FROM $tbl_student_publication_assignment WHERE publication_id = $index"); + } + my_delete($currentCourseRepositorySys.'/'.$work['url']); + } } + Database::query("DELETE FROM $tbl_student_publication WHERE session_id IN($id_checked)"); Database::query("DELETE FROM $tbl_session_rel_course WHERE session_id IN($id_checked)"); Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id IN($id_checked)"); Database::query("DELETE FROM $tbl_session_rel_user WHERE session_id IN($id_checked)"); From 8f218b9ea6b7018930826955a3832b7ffb43ac7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Fri, 14 Oct 2016 18:39:27 -0500 Subject: [PATCH 17/17] Fix Upload student work if you upload the same filename that previously was deleted --- main/work/work.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/work/work.lib.php b/main/work/work.lib.php index c886ef8244..00008f8991 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -3587,7 +3587,7 @@ function checkExistingWorkFileName($filename, $workId) $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); $filename = Database::escape_string($filename); $sql = "SELECT title FROM $work_table - WHERE parent_id = $workId AND title = '$filename'"; + WHERE parent_id = $workId AND title = '$filename' AND active = 1"; $result = Database::query($sql); return Database::fetch_assoc($result); }