Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

119 arlemlist using offset #120

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions classes/webservice/getdata_from_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
$sessionid = optional_param('sessionid', null, PARAM_RAW);
$userid = optional_param('userid', null, PARAM_INT);
$token = optional_param('token', null, PARAM_RAW);
$result_offset = optional_param('offset', 0, PARAM_RAW);
$result_quantity = optional_param('quantity', 0, PARAM_RAW);

//Check the request and do what needs be done
switch ($request) {
Expand Down Expand Up @@ -68,7 +70,7 @@
*/
function get_arlem_list() {

global $DB, $userid, $token;
global $DB, $userid, $token, $result_offset, $result_quantity;

$fields = "id , contextid , fileid , userid , itemid , sessionid , filename , title , views , filesize , upublic , rate , timecreated , timemodified";

Expand All @@ -85,7 +87,7 @@ function get_arlem_list() {
$params = [1, $userid];
//All public and user's ARLEMs
$sql = ' upublic = ? OR userid = ? ';
$unsortedarlems = $DB->get_records_select('arete_allarlems', $sql, $params, 'timecreated DESC', $fields);
$unsortedarlems = $DB->get_records_select('arete_allarlems', $sql, $params, 'timecreated DESC', $fields, $result_offset, $result_quantity);

//The moudules that the user enrolled to their activitie
$usermoduleids = get_user_arete_modules_ids();
Expand All @@ -111,7 +113,7 @@ function get_arlem_list() {
}

//Get only the public ARLEMs
$arlems = $DB->get_records('arete_allarlems', array('upublic' => 1), 'timecreated DESC', $fields);
$arlems = $DB->get_records('arete_allarlems', array('upublic' => 1), 'timecreated DESC', $fields, $result_offset, $result_quantity);
//
//Adding author name to the ARLEM object
foreach ($arlems as $arlem) {
Expand Down
208 changes: 206 additions & 2 deletions tests/postman/Moodle Arete.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"info": {
"_postman_id": "8a6546ad-def8-4422-8a83-184d914e9d6c",
"name": "Moodle Arete Copy 6",
"_postman_id": "903e635c-4cb6-4310-9fe2-bf1548b58934",
"name": "Moodle Arete",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
"_exporter_id": "4275912"
},
Expand Down Expand Up @@ -542,6 +542,210 @@
},
"response": []
},
{
"name": "Get Data from Database after storing as user that stored using offset",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"To Check if Values are Null\", function() {\r",
" var jsonData = pm.response.json();\r",
" pm.expect(Object.keys(jsonData).length).eq(1);\r",
" var id = Object.keys(jsonData)[0];\r",
" var arlemid = jsonData[id][\"itemid\"];\r",
" var sessionid = jsonData[id][\"sessionid\"];\r",
" pm.environment.set(\"ARLEM_ID\", arlemid);\r",
" pm.environment.set(\"SESSION_ID\", sessionid);\r",
" pm.expect(arlemid).not.eq(null);\r",
" pm.expect(arlemid).not.eq(\"\");\r",
" pm.expect(sessionid).not.eq(null);\r",
" pm.expect(sessionid).not.eq(\"\");\r",
"\r",
" var jsonData = pm.response.json();\r",
" var id = Object.keys(jsonData)[0];\r",
" var idjson = jsonData[id][\"id\"];\r",
" var contextidjson = jsonData[id][\"contextid\"];\r",
" pm.expect(null).not.eq(contextidjson);\r",
" var fileidjson = jsonData[id][\"fileid\"];\r",
" pm.expect(null).not.eq(fileidjson);\r",
" var useridjson = jsonData[id][\"userid\"];\r",
" pm.expect(null).not.eq(useridjson);\r",
" var itemidjson = jsonData[id][\"itemid\"];\r",
" pm.expect(null).not.eq(itemidjson);\r",
" var titlejson = jsonData[id][\"title\"];\r",
" pm.expect(null).not.eq(titlejson);\r",
" var viewsjson = jsonData[id][\"views\"];\r",
" pm.expect(null).not.eq(viewsjson);\r",
" var sessionidjson = jsonData[id][\"sessionid\"];\r",
" pm.expect(null).not.eq(sessionidjson);\r",
" var filesizejson = jsonData[id][\"filesize\"];\r",
" pm.expect(null).not.eq(filesizejson);\r",
" var upublicjson = jsonData[id][\"upublic\"];\r",
" pm.expect(null).not.eq(upublicjson);\r",
" var ratejson = jsonData[id][\"rate\"];\r",
" pm.expect(null).not.eq(ratejson);\r",
" var activityjson = jsonData[id][\"activity_json\"];\r",
" pm.expect(null).not.eq(activityjson);\r",
" var workplacejson = jsonData[id][\"workplace_json\"];\r",
" pm.expect(null).not.eq(workplacejson);\r",
" var timejson = jsonData[id][\"timecreated\"];\r",
" pm.expect(null).not.eq(timejson);\r",
" var timemodified = jsonData[id][\"timemodified\"];\r",
" pm.expect(null).not.eq(timemodified);\r",
" var author = jsonData[id][\"author\"];\r",
" pm.expect(null).not.eq(author);\r",
"})"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "request",
"value": "arlemlist",
"type": "text"
},
{
"key": "token",
"value": "{{TOKEN}}",
"type": "text"
},
{
"key": "userid",
"value": "{{USER_ID}}",
"type": "text"
},
{
"key": "offset",
"value": "1",
"type": "text"
},
{
"key": "quantity",
"value": "1",
"type": "text"
}
]
},
"url": "http://localhost/moodle/mod/arete/classes/webservice/getdata_from_db.php"
},
"response": []
},
{
"name": "Get Data from Database after storing as user that stored using offset",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"To Check if Values are Null\", function() {\r",
" var jsonData = pm.response.json();\r",
" pm.expect(Object.keys(jsonData).length).eq(1);\r",
" var id = Object.keys(jsonData)[0];\r",
" var arlemid = jsonData[id][\"itemid\"];\r",
" var sessionid = jsonData[id][\"sessionid\"];\r",
" pm.environment.set(\"ARLEM_ID\", arlemid);\r",
" pm.environment.set(\"SESSION_ID\", sessionid);\r",
" pm.expect(arlemid).not.eq(null);\r",
" pm.expect(arlemid).not.eq(\"\");\r",
" pm.expect(sessionid).not.eq(null);\r",
" pm.expect(sessionid).not.eq(\"\");\r",
"\r",
" var jsonData = pm.response.json();\r",
" var id = Object.keys(jsonData)[0];\r",
" var idjson = jsonData[id][\"id\"];\r",
" var contextidjson = jsonData[id][\"contextid\"];\r",
" pm.expect(null).not.eq(contextidjson);\r",
" var fileidjson = jsonData[id][\"fileid\"];\r",
" pm.expect(null).not.eq(fileidjson);\r",
" var useridjson = jsonData[id][\"userid\"];\r",
" pm.expect(null).not.eq(useridjson);\r",
" var itemidjson = jsonData[id][\"itemid\"];\r",
" pm.expect(null).not.eq(itemidjson);\r",
" var titlejson = jsonData[id][\"title\"];\r",
" pm.expect(null).not.eq(titlejson);\r",
" var viewsjson = jsonData[id][\"views\"];\r",
" pm.expect(null).not.eq(viewsjson);\r",
" var sessionidjson = jsonData[id][\"sessionid\"];\r",
" pm.expect(null).not.eq(sessionidjson);\r",
" var filesizejson = jsonData[id][\"filesize\"];\r",
" pm.expect(null).not.eq(filesizejson);\r",
" var upublicjson = jsonData[id][\"upublic\"];\r",
" pm.expect(null).not.eq(upublicjson);\r",
" var ratejson = jsonData[id][\"rate\"];\r",
" pm.expect(null).not.eq(ratejson);\r",
" var activityjson = jsonData[id][\"activity_json\"];\r",
" pm.expect(null).not.eq(activityjson);\r",
" var workplacejson = jsonData[id][\"workplace_json\"];\r",
" pm.expect(null).not.eq(workplacejson);\r",
" var timejson = jsonData[id][\"timecreated\"];\r",
" pm.expect(null).not.eq(timejson);\r",
" var timemodified = jsonData[id][\"timemodified\"];\r",
" pm.expect(null).not.eq(timemodified);\r",
" var author = jsonData[id][\"author\"];\r",
" pm.expect(null).not.eq(author);\r",
"})"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "request",
"value": "arlemlist",
"type": "text"
},
{
"key": "token",
"value": "{{TOKEN}}",
"type": "text"
},
{
"key": "userid",
"value": "{{USER_ID}}",
"type": "text"
},
{
"key": "offset",
"value": "0",
"type": "text"
},
{
"key": "quantity",
"value": "1",
"type": "text"
}
]
},
"url": "http://localhost/moodle/mod/arete/classes/webservice/getdata_from_db.php"
},
"response": []
},
{
"name": "Login as test 1 user",
"event": [
Expand Down