소스 검색

Fix gradebook tool: use course id, add api_get_cidreq, fix queries, remove use of globals

jmontoyaa 8 년 전
부모
커밋
8c9920e21b

+ 4 - 2
main/gradebook/gradebook_add_eval.php

@@ -90,13 +90,15 @@ $interbreadcrumb[] = array(
 ;
 $this_section = SECTION_COURSES;
 
-$htmlHeadXtra[] = '<script type="text/javascript">
+$url = api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight&'.api_get_cidreq();
+
+$htmlHeadXtra[] = '<script>
 $(document).ready( function() {
     $("#hid_category_id").change(function() {
        $("#hid_category_id option:selected").each(function () {
            var cat_id = $(this).val();
             $.ajax({
-                url: "' . api_get_path(WEB_AJAX_PATH) . 'gradebook.ajax.php?a=get_gradebook_weight",
+                url: "' . $url. '",
                 data: "cat_id="+cat_id,
                 success: function(return_value) {
                     if (return_value != 0 ) {

+ 3 - 2
main/gradebook/gradebook_add_link.php

@@ -6,7 +6,7 @@
  * @package chamilo.gradebook
  */
 require_once __DIR__.'/../inc/global.inc.php';
-require_once '../forum/forumfunction.inc.php';
+require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
 $current_course_tool = TOOL_GRADEBOOK;
 
 api_protect_course_script(true);
@@ -141,6 +141,7 @@ $interbreadcrumb[] = array(
     'name' => get_lang('Gradebook')
 );
 $this_section = SECTION_COURSES;
+$url = api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight&'.api_get_cidreq();
 
 $htmlHeadXtra[] = '<script>
 $(document).ready( function() {
@@ -148,7 +149,7 @@ $(document).ready( function() {
        $("#hide_category_id option:selected").each(function () {
            var cat_id = $(this).val();
             $.ajax({
-                url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
+                url: "'.$url.'",
                 data: "cat_id="+cat_id,
                 success: function(return_value) {
                     if (return_value != 0 ) {

+ 3 - 1
main/gradebook/gradebook_add_link_select_course.php

@@ -31,7 +31,9 @@ if ($form->validate()) {
     $values = $form->exportValues();
     $cat = new Category();
     $cat->set_course_code($values['select_course']);
-    $cat->set_name($values['name']);
+    if (isset($values['name'])) {
+        $cat->set_name($values['name']);
+    }
     header('location: gradebook_add_link.php?selectcat=' .$selectCat.'&course_code='.Security::remove_XSS($values['select_course']).'&'.api_get_cidreq());
     exit;
 }

+ 2 - 42
main/gradebook/gradebook_edit_all.php

@@ -33,48 +33,7 @@ $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
 $tbl_forum_thread = Database:: get_course_table(TABLE_FORUM_THREAD);
 $tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE);
 
-$table_evaluated[LINK_EXERCISE] = array(
-    TABLE_QUIZ_TEST,
-    'title',
-    'id',
-    get_lang('Exercise'),
-);
-$table_evaluated[LINK_DROPBOX] = array(
-    TABLE_DROPBOX_FILE,
-    'name',
-    'id',
-    get_lang('Dropbox'),
-);
-$table_evaluated[LINK_STUDENTPUBLICATION] = array(
-    TABLE_STUDENT_PUBLICATION,
-    'url',
-    'id',
-    get_lang('Student_publication'),
-);
-$table_evaluated[LINK_LEARNPATH] = array(
-    TABLE_LP_MAIN,
-    'name',
-    'id',
-    get_lang('Learnpath'),
-);
-$table_evaluated[LINK_FORUM_THREAD] = array(
-    TABLE_FORUM_THREAD,
-    'thread_title_qualify',
-    'thread_id',
-    get_lang('Forum'),
-);
-$table_evaluated[LINK_ATTENDANCE] = array(
-    TABLE_ATTENDANCE,
-    'attendance_title_qualify',
-    'id',
-    get_lang('Attendance'),
-);
-$table_evaluated[LINK_SURVEY] = array(
-    TABLE_SURVEY,
-    'code',
-    'survey_id',
-    get_lang('Survey'),
-);
+$table_evaluated = GradebookUtils::getEvaluateList();
 
 $submitted = isset($_POST['submitted']) ? $_POST['submitted'] : '';
 if ($submitted == 1) {
@@ -104,6 +63,7 @@ $links = Database::store_result($result, 'ASSOC');
 
 foreach ($links as &$row) {
     $item_weight = $row['weight'];
+
     $sql = 'SELECT * FROM '.GradebookUtils::get_table_type_course($row['type']).'
             WHERE c_id = '.$course_id.' AND '.$table_evaluated[$row['type']][2].' = '.$row['ref_id'];
     $result = Database::query($sql);

+ 2 - 1
main/gradebook/gradebook_edit_eval.php

@@ -53,13 +53,14 @@ $interbreadcrumb[] = array(
     'name' => get_lang('Gradebook'
 ));
 
+$url = api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight&'.api_get_cidreq();
 $htmlHeadXtra[] = '<script>
 $(document).ready( function() {
     $("#hid_category_id").change(function() {
        $("#hid_category_id option:selected").each(function () {
            var cat_id = $(this).val();
             $.ajax({
-                url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
+                url: "'.$url.'",
                 data: "cat_id="+cat_id,
                 success: function(return_value) {
                     if (return_value != 0 ) {

+ 2 - 1
main/gradebook/gradebook_edit_link.php

@@ -109,6 +109,7 @@ $interbreadcrumb[] = array(
     'url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$linkcat,
     'name' => get_lang('Gradebook')
 );
+$url = api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight&'.api_get_cidreq();
 
 $htmlHeadXtra[] = '<script>
 $(document).ready( function() {
@@ -116,7 +117,7 @@ $(document).ready( function() {
        $("#hide_category_id option:selected").each(function () {
            var cat_id = $(this).val();
             $.ajax({
-                url: "'.api_get_path(WEB_AJAX_PATH).'gradebook.ajax.php?a=get_gradebook_weight",
+                url: "'.$url.'",
                 data: "cat_id="+cat_id,
                 success: function(return_value) {
                     if (return_value != 0 ) {

+ 50 - 1
main/gradebook/lib/GradebookUtils.php

@@ -445,10 +445,59 @@ class GradebookUtils
      */
     public static function get_table_type_course($type)
     {
-        global $table_evaluated;
+        $table_evaluated = self::getEvaluateList();
         return Database::get_course_table($table_evaluated[$type][0]);
     }
 
+    public static function getEvaluateList()
+    {
+        $table_evaluated = [];
+        $table_evaluated[LINK_EXERCISE] = array(
+            TABLE_QUIZ_TEST,
+            'title',
+            'id',
+            get_lang('Exercise'),
+        );
+        $table_evaluated[LINK_DROPBOX] = array(
+            TABLE_DROPBOX_FILE,
+            'name',
+            'id',
+            get_lang('Dropbox'),
+        );
+        $table_evaluated[LINK_STUDENTPUBLICATION] = array(
+            TABLE_STUDENT_PUBLICATION,
+            'url',
+            'id',
+            get_lang('Student_publication'),
+        );
+        $table_evaluated[LINK_LEARNPATH] = array(
+            TABLE_LP_MAIN,
+            'name',
+            'id',
+            get_lang('Learnpath'),
+        );
+        $table_evaluated[LINK_FORUM_THREAD] = array(
+            TABLE_FORUM_THREAD,
+            'thread_title_qualify',
+            'thread_id',
+            get_lang('Forum'),
+        );
+        $table_evaluated[LINK_ATTENDANCE] = array(
+            TABLE_ATTENDANCE,
+            'attendance_title_qualify',
+            'id',
+            get_lang('Attendance'),
+        );
+        $table_evaluated[LINK_SURVEY] = array(
+            TABLE_SURVEY,
+            'code',
+            'survey_id',
+            get_lang('Survey'),
+        );
+
+        return $table_evaluated;
+    }
+
     /**
      * @param Category $cat
      * @param $users

+ 6 - 3
main/gradebook/lib/be/abstractlink.class.php

@@ -270,8 +270,11 @@ abstract class AbstractLink implements GradebookItem
             } else {
                 $sql .= ' WHERE';
             }
-            $sql .= " course_code = '".Database::escape_string($course_code)."'";
-            $paramcount ++;
+            $courseInfo = api_get_course_info($course_code);
+            if ($courseInfo) {
+                $sql .= " c_id = '".$courseInfo['real_id']."'";
+                $paramcount++;
+            }
         }
         if (isset($category_id)) {
             if ($paramcount != 0) {
@@ -310,7 +313,7 @@ abstract class AbstractLink implements GradebookItem
             $link->set_type($data['type']);
             $link->set_ref_id($data['ref_id']);
             $link->set_user_id($data['user_id']);
-            $link->set_course_code($data['course_code']);
+            $link->set_course_code(api_get_course_id());
             $link->set_category_id($data['category_id']);
             $link->set_date($data['created_at']);
             $link->set_weight($data['weight']);

+ 7 - 2
main/gradebook/lib/be/category.class.php

@@ -507,7 +507,8 @@ class Category implements GradebookItem
             $cat->set_name($data['name']);
             $cat->set_description($data['description']);
             $cat->set_user_id($data['user_id']);
-            //$cat->set_course_code($data['course_code']);
+            $courseInfo = api_get_course_info_by_id($data['c_id']);
+            $cat->set_course_code($courseInfo['code']);
             $cat->setCourseId($data['c_id']);
             $cat->set_parent_id($data['parent_id']);
             $cat->set_weight($data['weight']);
@@ -637,6 +638,7 @@ class Category implements GradebookItem
     {
         $em = Database::getManager();
 
+        /** @var  GradebookCategory $gradebookCategory */
         $gradebookCategory = $em
             ->getRepository('ChamiloCoreBundle:GradebookCategory')
             ->find($this->id);
@@ -645,10 +647,13 @@ class Category implements GradebookItem
             return false;
         }
 
+        $course = api_get_user_course_entity();
+
         $gradebookCategory->setName($this->name);
         $gradebookCategory->setDescription($this->description);
         $gradebookCategory->setUserId($this->user_id);
-        $gradebookCategory->setCourseCode($this->course_code);
+        $gradebookCategory->setCourse($course);
+        //$gradebookCategory->setCourseCode($this->course_code);
         $gradebookCategory->setParentId($this->parent);
         $gradebookCategory->setWeight($this->weight);
         $gradebookCategory->setVisible($this->visible);

+ 6 - 3
main/gradebook/lib/be/evaluation.class.php

@@ -324,7 +324,7 @@ class Evaluation implements GradebookItem
 			$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
 
 			$sql = 'INSERT INTO '.$tbl_grade_evaluations
-				.' (name, user_id, weight, max, visible';
+				.' (name, user_id, weight, max, visible, locked';
 			if (isset($this->description)) {
 				$sql .= ',description';
 			}
@@ -336,11 +336,14 @@ class Evaluation implements GradebookItem
 			}
 			$sql .= ', created_at';
 			$sql .= ',type';
-			$sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
+			$sql .= ") VALUES ('".Database::escape_string(
+			    $this->get_name())."'"
 				.','.intval($this->get_user_id())
 				.','.floatval($this->get_weight())
 				.','.intval($this->get_max())
-				.','.intval($this->is_visible());
+				.','.intval($this->is_visible())
+                .','.intval(0)
+            ;
 			if (isset($this->description)) {
 				$sql .= ",'".Database::escape_string($this->get_description())."'";
 			}