Browse Source

Add bulk actions (delete/change status) in student's work list see BT#15675

Julio Montoya 5 years ago
parent
commit
933b83d9b8
3 changed files with 123 additions and 22 deletions
  1. 41 1
      main/inc/ajax/work.ajax.php
  2. 21 17
      main/work/work.lib.php
  3. 61 4
      main/work/work_list_all.php

+ 41 - 1
main/inc/ajax/work.ajax.php

@@ -8,14 +8,54 @@ require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
 
 $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
 $isAllowedToEdit = api_is_allowed_to_edit();
+$courseInfo = api_get_course_info();
 
 switch ($action) {
+    case 'show_student_work':
+        api_protect_course_script(true);
+        if ($isAllowedToEdit) {
+            $itemList = isset($_REQUEST['item_list']) ? $_REQUEST['item_list'] : [];
+            $itemList = explode(',', $itemList);
+            if (!empty($itemList)) {
+                foreach ($itemList as $itemId) {
+                    makeVisible($itemId, $courseInfo);
+                }
+                echo '1';
+                exit;
+            }
+        }
+        echo '0';
+        break;
+    case 'hide_student_work':
+        api_protect_course_script(true);
+        if ($isAllowedToEdit) {
+            $itemList = isset($_REQUEST['item_list']) ? $_REQUEST['item_list'] : [];
+            $itemList = explode(',', $itemList);
+            if (!empty($itemList)) {
+                foreach ($itemList as $itemId) {
+                    makeInvisible($itemId, $courseInfo);
+                }
+                echo '1';
+                exit;
+            }
+        }
+        echo '0';
+        break;
+    case 'delete_student_work':
+        api_protect_course_script(true);
+        if ($isAllowedToEdit) {
+            $itemId = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
+            deleteWorkItem($itemId, $courseInfo);
+            echo '1';
+            exit;
+        }
+        echo '0';
+        break;
     case 'upload_file':
         api_protect_course_script(true);
         $workId = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
 
         $workInfo = get_work_data_by_id($workId);
-        $courseInfo = api_get_course_info();
         $sessionId = api_get_session_id();
         $userId = api_get_user_id();
         $groupId = api_get_group_id();

+ 21 - 17
main/work/work.lib.php

@@ -4445,13 +4445,17 @@ function deleteAllWorkPerUser($userId, $courseInfo)
  */
 function deleteWorkItem($item_id, $courseInfo)
 {
+    $item_id = (int) $item_id;
+
+    if (empty($item_id) || empty($courseInfo)) {
+        return false;
+    }
+
     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
     $TSTDPUBASG = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
     $currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/';
     $is_allowed_to_edit = api_is_allowed_to_edit();
     $file_deleted = false;
-    $item_id = intval($item_id);
-
     $is_author = user_is_author($item_id);
     $work_data = get_work_data_by_id($item_id);
     $locked = api_resource_is_locked_by_gradebook($work_data['parent_id'], LINK_STUDENTPUBLICATION);
@@ -4712,51 +4716,51 @@ function getUploadDocumentType()
 }
 
 /**
- * @param int   $item_id
+ * @param int   $itemId
  * @param array $course_info
  *
  * @return bool
  */
-function makeVisible($item_id, $course_info)
+function makeVisible($itemId, $course_info)
 {
-    if (empty($course_info) || empty($item_id)) {
+    $itemId = (int) $itemId;
+    if (empty($course_info) || empty($itemId)) {
         return false;
     }
     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
     $course_id = $course_info['real_id'];
-    $item_id = intval($item_id);
 
     $sql = "UPDATE $work_table SET accepted = 1
-            WHERE c_id = $course_id AND id = $item_id";
+            WHERE c_id = $course_id AND id = $itemId";
     Database::query($sql);
-    api_item_property_update($course_info, 'work', $item_id, 'visible', api_get_user_id());
+    api_item_property_update($course_info, 'work', $itemId, 'visible', api_get_user_id());
 
     return true;
 }
 
 /**
- * @param int   $item_id
+ * @param int   $itemId
  * @param array $course_info
  *
  * @return int
  */
-function makeInvisible($item_id, $course_info)
+function makeInvisible($itemId, $course_info)
 {
-    if (empty($course_info) || empty($item_id)) {
+    $itemId = (int) $itemId;
+    if (empty($course_info) || empty($itemId)) {
         return false;
     }
 
     $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
-    $item_id = intval($item_id);
     $course_id = $course_info['real_id'];
     $sql = "UPDATE $table
             SET accepted = 0
-            WHERE c_id = $course_id AND id = '".$item_id."'";
+            WHERE c_id = $course_id AND id = '".$itemId."'";
     Database::query($sql);
     api_item_property_update(
         $course_info,
         'work',
-        $item_id,
+        $itemId,
         'invisible',
         api_get_user_id()
     );
@@ -4778,9 +4782,9 @@ function generateMoveForm($item_id, $path, $courseInfo, $groupId, $sessionId)
     $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
     $courseId = $courseInfo['real_id'];
     $folders = [];
-    $session_id = intval($sessionId);
-    $groupId = intval($groupId);
-    $sessionCondition = empty($sessionId) ? " AND (session_id = 0 OR session_id IS NULL) " : " AND session_id='".$session_id."'";
+    $session_id = (int) $sessionId;
+    $groupId = (int) $groupId;
+    $sessionCondition = empty($sessionId) ? ' AND (session_id = 0 OR session_id IS NULL) ' : " AND session_id='".$session_id."'";
 
     $groupIid = 0;
     if ($groupId) {

+ 61 - 4
main/work/work_list_all.php

@@ -10,7 +10,7 @@ api_protect_course_script(true);
 require_once 'work.lib.php';
 $this_section = SECTION_COURSES;
 
-$workId = isset($_GET['id']) ? intval($_GET['id']) : null;
+$workId = isset($_GET['id']) ? (int) $_GET['id'] : null;
 $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();
 
 if (empty($workId)) {
@@ -81,7 +81,7 @@ $interbreadcrumb[] = [
 ];
 
 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
-$itemId = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
+$itemId = isset($_REQUEST['item_id']) ? (int) $_REQUEST['item_id'] : null;
 
 switch ($action) {
     case 'export_to_doc':
@@ -361,15 +361,72 @@ $extra_params = [
     'height' => 'auto',
     'sortname' => $orderName,
     'sortable' => 'false',
+    'multiselect' => 'true',
 ];
 
-$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_work_user_list_all&work_id='.$workId.'&type='.$type.'&'.api_get_cidreq();
+$url = api_get_path(WEB_AJAX_PATH).
+    'model.ajax.php?a=get_work_user_list_all&work_id='.$workId.'&type='.$type.'&'.api_get_cidreq();
+
+$workUrl = api_get_path(WEB_AJAX_PATH).'work.ajax.php?'.api_get_cidreq();
+$deleteUrl = $workUrl.'&a=delete_student_work';
+$showUrl = $workUrl.'&a=show_student_work';
+$hideUrl = $workUrl.'&a=hide_student_work';
+
 ?>
 <script>
 $(function() {
     <?php
     echo Display::grid_js('results', $url, $columns, $column_model, $extra_params);
-?>
+    ?>
+
+    $("#results").jqGrid(
+        "navGrid",
+        "#results_pager",
+        { edit: false, add: false, del: true },
+        { height:280, reloadAfterSubmit:false }, // edit options
+        { height:280, reloadAfterSubmit:false }, // add options
+        { reloadAfterSubmit:false, url: "<?php echo $deleteUrl; ?>" }, // del options
+        { width:500 } // search options
+    ).navButtonAdd('#results_pager', {
+        caption:"<i class=\"fa fa-eye\" ></i>",
+        buttonicon:"ui-icon-blank",
+        onClickButton: function(a) {
+            var userIdList = $("#results").jqGrid('getGridParam', 'selarrrow');
+            if (userIdList.length) {
+                $.ajax({
+                    type: "POST",
+                    url: "<?php echo $showUrl; ?>&item_list=" + userIdList,
+                    dataType: "json",
+                    success: function(data) {
+                        $('#results').trigger('reloadGrid');
+                    }
+                });
+            } else {
+                alert("<?php echo addslashes(get_lang('SelectAnOption')); ?>");
+            }
+        },
+        position:"last"
+    }).navButtonAdd('#results_pager', {
+        //caption:"<?php //echo addslashes(get_lang('SetVisible')); ?>//",
+        caption:"<i class=\"fa fa-eye-slash\" ></i>",
+        buttonicon:"ui-icon-blank",
+        onClickButton: function(a) {
+            var userIdList = $("#results").jqGrid('getGridParam', 'selarrrow');
+            if (userIdList.length) {
+                $.ajax({
+                    type: "POST",
+                    url: "<?php echo $hideUrl; ?>&item_list=" + userIdList,
+                    dataType: "json",
+                    success: function(data) {
+                        $('#results').trigger('reloadGrid');
+                    }
+                });
+            } else {
+                alert("<?php echo addslashes(get_lang('SelectAnOption')); ?>");
+            }
+        },
+        position:"last"
+    });
 });
 
 </script>