瀏覽代碼

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

Yannick Warnier 9 年之前
父節點
當前提交
717d954efb

+ 68 - 11
main/exercice/upload_exercise.php

@@ -12,7 +12,6 @@ use \ChamiloSession as Session;
 // setting the help
 // setting the help
 $help_content = 'exercise_upload';
 $help_content = 'exercise_upload';
 
 
-// including the global Dokeos file
 require_once '../inc/global.inc.php';
 require_once '../inc/global.inc.php';
 
 
 require_once api_get_path(LIBRARY_PATH) . 'pear/excelreader/reader.php';
 require_once api_get_path(LIBRARY_PATH) . 'pear/excelreader/reader.php';
@@ -35,9 +34,13 @@ $(document).ready( function(){
 // Action handling
 // Action handling
 lp_upload_quiz_action_handling();
 lp_upload_quiz_action_handling();
 
 
-$interbreadcrumb[]= array ("url"=>"exercise.php", "name"=> get_lang('Exercises'));
+$interbreadcrumb[] = array(
+    "url" => "exercise.php?".api_get_cidreq(),
+    "name" => get_lang('Exercises'),
+);
 
 
-Display::display_header(get_lang('ImportExcelQuiz'), 'Exercises');
+// Display the header
+Display :: display_header(get_lang('ImportExcelQuiz'), 'Exercises');
 
 
 if (isset($_GET['message'])) {
 if (isset($_GET['message'])) {
     if (in_array($_GET['message'], array('ExerciseEdited'))) {
     if (in_array($_GET['message'], array('ExerciseEdited'))) {
@@ -53,7 +56,8 @@ echo '</div>';
 // the main content
 // the main content
 lp_upload_quiz_main();
 lp_upload_quiz_main();
 
 
-function lp_upload_quiz_actions() {
+function lp_upload_quiz_actions()
+{
     $return = '<a href="exercise.php?'.api_get_cidReq().'">'.
     $return = '<a href="exercise.php?'.api_get_cidReq().'">'.
         Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
         Display::return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
     return $return;
     return $return;
@@ -83,7 +87,33 @@ function lp_upload_quiz_main() {
 
 
     $link = '<a href="../exercice/quiz_template.xls">'.
     $link = '<a href="../exercice/quiz_template.xls">'.
         Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate')).get_lang('DownloadExcelTemplate').'</a>';
         Display::return_icon('export_excel.png', get_lang('DownloadExcelTemplate')).get_lang('DownloadExcelTemplate').'</a>';
-    $form->addElement('label', '', $link);
+    $form->addElement('advanced_settings', $link);
+
+    $table = new HTML_Table(array('class' => 'table'));
+
+    $tableList = array(
+        UNIQUE_ANSWER => get_lang('UniqueSelect'),
+        MULTIPLE_ANSWER => get_lang('MultipleSelect'),
+        FILL_IN_BLANKS => get_lang('FillBlanks'),
+        MATCHING => get_lang('Matching'),
+        FREE_ANSWER => get_lang('FreeAnswer'),
+        GLOBAL_MULTIPLE_ANSWER => get_lang('GlobalMultipleAnswer')
+    );
+
+    $table->setHeaderContents(0, 0, get_lang('QuestionType'));
+    $table->setHeaderContents(0, 1, '#');
+
+    $row = 1;
+    foreach ($tableList as $key => $label ) {
+        $table->setCellContents($row, 0, $label);
+        $table->setCellContents($row, 1, $key);
+        $row++;
+    }
+    $table = $table->toHtml();
+
+    $form->addElement('label', get_lang('QuestionType'), $table);
+
+
     $form->addElement('checkbox', 'user_custom_score', null, get_lang('UseCustomScoreForAllQuestions'), array('id'=> 'user_custom_score'));
     $form->addElement('checkbox', 'user_custom_score', null, get_lang('UseCustomScoreForAllQuestions'), array('id'=> 'user_custom_score'));
     $form->addElement('html', '<div id="options" style="display:none">');
     $form->addElement('html', '<div id="options" style="display:none">');
     $form->addElement('text', 'correct_score', get_lang('CorrectScore'));
     $form->addElement('text', 'correct_score', get_lang('CorrectScore'));
@@ -150,6 +180,8 @@ function lp_upload_quiz_action_handling() {
     $noNegativeScoreIndex = array();
     $noNegativeScoreIndex = array();
     $questionTypeList = array();
     $questionTypeList = array();
     $questionTypeIndex = array();
     $questionTypeIndex = array();
+    $categoryList = array();
+    $categoryIndex = array();
 
 
     // Reading all the first column items sequentially to create breakpoints
     // Reading all the first column items sequentially to create breakpoints
     for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
     for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
@@ -172,6 +204,8 @@ function lp_upload_quiz_action_handling() {
             $noNegativeScoreIndex[] = $i;
             $noNegativeScoreIndex[] = $i;
         } elseif ($data->sheets[0]['cells'][$i][1] == 'QuestionType') {
         } elseif ($data->sheets[0]['cells'][$i][1] == 'QuestionType') {
             $questionTypeIndex[] = $i;
             $questionTypeIndex[] = $i;
+        } elseif ($data->sheets[0]['cells'][$i][1] == 'Category') {
+            $categoryIndex[] = $i;
         }
         }
     }
     }
 
 
@@ -238,9 +272,13 @@ function lp_upload_quiz_action_handling() {
             //a complete line where 1st column is 'EnrichQuestion'
             //a complete line where 1st column is 'EnrichQuestion'
             $question_description[$m] = $column_data;
             $question_description[$m] = $column_data;
             $m++;
             $m++;
+        } elseif (in_array($i, $categoryIndex)) {
+            //a complete line where 1st column is 'Category'
+            $categoryList[$n] = $column_data;
+            $n++;
         } elseif (in_array($i, $noNegativeScoreIndex)) {
         } elseif (in_array($i, $noNegativeScoreIndex)) {
             //a complete line where 1st column is 'NoNegativeScore'
             //a complete line where 1st column is 'NoNegativeScore'
-            $noNegativeScoreList[$z-1] = $column_data;
+            $noNegativeScoreList[$z - 1] = $column_data;
         }
         }
     }
     }
 
 
@@ -277,7 +315,7 @@ function lp_upload_quiz_action_handling() {
 
 
         // Quiz object
         // Quiz object
         $exercise = new Exercise();
         $exercise = new Exercise();
-        //
+
         $quiz_id = $exercise->createExercise(
         $quiz_id = $exercise->createExercise(
             $quiz_title,
             $quiz_title,
             $expired_time,
             $expired_time,
@@ -307,6 +345,16 @@ function lp_upload_quiz_action_handling() {
                 $question_title = $question[$i][2];
                 $question_title = $question[$i][2];
                 $description = isset($question_description[$i][2]) ? $question_description[$i][2] : '';
                 $description = isset($question_description[$i][2]) ? $question_description[$i][2] : '';
 
 
+                $categoryId = null;
+                if (isset($categoryList[$i]) && isset($categoryList[$i][2]) && !empty($categoryList[$i][2])) {
+                    $categoryName = $categoryList[$i][2];
+                    $categoryId = TestCategory::get_category_id_for_title($categoryName, $courseId);
+                    if (empty($categoryId)) {
+                        $category = new TestCategory(null, $categoryName, '');
+                        $categoryId = $category->addCategoryInBDD();
+                    }
+                }
+
                 $question_description_text = "<p></p>";
                 $question_description_text = "<p></p>";
                 if (!empty($description)) {
                 if (!empty($description)) {
                     // Question description.
                     // Question description.
@@ -359,6 +407,14 @@ function lp_upload_quiz_action_handling() {
                         0, // max score
                         0, // max score
                         $answer->type
                         $answer->type
                     );
                     );
+
+                    if (!empty($categoryId)) {
+                        TestCategory::add_category_for_question_id(
+                            $categoryId,
+                            $question_id,
+                            $courseId
+                        );
+                    }
                 }
                 }
 
 
                 switch ($detectQuestionType) {
                 switch ($detectQuestionType) {
@@ -368,7 +424,6 @@ function lp_upload_quiz_action_handling() {
                         $total = 0;
                         $total = 0;
                         if (is_array($answerList) && !empty($question_id)) {
                         if (is_array($answerList) && !empty($question_id)) {
                             $id = 1;
                             $id = 1;
-                            $globalScore = null;
                             $objAnswer = new Answer($question_id, $courseId);
                             $objAnswer = new Answer($question_id, $courseId);
                             $globalScore = $score_list[$i][3];
                             $globalScore = $score_list[$i][3];
 
 
@@ -471,7 +526,7 @@ function lp_upload_quiz_action_handling() {
                         $size = array();
                         $size = array();
 
 
                         $globalScore = 0;
                         $globalScore = 0;
-                        foreach($answerList as $data) {
+                        foreach ($answerList as $data) {
                             $score = isset($data[3]) ? $data[3] : 0;
                             $score = isset($data[3]) ? $data[3] : 0;
                             $globalScore += $score;
                             $globalScore += $score;
                             $scoreList[] = $score;
                             $scoreList[] = $score;
@@ -482,7 +537,7 @@ function lp_upload_quiz_action_handling() {
                         $sizeToString = implode(',', $size);
                         $sizeToString = implode(',', $size);
 
 
                         //<p>Texte long avec les [mots] à [remplir] mis entre [crochets]</p>::10,10,10:200.36363999999998,200,200:0@'
                         //<p>Texte long avec les [mots] à [remplir] mis entre [crochets]</p>::10,10,10:200.36363999999998,200,200:0@'
-                        $answerValue  = $description.'::'.$scoreToString.':'.$sizeToString.':0@';
+                        $answerValue = $description.'::'.$scoreToString.':'.$sizeToString.':0@';
                         $objAnswer = new Answer($question_id, $courseId);
                         $objAnswer = new Answer($question_id, $courseId);
                         $objAnswer->createAnswer(
                         $objAnswer->createAnswer(
                             $answerValue,
                             $answerValue,
@@ -500,7 +555,9 @@ function lp_upload_quiz_action_handling() {
                         break;
                         break;
                     case MATCHING:
                     case MATCHING:
                         $globalScore = $score_list[$i][3];
                         $globalScore = $score_list[$i][3];
+
                         $position = 1;
                         $position = 1;
+
                         $objAnswer = new Answer($question_id, $courseId);
                         $objAnswer = new Answer($question_id, $courseId);
                         foreach ($answerList as $data) {
                         foreach ($answerList as $data) {
                             $option = isset($data[3]) ? $data[3] : '';
                             $option = isset($data[3]) ? $data[3] : '';
@@ -565,7 +622,7 @@ function lp_upload_quiz_action_handling() {
             header('location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.Security::remove_XSS($_GET['lp_id']));
             header('location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.Security::remove_XSS($_GET['lp_id']));
             exit;
             exit;
         } else {
         } else {
-            //  header('location: exercise.php?' . api_get_cidreq());
+            //  header('location: exercice.php?' . api_get_cidreq());
             echo '<script>window.location.href = "'.api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidReq().'&exerciseId='.$quiz_id.'&session_id='.api_get_session_id().'"</script>';
             echo '<script>window.location.href = "'.api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidReq().'&exerciseId='.$quiz_id.'&session_id='.api_get_session_id().'"</script>';
         }
         }
     }
     }

+ 4 - 7
main/inc/lib/agenda.lib.php

@@ -156,13 +156,10 @@ class Agenda
                     'text' => $content,
                     'text' => $content,
                     'date' => $start,
                     'date' => $start,
                     'enddate' => $end,
                     'enddate' => $end,
-                    'all_day' => $allDay
+                    'all_day' => $allDay,
+                    'color' => $color
                 );
                 );
 
 
-                if ($this->allowEventColoring) {
-                    $attributes['color'] = $color;
-                }
-
                 $id = Database::insert(
                 $id = Database::insert(
                     $this->tbl_personal_agenda,
                     $this->tbl_personal_agenda,
                     $attributes
                     $attributes
@@ -1498,7 +1495,7 @@ class Agenda
                 (
                 (
                     agenda.session_id = $session_id AND
                     agenda.session_id = $session_id AND
                     ip.session_id = $session_id
                     ip.session_id = $session_id
-                ) ";                
+                ) ";
             }
             }
 
 
             $sql = "SELECT DISTINCT
             $sql = "SELECT DISTINCT
@@ -1545,7 +1542,7 @@ class Agenda
                 (
                 (
                     agenda.session_id = $session_id AND
                     agenda.session_id = $session_id AND
                     ip.session_id = $session_id
                     ip.session_id = $session_id
-                ) ";                
+                ) ";
             }
             }
 
 
             $sql = "SELECT DISTINCT
             $sql = "SELECT DISTINCT

+ 5 - 3
main/inc/lib/api.lib.php

@@ -1507,7 +1507,7 @@ function _api_format_user($user, $add_password = false)
  * @param bool $checkIfUserOnline
  * @param bool $checkIfUserOnline
  * @param bool $showPassword
  * @param bool $showPassword
  * @param bool $loadExtraData
  * @param bool $loadExtraData
- *
+ * @param bool $loadOnlyVisibleExtraData Get the user extra fields that are visible
  * @return array $user_info user_id, lastname, firstname, username, email, etc
  * @return array $user_info user_id, lastname, firstname, username, email, etc
  * @author Patrick Cool <patrick.cool@UGent.be>
  * @author Patrick Cool <patrick.cool@UGent.be>
  * @author Julio Montoya
  * @author Julio Montoya
@@ -1517,7 +1517,8 @@ function api_get_user_info(
     $user_id = 0,
     $user_id = 0,
     $checkIfUserOnline = false,
     $checkIfUserOnline = false,
     $showPassword = false,
     $showPassword = false,
-    $loadExtraData = false
+    $loadExtraData = false,
+    $loadOnlyVisibleExtraData = false
 ) {
 ) {
     if (empty($user_id)) {
     if (empty($user_id)) {
         $userFromSession = Session::read('_user');
         $userFromSession = Session::read('_user');
@@ -1557,7 +1558,8 @@ function api_get_user_info(
             $fieldValue = new ExtraFieldValue('user');
             $fieldValue = new ExtraFieldValue('user');
 
 
             $result_array['extra'] = $fieldValue->getAllValuesForAnItem(
             $result_array['extra'] = $fieldValue->getAllValuesForAnItem(
-                $user_id
+                $user_id,
+                $loadOnlyVisibleExtraData
             );
             );
         }
         }
         $user = _api_format_user($result_array, $showPassword);
         $user = _api_format_user($result_array, $showPassword);

+ 34 - 0
main/inc/lib/array.lib.php

@@ -141,3 +141,37 @@ function array_to_string($array, $separator = ',')
 
 
     return implode($separator.' ', $array);
     return implode($separator.' ', $array);
 }
 }
+
+/**
+ * @param array $array
+ * @return array
+ */
+function array_flatten(array $array)
+{
+    $flatten = array();
+    array_walk_recursive(
+        $array,
+        function ($value) use (&$flatten) {
+            $flatten[] = $value;
+        }
+    );
+
+    return $flatten;
+}
+
+/**
+ * Shuffles an array keeping the associations
+ * @param $array
+ * @return bool
+ */
+function shuffle_assoc(&$array)
+{
+    $keys = array_keys($array);
+    shuffle($keys);
+    $new = array();
+    foreach ($keys as $key) {
+        $new[$key] = $array[$key];
+    }
+    $array = $new;
+    return true;
+}

+ 1 - 1
main/inc/lib/social.lib.php

@@ -1672,7 +1672,7 @@ class SocialManager extends UserManager
 
 
         $vCardUserLink = Display::getVCardUserLink($userId);
         $vCardUserLink = Display::getVCardUserLink($userId);
 
 
-        $userInfo = api_get_user_info($userId, true, false, true);
+        $userInfo = api_get_user_info($userId, true, false, true, true);
 
 
         $template->assign('user', $userInfo);
         $template->assign('user', $userInfo);
         $template->assign('social_avatar_block', $socialAvatarBlock);
         $template->assign('social_avatar_block', $socialAvatarBlock);

+ 4 - 0
main/lang/english/trad4all.inc.php

@@ -7603,4 +7603,8 @@ $CropYourPicture = "Crop your picture";
 $DownloadBadge = "Download badge";
 $DownloadBadge = "Download badge";
 $NoXMLFileFoundInTheZip = "No XML file found in the zip archive. This is a requirement for this type of import.";
 $NoXMLFileFoundInTheZip = "No XML file found in the zip archive. This is a requirement for this type of import.";
 $BakedBadgeProblem = "There was a problem embedding the badge assertion info into the badge image, but you can still use this page as a valid proof.";
 $BakedBadgeProblem = "There was a problem embedding the badge assertion info into the badge image, but you can still use this page as a valid proof.";
+$ConfirmAssociateForumToLPItem = "This action will associate a forum thread to this learning path item. Do you want to proceed?";
+$ConfirmDissociateForumToLPItem = "This action will dissociate the forum thread of this learning path item. Do you want to proceed?";
+$DissociateForumToLPItem = "Dissociate the forum of this learning path item";
+$AssociateForumToLPItem = "Associate a forum to this learning path item";
 ?>
 ?>

+ 4 - 0
main/lang/spanish/trad4all.inc.php

@@ -7628,4 +7628,8 @@ $CropYourPicture = "Recorta tu foto";
 $DownloadBadge = "Descargar la insignia";
 $DownloadBadge = "Descargar la insignia";
 $NoXMLFileFoundInTheZip = "No se encontró ningún archivo XML en el zip. Se requiere uno para este tipo de importación.";
 $NoXMLFileFoundInTheZip = "No se encontró ningún archivo XML en el zip. Se requiere uno para este tipo de importación.";
 $BakedBadgeProblem = "Ha ocurrido un problema al insertar la información de la insignia dentro de la imagen de la insignia, pero puede usar esta página como prueba de su logro.";
 $BakedBadgeProblem = "Ha ocurrido un problema al insertar la información de la insignia dentro de la imagen de la insignia, pero puede usar esta página como prueba de su logro.";
+$ConfirmAssociateForumToLPItem = "Esta acción asociará un hilo de conversación de foro a este paso de la lección. ¿Desea proceder?";
+$ConfirmDissociateForumToLPItem = "Esta acción disociará el hilo de conversación de este paso de la lección. ¿Desea proceder?";
+$DissociateForumToLPItem = "Disociar el hilo de la conversión de este paso de lección";
+$AssociateForumToLPItem = "Asociar un hilo de conversación de foro a este paso de la lección";
 ?>
 ?>

+ 10 - 5
main/newscorm/learnpath.class.php

@@ -5641,10 +5641,15 @@ class learnpath
                                 $this->lp_session_id
                                 $this->lp_session_id
                             )
                             )
                             ) {
                             ) {
+                                $forumIconUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
+                                        'action' => 'dissociate_forum',
+                                        'id' => $arrLP[$i]['id'],
+                                        'lp_id' => $this->lp_id
+                                    ]);
                                 $forumIcon = Display::url(
                                 $forumIcon = Display::url(
-                                    Display::return_icon('forum.png', get_lang('CreateForum'), [], ICON_SIZE_TINY),
-                                    '#',
-                                    ['class' => 'btn btn-default disabled']
+                                    Display::return_icon('forum.png', get_lang('DissociateForumToLPItem'), [], ICON_SIZE_TINY),
+                                    $forumIconUrl,
+                                    ['class' => 'btn btn-default lp-btn-dissociate-forum']
                                 );
                                 );
                             } else {
                             } else {
                                 $forumIconUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
                                 $forumIconUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
@@ -5653,9 +5658,9 @@ class learnpath
                                         'lp_id' => $this->lp_id
                                         'lp_id' => $this->lp_id
                                     ]);
                                     ]);
                                 $forumIcon = Display::url(
                                 $forumIcon = Display::url(
-                                    Display::return_icon('forum.png', get_lang('CreateForum'), [], ICON_SIZE_TINY),
+                                    Display::return_icon('forum.png', get_lang('AssociateForumToLPItem'), [], ICON_SIZE_TINY),
                                     $forumIconUrl,
                                     $forumIconUrl,
-                                    ['class' => "btn btn-default"]
+                                    ['class' => "btn btn-default lp-btn-associate-forum"]
                                 );
                                 );
                             }
                             }
                         }
                         }

+ 70 - 21
main/newscorm/learnpathItem.class.php

@@ -4437,7 +4437,11 @@ class learnpathItem
                     'ip.visibility != ? AND ' => 2,
                     'ip.visibility != ? AND ' => 2,
                     'ip.tool = ? AND ' => TOOL_FORUM_THREAD,
                     'ip.tool = ? AND ' => TOOL_FORUM_THREAD,
                     'ft.c_id = ? AND ' => intval($lpCourseId),
                     'ft.c_id = ? AND ' => intval($lpCourseId),
-                    'ft.lp_item_id = ?' => intval($this->db_id)
+                    '(ft.lp_item_id = ? OR (ft.thread_title = ? AND ft.lp_item_id = ?))' => [
+                        intval($this->db_id),
+                        "{$this->title} - {$this->db_id}",
+                        intval($this->db_id)
+                    ]
                 ]
                 ]
             ],
             ],
             'first'
             'first'
@@ -4490,7 +4494,11 @@ class learnpathItem
                     'ip.tool = ? AND ' => TOOL_FORUM_THREAD,
                     'ip.tool = ? AND ' => TOOL_FORUM_THREAD,
                     'ft.session_id = ? AND ' => $lpSessionId,
                     'ft.session_id = ? AND ' => $lpSessionId,
                     'ft.c_id = ? AND ' => intval($lpCourseId),
                     'ft.c_id = ? AND ' => intval($lpCourseId),
-                    'ft.lp_item_id = ?' => intval($this->db_id)
+                    '(ft.lp_item_id = ? OR (ft.thread_title = ? AND ft.lp_item_id = ?))' => [
+                        intval($this->db_id),
+                        "{$this->title} - {$this->db_id}",
+                        intval($this->db_id)
+                    ]
                 ]
                 ]
             ],
             ],
             'first'
             'first'
@@ -4512,27 +4520,68 @@ class learnpathItem
     {
     {
         require_once api_get_path(SYS_CODE_PATH) . '/forum/forumfunction.inc.php';
         require_once api_get_path(SYS_CODE_PATH) . '/forum/forumfunction.inc.php';
 
 
-        $forumInfo = get_forum_information($currentForumId);
+        $em = Database::getManager();
+        $threadRepo = $em->getRepository('ChamiloCourseBundle:CForumThread');
+        $forumThread = $threadRepo->findOneBy([
+            'threadTitle' => "{$this->title} - {$this->db_id}",
+            'forumId' => intval($currentForumId)
+        ]);
+
+        if (!$forumThread) {
+            $forumInfo = get_forum_information($currentForumId);
+
+            store_thread(
+                $forumInfo,
+                [
+                    'forum_id' => intval($currentForumId),
+                    'thread_id' => 0,
+                    'gradebook' => 0,
+                    'post_title' => "{$this->name} - {$this->db_id}",
+                    'post_text' => $this->description,
+                    'category_id' => 1,
+                    'numeric_calification' => 0,
+                    'calification_notebook_title' => 0,
+                    'weight_calification' => 0.00,
+                    'thread_peer_qualify' => 0,
+                    'lp_item_id' => $this->db_id
+                ],
+                [],
+                false
+            );
 
 
-        $threadId = store_thread(
-            $forumInfo,
-            [
-                'forum_id' => intval($currentForumId),
-                'thread_id' => 0,
-                'gradebook' => 0,
-                'post_title' => $this->name,
-                'post_text' => $this->description,
-                'category_id' => 1,
-                'numeric_calification' => 0,
-                'calification_notebook_title' => 0,
-                'weight_calification' => 0.00,
-                'thread_peer_qualify' => 0,
-                'lp_item_id' => $this->db_id
-            ],
-            [],
-            false
+            return;
+        }
+
+        $forumThread->setLpItemId($this->db_id);
+
+        $em->persist($forumThread);
+        $em->flush();
+    }
+
+    /**
+     * Allow dissociate a forum to this LP item
+     * @param int $threadIid The thread id
+     * @return boolean
+     */
+    public function dissociateForumThread($threadIid)
+    {
+        $threadIid = intval($threadIid);
+        $em = Database::getManager();
+
+        $forumThread = $em->find('ChamiloCourseBundle:CForumThread', $threadIid);
+
+        if (!$forumThread) {
+            return false;
+        }
+
+        $forumThread->setThreadTitle(
+            "{$this->get_title()} - {$this->db_id}"
         );
         );
+        $forumThread->setLpItemId(0);
 
 
-        return $threadId;
+        $em->persist($forumThread);
+        $em->flush();
+
+        return true;
     }
     }
 }
 }

+ 16 - 1
main/newscorm/lp_add_item.php

@@ -172,7 +172,22 @@ $(document).ready(function() {
        
        
         $("#hide_bar_template").toggleClass("hide_bar_template_not_hide");
         $("#hide_bar_template").toggleClass("hide_bar_template_not_hide");
     });
     });
-    
+
+    $('.lp-btn-associate-forum').on('click', function (e) {
+        var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem') ?>');
+
+        if (!associate) {
+            e.preventDefault();
+        }
+    });
+
+    $('.lp-btn-dissociate-forum').on('click', function (e) {
+        var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem') ?>');
+
+        if (!dissociate) {
+            e.preventDefault();
+        }
+    });
 });
 });
 </script>
 </script>
 <?php
 <?php

+ 38 - 0
main/newscorm/lp_controller.php

@@ -1340,6 +1340,44 @@ switch ($action) {
     case 'report':
     case 'report':
         require 'lp_report.php';
         require 'lp_report.php';
         break;
         break;
+    case 'dissociate_forum':
+        if (!isset($_GET['id'])) {
+            break;
+        }
+
+        $selectedItem = null;
+
+        foreach ($_SESSION['oLP']->items as $item) {
+            if ($item->db_id != $_GET['id']) {
+                continue;
+            }
+
+            $selectedItem = $item;
+        }
+
+        if (!empty($selectedItem)) {
+            $forumThread = $selectedItem->getForumThread(
+                $_SESSION['oLP']->course_int_id,
+                $_SESSION['oLP']->lp_session_id
+            );
+
+            if (!empty($forumThread)) {
+                $dissoaciated = $selectedItem->dissociateForumThread($forumThread['iid']);
+
+                if ($dissoaciated) {
+                    Display::addFlash(
+                        Display::return_message(get_lang('ForumDissociate'), 'success')
+                    );
+                }
+            }
+        }
+
+        header('Location:' . api_get_path(WEB_PATH) . api_get_self() . '?' . http_build_query([
+            'action' => 'add_item',
+            'type' => 'step',
+            'lp_id' => $_SESSION['oLP']->lp_id
+        ]));
+        break;
     default:
     default:
         if ($debug > 0) error_log('New LP - default action triggered', 0);
         if ($debug > 0) error_log('New LP - default action triggered', 0);
         require 'lp_list.php';
         require 'lp_list.php';

+ 18 - 0
main/newscorm/lp_edit_item.php

@@ -125,6 +125,24 @@ function confirmation(name) {
         return false;
         return false;
     }
     }
 }
 }
+
+$(document).ready(function() {
+    $('.lp-btn-associate-forum').on('click', function (e) {
+        var associate = confirm('<?php echo get_lang('ConfirmAssociateForumToLPItem') ?>');
+
+        if (!associate) {
+            e.preventDefault();
+        }
+    });
+
+    $('.lp-btn-dissociate-forum').on('click', function (e) {
+        var dissociate = confirm('<?php echo get_lang('ConfirmDissociateForumToLPItem') ?>');
+
+        if (!dissociate) {
+            e.preventDefault();
+        }
+    });
+});
 </script>
 </script>
 <?php
 <?php
 
 

+ 153 - 120
main/webservices/registration.soap.php

@@ -987,8 +987,8 @@ $server->wsdl->addComplexType(
 );
 );
 
 
 $server->register(
 $server->register(
-	'WSSubscribeTeacherToSessionCourse',
-	array('SubscribeTeacherToSessionCourse' => 'tns:SubscribeTeacherToSessionCourse'),
+    'WSSubscribeTeacherToSessionCourse',
+    array('SubscribeTeacherToSessionCourse' => 'tns:SubscribeTeacherToSessionCourse'),
     array('return' => 'xsd:string'),
     array('return' => 'xsd:string'),
     'urn:WSRegistration',
     'urn:WSRegistration',
     'urn:WSRegistration#WSSubscribeTeacherToSessionCourse',
     'urn:WSRegistration#WSSubscribeTeacherToSessionCourse',
@@ -1013,8 +1013,8 @@ $server->wsdl->addComplexType(
 );
 );
 
 
 $server->register(
 $server->register(
-	'WSUnsubscribeTeacherFromSessionCourse',
-	array('UnsubscribeTeacherFromSessionCourse' => 'tns:UnsubscribeTeacherFromSessionCourse'),
+    'WSUnsubscribeTeacherFromSessionCourse',
+    array('UnsubscribeTeacherFromSessionCourse' => 'tns:UnsubscribeTeacherFromSessionCourse'),
     array('return' => 'xsd:string'),
     array('return' => 'xsd:string'),
     'urn:WSRegistration',
     'urn:WSRegistration',
     'urn:WSRegistration#WSUnsubscribeTeacherFromSessionCourse',
     'urn:WSRegistration#WSUnsubscribeTeacherFromSessionCourse',
@@ -1023,54 +1023,54 @@ $server->register(
     'This webservice unsubscribe a teacher from a session course'
     'This webservice unsubscribe a teacher from a session course'
 );
 );
 
 
-    /**
-     * Subscribe teacher to a session course
-     *
-     * @param array $params - WSFunction parameters (include VerifyKey)
-     * @return bool|null|soap_fault A simple boolean (true if teacher successful subscribed, false otherwise)
-     */
-    function WSSubscribeTeacherToSessionCourse($params)
-    {
-        global $debug;
+/**
+ * Subscribe teacher to a session course
+ *
+ * @param array $params - WSFunction parameters (include VerifyKey)
+ * @return bool|null|soap_fault A simple boolean (true if teacher successful subscribed, false otherwise)
+ */
+function WSSubscribeTeacherToSessionCourse($params)
+{
+    global $debug;
 
 
-        if ($debug) error_log('WSSubscribeTeacherToSessionCourse');
-        if ($debug) error_log('Params '. print_r($params, 1));
+    if ($debug) error_log('WSSubscribeTeacherToSessionCourse');
+    if ($debug) error_log('Params '. print_r($params, 1));
 
 
-        if (!WSHelperVerifyKey($params)) {
-            return return_error(WS_ERROR_SECRET_KEY);
-        }
+    if (!WSHelperVerifyKey($params)) {
+        return return_error(WS_ERROR_SECRET_KEY);
+    }
 
 
-        $userId = $params['userId']; // Chamilo user Id
-        $sessionId = $params['sessionId']; // Current Session course ID
-        $courseId = $params['courseId']; // Course Real Id
+    $userId = $params['userId']; // Chamilo user Id
+    $sessionId = $params['sessionId']; // Current Session course ID
+    $courseId = $params['courseId']; // Course Real Id
 
 
-        return (SessionManager::set_coach_to_course_session($userId, $sessionId, $courseId));
-    }
+    return (SessionManager::set_coach_to_course_session($userId, $sessionId, $courseId));
+}
 
 
-    /**
-     * Subscribe teacher to a session course
-     *
-     *  @param array $params - WSFunction parameters (include VerifyKey)
-     *  @return bool|null|soap_fault A simple boolean (true if teacher successful unsubscribed, false otherwise)
-     */
-    function WSUnsubscribeTeacherFromSessionCourse($params)
-    {
-        global $debug;
+/**
+ * Subscribe teacher to a session course
+ *
+ *  @param array $params - WSFunction parameters (include VerifyKey)
+ *  @return bool|null|soap_fault A simple boolean (true if teacher successful unsubscribed, false otherwise)
+ */
+function WSUnsubscribeTeacherFromSessionCourse($params)
+{
+    global $debug;
 
 
-        if ($debug) error_log('WSSubscribeTeacherToSessionCourse');
-        if ($debug) error_log('Params '. print_r($params, 1));
+    if ($debug) error_log('WSSubscribeTeacherToSessionCourse');
+    if ($debug) error_log('Params '. print_r($params, 1));
 
 
-        if (!WSHelperVerifyKey($params)) {
-            return return_error(WS_ERROR_SECRET_KEY);
-        }
+    if (!WSHelperVerifyKey($params)) {
+        return return_error(WS_ERROR_SECRET_KEY);
+    }
 
 
-        $userId = $params['userId']; // Chamilo user Id
-        $sessionId = $params['sessionId']; // Current Session course ID
-        $courseId = $params['courseId']; // Course Real Id
+    $userId = $params['userId']; // Chamilo user Id
+    $sessionId = $params['sessionId']; // Current Session course ID
+    $courseId = $params['courseId']; // Course Real Id
 
 
-        return (SessionManager::removeUsersFromCourseSession($userId, $sessionId, $courseId));
+    return (SessionManager::removeUsersFromCourseSession($userId, $sessionId, $courseId));
 
 
-    }
+}
 
 
 
 
 /* Register WSCreateUserPasswordCrypted function */
 /* Register WSCreateUserPasswordCrypted function */
@@ -2602,6 +2602,7 @@ $server->wsdl->addComplexType(
         'wanted_code' => array('name' => 'wanted_code', 'type' => 'xsd:string'),
         'wanted_code' => array('name' => 'wanted_code', 'type' => 'xsd:string'),
         'tutor_name' => array('name' => 'tutor_name', 'type' => 'xsd:string'),
         'tutor_name' => array('name' => 'tutor_name', 'type' => 'xsd:string'),
         'course_language' => array('name' => 'course_language', 'type' => 'xsd:string'),
         'course_language' => array('name' => 'course_language', 'type' => 'xsd:string'),
+        'disk_quota' => array('name' => 'disk_quota', 'type' => 'xsd:string'), // disk_quota in MB
         'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
         'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
         'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
         'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
         'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
         'extra' => array('name' => 'extra', 'type' => 'tns:extrasList')
@@ -2683,6 +2684,10 @@ function WSCreateCourse($params)
         $category_code = isset($course_param['category_code']) ? $course_param['category_code'] : '';
         $category_code = isset($course_param['category_code']) ? $course_param['category_code'] : '';
         $wanted_code = $course_param['wanted_code'];
         $wanted_code = $course_param['wanted_code'];
         $tutor_name = isset($course_param['tutor_name']) ? $course_param['tutor_name'] : '';
         $tutor_name = isset($course_param['tutor_name']) ? $course_param['tutor_name'] : '';
+        $diskQuota = isset($course_param['disk_quota']) ? $course_param['disk_quota'] : '100';
+        // Convert to MB
+        $diskQuota = $diskQuota * 1024 * 1024;
+
         $course_language = 'english'; // TODO: A hard-coded value.
         $course_language = 'english'; // TODO: A hard-coded value.
         $original_course_id_name = $course_param['original_course_id_name'];
         $original_course_id_name = $course_param['original_course_id_name'];
         $original_course_id_value = $course_param['original_course_id_value'];
         $original_course_id_value = $course_param['original_course_id_value'];
@@ -2769,6 +2774,7 @@ function WSCreateCourse($params)
         $params['course_language'] = $course_language;
         $params['course_language'] = $course_language;
         $params['user_id'] = api_get_user_id();
         $params['user_id'] = api_get_user_id();
         $params['visibility'] = $visibility;
         $params['visibility'] = $visibility;
+        $params['disk_quota'] = $diskQuota;
 
 
         $course_info = CourseManager::create_course($params);
         $course_info = CourseManager::create_course($params);
 
 
@@ -4309,6 +4315,19 @@ $server->wsdl->addComplexType(
 );
 );
 
 
 
 
+$server->wsdl->addComplexType(
+    'subscribeUserToCourse_return',
+    'complexType',
+    'struct',
+    'all',
+    '',
+    array(
+        'original_user_id_value'    => array('name' => 'original_user_id_value',    'type' => 'xsd:string'),
+        'original_course_id_value'  => array('name' => 'original_course_id_value',  'type' => 'xsd:string'),
+        'result'                    => array('name' => 'result',                    'type' => 'xsd:int')
+    )
+);
+
 $server->wsdl->addComplexType(
 $server->wsdl->addComplexType(
     'subscribeUserToCourse_return_global',
     'subscribeUserToCourse_return_global',
     'complexType',
     'complexType',
@@ -4349,7 +4368,7 @@ function WSSubscribeUserToCourse($params) {
             $status = $usercourse['status'];
             $status = $usercourse['status'];
         }
         }
 
 
-        $resultValue = 1;
+        $resultValue = 0;
 
 
         // Get user id
         // Get user id
         $user_id = UserManager::get_user_id_from_original_id(
         $user_id = UserManager::get_user_id_from_original_id(
@@ -4373,8 +4392,12 @@ function WSSubscribeUserToCourse($params) {
                 $resultValue = 0;
                 $resultValue = 0;
             } else {
             } else {
                 if ($debug) error_log('WSSubscribeUserToCourse courseCode: '.$courseCode);
                 if ($debug) error_log('WSSubscribeUserToCourse courseCode: '.$courseCode);
-                if (!CourseManager::add_user_to_course($user_id, $courseCode, $status)) {
-                    $resultValue = 0;
+                $result = CourseManager::add_user_to_course($user_id, $courseCode, $status, false);
+                if ($result) {
+                    $resultValue = 1;
+                    if ($debug) error_log('WSSubscribeUserToCourse subscribed');
+                } else {
+                    if ($debug) error_log('WSSubscribeUserToCourse NOT subscribed: ');
                 }
                 }
             }
             }
         }
         }
@@ -4753,6 +4776,91 @@ function WSUnsubscribeUserFromCourse($params)
     return $output;
     return $output;
 }
 }
 
 
+/* Register WSSuscribeUsersToSession function */
+$server->wsdl->addComplexType(
+    'unSubscribeUserFromCourseSimple',
+    'complexType',
+    'struct',
+    'all',
+    '',
+    array(
+        'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
+        'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
+        'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
+        'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
+        'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
+    )
+);
+
+
+// Register the method to expose
+$server->register('WSUnSubscribeUserFromCourseSimple',                         // method name
+    array('unSubscribeUserFromCourseSimple' => 'tns:unSubscribeUserFromCourseSimple'), // input parameters
+    array('return' => 'tns:result_createUsersPassEncrypt'),           // output parameters
+    'urn:WSRegistration',                                                // namespace
+    'urn:WSRegistration#WSUnSubscribeUserFromCourseSimple',                    // soapaction
+    'rpc',                                                               // style
+    'encoded',                                                           // use
+    'This service unsubscribe a user from a course'                     // documentation
+);
+/**
+ * @param array $params
+ * @return array|null|soap_fault
+ */
+function WSUnSubscribeUserFromCourseSimple($params)
+{
+    global $debug;
+    error_log('WSUnSubscribeUserFromCourseSimple');
+    if (!WSHelperVerifyKey($params)) {
+        return return_error(WS_ERROR_SECRET_KEY);
+    }
+
+    $original_user_id_value = $params['original_user_id_value'];
+    $original_user_id_name = $params['original_user_id_name'];
+    $original_course_id_value = $params['original_course_id_value'];
+    $original_course_id_name = $params['original_course_id_name'];
+
+    $result = array();
+    $result['original_user_id_value'] = $original_user_id_value;
+    $result['result'] = 0;
+
+    $user_id = UserManager::get_user_id_from_original_id(
+        $original_user_id_value,
+        $original_user_id_name
+    );
+
+    if ($user_id) {
+        if ($debug) {
+            error_log("User $original_user_id_value, $original_user_id_name found");
+            error_log("Course $original_course_id_value, $original_course_id_name found");
+        }
+
+        $courseCode = CourseManager::get_course_id_from_original_id(
+            $original_course_id_value,
+            $original_course_id_name
+        );
+
+        if (empty($courseCode)) {
+            // Course was not found
+            if ($debug) {
+                error_log("course not found");
+            }
+        } else {
+            if ($debug) {
+                error_log("Course $courseCode found");
+            }
+            CourseManager::unsubscribe_user($user_id, $courseCode, 0);
+            $result['result'] = 1;
+        }
+    } else {
+        if ($debug) {
+            error_log("User not found");
+        }
+    }
+
+    return $result;
+}
+
 /* Register WSSuscribeUsersToSession function */
 /* Register WSSuscribeUsersToSession function */
 // Register the data structures used by the service
 // Register the data structures used by the service
 $server->wsdl->addComplexType(
 $server->wsdl->addComplexType(
@@ -6730,81 +6838,6 @@ function WSDeleteUserFromGroup($params)
 }
 }
 
 
 
 
-$server->wsdl->addComplexType(
-    'unSubscribeUserFromCourseSimple',
-    'complexType',
-    'struct',
-    'all',
-    '',
-    array(
-        'original_user_id_value' => array('name' => 'original_user_id_value', 'type' => 'xsd:string'),
-        'original_user_id_name' => array('name' => 'original_user_id_name', 'type' => 'xsd:string'),
-        'original_course_id_value' => array('name' => 'original_course_id_value', 'type' => 'xsd:string'),
-        'original_course_id_name' => array('name' => 'original_course_id_name', 'type' => 'xsd:string'),
-        'secret_key' => array('name' => 'secret_key', 'type' => 'xsd:string')
-    )
-);
-
-
-
-/**
- * @param array $params
- * @return array|null|soap_fault
- */
-function WSUnSubscribeUserFromCourseSimple($params)
-{
-    global $debug;
-    error_log('WSUnSubscribeUserFromCourseSimple');
-    if (!WSHelperVerifyKey($params)) {
-        return return_error(WS_ERROR_SECRET_KEY);
-    }
-
-    $original_user_id_value = $params['original_user_id_value'];
-    $original_user_id_name = $params['original_user_id_name'];
-    $original_course_id_value = $params['original_course_id_value'];
-    $original_course_id_name = $params['original_course_id_name'];
-
-    $result = array();
-    $result['original_user_id_value'] = $original_user_id_value;
-    $result['result'] = 0;
-
-    $user_id = UserManager::get_user_id_from_original_id(
-        $original_user_id_value,
-        $original_user_id_name
-    );
-
-    if ($user_id) {
-        if ($debug) {
-            error_log(
-                "User $original_user_id_value, $original_user_id_name found"
-            );
-        }
-        $courseCode = CourseManager::get_course_id_from_original_id(
-            $original_course_id_value,
-            $original_course_id_name
-        );
-
-        if (empty($courseCode)) {
-            // Course was not found
-            if ($debug) {
-                error_log("course not found");
-            }
-        } else {
-            if ($debug) {
-                error_log("Course $courseCode found");
-            }
-            CourseManager::unsubscribe_user($user_id, $courseCode, 0);
-            $result['result'] = 1;
-        }
-    } else {
-        if ($debug) {
-            error_log("User not found");
-        }
-    }
-}
-
-
-
 /* Delete user from group Web Service end */
 /* Delete user from group Web Service end */
 
 
 // Add more webservices through hooks from plugins
 // Add more webservices through hooks from plugins