Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit da08752

Browse files
author
Dmitry Kochnev
committed
[FEATURE] adding lrnuid for submit URL and respect it for reports (if no logged in users)
1 parent 982834c commit da08752

File tree

2 files changed

+39
-32
lines changed

2 files changed

+39
-32
lines changed

classes/Learnosity/Shortcodes/ItemsEmbed.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public function __construct($options, $mode)
2525
'timestamp' => gmdate('Ymd-Hi')
2626
);
2727

28-
$this->sessionId = \UUID::generateUuid();
29-
3028
//Handling URL parameters
3129
$lrnactid = \UrlHelper::get_url_parameter('lrnactid','');
3230
$lrnactname = \UrlHelper::get_url_parameter('lrnactname','My Activity');
@@ -37,7 +35,7 @@ public function __construct($options, $mode)
3735
'autorender' => true,
3836
'name' => $lrnactname,
3937
'rendersubmit' => false,
40-
'sessionid' => $this->sessionId,
38+
'sessionid' => \UUID::generateUuid(),
4139
'state' => 'initial',
4240
'studentid' => $this->student_prefix . get_current_user_id(),
4341
'type' => get_option('lrn_default_type', 'submit_practice')
@@ -102,14 +100,16 @@ private function generate_signed_request()
102100
// adding learnosity parameter with "&" prefix
103101
// using html_entity_decode as last & is converted to "&"
104102
if (substr(html_entity_decode($url_parsed['query']), -1) != '&') {
105-
$url_parsed['query'] .= '&lrnsid=' . $this->sessionId;
103+
$url_parsed['query'] .= '&lrnsid=' . $this->config['sessionid'];
106104
} else {
107-
$url_parsed['query'] .= 'lrnsid=' . $this->sessionId;
105+
$url_parsed['query'] .= 'lrnsid=' . $this->config['sessionid'];
108106
}
109107
} else {
110108
// adding just learnosity parameter as the only parameter
111-
$url_parsed['query'] = 'lrnsid=' . $this->sessionId;
109+
$url_parsed['query'] = 'lrnsid=' . $this->config['sessionid'];
112110
}
111+
// adding student_id for detailed report for non-logged users
112+
$url_parsed['query'] .= '&lrnuid=' . $this->config['studentid'];
113113

114114
// building new URL with new 'lrnsid' parameter added
115115
// TODO

classes/Learnosity/Shortcodes/ReportEmbed.php

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require_once __DIR__ . '/../../../vendor/learnosity-utils/RequestHelper.php';
77
require_once __DIR__ . '/../../../vendor/learnosity-utils/UrlHelper.php';
88

9+
910
class 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

Comments
 (0)