66require_once __DIR__ . '/../../../vendor/learnosity-utils/RequestHelper.php ' ;
77require_once __DIR__ . '/../../../vendor/learnosity-utils/UrlHelper.php ' ;
88
9+
910class ReportEmbed
1011{
1112
@@ -15,18 +16,18 @@ class ReportEmbed
1516 private $ security ;
1617
1718 private $ report_id ;
18-
19+
1920 private $ student_prefix ;
2021
2122
2223 private $ supported_reports = array (
23- 'sessions-list ' ,
24- 'session-detail-by-item ' );
24+ 'sessions-list ' ,
25+ 'session-detail-by-item ' );
2526
2627 public function __construct ($ options )
2728 {
2829 $ this ->report_id = \UUID ::generateUuid ();
29- $ this ->student_prefix = get_option ('lrn_student_prefix ' ,'student_ ' );
30+ $ this ->student_prefix = get_option ('lrn_student_prefix ' , 'student_ ' );
3031
3132 $ this ->security = array (
3233 'consumer_key ' => get_option ('lrn_consumer_key ' ),
@@ -35,42 +36,46 @@ public function __construct($options)
3536 );
3637
3738 //Handling URL parameters
38- $ lrnsid = \UrlHelper::get_url_parameter ('lrnsid ' ,'' );
39+ $ lrnsid = \UrlHelper::get_url_parameter ('lrnsid ' , '' );
40+ $ lrnuid = \UrlHelper::get_url_parameter ('lrnuid ' , '' );
41+
42+ // get_current_user_id() - (int) The current user's ID, or 0 if no user is logged in
43+ $ lrnRepUserId = get_current_user_id ();
44+ if ($ lrnRepUserId == 0 && $ lrnuid != '' ) {
45+ // get only id without prefix as prefix will be added later
46+ $ lrnRepUserId = str_replace ($ this ->student_prefix ,"" ,$ lrnuid );
47+ }
3948
4049 $ defaults = array (
4150 'id ' => $ this ->report_id ,
4251 'type ' => '' ,
43-
52+
4453 //settings for sessions-list
4554 'limit ' => 10 ,
4655
4756 'display_user ' => 'true ' ,
4857 'display_activity ' => 'true ' ,
4958
50- 'users ' => get_current_user_id () ,
59+ 'users ' => $ lrnRepUserId ,
5160 'activities ' => '' ,
5261
5362 //settings for session-detail-by-item
54- 'user_id ' => get_current_user_id () ,
63+ 'user_id ' => $ lrnRepUserId ,
5564 'session_id ' => $ lrnsid ,
5665 'show_correct_answers ' => 'true ' ,
57- );
58-
66+ );
5967
6068 $ this ->config = array_merge ($ defaults , $ options );
61-
6269 }
6370
6471 public function render ()
6572 {
6673 ob_start ();
6774
6875 //Check this is a supported report
69- if (!in_array ($ this ->config ['type ' ],$ this ->supported_reports )){
76+ if (!in_array ($ this ->config ['type ' ], $ this ->supported_reports )) {
7077 $ this ->render_error ("Unsupported report type: {$ this ->config ['type ' ]}" );
71- }
72- else
73- {
78+ } else {
7479 $ this ->render_init_js ($ this ->config );
7580
7681 $ this ->render_report ($ this ->report_id );
@@ -88,30 +93,32 @@ private function get_user_name($user_id)
8893 }
8994
9095 // Takes a comma seperated list of users and returns an array for reports
91- private function get_users_array ($ users_list ){
96+ private function get_users_array ($ users_list )
97+ {
9298 $ user_array = array ();
9399
94100 foreach (explode (', ' , $ users_list ) as $ key => $ value ) {
95101 array_push ($ user_array ,
96102 array (
97103 'id ' => $ this ->student_prefix . $ value ,
98104 'name ' => $ this ->get_user_name ($ value )
99- )
100- );
105+ )
106+ );
101107 }
102108 return $ user_array ;
103109 }
104110
105111 // Takes a comma seperated list of users and returns an array for reports
106- private function get_activities_array ($ activities_list ){
112+ private function get_activities_array ($ activities_list )
113+ {
107114 $ act_array = array ();
108115
109116 foreach (explode (', ' , $ activities_list ) as $ key => $ value ) {
110117 array_push ($ act_array ,
111118 array (
112119 'id ' => $ value ,
113- )
114- );
120+ )
121+ );
115122 }
116123 return $ act_array ;
117124 }
@@ -125,13 +132,13 @@ private function generate_signed_request()
125132 'type ' => $ this ->config ['type ' ]);
126133
127134 //Handle different type of reports
128- switch ($ this ->config ['type ' ]){
135+ switch ($ this ->config ['type ' ]) {
129136 case "sessions-list " :
130- $ report ['limit ' ] = (int ) $ this ->config ['limit ' ];
137+ $ report ['limit ' ] = (int )$ this ->config ['limit ' ];
131138 $ report ['display_user ' ] = $ this ->parse_boolean ($ this ->config ['display_user ' ]);
132139 $ report ['display_activity ' ] = $ this ->parse_boolean ($ this ->config ['display_activity ' ]);
133140 $ report ['users ' ] = $ this ->get_users_array ($ this ->config ['users ' ]);
134- if ($ this ->config ['activities ' ] != "" ) {
141+ if ($ this ->config ['activities ' ] != "" ) {
135142 $ report ['activities ' ] = $ this ->get_activities_array ($ this ->config ['activities ' ]);
136143 }
137144 break ;
@@ -161,7 +168,7 @@ private function generate_signed_request()
161168 private function parse_boolean ($ str_val )
162169 {
163170 return $ str_val === 'true ' ||
164- ($ str_val !== 'false ' && intval ($ str_val ) > 0 );
171+ ($ str_val !== 'false ' && intval ($ str_val ) > 0 );
165172 }
166173
167174
@@ -175,7 +182,7 @@ private function render_report($report_id)
175182 {
176183 include (__DIR__ . '/../../../templates/report.php ' );
177184 }
178-
185+
179186 private function render_error ($ msg )
180187 {
181188 include (__DIR__ . '/../../../templates/report_error.php ' );
0 commit comments