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

Feature - Form that allow to create multiple slots by selecting dates in calendar (updated) #23

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0b29161
Merge branch 'hotfixes'
semteacher Nov 11, 2012
0f52ea7
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Nov 28, 2012
793935c
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Oct 6, 2013
4877520
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Dec 12, 2013
8d47315
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Dec 22, 2013
318b769
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Jan 13, 2014
045354a
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Feb 12, 2014
7896bae
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Mar 12, 2014
2cde4f4
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Apr 24, 2014
0c2edc7
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Jun 15, 2014
e291895
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Jul 25, 2014
ff04db2
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Oct 5, 2014
9d9bc9f
refactoring aperiodic session feature
semteacher Nov 23, 2014
b833082
refactoring
semteacher Nov 23, 2014
89f17f7
refactoring
semteacher Nov 23, 2014
de5a605
refactoring
semteacher Nov 23, 2014
e642737
clean-up
semteacher Nov 23, 2014
d63299c
refactoring
semteacher Nov 23, 2014
de1147a
fix "calendar pane" script for the "add aperiodic slots" function
semteacher Nov 23, 2014
dab6787
refactoring
semteacher Nov 24, 2014
2eecf01
clean-up
semteacher Nov 24, 2014
6419638
use same conflictsLocal setting as in "add single slot"
semteacher Nov 24, 2014
343430e
clean-up script
semteacher Nov 24, 2014
2680fb9
fix localization issue - calendar do not shown when a course language…
semteacher Nov 26, 2014
52df2c4
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Dec 13, 2014
a132f11
fix bug when was impossible to overlap conflict in the "remote" sched…
semteacher Dec 13, 2014
1013bf6
Merge branch 'master' into 02-addsession-aperiodic-v27
semteacher Dec 13, 2014
a29c62c
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Jul 21, 2015
bfbb943
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Jun 6, 2016
87339ba
Merge branch 'master' of git://github.com/bostelm/moodle-mod_scheduler
semteacher Nov 5, 2016
e68e5f9
Merge branch 'master' into 02-addsession-aperiodic-v27
semteacher Nov 5, 2016
f60db65
Moodle 3.1 version changes adopted in general
semteacher Nov 5, 2016
091767e
Adopt conflict management according v.3.1. style
semteacher Nov 5, 2016
cb73d91
remove obsolete functions
semteacher Nov 5, 2016
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
3 changes: 2 additions & 1 deletion lang/en/scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
$string['addappointment'] = 'Add another student';
$string['addcommands'] = 'Add slots';
$string['addondays'] = 'Add appointments on';
$string['addsession'] = 'Add repeated slots';
$string['addaperiodsession'] = 'Add repeated slots (via calendar)';
$string['addsession'] = 'Add repeated slots (by weekdays)';
$string['addsingleslot'] = 'Add single slot';
$string['addslot'] = 'You can add additional appointment slots at any time.';
$string['addstudenttogroup'] = 'Add this student to appointment group';
Expand Down
110 changes: 110 additions & 0 deletions slotforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,113 @@ public function validation($data, $files) {
return $errors;
}
}

class scheduler_addaperiodsession_form extends scheduler_slotform_base {

protected function definition() {

global $DB, $CFG, $COURSE;

$mform = $this->_form;

$listdates = "";
$mform->addElement('hidden', 'getlistdates', $listdates);

// Define Calendar panel
$mform->addElement('html', '<div id="calendar" class="yui3-skin-sam">');
$mform->addElement('html', '<div id="calContainer"></div>');
$mform->addElement('html', '</div>');
// Start and end time
$hours = array();
$minutes = array();
for ($i=0; $i<=23; $i++) {
$hours[$i] = sprintf("%02d", $i);
}
for ($i=0; $i<60; $i+=5) {
$minutes[$i] = sprintf("%02d", $i);
}

$timegroup = array();
$timegroup[] = $mform->createElement('static', 'timefrom', '', get_string('timefrom', 'scheduler'));
$timegroup[] = $mform->createElement('select', 'starthour', get_string('hour', 'form'), $hours);
$timegroup[] = $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes);
$timegroup[] = $mform->createElement('static', 'timeto', '', get_string('timeto', 'scheduler'));
$timegroup[] = $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours);
$timegroup[] = $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes);
$mform->addGroup($timegroup, 'timerange', get_string('timerange', 'scheduler'), null, false);

// Divide into slots?
$mform->addElement('selectyesno', 'divide', get_string('divide', 'scheduler'));
$mform->setDefault('divide', 1);

// Duration of the slot
$this->add_duration_field('minutesperslot');

// Break between slots
$this->add_minutes_field('break', 'break', 0, 'minutes');

// Force when overlap?
$mform->addElement('selectyesno', 'forcewhenoverlap', get_string('forcewhenoverlap', 'scheduler'));

// Ignore conflict checkbox
$mform->addElement('checkbox', 'ignoreconflicts', get_string('ignoreconflicts', 'scheduler'));
$mform->setDefault('ignoreconflicts', false);
$mform->addHelpButton('ignoreconflicts', 'ignoreconflicts', 'scheduler');

// Common fields
$this->add_base_fields();

// Display slot from date - relative
$hideuntilsel = array();
$hideuntilsel[0] = get_string('now', 'scheduler');
$hideuntilsel[DAYSECS] = get_string('onedaybefore', 'scheduler');
for ($i = 2; $i < 7; $i++) {
$hideuntilsel[DAYSECS*$i] = get_string('xdaysbefore', 'scheduler', $i);
}
$hideuntilsel[WEEKSECS] = get_string('oneweekbefore', 'scheduler');
for ($i = 2; $i < 7; $i++) {
$hideuntilsel[WEEKSECS*$i] = get_string('xweeksbefore', 'scheduler', $i);
}
$mform->addElement('select', 'hideuntilrel', get_string('displayfrom', 'scheduler'), $hideuntilsel);
$mform->setDefault('hideuntilsel', 0);

// E-mail reminder from
$remindersel = array();
$remindersel[-1] = get_string('never', 'scheduler');
$remindersel[0] = get_string('onthemorningofappointment', 'scheduler');
$remindersel[DAYSECS] = get_string('onedaybefore', 'scheduler');
for ($i = 2; $i < 7; $i++) {
$remindersel[DAYSECS * $i] = get_string('xdaysbefore', 'scheduler', $i);
}
$remindersel[WEEKSECS] = get_string('oneweekbefore', 'scheduler');
for ($i = 2; $i < 7; $i++) {
$remindersel[WEEKSECS*$i] = get_string('xweeksbefore', 'scheduler', $i);
}

$mform->addElement('select', 'emaildaterel', get_string('emailreminder', 'scheduler'), $remindersel);
$mform->setDefault('remindersel', -1);

$this->add_action_buttons();

}

public function validation($data, $files) {
$errors = parent::validation($data, $files);

// Time range is negative
$starttime = $data['starthour']*60+$data['startminute'];
$endtime = $data['endhour']*60+$data['endminute'];
if ($starttime > $endtime) {
$errors['endtime'] = get_string('negativerange', 'scheduler');
}

// Break must be nonnegative
if ($data['break'] < 0) {
$errors['breakgroup'] = get_string('breaknotnegative', 'scheduler');
}

// Conflict checks are now being done after submitting the form.

return $errors;
}
}
4 changes: 4 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,7 @@ body.path-mod-scheduler.jsenabled input.studentselectsubmit {
.path-mod-scheduler #id_datafieldhdr fieldset.fgroup span label {
margin-left: 0.4em;
}

.yui3-skin-sam .redtext {
color:#ff0000;
}
98 changes: 98 additions & 0 deletions teacherview.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,104 @@ function scheduler_delete_slots_from_ui(array $slots, $action) {
echo $output->action_message($msg);
}

function scheduler_action_doaddaperiodsession($scheduler, $formdata) {

global $DB, $output;

$data = (object) $formdata;

$listdatesarr = json_decode($data->getlistdates, true);

// Create as many slots of $duration on the given dates list $listdates and that do not conflict.
$countslots = 0;
$couldnotcreateslots = '';
$slot = new stdClass();
$slot->schedulerid = $scheduler->id;
$slot->teacherid = $data->teacherid;
$slot->appointmentlocation = $data->appointmentlocation;
$slot->exclusivity = $data->exclusivityenable ? $data->exclusivity : 0;
if ($data->divide) {
$slot->duration = $data->duration;
} else {
$slot->duration = $data->endhour * 60 + $data->endminute - $data->starthour * 60 - $data->startminute;
};
$slot->notes = '';
$slot->notesformat = FORMAT_HTML;
$slot->timemodified = time();

for ($d = 0; $d <= count($listdatesarr[0])-1; $d ++){
$year = date("Y", strtotime($listdatesarr[0][$d]));
$month = date("m", strtotime($listdatesarr[0][$d]));
$day = date("d", strtotime($listdatesarr[0][$d]));
$slot->starttime = make_timestamp($year, $month, $day, $data->starthour, $data->startminute);
$eventdate = usergetdate($slot->starttime);
$data->timestart = $slot->starttime;
$data->timeend = make_timestamp(date('Y',$data->timestart), date('m',$data->timestart), date('d',$data->timestart), $data->endhour, $data->endminute);

// this corrects around midnight bug
if ($data->timestart > $data->timeend){
$data->timeend += DAYSECS;
}
if ($data->hideuntilrel == 0) {
$slot->hideuntil = time();
} else {
$slot->hideuntil = make_timestamp($eventdate['year'], $eventdate['mon'], $eventdate['mday'], 6, 0) - $data->hideuntilrel;
}
if ($data->emaildaterel == -1) {
$slot->emaildate = 0;
} else {
$slot->emaildate = make_timestamp($eventdate['year'], $eventdate['mon'], $eventdate['mday'], 0, 0) - $data->emaildaterel;
}

while ($slot->starttime <= $data->timeend - $data->duration * 60) {
if (!isset($data->ignoreconflicts)) {
//check against ALL conflicts
$conflicts = $scheduler->get_conflicts($data->timestart, $data->timestart + $slot->duration * 60,
$data->teacherid, 0, SCHEDULER_ALL);
}
else {
//check against LOCAL conflicts only
$conflicts = $scheduler->get_conflicts($data->timestart, $data->timestart + $slot->duration * 60,
$data->teacherid, 0, SCHEDULER_SELF);
}
$resolvable = (boolean) $data->forcewhenoverlap;
foreach ($conflicts as $conflict) {
$resolvable = $resolvable
&& $conflict->isself == 1 // Do not delete slots outside the current scheduler.
&& $conflict->numstudents == 0; // Do not delete slots with bookings.
}

if ($conflicts) {
$cl = new scheduler_conflict_list();
$cl->add_conflicts($conflicts);
if (!$resolvable) {
print_string('conflictingslots', 'scheduler', userdate($data->timestart));
echo $output->doc_link('mod/scheduler/conflict', '', true);
echo $output->render($cl);
} else { // We force, so delete all conflicting before inserting.
foreach ($conflicts as $conflict) {
$cslot = $scheduler->get_slot($conflict->id);
\mod_scheduler\event\slot_deleted::create_from_slot($cslot, 'addsession-conflict')->trigger();
$cslot->delete();
}
print_string('deletedconflictingslots', 'scheduler', userdate($data->timestart));
echo $output->doc_link('mod/scheduler/conflict', '', true);
echo $output->render($cl);
}
}
if (!$conflicts || $resolvable) {
$slotid = $DB->insert_record('scheduler_slots', $slot, true, true);
$slotobj = $scheduler->get_slot($slotid);
\mod_scheduler\event\slot_added::create_from_slot($slotobj)->trigger();
$countslots++;
}
$slot->starttime += ($data->duration + $data->break) * 60;
$data->timestart += ($data->duration + $data->break) * 60;
}
}
echo $output->action_message(get_string('slotsadded', 'scheduler', $countslots));
}

// Require valid session key for all actions.
require_sesskey();

Expand Down
38 changes: 37 additions & 1 deletion teacherview.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function scheduler_print_schedulebox(scheduler_instance $scheduler, $studentid,
}

}
/************************************ Add session multiple slots form ****************************************/
/************************************ Add session multiple slots (by weekdays) form ****************************************/
if ($action == 'addsession') {

$actionurl = new moodle_url('/mod/scheduler/view.php',
Expand All @@ -189,6 +189,41 @@ function scheduler_print_schedulebox(scheduler_instance $scheduler, $studentid,
}
}

/************************************ Add session multiple slots (via YUI calendar) form ************************************/
if ($action == 'addaperiodsession') {

$courselang = substr($COURSE->lang, 0, 2); //need to localization option

$actionurl = new moodle_url('/mod/scheduler/view.php',
array('what' => 'addaperiodsession', 'id' => $cm->id, 'subpage' => $subpage));
$returnurl = new moodle_url('/mod/scheduler/view.php',
array('what' => 'view', 'id' => $cm->id, 'subpage' => $subpage));

if (!$scheduler->has_available_teachers()) {
print_error('needteachers', 'scheduler', $returnurl);
}

$mform = new scheduler_addaperiodsession_form($actionurl, $scheduler, $cm, $usergroups);

//process form response
if ($mform->is_cancelled()) {
redirect($returnurl);
} else if ($formdata = $mform->get_data()) {
scheduler_action_doaddaperiodsession($scheduler, $formdata);
} else {
//prepare and load the YUI module
$calconfig=array($courselang);
$calfunction ='M.mod_scheduler.calpane.init';
$calmodule = 'moodle-mod_scheduler-calpane';
$PAGE->requires->yui_module($calmodule, $calfunction, $calconfig);
//display form
echo $output->heading(get_string('addaperiodsession', 'scheduler'));
$mform->display();
echo $output->footer($course);
die;
}
}

/************************************ Schedule a student form ***********************************************/
if ($action == 'schedule') {
if ($subaction == 'dochooseslot') {
Expand Down Expand Up @@ -404,6 +439,7 @@ function scheduler_print_schedulebox(scheduler_instance $scheduler, $studentid,

$addbuttons = array();
$addbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'addsession')), 'addsession', 't/add');
$addbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'addaperiodsession')), 'addaperiodsession', 't/add');
$addbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'addslot')), 'addsingleslot', 't/add');
$commandbar->add_group(get_string('addcommands', 'scheduler'), $addbuttons);

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

$plugin->component = 'mod_scheduler'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2016100500; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2016103000; // The current module version (Date: YYYYMMDDXX).
$plugin->release = '3.x dev'; // Human-friendly version name.
$plugin->requires = 2016052300; // Requires Moodle 3.1.
$plugin->maturity = MATURITY_ALPHA; // Alpha development code - not for production sites!
Loading