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

Added two new features to facetoface #3

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
31d18ba
Added two new features: (1)Disable Auto Enrollemnt xx days before a s…
May 28, 2013
4be1c65
removed unnecessary blocks/comments, white spaces, dubugging notices
May 29, 2013
c3684ad
Fixed the comments/issues, white spaces, indentation; except for the …
May 30, 2013
e3cd552
Fixed all the issues according to your last comment regarding white s…
Jun 5, 2013
b7b0ae5
Removed some database call from renderer.php
Jun 5, 2013
8c3f13c
Removed a database call on lib.php. Got the date from facetoface_get_…
Jun 5, 2013
b8733aa
custom facetoface for moodle 2.5.1 for servicetraining
Oct 10, 2013
55b1e9b
mod_form.php: add set type for thirdparty parameter
Feb 23, 2014
25f6447
session_form.php: add set type for session form options
Feb 23, 2014
bf679f6
lib.php: use sql_compare_text when deleting session calendar events
Feb 23, 2014
aed3c38
cancelsignup_form.php: add set type for cancelsignup_form.php
Feb 23, 2014
c592465
mod_form.php: use correct type PARAM_EMAIL for thirdparty parameter
Feb 24, 2014
5fa03ad
lang/en: remove broken <p> tag from allowoverbooking_desc
Feb 27, 2014
af80a85
misc/forms: ensure setType is set on form elements
Feb 27, 2014
92e28fd
version.php: bumping to version 2.2.4.1
Feb 27, 2014
c3ff5ac
version.php: update phpdoc
Feb 28, 2014
e928fd3
settings.php: fix get system roles
Feb 28, 2014
4686dcd
2.6: add get_all_user_name_fields calls where user firstname/lastname is
Mar 1, 2014
92c9da2
version.php bump for version 2.3.0 (Moodle 2.6)
Mar 1, 2014
0566794
ChangeLog.txt: update changelog
Mar 1, 2014
476ee77
lib.php: count ID value not all records
Mar 6, 2014
5abf016
lib.php: fix bug in cancelled users GROUP BY and candidate status check
Mar 6, 2014
7ee079a
Bumping to version 2.3.1
Mar 6, 2014
8be19c8
README: update readme with correct maintainer information
Mar 6, 2014
cf5b32f
lib.php: fix bug with missing u.id in GROUP BY clause
Mar 6, 2014
7f6e3d9
version.php: bump for development versioning
Mar 6, 2014
9bc6814
changes from catalyst Stacey Walker
stgabhas Oct 10, 2014
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
9 changes: 6 additions & 3 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<FIELD NAME="shortname" TYPE="char" LENGTH="32" NOTNULL="false" SEQUENCE="false" PREVIOUS="timemodified" NEXT="showoncalendar"/>
<FIELD NAME="showoncalendar" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="shortname" NEXT="approvalreqd"/>
<FIELD NAME="approvalreqd" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="showoncalendar" NEXT="usercalentry"/>
<FIELD NAME="usercalentry" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="approvalreqd"/>
<FIELD NAME="usercalentry" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="approvalreqd" NEXT="disablewithindays"/>
<FIELD NAME="disablewithindays" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="usercalentry"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

fix indenting of this line

</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for facetoface"/>
Expand Down Expand Up @@ -67,8 +68,10 @@
<FIELD NAME="normalcost" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The normal (non-discounted) cost of the session" PREVIOUS="duration" NEXT="discountcost"/>
<FIELD NAME="discountcost" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Discounted cost of the event" PREVIOUS="normalcost" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="discountcost" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
</FIELDS>
<FIELD NAME="timemodified" TYPE="int" LENGTH="20" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="disablenewenrolldays"/>
<FIELD NAME="disablenewenrolldays" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timemodified" NEXT="disableoption"/>
<FIELD NAME="disableoption" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="disablenewenrolldays"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this field does not describe what it does. A better name might be "disablesignup".

</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="facetoface"/>
<KEY NAME="facetoface" TYPE="foreign" FIELDS="facetoface" REFTABLE="facetoface" REFFIELDS="id" PREVIOUS="primary"/>
Expand Down
34 changes: 34 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,5 +697,39 @@ function xmldb_facetoface_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2013010400, 'facetoface');
}

if ($oldversion < 2013010401) {

$table = new xmldb_table('facetoface');
$field = new xmldb_field('disablewithindays', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'approvalreqd');


Copy link
Contributor

Choose a reason for hiding this comment

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

Remove extra new line

if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// facetoface savepoint reached
upgrade_mod_savepoint(true, 2012051100, 'facetoface');

$table = new xmldb_table('facetoface_sessions');
$field = new xmldb_field('disablenewenrolldays', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'timemodified');

if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// facetoface savepoint reached
upgrade_mod_savepoint(true, 2012051200, 'facetoface');
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line and the comment and newline above so there is only only new line between this and the next line of code. This will break the upgrade


$table = new xmldb_table('facetoface_sessions');
$field = new xmldb_field('disableoption', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, 'disablenewenrolldays');

if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// facetoface savepoint reached
upgrade_mod_savepoint(true, 2012053002, 'facetoface');
Copy link
Contributor

Choose a reason for hiding this comment

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

This version number needs to match the version number at the start of the upgrade block

}

return $result;
}
12 changes: 12 additions & 0 deletions lang/en/facetoface.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,15 @@
The **Venue** displays on the \'Sign-up\' page, the \'View all sessions\' page and in all email notifications.';

$string['waitlistedmessage_help'] = 'This message is sent out whenever users sign-up for a wait-listed session.';

$string['disableautoenroll'] = 'Disable Auto Enrollment';
$string['disableautoenroll_help'] = 'Disable the waitlist auto enrollment option when within X days of a session';
$string['disablewithindays'] = 'Days before a session starts';
$string['disablewithindays_help'] = 'Set how many days before a session starts';

$string['disableoption'] = 'Disable New Enrollment';
$string['disableoption_help'] = 'Disable a new enrollment option when within X days of a session. 0 day means an user will not be enrolled on the same day the session is ';
$string['disablenewenrolldays'] = 'Days before a session starts';
$string['disablenewenrolldays_help'] = 'Set how many days before a session starts. 0 day means an user will not be enrolled on the same day the session is';
$string['showall'] = 'Show all';

15 changes: 11 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ function facetoface_update_attendees($session) {
$booked++;
}
}

$currenttime = new DateTime(date('c', time()));
$start = $DB->get_record('facetoface_sessions_dates', array('sessionid'=>$session->id));
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a function in lib.php called "facetoface_get_session_dates" with a parameter of $sessionid. Use this instead of making a database call

$starttime = new DateTime(date('c', $start->timestart));
Copy link
Contributor

Choose a reason for hiding this comment

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

A session may have many dates, this code will not work correctly if a session has more than one date

$interval = $starttime->diff($currenttime);
$diffdays = $interval->format('%a');
$disableddaysDB = $DB->get_record('facetoface', array('id'=>$session->id));
$disableddays = $disableddaysDB->disablewithindays;

// If booked less than capacity, book some new users
if ($booked < $capacity) {
Expand All @@ -606,8 +614,7 @@ function facetoface_update_attendees($session) {
break;
}

if ($user->statuscode == MDL_F2F_STATUS_WAITLISTED) {

if (($user->statuscode == MDL_F2F_STATUS_WAITLISTED)&($diffdays>$disableddays)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

in this you should use "&&" instead of "&". The way it is currently done it is performing a bitwise operation rather than a logical comparison. Also put a space on either side of the "&&" after changing

if (!facetoface_user_signup($session, $facetoface, $course, $user->discountcode, $user->notificationtype, MDL_F2F_STATUS_BOOKED, $user->id)) {
// rollback_sql();
return false;
Expand All @@ -618,7 +625,6 @@ function facetoface_update_attendees($session) {
}
}
}

return $session->id;
}

Expand Down Expand Up @@ -1447,7 +1453,8 @@ function facetoface_write_activity_attendance(&$worksheet, $startingrow, $faceto
s.facetoface = ?
AND d.sessionid = s.id
$locationcondition
ORDER BY s.datetimeknown, d.timestart";
ORDER BY s.datetimeknown, d.timestart";
Copy link
Contributor

Choose a reason for hiding this comment

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

This line has an extra space at the end which needs to be removed


Copy link
Contributor

Choose a reason for hiding this comment

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

remove extra new line


$sessions = $DB->get_records_sql($sql, array_merge(array($facetofaceid), $locationparam));

Expand Down
13 changes: 13 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ function definition()
$mform->addElement('textarea', 'waitlistedmessage', get_string('email:message', 'facetoface'), 'wrap="virtual" rows="15" cols="70"');
$mform->setDefault('waitlistedmessage', get_string('setting:defaultwaitlistedmessagedefault', 'facetoface'));

$mform->addElement('checkbox', 'disableautoenroll', get_string('disableautoenroll','facetoface'));
$mform->addHelpButton('disableautoenroll', 'disableautoenroll', 'facetoface');

$disableperiod = array();
for ($i=0; $i<=60; $i += 1) {
$disableperiod[$i] = $i;
}

$mform->addElement('select', 'disablewithindays', get_string('disablewithindays', 'facetoface'),$disableperiod);
$mform->setDefault('disablewithindays', 0);
$mform->disabledIf('disablewithindays', 'disableautoenroll');
$mform->addHelpButton('disablewithindays', 'disablewithindays', 'facetoface');

// CANCELLATION MESSAGE
$mform->addElement('header', 'cancellation', get_string('cancellationmessage', 'facetoface'));
$mform->addHelpButton('cancellation', 'cancellationmessage', 'facetoface');
Expand Down
25 changes: 22 additions & 3 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class mod_facetoface_renderer extends plugin_renderer_base {
* Builds session list table given an array of sessions
*/
public function print_session_list_table($customfields, $sessions, $viewattendees, $editsessions) {
$output = '';
global $DB;
$output = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

fix indenting


$tableheader = array();
foreach ($customfields as $field) {
Expand All @@ -32,6 +33,7 @@ public function print_session_list_table($customfields, $sessions, $viewattendee
$table = new html_table();
$table->summary = get_string('previoussessionslist', 'facetoface');
$table->head = $tableheader;
$table->width = '100%';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add styling by adding a class to the table and adding appropriate css to styles.css

Copy link
Author

Choose a reason for hiding this comment

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

To perform this:
I removed the line: $table->width = '100%';
I added the line: $table->attributes['class'] = 'sessionlisttable'; on renderer.php
And I added the line: .sessionlisttable { width: 100%; } on styles.css

But the width of the table is Not 100% on the output page. Can you please check what I did wrong. I looked into moodle api and into moodle forums and I see that is how it is done, but still I did not get the desired output.

$table->data = array();

foreach ($sessions as $session) {
Expand Down Expand Up @@ -138,8 +140,25 @@ public function print_session_list_table($customfields, $sessions, $viewattendee
$options .= html_writer::link('cancelsignup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface')));
}
elseif (!$sessionstarted and !$bookedsession) {
$options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('signup', 'facetoface'));
}
$currenttime = new DateTime(date('c', time()));
$start = $DB->get_record('facetoface_sessions_dates', array('sessionid'=>$session->id));
Copy link
Contributor

Choose a reason for hiding this comment

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

Database calls should not be make in the renderer. All data that is needed in the renderer should be fetched then passed into the rendering function

Copy link
Author

Choose a reason for hiding this comment

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

To fix this, can I write the code below in view.php

143                 $currenttime = new DateTime(date('c', time()));
144                 $start = $DB->get_record('facetoface_sessions_dates', array('sessionid'=>$session->id));
145                 $starttime = new DateTime(date('c', $start->timestart));
146                 $interval = $starttime->diff($currenttime);
147                 $diffdays =  $interval->format('%a');
148                 $disableddaysDB = $DB->get_record('facetoface_sessions', array('id'=>$session->id));
149                 $disableddays = $disableddaysDB->disablenewenrolldays;
150                 $disableoption = $disableddaysDB->disableoption;

and pass $disableoption as an argument in (print_session_list_table) that is being called in line 182 and 192 in view.php

Copy link
Contributor

Choose a reason for hiding this comment

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

I've had a closer look at the renderer and the date information is already available. If you look at the code around like 68 or renderer.php you will see that the code loops through all the dates for the session. You should be able to use this information to achieve what you need to. Note that the session may contain multiple dates so I'm assuming you will want to compare again the earliest one.

$starttime = new DateTime(date('c', $start->timestart));
$interval = $starttime->diff($currenttime);
$diffdays = $interval->format('%a');
$disableddaysDB = $DB->get_record('facetoface_sessions', array('id'=>$session->id));
Copy link
Contributor

Choose a reason for hiding this comment

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

This DB call is a little harder to remove but you should be able to pass through the information you need from where print_session_list_table is called. In view.php

$disableddays = $disableddaysDB->disablenewenrolldays;
$disableoption = $disableddaysDB->disableoption;

if($disableoption) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add space after if and before (

if($diffdays > $disableddays) {
$options .= new moodle_url('signup.php', array('s' => $session->id, 'backtoallsessions' => $session->facetoface), get_string('signup', 'facetoface'));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

need to move else on the same line as this bracket as shown in Moodle coding style guidelines

else {
$options .= new moodle_url('signup.php', array('s' => $session->id, 'backtoallsessions' => $session-facetoface), get_string('signup', 'facetoface'));
}
}

if (empty($options)) {
$options = get_string('none', 'facetoface');
}
Expand Down
15 changes: 15 additions & 0 deletions session_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ function definition() {
$mform->setType('details_editor', PARAM_RAW);
$mform->addHelpButton('details_editor', 'details', 'facetoface');

$mform->addElement('checkbox', 'disableoption', get_string('disableoption','facetoface'));
$mform->setType('disableoption', PARAM_INT);
$mform->setDefault('disableoption', 0);
$mform->addHelpButton('disableoption', 'disableoption', 'facetoface');

$disableperiod = array();
for ($i=0; $i<=60; $i += 1) {
$disableperiod[$i] = $i;
}
$mform->addElement('select', 'disablenewenrolldays', get_string('disablenewenrolldays', 'facetoface'), $disableperiod);
$mform->setType('disablenewenrolldays', PARAM_INT);
$mform->setDefault('disablenewenrolldays', 0);
$mform->disabledIf('disablenewenrolldays', 'disableoption');
$mform->addHelpButton('disablenewenrolldays', 'disablenewenrolldays', 'facetoface');

// Choose users for trainer roles
$rolenames = facetoface_get_trainer_roles();

Expand Down
17 changes: 17 additions & 0 deletions sessions.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@
$fromform->discountcost = 0;
}

if (empty($fromform->disablenewenrolldays)) {
$fromform->disablenewenrolldays = 0;
}

if (empty($fromform->disableoption))
Copy link
Contributor

Choose a reason for hiding this comment

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

move bracket onto same line as if statement

{
$fromform->disableoption = 0;
}

$sessiondates = array();
for ($i = 0; $i < $fromform->date_repeats; $i++) {
if (!empty($fromform->datedelete[$i])) {
Expand All @@ -147,6 +156,10 @@
$todb->normalcost = $fromform->normalcost;
$todb->discountcost = $fromform->discountcost;

$todb->details = $fromform->details;
$todb->disablenewenrolldays = $fromform->disablenewenrolldays;
$todb->disableoption = $fromform->disableoption;

$sessionid = null;
$transaction = $DB->start_delegated_transaction();

Expand Down Expand Up @@ -228,6 +241,10 @@
$toform->normalcost = $session->normalcost;
$toform->discountcost = $session->discountcost;

$toform->details = $session->details;
$toform->disableoption = $session->disableoption;
$toform->disablenewenrolldays = $session->disablenewenrolldays;

if ($session->sessiondates) {
$i = 0;
foreach ($session->sessiondates as $date) {
Expand Down