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

Crowd Assessment: Url for url generation #1672

Draft
wants to merge 1 commit into
base: v25.0.00
Choose a base branch
from
Draft
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
13 changes: 12 additions & 1 deletion modules/Crowd Assessment/crowdAssess_view_discuss_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

use Gibbon\Forms\Form;
use Gibbon\Http\Url;

//Module includes
require_once __DIR__ . '/moduleFunctions.php';
Expand Down Expand Up @@ -70,7 +71,17 @@
}

// FORM
$form = Form::create('crowdAssessment', $gibbon->session->get('absoluteURL').'/modules/'.$session->get('module')."/crowdAssess_view_discuss_postProcess.php?gibbonPlannerEntryID=$gibbonPlannerEntryID&gibbonPlannerEntryHomeworkID=$gibbonPlannerEntryHomeworkID&address=".$_GET['q']."&gibbonPersonID=$gibbonPersonID&replyTo=$replyTo");
$form = Form::create(
'crowdAssessment',
Url::fromModuleRoute('Crowd Assessment', 'crowdAssess_view_discuss_postProcess')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Koala, I've taken a look at this but I think there may be a type of Url that the Url class cannot properly generate. For forms and process pages, the url needs to go directly to the script itself rather than prepending the index.php module route. In this case, testing your changes in a local system, this form will create an error when submitted because it is trying to go to index.php as a front-end page, not the script itself. I'm curious to hear the best way to handle this, do we add a new method to Url, or add a qualifier to the methods used to build the Url after fromModuleRoute is called. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to try (in fact I tried to write tests for Crowd Assessment in the past few weeks) but I don't quite know how to use and test it :-(

Can you give me some directions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, this one is a bit tricky to setup for testing! 😅 Ff you go into the Planner, pick a demo Class that you "teach" and then add a new lesson plan. Make sure the lesson plan date is in the past week or so (not the future), then enable the Homework option with a deadline in the future, then enable Online Submission, and finally enable the Crowd Assessment option. This should create a crowd-assessable lesson. Once created, click to View your lesson plan and you can manually add a submission for a student using the Edit option. Once a student has a submission it should show up in the Crowd Assessment module list. Hope this helps!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SKuipers In the demo data, which class do "I" actually "teach"? Or how do I make my account "teach" a class?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the demo data you'll have the FL07.1, FL07.2, FL07.3 and FL07.4 classes, they often show up at the top of the classes list under My Classes. To add yourself to a class, you can go into Timetable Admin > Course Enrolment by Person (or by Class). Hope this helps!

->withQueryParams([
'gibbonPlannerEntryID' => $gibbonPlannerEntryID,
'gibbonPlannerEntryHomeworkID' => $gibbonPlannerEntryHomeworkID,
'address' => $_GET['q'],
'gibbonPersonID' => $gibbonPersonID,
'replyTo' => $replyTo,
])
);

$form->addHiddenValue('address', $gibbon->session->get('address'));

Expand Down
38 changes: 17 additions & 21 deletions modules/Crowd Assessment/crowdAssess_view_discuss_postProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
use Gibbon\Data\Validator;
use Gibbon\Comms\NotificationSender;
use Gibbon\Domain\System\SettingGateway;
use Gibbon\Http\Url;

require_once '../../gibbon.php';
require_once __DIR__ . '/../../gibbon.php';

$_POST = $container->get(Validator::class)->sanitize($_POST, ['comment' => 'HTML']);

Expand All @@ -32,41 +33,41 @@
$gibbonPlannerEntryHomeworkID = $_GET['gibbonPlannerEntryHomeworkID'] ?? '';
$gibbonPersonID = $_GET['gibbonPersonID'] ?? '';

$URL = $session->get('absoluteURL').'/index.php?q=/modules/'.getModuleName($_GET['address'])."/crowdAssess_view_discuss.php&gibbonPlannerEntryID=$gibbonPlannerEntryID&gibbonPlannerEntryHomeworkID=$gibbonPlannerEntryHomeworkID&gibbonPersonID=$gibbonPersonID";
$URL = Url::fromModuleRoute('Crowd Assessment', 'crowdAssess_view_discuss')
->withQueryParams([
'gibbonPlannerEntryID' => $gibbonPlannerEntryID,
'gibbonPlannerEntryHomeworkID' => $gibbonPlannerEntryHomeworkID,
'gibbonPersonID' => $gibbonPersonID,
]);

if (isActionAccessible($guid, $connection2, '/modules/Crowd Assessment/crowdAssess_view_discuss_post.php') == false) {
$URL .= '&return=error0';
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('error0'));
} else {
//Proceed!
//Check if gibbonPlannerEntryID, gibbonPlannerEntryHomeworkID, and gibbonPersonID specified
if ($gibbonPlannerEntryID == '' or $gibbonPlannerEntryHomeworkID == '' or $gibbonPersonID == '') {
$URL .= '&return=error1';
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('error1'));
} else {
$and = " AND gibbonPlannerEntryID=$gibbonPlannerEntryID";
$sql = getLessons($guid, $connection2, $and);
try {
$result = $connection2->prepare($sql[1]);
$result->execute($sql[0]);
} catch (PDOException $e) {
$URL .= '&return=error2';
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('error2'));
exit();
}

if ($result->rowCount() != 1) {
$URL .= '&return=error1';
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('error1'));
} else {
$row = $result->fetch();

$comment = $_POST['comment'] ?? '';
$role = getCARole($guid, $connection2, $row['gibbonCourseClassID']);

if ($role == '' or empty($comment)) {
$URL .= '&return=error2';
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('error2'));
} else {
$sqlList = getStudents($guid, $connection2, $role, $row['gibbonCourseClassID'], $row['homeworkCrowdAssessOtherTeachersRead'], $row['homeworkCrowdAssessOtherParentsRead'], $row['homeworkCrowdAssessSubmitterParentsRead'], $row['homeworkCrowdAssessClassmatesParentsRead'], $row['homeworkCrowdAssessOtherStudentsRead'], $row['homeworkCrowdAssessClassmatesRead'], " AND gibbonPerson.gibbonPersonID=$gibbonPersonID");

Expand All @@ -75,14 +76,12 @@
$resultList = $connection2->prepare($sqlList[1]);
$resultList->execute($sqlList[0]);
} catch (PDOException $e) {
$URL .= '&return=erorr2';
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('error2'));
exit();
}

if ($resultList->rowCount() != 1) {
$URL .= '&return=error2';
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('error2'));
} else {
//INSERT
$replyTo = !empty($_GET['replyTo']) ? $_GET['replyTo'] : null;
Expand All @@ -94,11 +93,9 @@
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
$URL .= '&return=erorr2';
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('error2'));
exit();
}
$hash = '#'.$replyTo;


//Work out who we are replying too
Expand Down Expand Up @@ -140,8 +137,7 @@

$notificationSender->sendNotifications();

$URL .= "&return=success0$hash";
header("Location: {$URL}");
header('Location: ' . $URL->withReturn('success0')->withFragment($replyTo));
}
}
}
Expand Down