@@ -60,7 +60,19 @@ class Rest extends WebService
60
60
const SAVE_FORUM_THREAD = 'save_forum_thread ' ;
61
61
const SET_THREAD_NOTIFY = 'set_thread_notify ' ;
62
62
63
+ const GET_WORK_LIST = 'get_work_list ' ;
64
+ const GET_WORK_STUDENTS_WITHOUT_PUBLICATIONS = 'get_work_students_without_publications ' ;
65
+ const GET_WORK_USERS = 'get_work_users ' ;
66
+ const GET_WORK_STUDENT_LIST = 'get_work_student_list ' ;
63
67
const PUT_WORK_STUDENT_ITEM_VISIBILITY = 'put_course_work_visibility ' ;
68
+ const DELETE_WORK_STUDENT_ITEM = 'delete_work_student_item ' ;
69
+ const DELETE_WORK_CORRECTIONS = 'delete_work_corrections ' ;
70
+
71
+ const VIEW_DOCUMENT_IN_FRAME = 'view_document_in_frame ' ;
72
+
73
+ const VIEW_QUIZ_TOOL = 'view_quiz_tool ' ;
74
+
75
+ const VIEW_SURVEY_TOOL = 'view_survey_tool ' ;
64
76
65
77
const CREATE_CAMPUS = 'add_campus ' ;
66
78
const EDIT_CAMPUS = 'edit_campus ' ;
@@ -178,6 +190,8 @@ public static function decodeParams($encoded)
178
190
*/
179
191
public function setCourse ($ id )
180
192
{
193
+ global $ _course ;
194
+
181
195
if (!$ id ) {
182
196
$ this ->course = null ;
183
197
@@ -198,9 +212,12 @@ public function setCourse($id)
198
212
199
213
$ this ->course = $ course ;
200
214
215
+ $ courseInfo = api_get_course_info ($ course ->getCode ());
216
+ $ _course = $ courseInfo ;
217
+
201
218
ChamiloSession::write ('_real_cid ' , $ course ->getId ());
202
219
ChamiloSession::write ('_cid ' , $ course ->getCode ());
203
- ChamiloSession::write ('_course ' , api_get_course_info ( $ course -> getCode ()) );
220
+ ChamiloSession::write ('_course ' , $ courseInfo );
204
221
}
205
222
206
223
/**
@@ -2608,6 +2625,306 @@ public function putCourseWorkVisibility(int $workId, int $status): bool
2608
2625
}
2609
2626
}
2610
2627
2628
+ public function deleteWorkStudentItem (int $ workId ): string
2629
+ {
2630
+ Event::event_access_tool (TOOL_STUDENTPUBLICATION );
2631
+
2632
+ require_once api_get_path (SYS_CODE_PATH ).'work/work.lib.php ' ;
2633
+
2634
+ $ courseInfo = api_get_course_info_by_id ($ this ->course ->getId ());
2635
+
2636
+ $ fileDeleted = deleteWorkItem ($ workId , $ courseInfo );
2637
+
2638
+ if ($ fileDeleted ) {
2639
+ return get_lang ('TheDocumentHasBeenDeleted ' );
2640
+ }
2641
+
2642
+ return get_lang ('YouAreNotAllowedToDeleteThisDocument ' );
2643
+ }
2644
+
2645
+ public function deleteWorkCorrections (int $ workId ): string
2646
+ {
2647
+ Event::event_access_tool (TOOL_STUDENTPUBLICATION );
2648
+
2649
+ require_once api_get_path (SYS_CODE_PATH ).'work/work.lib.php ' ;
2650
+
2651
+ $ courseInfo = api_get_course_info_by_id ($ this ->course ->getId ());
2652
+
2653
+ $ result = get_work_user_list (null , null , null , null , $ workId );
2654
+
2655
+ if ($ result ) {
2656
+ foreach ($ result as $ item ) {
2657
+ $ workInfo = get_work_data_by_id ($ item ['id ' ]);
2658
+
2659
+ deleteCorrection ($ courseInfo , $ workInfo );
2660
+ }
2661
+ }
2662
+
2663
+ return get_lang ('Deleted ' );
2664
+ }
2665
+
2666
+ public function getWorkList (int $ workId ): array
2667
+ {
2668
+ $ isAllowedToEdit = api_is_allowed_to_edit ();
2669
+
2670
+ Event::event_access_tool (TOOL_STUDENTPUBLICATION );
2671
+
2672
+ require_once api_get_path (SYS_CODE_PATH ).'work/work.lib.php ' ;
2673
+
2674
+ $ userId = $ this ->user ->getId ();
2675
+ $ courseId = $ this ->course ->getId ();
2676
+ $ sessionId = $ this ->session ? $ this ->session ->getId () : 0 ;
2677
+
2678
+ $ courseInfo = api_get_course_info_by_id ($ courseId );
2679
+ $ webPath = api_get_path (WEB_PATH );
2680
+
2681
+ $ whereCondition = !$ isAllowedToEdit ? " AND u.id = $ userId " : '' ;
2682
+
2683
+ $ works = get_work_user_list (
2684
+ 0 ,
2685
+ 0 ,
2686
+ 'title ' ,
2687
+ 'asc ' ,
2688
+ $ workId ,
2689
+ $ whereCondition ,
2690
+ null ,
2691
+ false ,
2692
+ $ courseId ,
2693
+ $ sessionId
2694
+ );
2695
+
2696
+ return array_map (
2697
+ function (array $ work ) use ($ courseInfo , $ webPath ) {
2698
+ $ itemId = $ work ['id ' ];
2699
+ $ count = getWorkCommentCount ($ itemId , $ courseInfo );
2700
+
2701
+ $ work ['feedback ' ] = $ count .' ' .Display::returnFontAwesomeIcon ('comments-o ' );
2702
+ $ work ['feedback_clean ' ] = $ count ;
2703
+
2704
+ $ workInfo = get_work_data_by_id ($ itemId );
2705
+ $ commentsTmp = getWorkComments ($ workInfo );
2706
+ $ comments = [];
2707
+
2708
+ foreach ($ commentsTmp as $ comment ) {
2709
+ $ comment ['comment ' ] = str_replace ('src="/ ' , 'src=" ' .$ webPath .'app/ ' , $ comment ['comment ' ]);
2710
+ $ comments [] = $ comment ;
2711
+ }
2712
+
2713
+ $ work ['comments ' ] = $ comments ;
2714
+
2715
+ if (empty ($ workInfo ['qualificator_id ' ])) {
2716
+ $ qualificator_id = Display::label (get_lang ('NotRevised ' ), 'warning ' );
2717
+ } else {
2718
+ $ qualificator_id = Display::label (get_lang ('Revised ' ), 'success ' );
2719
+ }
2720
+
2721
+ $ work ['qualificator_id ' ] = $ qualificator_id ;
2722
+
2723
+ return $ work ;
2724
+ },
2725
+ $ works
2726
+ );
2727
+ }
2728
+
2729
+ public function getWorkStudentsWithoutPublications (int $ workId ): array
2730
+ {
2731
+ Event::event_access_tool (TOOL_STUDENTPUBLICATION );
2732
+
2733
+ require_once api_get_path (SYS_CODE_PATH ).'work/work.lib.php ' ;
2734
+
2735
+ return get_list_users_without_publication ($ workId );
2736
+ }
2737
+
2738
+ public function getWorkUsers (int $ workId ): array
2739
+ {
2740
+ Event::event_access_tool (TOOL_STUDENTPUBLICATION );
2741
+
2742
+ require_once api_get_path (SYS_CODE_PATH ).'work/work.lib.php ' ;
2743
+
2744
+ $ courseId = $ this ->course ->getId ();
2745
+ $ sessionId = $ this ->session ? $ this ->session ->getId () : 0 ;
2746
+ $ courseInfo = api_get_course_info_by_id ($ courseId );
2747
+
2748
+ $ items = getAllUserToWork ($ workId , $ courseId );
2749
+ $ usersAdded = [];
2750
+ $ result = [
2751
+ 'users_added ' => [],
2752
+ 'users_to_add ' => [],
2753
+ ];
2754
+
2755
+ if (!empty ($ items )) {
2756
+ foreach ($ items as $ data ) {
2757
+ $ usersAdded [] = $ data ['user_id ' ];
2758
+
2759
+ $ userInfo = api_get_user_info ($ data ['user_id ' ]);
2760
+
2761
+ $ result ['users_added ' ][] = [
2762
+ 'user_id ' => (int ) $ data ['user_id ' ],
2763
+ 'complete_name_with_username ' => $ userInfo ['complete_name_with_username ' ],
2764
+ ];
2765
+ }
2766
+ }
2767
+
2768
+ if (empty ($ sessionId )) {
2769
+ $ status = STUDENT ;
2770
+ } else {
2771
+ $ status = 0 ;
2772
+ }
2773
+
2774
+ $ userList = CourseManager::get_user_list_from_course_code (
2775
+ $ courseInfo ['code ' ],
2776
+ $ sessionId ,
2777
+ null ,
2778
+ null ,
2779
+ $ status
2780
+ );
2781
+
2782
+ $ userToAddList = [];
2783
+ foreach ($ userList as $ user ) {
2784
+ if (!in_array ($ user ['user_id ' ], $ usersAdded )) {
2785
+ $ userToAddList [] = $ user ;
2786
+ }
2787
+ }
2788
+
2789
+ if (!empty ($ userToAddList )) {
2790
+ foreach ($ userToAddList as $ user ) {
2791
+ $ userName = api_get_person_name ($ user ['firstname ' ], $ user ['lastname ' ]).' ( ' .$ user ['username ' ].') ' ;
2792
+
2793
+ $ result ['users_to_add ' ][] = [
2794
+ 'user_id ' => (int ) $ user ['user_id ' ],
2795
+ 'complete_name_with_username ' => $ userName ,
2796
+ ];
2797
+ }
2798
+ }
2799
+
2800
+ return $ result ;
2801
+ }
2802
+
2803
+ public function getWorkStudentList (int $ workId ): array
2804
+ {
2805
+ Event::event_access_tool (TOOL_STUDENTPUBLICATION );
2806
+
2807
+ require_once api_get_path (SYS_CODE_PATH ).'work/work.lib.php ' ;
2808
+
2809
+ $ courseId = $ this ->course ->getId ();
2810
+ $ courseCode = $ this ->course ->getCode ();
2811
+ $ sessionId = $ this ->session ? $ this ->session ->getId () : 0 ;
2812
+
2813
+ $ myFolderData = get_work_data_by_id ($ workId );
2814
+
2815
+ $ workParents = [];
2816
+
2817
+ if (empty ($ myFolderData )) {
2818
+ $ workParents = getWorkList ($ workId , $ myFolderData );
2819
+ }
2820
+
2821
+ $ workIdList = [];
2822
+
2823
+ if (!empty ($ workParents )) {
2824
+ foreach ($ workParents as $ work ) {
2825
+ $ workIdList [] = $ work ->id ;
2826
+ }
2827
+ }
2828
+
2829
+ $ userList = getWorkUserList (
2830
+ $ courseCode ,
2831
+ $ sessionId ,
2832
+ 0 ,
2833
+ 0 ,
2834
+ null ,
2835
+ null ,
2836
+ null
2837
+ );
2838
+
2839
+ return array_map (
2840
+ function ($ userId ) use ($ courseId , $ sessionId , $ workParents , $ workIdList ) {
2841
+ $ user = api_get_user_info ($ userId );
2842
+
2843
+ $ userWorks = 0 ;
2844
+
2845
+ if (!empty ($ workIdList )) {
2846
+ $ userWorks = getUniqueStudentAttempts (
2847
+ $ workIdList ,
2848
+ 0 ,
2849
+ $ courseId ,
2850
+ $ sessionId ,
2851
+ $ user ['user_id ' ]
2852
+ );
2853
+ }
2854
+
2855
+ $ works = $ userWorks ." / " .count ($ workParents );
2856
+
2857
+ return [
2858
+ 'id ' => $ userId ,
2859
+ 'complete_name ' => api_get_person_name ($ user ['firstname ' ], $ user ['lastname ' ]),
2860
+ 'works ' => $ works ,
2861
+ ];
2862
+ },
2863
+ $ userList
2864
+ );
2865
+ }
2866
+
2867
+ public function viewDocumentInFrame (int $ documentId )
2868
+ {
2869
+ $ courseCode = $ this ->course ->getCode ();
2870
+ $ sessionId = $ this ->session ? $ this ->session ->getId () : 0 ;
2871
+
2872
+ $ url = api_get_path (WEB_CODE_PATH ).'document/showinframes.php? '
2873
+ .http_build_query (
2874
+ [
2875
+ 'cidReq ' => $ courseCode ,
2876
+ 'id_session ' => $ sessionId ,
2877
+ 'gidReq ' => 0 ,
2878
+ 'gradebook ' => 0 ,
2879
+ 'origin ' => self ::SERVICE_NAME ,
2880
+ 'id ' => $ documentId ,
2881
+ ]
2882
+ );
2883
+
2884
+ header ("Location: $ url " );
2885
+ exit ;
2886
+ }
2887
+
2888
+ public function viewQuizTool ()
2889
+ {
2890
+ $ courseCode = $ this ->course ->getCode ();
2891
+ $ sessionId = $ this ->session ? $ this ->session ->getId () : 0 ;
2892
+
2893
+ $ url = api_get_path (WEB_CODE_PATH ).'exercise/exercise.php? '
2894
+ .http_build_query (
2895
+ [
2896
+ 'cidReq ' => $ courseCode ,
2897
+ 'id_session ' => $ sessionId ,
2898
+ 'gidReq ' => 0 ,
2899
+ 'gradebook ' => 0 ,
2900
+ 'origin ' => self ::SERVICE_NAME ,
2901
+ ]
2902
+ );
2903
+
2904
+ header ("Location: $ url " );
2905
+ exit ;
2906
+ }
2907
+
2908
+ public function viewSurveyTool ()
2909
+ {
2910
+ $ courseCode = $ this ->course ->getCode ();
2911
+ $ sessionId = $ this ->session ? $ this ->session ->getId () : 0 ;
2912
+
2913
+ $ url = api_get_path (WEB_CODE_PATH ).'survey/survey_list.php? '
2914
+ .http_build_query (
2915
+ [
2916
+ 'cidReq ' => $ courseCode ,
2917
+ 'id_session ' => $ sessionId ,
2918
+ 'gidReq ' => 0 ,
2919
+ 'gradebook ' => 0 ,
2920
+ 'origin ' => self ::SERVICE_NAME ,
2921
+ ]
2922
+ );
2923
+
2924
+ header ("Location: $ url " );
2925
+ exit ;
2926
+ }
2927
+
2611
2928
public static function isAllowedByRequest (bool $ inpersonate = false ): bool
2612
2929
{
2613
2930
$ username = $ _GET ['username ' ] ?? null ;
0 commit comments