Adding TWO new features

Adding TWO new features

by A B -
Number of replies: 7

hello,
I am trying to add two more features to facetoface which are listed below: (the post might be a little long, but I am trying to add as much detail as possible)
    1) Under "Wait-listed message" (while adding/editing facetoface activity) I am trying to add "Disable Auto Enrollment xx days before a session starts"
    2) Under adding/editing sessions, I am trying to add "Disable New Enrollment xx days before a session starts"

To add the above listed functionality these are the files I have edited so far:

I think the problem is in renderer.php (ANY SUGGESTIONS on how to display the session list and improving code is GREATLY APPRECIATED)

  • ./lang/en/facetoface.php : I added the following lines

    $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';
    $string['disablenewenrolldays'] = 'Days before a session starts';
    $string['disablenewenrolldays_help'] = 'Set how many days before a session starts';

  • ./session_form.php : (to display the disable new enrollment in add/edit session page)

        $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<=365; $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');
               

  • ./mod_form.php : (to display the disable auto enroll in the add/edit facetoface page)

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

        $disableperiod = array();
        for ($i=0; $i<=365; $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');
               

  • ./renderer.php : I add the following lines

           elseif (!$sessionstarted and !$bookedsession) {
               // $options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('signup', 'facetoface'));
               //AB
               // $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));
                $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));
                $disableddays = $disableddaysDB->disablenewenrolldays;
                $disableoption = $disableddaysDB->disableoption;

                if($disableoption)
                {
                        if($diffdays > $disableddays)
                        {
                                $options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('signup', 'facetoface'));                        }

                }
                else
                {
                        $options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('signup', 'facetoface'));
                }

    

 

  • ./db/upgrade.php :

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

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

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

    if ($oldversion < 2012051200) {
        $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');
    }

    if ($oldversion < 2012053002) {
        $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');
    }


  • ./db/install.xml
    • under the table "facetoface"

        <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"/>

    •     under table "facetoface_sessions"

        <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"/>

Average of ratings: Useful (1)
In reply to A B

Re: Adding TWO new features

by A B -

Quick update:

The session list table is printed if the session start data is past todays date. So the session status can be 'session over' or 'session in progress'. If there is a session that has not started yet, instead of showing session status as 'booking open', the whole session list table disappears, (including the one that were being shown as session over or session in progress)

I found out the block in ./view.php file that is calling the method "print_session_list_table" that is in ./renderer.php

The first line in // Upcoming sessions

 echo $OUTPUT->heading(get_string('upcomingsessions', 'facetoface'));
is being executed because you can see the "Upcoming sessions" text as heading... but the conditional statements after that is not executed.

If someone could shed a light, that'd be great.

(I hope I am making sense, if not please ask, and I will try to make it clear.)

In reply to A B

Re: Adding TWO new features

by A B -

Update 3: I think I know where the error is:

On ./renderer.php, the line I wrote

$start = $DB->get_record('facetoface_sessions_dates', array('sessionid'=>$session->id));

is the problem.

For getting all the records in $start from 'facetoface_sessions_dates' where sessionid = 'ID', According to this moodle documentation the above line seem ok (right?)...

Anyone, any help??

Thanks

In reply to A B

Re: Adding TWO new features

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, calling a database function in a renderer is a mistake.

The whole point of renderers is to separate the display code from the logic.

In reply to Tim Hunt

Re: Adding TWO new features

by A B -

Thank you for the answer... If you don't mind can you please point me where to call the database function.

Right now I am doing some tests, but its just hit and try for me right now.

In reply to A B

Re: Adding TWO new features

by Ramchadnra Pujari -

Yes Avas, you are great these also needed for classroom course. If you got any solution please impliment i am also intersted in this. Thank you so much and best of luck.

In reply to A B

Re: Adding TWO new features

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sorry, I don't know how the face-to-face code is organised.

In reply to A B

Re: Adding TWO new features

by A B -

New Update:

I am able to fix the session list not showing up, and I am able to implement the functionality of Disabling New Enrollment XX days before a session starts. (though the code might be messy and not up to standards mixed)

Now the only thing remaining is Disabling Auto Enrollment XX days before a session starts. (to be more clear, the person in the waiting list will be still in waiting list if xx or 'less' days are remaining for the session to start.)

Like I mentioned, I am new to moodle and facetoface, so my approach until now is just trial and error, so if anyone knows where the logic for auto enrolling is implemented, please let me know... (I'm guessing its in ./lib.php)