예제 #1
0
/**
 * Overwrites the content in the course-module object with the folder files list
 * if folder.display == FOLDER_DISPLAY_INLINE
 *
 * @param cm_info $cm
 */
function folder_cm_info_view(cm_info $cm)
{
    global $PAGE;
    if ($cm->uservisible && $cm->get_custom_data() && has_capability('mod/folder:view', $cm->context)) {
        // Restore folder object from customdata.
        // Note the field 'customdata' is not empty IF AND ONLY IF we display contens inline.
        // Otherwise the content is default.
        $folder = $cm->get_custom_data();
        $folder->id = (int) $cm->instance;
        $folder->course = (int) $cm->course;
        $folder->display = FOLDER_DISPLAY_INLINE;
        $folder->name = $cm->name;
        if (empty($folder->intro)) {
            $folder->intro = '';
        }
        if (empty($folder->introformat)) {
            $folder->introformat = FORMAT_MOODLE;
        }
        // display folder
        $renderer = $PAGE->get_renderer('mod_folder');
        $cm->set_content($renderer->display_folder($folder));
    }
}
예제 #2
0
/**
 * Overwrites the content in the course-module object with the Dataform view content
 * if dataform.inlineview is not empty
 *
 * @param cm_info $cm
 */
function dataform_cm_info_view(cm_info $cm)
{
    global $PAGE, $CFG, $OUTPUT;
    if (!$cm->uservisible) {
        return;
    }
    // Default content if not displaying inline view.
    if (!($dataform = $cm->customdata) or empty($dataform->inlineview)) {
        return;
    }
    if (!empty($dataform->embedded)) {
        $content = mod_dataform_dataform::get_content_embedded($dataform->id, $dataform->inlineview);
    } else {
        $content = mod_dataform_dataform::get_content_inline($dataform->id, $dataform->inlineview);
    }
    if (!empty($content)) {
        $cm->set_content($content);
    }
}
예제 #3
0
/**
 * Called when viewing course page.
 *
 * @param cm_info $coursemodule
 */
function facetoface_cm_info_view(cm_info $coursemodule) {
    global $USER, $DB;

    if (!($facetoface = $DB->get_record('facetoface', array('id' => $coursemodule->instance)))) {
        return null;
    }

    $coursemodule->set_name($facetoface->name);

    $contextmodule = context_module::instance($coursemodule->id);
    if (!has_capability('mod/facetoface:view', $contextmodule)) {
        return null; // Not allowed to view this activity.
    }
    $contextcourse = context_course::instance($coursemodule->course);
    // Can view attendees.
    $viewattendees = has_capability('mod/facetoface:viewattendees', $contextcourse);
    // Can see "view all sessions" link even if activity is hidden/currently unavailable.
    $iseditor = has_any_capability(array('mod/facetoface:viewattendees', 'mod/facetoface:editsessions',
                                        'mod/facetoface:addattendees', 'mod/facetoface:addattendees',
                                        'mod/facetoface:takeattendance'), $contextcourse);

    $table = html_writer::start_tag('table', array('class' => 'table90 inlinetable'));
    $timenow = time();

    $strviewallsessions = get_string('viewallsessions', 'facetoface');
    $sessions_url = new moodle_url('/mod/facetoface/view.php', array('f' => $facetoface->id));
    $htmlviewallsessions = html_writer::link($sessions_url, $strviewallsessions, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strviewallsessions));

    if ($submissions = facetoface_get_user_submissions($facetoface->id, $USER->id)) {
        // User has signedup for the instance.
        if (!$facetoface->multiplesessions) {
            // First submission only.
            $submissions = array(array_shift($submissions));
        }
        foreach ($submissions as $submission) {

            if ($session = facetoface_get_session($submission->sessionid)) {
                $allowcancellation = false;
                if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) {
                    $status = get_string('sessioninprogress', 'facetoface');
                    if ($submission->statuscode == MDL_F2F_STATUS_WAITLISTED) {
                        $allowcancellation = true;
                    }
                } else if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) {
                    $status = get_string('sessionover', 'facetoface');
                    if ($submission->statuscode == MDL_F2F_STATUS_WAITLISTED) {
                        $allowcancellation = true;
                    }
                } else {
                    $status = get_string('bookingstatus', 'facetoface');
                }

                $sessiondates = '';

                if ($session->datetimeknown) {
                    foreach ($session->sessiondates as $date) {
                        if (!empty($sessiondates)) {
                            $sessiondates .= html_writer::empty_tag('br');
                        }
                        $sessionobj = facetoface_format_session_times($date->timestart, $date->timefinish, $date->sessiontimezone);
                        if ($sessionobj->startdate == $sessionobj->enddate) {
                            $sessiondates .= get_string('sessionstartdateandtime', 'facetoface', $sessionobj);
                        } else {
                            $sessiondates .= get_string('sessionstartfinishdateandtime', 'facetoface', $sessionobj);
                        }
                    }
                } else {
                    $sessiondates = get_string('wait-listed', 'facetoface');
                }

                $span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice'));
                $options = html_writer::tag('tr', html_writer::tag('td', ' '));

                // Don't include the link to cancel a session if it has already occurred.
                $moreinfolink = '';
                $cancellink = '';
                $strcancelbooking = get_string('cancelbooking', 'facetoface');
                $cancel_url = new moodle_url('/mod/facetoface/cancelsignup.php', array('s' => $session->id));
                if (!facetoface_has_session_started($session, $timenow)) {
                    $strmoreinfo  = get_string('moreinfo', 'facetoface');
                    $signup_url   = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id));
                    $moreinfolink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($signup_url, $strmoreinfo, array('class' => 'f2fsessionlinks f2fsessioninfolink', 'title' => $strmoreinfo))));

                    $cancellink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($cancel_url, $strcancelbooking, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strcancelbooking))));
                    $options    = html_writer::tag('tr', html_writer::tag('td', $span));
                } else {
                    // Session is started.
                    if ($allowcancellation) {
                        $cancellink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($cancel_url, $strcancelbooking, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strcancelbooking))));
                    }
                }

                // Get room data.
                $roomtext = '';
                $roomdata = $DB->get_record('facetoface_room', array('id' => $session->roomid));
                if (!empty($roomdata)) {
                    $roomtext  = isset($roomdata->name)     ? format_string($roomdata->name)    .', '.html_writer::empty_tag('br') : '';
                    $roomtext .= isset($roomdata->building) ? format_string($roomdata->building).', '.html_writer::empty_tag('br') : '';
                    $roomtext .= isset($roomdata->address)  ? format_string($roomdata->address) .', '.html_writer::empty_tag('br') : '';
                }

                // Don't include the link to view attendees if user is lacking capability.
                $attendeeslink = '';
                if ($viewattendees) {
                    $strseeattendees = get_string('seeattendees', 'facetoface');
                    $attendees_url = new moodle_url('/mod/facetoface/attendees.php', array('s' => $session->id));
                    $attendeeslink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($attendees_url, $strseeattendees, array('class' => 'f2fsessionlinks f2fviewattendees', 'title' => $strseeattendees))));
                    $options       = html_writer::tag('tr', html_writer::tag('td', $span));
                }

                $table .= html_writer::start_tag('tr')
                    .html_writer::tag('td', $status, array('class' => 'f2fsessionnotice', 'colspan' => '2'))
                    .html_writer::end_tag('tr')
                    .html_writer::start_tag('tr', array('class' => 'f2fsessioninfo'))
                    .html_writer::tag('td', $roomtext . $sessiondates . html_writer::empty_tag('br'), array('class' => 'f2fwidth'))
                    .html_writer::tag('td', html_writer::start_tag('table'))
                        .$options
                        .$moreinfolink
                        .$attendeeslink
                        .$cancellink
                        .html_writer::end_tag('table')
                    .html_writer::end_tag('td')
                    .html_writer::end_tag('tr');
            }
        }
        // Add closing "view all sessions" row to table.
        $table .= html_writer::start_tag('tr')
            .html_writer::tag('td', $htmlviewallsessions, array('colspan' => '2'))
            .html_writer::end_tag('tr')
            .html_writer::end_tag('table');
    } else if ($sessions = facetoface_get_sessions($facetoface->id)) {
        if ($facetoface->display > 0) {
            $j=1;

            $sessionsinprogress = array();
            $futuresessions = array();

            foreach ($sessions as $session) {
                if (!facetoface_session_has_capacity($session, $contextmodule, MDL_F2F_STATUS_WAITLISTED) && !$session->allowoverbook) {
                    continue;
                }

                if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && !facetoface_is_session_in_progress($session, $timenow)) {
                    // Finished session, don't display.
                    continue;
                } else {
                    $signup = get_string('signup', 'facetoface');
                    $signup_url   = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id));
                    $moreinfolink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($signup_url, $signup, array('class' => 'f2fsessionlinks f2fsessioninfolink', 'title' => $signup))));

                    $span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice'));
                    $options = html_writer::tag('tr', html_writer::tag('td', $span));
                }

                $multidate = '';
                $sessiondate = '';
                $sessiontime = '';
                if ($session->datetimeknown) {
                    if (empty($session->sessiondates)) {
                        $sessiondate = get_string('unknowndate', 'facetoface');
                        $sessiontime = get_string('unknowntime', 'facetoface');
                    } else {
                        $sessionobj = facetoface_format_session_times($session->sessiondates[0]->timestart, $session->sessiondates[0]->timefinish, $session->sessiondates[0]->sessiontimezone);
                        if ($sessionobj->startdate == $sessionobj->enddate) {
                            $sessiondate = get_string('sessionstartdateandtime', 'facetoface', $sessionobj);
                        } else {
                            $sessiondate .= get_string('sessionstartfinishdateandtime', 'facetoface', $sessionobj);
                        }
                        if (count($session->sessiondates) > 1) {
                            $multidate = html_writer::start_tag('br') . get_string('multidate', 'facetoface');
                        }
                    }
                } else {
                    $sessiondate = get_string('wait-listed', 'facetoface');
                }

                $locationstring = '';
                $roomdata = $DB->get_record('facetoface_room', array('id' => $session->roomid));
                if (!empty($roomdata)) {
                    $locationstring  = isset($roomdata->name)     ? format_string($roomdata->name)    .', '.html_writer::empty_tag('br') : '';
                    $locationstring .= isset($roomdata->building) ? format_string($roomdata->building).', '.html_writer::empty_tag('br') : '';
                    $locationstring .= isset($roomdata->address)  ? format_string($roomdata->address) .', '.html_writer::empty_tag('br') : '';
                }

                $sessionobject = new stdClass();
                $sessionobject->location = $locationstring;
                $sessionobject->date = $sessiondate;
                $sessionobject->multidate = $multidate;

                if ($session->datetimeknown && (facetoface_has_session_started($session, $timenow)) && facetoface_is_session_in_progress($session, $timenow)) {
                    $sessionsinprogress[] = $sessionobject;
                } else {
                    $sessionobject->options = $options;
                    $sessionobject->moreinfolink = $moreinfolink;
                    $futuresessions[] = $sessionobject;
                }

                $j++;
                if ($j > $facetoface->display) {
                    break;
                }
            }

            if (!empty($sessionsinprogress)) {
                $table .= html_writer::start_tag('tr')
                    . html_writer::tag('td', get_string('sessioninprogress', 'facetoface'), array('class' => 'f2fsessionnotice', 'colspan' => '2'))
                    . html_writer::end_tag('tr');

                foreach ($sessionsinprogress as $session) {
                    $table .= html_writer::start_tag('tr')
                        .html_writer::tag('td', html_writer::tag('span', $session->location.$session->date.$session->multidate, array('class' => 'f2fsessiontime')), array('class' => 'f2fwidth'))
                        .html_writer::tag('td', html_writer::start_tag('table'))
                        .html_writer::tag('tr', html_writer::tag('td', ' '))
                        .html_writer::end_tag('table')
                        .html_writer::end_tag('td')
                        .html_writer::end_tag('tr');
                }
            }

            if (!empty($futuresessions)) {
                $table .= html_writer::start_tag('tr')
                    . html_writer::tag('td', get_string('signupforsession', 'facetoface'), array('class' => 'f2fsessionnotice', 'colspan' => '2'))
                    . html_writer::end_tag('tr');

                foreach ($futuresessions as $session) {
                    $table .= html_writer::start_tag('tr')
                        .html_writer::tag('td', html_writer::tag('span', $session->location.$session->date.$session->multidate, array('class' => 'f2fsessiontime')), array('class' => 'f2fwidth'))
                        .html_writer::tag('td', html_writer::start_tag('table'))
                        .$session->options
                        .$session->moreinfolink
                        .html_writer::end_tag('table')
                        .html_writer::end_tag('td')
                        .html_writer::end_tag('tr');
                }
            }

            $table .= html_writer::start_tag('tr')
                .html_writer::tag('td', ($iseditor || ($coursemodule->visible && $coursemodule->available)) ? $htmlviewallsessions : $strviewallsessions, array('colspan' => '2'))
                .html_writer::end_tag('tr')
                .html_writer::end_tag('table');
        } else {
            // Show only name if session display is set to zero.
            $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname f2fonepointfive'));
            $coursemodule->set_content($content);
            return;
        }
    } else if (has_capability('mod/facetoface:viewemptyactivities', $contextmodule)) {
        $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname f2fonepointfive'));
        $coursemodule->set_content($content);
        return;
    } else {
        // Nothing to display to this user.
        $coursemodule->set_content('');
        return;
    }
    $coursemodule->set_content($table);
}
예제 #4
0
/**
 * Called when viewing course page. Adds information to the course-module object.
 *
 * @see: /lib/modinfolib.php  class cm_info
 *
 * Allowed methods:
 * - {@link cm_info::set_after_edit_icons()}
 * - {@link cm_info::set_after_link()}
 * - {@link cm_info::set_content()}
 * - {@link cm_info::set_extra_classes()
 * 
 * @param cm_info $cm Course-module object
 */
function activitytask_cm_info_view(cm_info $cm)
{
    global $USER, $PAGE, $DB;
    //we will create a done button for marking whether or not an item is complete
    $done = '';
    $view = '';
    //create a view button
    if ($cm->customdata) {
        $view = '<a class="activitytask-button-view btn btn-primary"' . ' href="' . new moodle_url('/mod/activitytask/view.php?id=' . $cm->id) . '"' . '>' . get_string('btn_label_view', 'activitytask') . '</a>';
    }
    //let's see if the user has a capability to add an activity instance
    //this indicates that they are a teacher or the like and not a student
    //we don't need to show a done button if the user can edit the instance
    if (!has_capability('mod/activitytask:addinstance', context_course::instance($cm->course))) {
        //pull this users status for this activity
        $params = array('userid' => $USER->id, 'activitytask' => $cm->instance);
        $fields = 'datedone';
        $status = $DB->get_record('activitytask_status', $params, $fields);
        //if not done, then show a button
        if (!$status || !$status->datedone) {
            //add the javascript to make it possible to update using ajax
            $PAGE->requires->js('/mod/activitytask/activitytask.js');
            $done = '<a class="activitytask-button btn btn-primary"' . ' href="' . new moodle_url('/mod/activitytask/markdone.php?id=' . $cm->instance) . '"' . ' >' . get_string('btn_label_done', 'activitytask') . '</a>';
        } else {
            $dt = new DateTime($status->datedone);
            $done = '<span class="activitytask-done">(' . $dt->format('M j') . ')</span>';
        }
    }
    if (!$PAGE->user_is_editing()) {
        //if no view link is set, then the url will be blank
        if (!$cm->url) {
            //we have to add our own icon
            $cm->set_content('<img role="presentation" class="iconlarge activityicon" src="' . $cm->get_icon_url() . '">' . '<span class="instancename">' . $cm->name . '<span class="accesshide "> Activity Task</span>' . '</span>' . $view . $done);
        } else {
            $cm->set_after_link($view . $done);
        }
    }
}