Esempio n. 1
0
function glossary_rss_feeds()
{
    global $CFG;
    $status = true;
    //Check CFG->enablerssfeeds
    if (empty($CFG->enablerssfeeds)) {
        debugging("DISABLED (admin variables)");
        //Check CFG->glossary_enablerssfeeds
    } else {
        if (empty($CFG->glossary_enablerssfeeds)) {
            debugging("DISABLED (module configuration)");
            //It's working so we start...
        } else {
            //Iterate over all glossaries
            if ($glossaries = get_records("glossary")) {
                foreach ($glossaries as $glossary) {
                    if (!empty($glossary->rsstype) && !empty($glossary->rssarticles) && $status) {
                        $filename = rss_file_name('glossary', $glossary);
                        // RSS file
                        //First let's make sure there is work to do by checking existing files
                        if (file_exists($filename)) {
                            if ($lastmodified = filemtime($filename)) {
                                if (!glossary_rss_newstuff($glossary, $lastmodified)) {
                                    continue;
                                }
                            }
                        }
                        //Ignore hidden forums
                        if (!instance_is_visible('glossary', $glossary)) {
                            if (file_exists($filename)) {
                                @unlink($filename);
                            }
                            continue;
                        }
                        mtrace("Updating RSS feed for " . format_string($glossary->name, true) . ", ID: {$glossary->id}");
                        //Get the XML contents
                        $result = glossary_rss_feed($glossary);
                        //Save the XML contents to file
                        if (!empty($result)) {
                            $status = rss_save_file("glossary", $glossary, $result);
                        }
                        //Some debug...
                        if (debugging()) {
                            if (empty($result)) {
                                echo "ID: {$glossary->id}-> (empty) ";
                            } else {
                                if (!empty($status)) {
                                    echo "ID: {$glossary->id}-> OK ";
                                } else {
                                    echo "ID: {$glossary->id}-> FAIL ";
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $status;
}
function lightboxgallery_rss_feeds()
{
    global $CFG;
    $status = true;
    if (!$CFG->enablerssfeeds) {
        debugging('DISABLED (admin variables)');
    } else {
        if (!get_config('lightboxgallery', 'enablerssfeeds')) {
            debugging('DISABLED (module configuration)');
        } else {
            if ($galleries = get_records('lightboxgallery')) {
                foreach ($galleries as $gallery) {
                    if ($gallery->rss && $status) {
                        $filename = rss_file_name('lightboxgallery', $gallery);
                        if (file_exists($filename)) {
                            if ($lastmodified = filemtime($filename)) {
                                if ($lastmodified > time() - HOURSECS) {
                                    continue;
                                }
                            }
                        }
                        if (!instance_is_visible('lightboxgallery', $gallery)) {
                            if (file_exists($filename)) {
                                @unlink($filename);
                            }
                            continue;
                        }
                        mtrace('Updating RSS feed for ' . format_string($gallery->name, true) . ', ID: ' . $gallery->id);
                        $result = lightboxgallery_rss_feed($gallery);
                        if (!empty($result)) {
                            $status = rss_save_file('lightboxgallery', $gallery, $result);
                        }
                        if (debugging()) {
                            if (empty($result)) {
                                echo 'ID: ' . $gallery->id . '-> (empty) ';
                            } else {
                                if (!empty($status)) {
                                    echo 'ID: ' . $gallery->id . '-> OK ';
                                } else {
                                    echo 'ID: ' . $gallery->id . '-> FAIL ';
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $status;
}
Esempio n. 3
0
function wiki_print_recent_activity($course, $isteacher, $timestart)
{
    /// Given a course and a time, this module should find recent activity
    /// that has occurred in wiki activities and print it out.
    /// Return true if there was output, or false is there was none.
    global $CFG;
    $sql = "SELECT l.*, cm.instance FROM {$CFG->prefix}log l \n                INNER JOIN {$CFG->prefix}course_modules cm ON l.cmid = cm.id \n            WHERE l.time > '{$timestart}' AND l.course = {$course->id} \n                AND l.module = 'wiki' AND action LIKE 'edit%'\n            ORDER BY l.time ASC";
    if (!($logs = get_records_sql($sql))) {
        return false;
    }
    foreach ($logs as $log) {
        //Create a temp valid module structure (course,id)
        $tempmod = new Object();
        $tempmod->course = $log->course;
        $tempmod->id = $log->instance;
        //Obtain the visible property from the instance
        $modvisible = instance_is_visible($log->module, $tempmod);
        //Only if the mod is visible
        if ($modvisible) {
            $wikis[$log->info] = wiki_log_info($log);
            $wikis[$log->info]->pagename = $log->info;
            $wikis[$log->info]->time = $log->time;
            $wikis[$log->info]->url = str_replace('&', '&', $log->url);
        }
    }
    if (isset($wikis)) {
        $content = true;
        print_headline(get_string('updatedwikipages', 'wiki') . ':', 3);
        foreach ($wikis as $wiki) {
            print_recent_activity_note($wiki->time, $wiki, $wiki->pagename, $CFG->wwwroot . '/mod/wiki/' . $wiki->url);
        }
    }
    return true;
    //  True if anything was printed, otherwise false
}
Esempio n. 4
0
/**
 * Print recent activity from all assignments in a given course
 *
 * This is used by the recent activity block
 */
function assignment_print_recent_activity($course, $isteacher, $timestart)
{
    global $CFG;
    $content = false;
    $assignments = array();
    if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'assignment\' AND ' . 'action = \'upload\' ', 'time ASC'))) {
        return false;
    }
    foreach ($logs as $log) {
        //Create a temp valid module structure (course,id)
        $tempmod = new object();
        $tempmod->course = $log->course;
        $tempmod->id = $log->info;
        //Obtain the visible property from the instance
        $modvisible = instance_is_visible($log->module, $tempmod);
        //Only if the mod is visible
        if ($modvisible) {
            if ($info = assignment_log_info($log)) {
                $assignments[$log->info] = $info;
                $assignments[$log->info]->time = $log->time;
                $assignments[$log->info]->url = str_replace('&', '&', $log->url);
            }
        }
    }
    if (!empty($assignments)) {
        print_headline(get_string('newsubmissions', 'assignment') . ':');
        foreach ($assignments as $assignment) {
            print_recent_activity_note($assignment->time, $assignment, $assignment->name, $CFG->wwwroot . '/mod/assignment/' . $assignment->url);
        }
        $content = true;
    }
    return $content;
}
Esempio n. 5
0
    $learningtable->align[] = 'center';
}
/// Now let's process the learning forums
if ($course->id != SITEID) {
    // Only real courses have learning forums
    // Add extra field for section number, at the front
    if ($course->format == 'weeks' or $course->format == 'weekscss') {
        array_unshift($learningtable->head, $strweek);
    } else {
        array_unshift($learningtable->head, $strsection);
    }
    array_unshift($learningtable->align, "center");
    if ($learningforums) {
        $currentsection = "";
        foreach ($learningforums as $key => $forum) {
            $forum->visible = instance_is_visible("forum", $forum) || has_capability('moodle/course:view', $coursecontext);
            $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
            if (!groups_course_module_visible($cm)) {
                continue;
            }
            $currentgroup = groups_get_activity_group($cm);
            $groupmode = groups_get_activity_groupmode($cm);
            $cantaccessagroup = $groupmode and !has_capability('moodle/site:accessallgroups', $context) and !mygroupid($course->id);
            if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
                $count = count_records("forum_discussions", "forum", "{$forum->id}", "groupid", $currentgroup);
            } else {
                $count = count_records("forum_discussions", "forum", "{$forum->id}");
            }
            if ($usetracking) {
                if ($forum->trackingtype == FORUM_TRACKING_ON || !isset($untracked[$forum->id])) {
Esempio n. 6
0
/**
 * Runs any processes that must be run
 * after a lesson insert/update
 *
 * @param object $lesson Lesson form data
 * @return void
 **/
function lesson_process_post_save(&$lesson)
{
    if ($events = get_records_select('event', "modulename = 'lesson' and instance = '{$lesson->id}'")) {
        foreach ($events as $event) {
            delete_event($event->id);
        }
    }
    $event = new stdClass();
    $event->description = $lesson->name;
    $event->courseid = $lesson->course;
    $event->groupid = 0;
    $event->userid = 0;
    $event->modulename = 'lesson';
    $event->instance = $lesson->id;
    $event->eventtype = 'open';
    $event->timestart = $lesson->available;
    $event->visible = instance_is_visible('lesson', $lesson);
    $event->timeduration = $lesson->deadline - $lesson->available;
    if ($lesson->deadline and $lesson->available and $event->timeduration <= LESSON_MAX_EVENT_LENGTH) {
        // Single event for the whole lesson.
        $event->name = $lesson->name;
        add_event($event);
    } else {
        // Separate start and end events.
        $event->timeduration = 0;
        if ($lesson->available) {
            $event->name = $lesson->name . ' (' . get_string('lessonopens', 'lesson') . ')';
            add_event($event);
            unset($event->id);
            // So we can use the same object for the close event.
        }
        if ($lesson->deadline) {
            $event->name = $lesson->name . ' (' . get_string('lessoncloses', 'lesson') . ')';
            $event->timestart = $lesson->deadline;
            $event->eventtype = 'close';
            add_event($event);
        }
    }
}
Esempio n. 7
0
/**
 * Updates the calendar events associated to the given workshop
 *
 * @param stdClass $workshop the workshop instance record
 * @param int $cmid course module id
 */
function workshop_calendar_update(stdClass $workshop, $cmid) {
    global $DB;

    // get the currently registered events so that we can re-use their ids
    $currentevents = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id));

    // the common properties for all events
    $base = new stdClass();
    $base->description  = format_module_intro('workshop', $workshop, $cmid, false);
    $base->courseid     = $workshop->course;
    $base->groupid      = 0;
    $base->userid       = 0;
    $base->modulename   = 'workshop';
    $base->eventtype    = 'pluginname';
    $base->instance     = $workshop->id;
    $base->visible      = instance_is_visible('workshop', $workshop);
    $base->timeduration = 0;

    if ($workshop->submissionstart) {
        $event = clone($base);
        $event->name = get_string('submissionstartevent', 'mod_workshop', $workshop->name);
        $event->timestart = $workshop->submissionstart;
        if ($reusedevent = array_shift($currentevents)) {
            $event->id = $reusedevent->id;
        } else {
            // should not be set but just in case
            unset($event->id);
        }
        // update() will reuse a db record if the id field is set
        $eventobj = new calendar_event($event);
        $eventobj->update($event, false);
    }

    if ($workshop->submissionend) {
        $event = clone($base);
        $event->name = get_string('submissionendevent', 'mod_workshop', $workshop->name);
        $event->timestart = $workshop->submissionend;
        if ($reusedevent = array_shift($currentevents)) {
            $event->id = $reusedevent->id;
        } else {
            // should not be set but just in case
            unset($event->id);
        }
        // update() will reuse a db record if the id field is set
        $eventobj = new calendar_event($event);
        $eventobj->update($event, false);
    }

    if ($workshop->assessmentstart) {
        $event = clone($base);
        $event->name = get_string('assessmentstartevent', 'mod_workshop', $workshop->name);
        $event->timestart = $workshop->assessmentstart;
        if ($reusedevent = array_shift($currentevents)) {
            $event->id = $reusedevent->id;
        } else {
            // should not be set but just in case
            unset($event->id);
        }
        // update() will reuse a db record if the id field is set
        $eventobj = new calendar_event($event);
        $eventobj->update($event, false);
    }

    if ($workshop->assessmentend) {
        $event = clone($base);
        $event->name = get_string('assessmentendevent', 'mod_workshop', $workshop->name);
        $event->timestart = $workshop->assessmentend;
        if ($reusedevent = array_shift($currentevents)) {
            $event->id = $reusedevent->id;
        } else {
            // should not be set but just in case
            unset($event->id);
        }
        // update() will reuse a db record if the id field is set
        $eventobj = new calendar_event($event);
        $eventobj->update($event, false);
    }

    // delete any leftover events
    foreach ($currentevents as $oldevent) {
        $oldevent = calendar_event::load($oldevent);
        $oldevent->delete();
    }
}
Esempio n. 8
0
function chat_print_recent_activity($course, $isteacher, $timestart)
{
    /// Given a course and a date, prints a summary of all chat rooms
    /// that currently have people in them.
    /// This function is called from course/lib.php: print_recent_activity()
    global $CFG;
    $timeold = time() - $CFG->chat_old_ping;
    $lastpingsearch = $CFG->chat_method == 'sockets' ? '' : 'AND cu.lastping > \'' . $timeold . '\'';
    if (!($chatusers = get_records_sql("SELECT u.id, cu.chatid, u.firstname, u.lastname\n                                        FROM {$CFG->prefix}chat_users cu,\n                                             {$CFG->prefix}chat ch,\n                                             {$CFG->prefix}user u\n                                       WHERE cu.userid = u.id\n                                         AND cu.chatid = ch.id {$lastpingsearch}\n                                         AND ch.course = '{$course->id}'\n                                       ORDER BY cu.chatid ASC"))) {
        return false;
    }
    $outputstarted = false;
    $current = 0;
    foreach ($chatusers as $chatuser) {
        if ($current != $chatuser->chatid) {
            if ($current) {
                echo '</ul></div>';
                // room
                $current = 0;
            }
            if ($chat = get_record('chat', 'id', $chatuser->chatid)) {
                // we find the course module id
                $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id);
                $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                // needs to be fixed
                if (!(has_capability('mod/chat:readlog', $context) or instance_is_visible('chat', $chat))) {
                    // Chat hidden to students
                    continue;
                }
                if (!$outputstarted) {
                    print_headline(get_string('currentchats', 'chat') . ':');
                    $outputstarted = true;
                }
                echo '<div class="room"><p class="head"><a href="' . $CFG->wwwroot . '/mod/chat/view.php?c=' . $chat->id . '">' . format_string($chat->name, true) . '</a></p><ul>';
            }
            $current = $chatuser->chatid;
        }
        $fullname = fullname($chatuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
        echo '<li class="info name">' . $fullname . '</li>';
    }
    if ($current) {
        echo '</ul></div>';
        // room
    }
    return true;
}
Esempio n. 9
0
/**
 * Run periodically to check for vpl visibility update
 *
 * @uses $CFG
 * @return boolean
 **/
function vpl_cron()
{
    global $DB;
    $rebuilds = array();
    $now = time();
    $sql = 'SELECT id, startdate, duedate, course, name
    FROM {vpl}
    WHERE startdate > ?
      and startdate <= ?
      and (duedate > ? or duedate = 0)';
    $parms = array($now - 2 * 3600, $now, $now);
    $vpls = $DB->get_records_sql($sql, $parms);
    foreach ($vpls as $instance) {
        if (!instance_is_visible(VPL, $instance)) {
            $vpl = new mod_vpl(null, $instance->id);
            echo 'Setting visible "' . s($vpl->get_printable_name()) . '"';
            $cm = $vpl->get_course_module();
            $rebuilds[$cm->id] = $cm;
        }
    }
    foreach ($rebuilds as $cmid => $cm) {
        set_coursemodule_visible($cm->id, true);
        rebuild_course_cache($cm->course);
    }
    return true;
}
Esempio n. 10
0
/**
 * Given a course and a date, prints a summary of all the new
 * messages posted in the course since that date
 */
function forum_print_recent_activity($course, $isteacher, $timestart)
{
    global $CFG;
    $LIKE = sql_ilike();
    $heading = false;
    $content = false;
    if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'forum\' AND ' . 'action ' . $LIKE . ' \'add %\' ', 'time ASC'))) {
        return false;
    }
    $strftimerecent = get_string('strftimerecent');
    $mygroupid = mygroupid($course->id);
    $groupmode = array();
    // To cache group modes
    $count = 0;
    foreach ($logs as $log) {
        //Get post info, I'll need it later
        if ($post = forum_get_post_from_log($log)) {
            //Create a temp valid module structure (course,id)
            $tempmod = new object();
            $tempmod->course = $log->course;
            $tempmod->id = $post->forum;
            //Obtain the visible property from the instance
            $coursecontext = get_context_instance(CONTEXT_COURSE, $tempmod->course);
            $modvisible = instance_is_visible('forum', $tempmod) || has_capability('moodle/course:viewhiddenactivities', $coursecontext);
        }
        //Only if the post exists and mod is visible
        if ($post && $modvisible) {
            if (!isset($cm[$post->forum])) {
                $cm[$post->forum] = get_coursemodule_from_instance('forum', $post->forum, $course->id);
            }
            $modcontext = get_context_instance(CONTEXT_MODULE, $cm[$post->forum]->id);
            // Check whether this is belongs to a discussion in a group that
            // should NOT be accessible to the current user
            if (!has_capability('moodle/site:accessallgroups', $modcontext) && $post->groupid != -1) {
                // Open discussions have groupid -1
                $groupmode[$post->forum] = groups_get_activity_groupmode($cm[$post->forum]);
                if ($groupmode[$post->forum]) {
                    //hope i didn't break anything
                    if (!@in_array($mygroupid, $post->groupid)) {
                        continue;
                    }
                }
            }
            if (!$heading) {
                print_headline(get_string('newforumposts', 'forum') . ':', 3);
                $heading = true;
                $content = true;
            }
            $date = userdate($post->modified, $strftimerecent);
            $subjectclass = $log->action == 'add discussion' ? ' bold' : '';
            //Accessibility: markup as a list.
            if ($count < 1) {
                echo "\n<ul class='unlist'>\n";
            }
            $count++;
            echo '<li><div class="head">' . '<div class="date">' . $date . '</div>' . '<div class="name">' . fullname($post, has_capability('moodle/site:viewfullnames', $coursecontext)) . '</div>' . '</div>';
            echo '<div class="info' . $subjectclass . '">';
            echo '"<a href="' . $CFG->wwwroot . '/mod/forum/' . str_replace('&', '&amp;', $log->url) . '">';
            $post->subject = break_up_long_words(format_string($post->subject, true));
            echo $post->subject;
            echo "</a>\"</div></li>\n";
        }
    }
    echo "</ul>\n";
    return $content;
}
Esempio n. 11
0
/**
 * This function updates the events associated to the lesson.
 * If $override is non-zero, then it updates only the events
 * associated with the specified override.
 *
 * @uses LESSON_MAX_EVENT_LENGTH
 * @param object $lesson the lesson object.
 * @param object $override (optional) limit to a specific override
 */
function lesson_update_events($lesson, $override = null)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/calendar/lib.php';
    // Load the old events relating to this lesson.
    $conds = array('modulename' => 'lesson', 'instance' => $lesson->id);
    if (!empty($override)) {
        // Only load events for this override.
        if (isset($override->userid)) {
            $conds['userid'] = $override->userid;
        } else {
            $conds['groupid'] = $override->groupid;
        }
    }
    $oldevents = $DB->get_records('event', $conds);
    // Now make a todo list of all that needs to be updated.
    if (empty($override)) {
        // We are updating the primary settings for the lesson, so we
        // need to add all the overrides.
        $overrides = $DB->get_records('lesson_overrides', array('lessonid' => $lesson->id));
        // As well as the original lesson (empty override).
        $overrides[] = new stdClass();
    } else {
        // Just do the one override.
        $overrides = array($override);
    }
    foreach ($overrides as $current) {
        $groupid = isset($current->groupid) ? $current->groupid : 0;
        $userid = isset($current->userid) ? $current->userid : 0;
        $available = isset($current->available) ? $current->available : $lesson->available;
        $deadline = isset($current->deadline) ? $current->deadline : $lesson->deadline;
        // Only add open/close events for an override if they differ from the lesson default.
        $addopen = empty($current->id) || !empty($current->available);
        $addclose = empty($current->id) || !empty($current->deadline);
        if (!empty($lesson->coursemodule)) {
            $cmid = $lesson->coursemodule;
        } else {
            $cmid = get_coursemodule_from_instance('lesson', $lesson->id, $lesson->course)->id;
        }
        $event = new stdClass();
        $event->description = format_module_intro('lesson', $lesson, $cmid);
        // Events module won't show user events when the courseid is nonzero.
        $event->courseid = $userid ? 0 : $lesson->course;
        $event->groupid = $groupid;
        $event->userid = $userid;
        $event->modulename = 'lesson';
        $event->instance = $lesson->id;
        $event->timestart = $available;
        $event->timeduration = max($deadline - $available, 0);
        $event->visible = instance_is_visible('lesson', $lesson);
        $event->eventtype = 'open';
        // Determine the event name.
        if ($groupid) {
            $params = new stdClass();
            $params->lesson = $lesson->name;
            $params->group = groups_get_group_name($groupid);
            if ($params->group === false) {
                // Group doesn't exist, just skip it.
                continue;
            }
            $eventname = get_string('overridegroupeventname', 'lesson', $params);
        } else {
            if ($userid) {
                $params = new stdClass();
                $params->lesson = $lesson->name;
                $eventname = get_string('overrideusereventname', 'lesson', $params);
            } else {
                $eventname = $lesson->name;
            }
        }
        if ($addopen or $addclose) {
            if ($deadline and $available and $event->timeduration <= LESSON_MAX_EVENT_LENGTH) {
                // Single event for the whole lesson.
                if ($oldevent = array_shift($oldevents)) {
                    $event->id = $oldevent->id;
                } else {
                    unset($event->id);
                }
                $event->name = $eventname;
                // The method calendar_event::create will reuse a db record if the id field is set.
                calendar_event::create($event);
            } else {
                // Separate start and end events.
                $event->timeduration = 0;
                if ($available && $addopen) {
                    if ($oldevent = array_shift($oldevents)) {
                        $event->id = $oldevent->id;
                    } else {
                        unset($event->id);
                    }
                    $event->name = $eventname . ' (' . get_string('lessonopens', 'lesson') . ')';
                    // The method calendar_event::create will reuse a db record if the id field is set.
                    calendar_event::create($event);
                }
                if ($deadline && $addclose) {
                    if ($oldevent = array_shift($oldevents)) {
                        $event->id = $oldevent->id;
                    } else {
                        unset($event->id);
                    }
                    $event->name = $eventname . ' (' . get_string('lessoncloses', 'lesson') . ')';
                    $event->timestart = $deadline;
                    $event->eventtype = 'close';
                    calendar_event::create($event);
                }
            }
        }
    }
    // Delete any leftover events.
    foreach ($oldevents as $badevent) {
        $badevent = calendar_event::load($badevent);
        $badevent->delete();
    }
}
/**
 * This function is called at the end of qcreate_add_instance
 * and qcreate_update_instance, to do the common processing.
 *
 * @param object $qcreate the qcreate object.
 */
function qcreate_after_add_or_update($qcreate)
{
    global $COURSE;
    // Update the events relating to this qcreate.
    // This is slightly inefficient, deleting the old events and creating new ones. However,
    // there are at most two events, and this keeps the code simpler.
    if ($events = get_records_select('event', "modulename = 'qcreate' and instance = '{$qcreate->id}'")) {
        foreach ($events as $event) {
            delete_event($event->id);
        }
    }
    $event = new stdClass();
    $event->description = $qcreate->intro;
    $event->courseid = $qcreate->course;
    $event->groupid = 0;
    $event->userid = 0;
    $event->modulename = 'qcreate';
    $event->instance = $qcreate->id;
    $event->timestart = $qcreate->timeopen;
    $event->timeduration = $qcreate->timeclose - $qcreate->timeopen;
    $event->visible = instance_is_visible('qcreate', $qcreate);
    $event->eventtype = 'open';
    if ($qcreate->timeclose and $qcreate->timeopen and $event->timeduration <= QCREATE_MAX_EVENT_LENGTH) {
        // Single event for the whole qcreate.
        $event->name = $qcreate->name;
        add_event($event);
    } else {
        // Separate start and end events.
        $event->timeduration = 0;
        if ($qcreate->timeopen) {
            $event->name = $qcreate->name . ' (' . get_string('qcreateopens', 'qcreate') . ')';
            add_event($event);
            unset($event->id);
            // So we can use the same object for the close event.
        }
        if ($qcreate->timeclose) {
            $event->name = $qcreate->name . ' (' . get_string('qcreatecloses', 'qcreate') . ')';
            $event->timestart = $qcreate->timeclose;
            $event->eventtype = 'close';
            add_event($event);
        }
    }
    //update related grade item
    qcreate_grade_item_update(stripslashes_recursive($qcreate));
}
Esempio n. 13
0
function lesson_update_instance($lesson)
{
    /// Given an object containing all the necessary data,
    /// (defined by the form in mod.html) this function
    /// will update an existing instance with new data.
    $lesson->timemodified = time();
    $lesson->id = $lesson->instance;
    if (empty($lesson->timespent) or !is_numeric($lesson->timespent) or $lesson->timespent < 0) {
        $lesson->timespent = 0;
    }
    if (!isset($lesson->completed)) {
        $lesson->completed = 0;
    }
    if (empty($lesson->gradebetterthan) or !is_numeric($lesson->gradebetterthan) or $lesson->gradebetterthan < 0) {
        $lesson->gradebetterthan = 0;
    } else {
        if ($lesson->gradebetterthan > 100) {
            $lesson->gradebetterthan = 100;
        }
    }
    // conditions for dependency
    $conditions = new stdClass();
    $conditions->timespent = $lesson->timespent;
    $conditions->completed = $lesson->completed;
    $conditions->gradebetterthan = $lesson->gradebetterthan;
    $lesson->conditions = addslashes(serialize($conditions));
    unset($lesson->timespent);
    unset($lesson->completed);
    unset($lesson->gradebetterthan);
    if (!empty($lesson->password)) {
        $lesson->password = md5($lesson->password);
    } else {
        unset($lesson->password);
    }
    if ($lesson->lessondefault) {
        $default = new stdClass();
        $default = clone $lesson;
        unset($default->lessondefault);
        unset($default->name);
        unset($default->timemodified);
        unset($default->available);
        unset($default->deadline);
        if ($default->id = get_field("lesson_default", "id", "course", $default->course)) {
            update_record("lesson_default", $default);
        } else {
            insert_record("lesson_default", $default);
        }
    } else {
        unset($lesson->lessondefault);
    }
    // update the calendar events (credit goes to quiz module)
    if ($events = get_records_select('event', "modulename = 'lesson' and instance = '{$lesson->id}'")) {
        foreach ($events as $event) {
            delete_event($event->id);
        }
    }
    $event = new stdClass();
    $event->name = $lesson->name;
    $event->description = $lesson->name;
    $event->courseid = $lesson->course;
    $event->groupid = 0;
    $event->userid = 0;
    $event->modulename = 'lesson';
    $event->instance = $lesson->id;
    $event->eventtype = 'open';
    $event->timestart = $lesson->available;
    $event->visible = instance_is_visible('lesson', $lesson);
    $event->timeduration = $lesson->deadline - $lesson->available;
    if ($event->timeduration > LESSON_MAX_EVENT_LENGTH) {
        /// Long durations create two events
        $event2 = clone $event;
        $event->name .= ' (' . get_string('lessonopens', 'lesson') . ')';
        $event->timeduration = 0;
        $event2->timestart = $lesson->deadline;
        $event2->eventtype = 'close';
        $event2->timeduration = 0;
        $event2->name .= ' (' . get_string('lessoncloses', 'lesson') . ')';
        add_event($event2);
    }
    add_event($event);
    return update_record("lesson", $lesson);
}
Esempio n. 14
0
/**
 * Updates an instance of the grouptool in the database
 *
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will update an existing instance with new data.
 *
 * @param stdClass $grouptool An object from the form in mod_form.php
 * @param mod_grouptool_mod_form $mform
 * @return boolean Success/Fail
 */
function grouptool_update_instance(stdClass $grouptool, mod_grouptool_mod_form $mform = null)
{
    global $DB, $CFG;
    $grouptool->timemodified = time();
    $grouptool->id = $grouptool->instance;
    $cmid = $grouptool->coursemodule;
    if (!isset($grouptool->use_size)) {
        $grouptool->use_size = 0;
    }
    if (!isset($grouptool->use_individual)) {
        $grouptool->use_individual = 0;
    }
    if (!isset($grouptool->use_queue)) {
        $queues = $DB->count_records_sql("SELECT COUNT(DISTINCT queues.id)\n                                            FROM {grouptool_agrps} agrps\n                                       LEFT JOIN {grouptool_queued} queues ON queues.agrpid = agrps.id\n                                           WHERE agrps.grouptoolid = ?", array($grouptool->instance));
        if (!empty($queues)) {
            $grouptool->use_queue = 1;
        } else {
            $grouptool->use_queue = 0;
        }
    }
    if (!isset($grouptool->allow_multiple)) {
        $grouptool->allow_multiple = 0;
    }
    $grouptool->grpsize = clean_param($grouptool->grpsize, PARAM_INT);
    $grouptool->choose_min = clean_param($grouptool->choose_min, PARAM_INT);
    $grouptool->choose_max = clean_param($grouptool->choose_max, PARAM_INT);
    // Register students if immediate registration has been turned on!
    if ($grouptool->immediate_reg) {
        require_once $CFG->dirroot . '/mod/grouptool/locallib.php';
        $instance = new mod_grouptool($grouptool->coursemodule, $grouptool);
        $instance->push_registrations();
    }
    require_once $CFG->dirroot . '/calendar/lib.php';
    $event = new stdClass();
    if ($grouptool->allow_reg) {
        $event->name = get_string('registration_period_start', 'grouptool') . ' ' . $grouptool->name;
    } else {
        $event->name = $grouptool->name . ' ' . get_string('availabledate', 'grouptool');
    }
    $event->description = format_module_intro('grouptool', $grouptool, $grouptool->coursemodule);
    if (!empty($grouptool->timeavailable)) {
        $event->timestart = $grouptool->timeavailable;
    } else {
        $grouptool->timecreated = $DB->get_field('grouptool', 'timecreated', array('id' => $grouptool->id));
        $event->timestart = $grouptool->timecreated;
    }
    $event->visible = instance_is_visible('grouptool', $grouptool);
    $event->timeduration = 0;
    if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'grouptool', 'instance' => $grouptool->id, 'eventtype' => 'availablefrom'))) {
        $calendarevent = calendar_event::load($event->id);
        $calendarevent->update($event, false);
    } else {
        $event->courseid = $grouptool->course;
        $event->groupid = 0;
        $event->userid = 0;
        $event->modulename = 'grouptool';
        $event->instance = $grouptool->id;
        /*
         *  For activity module's events, this can be used to set the alternative text of the
         *  event icon. Set it to 'pluginname' unless you have a better string.
         */
        $event->eventtype = 'availablefrom';
        calendar_event::create($event);
    }
    if ($grouptool->timedue != 0) {
        unset($event->id);
        unset($calendarevent);
        if ($grouptool->allow_reg) {
            $event->name = get_string('registration_period_end', 'grouptool') . ' ' . $grouptool->name;
        } else {
            $event->name = $grouptool->name . ' ' . get_string('duedate', 'grouptool');
        }
        $event->timestart = $grouptool->timedue;
        $event->eventtype = 'deadline';
        /*
         *  For activity module's events, this can be used to set the alternative text of the
         *  event icon. Set it to 'pluginname' unless you have a better string.
         */
        if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'grouptool', 'instance' => $grouptool->id, 'eventtype' => 'due'))) {
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->update($event, false);
        } else {
            unset($event->id);
            $event->courseid = $grouptool->course;
            // We've got some permission issues with calendar_event::create() so we work around that!
            $calev = new calendar_event($event);
            $calev->update($event, false);
        }
    } else {
        if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'grouptool', 'instance' => $grouptool->id, 'eventtype' => 'due'))) {
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->delete(true);
        }
    }
    $coursegroups = $DB->get_fieldset_select('groups', 'id', 'courseid = ?', array($grouptool->course));
    foreach ($coursegroups as $groupid) {
        if (!$DB->record_exists('grouptool_agrps', array('grouptoolid' => $grouptool->instance, 'groupid' => $groupid))) {
            $record = new stdClass();
            $record->grouptoolid = $grouptool->instance;
            $record->groupid = $groupid;
            $record->sort_order = 9999999;
            $record->grpsize = $grouptool->grpsize;
            $record->active = 0;
            $DB->insert_record('grouptool_agrps', $record);
        }
    }
    // We have to override the functions fetching of data, because it's not updated yet!
    grouptool_update_queues($grouptool);
    return $DB->update_record('grouptool', $grouptool);
}
Esempio n. 15
0
/**
 * @todo Document this function
 */
function forum_menu_list($course)
{
    $menu = array();
    $currentgroup = get_and_set_current_group($course, groupmode($course));
    if ($forums = get_all_instances_in_course("forum", $course)) {
        if ($course->format == 'weeks') {
            $strsection = get_string('week');
        } else {
            $strsection = get_string('topic');
        }
        foreach ($forums as $forum) {
            if ($cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
                $context = get_context_instance(CONTEXT_MODULE, $cm->id);
                if (!isset($forum->visible)) {
                    if (!instance_is_visible("forum", $forum) && !has_capability('moodle/course:viewhiddenactivities', $context)) {
                        continue;
                    }
                }
                $groupmode = groupmode($course, $cm);
                // Groups are being used
                if ($groupmode == SEPARATEGROUPS && $currentgroup === false && !has_capability('moodle/site:accessallgroups', $context)) {
                    continue;
                }
            }
            $menu[$forum->id] = format_string($forum->name, true);
        }
    }
    return $menu;
}
Esempio n. 16
0
/**
 * This creates new calendar events given as timeavailablefrom and timeclose by $data.
 *
 * @param stdClass $data
 * @return void
 */
function data_set_events($data)
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/calendar/lib.php';
    // Get CMID if not sent as part of $data.
    if (!isset($data->coursemodule)) {
        $cm = get_coursemodule_from_instance('data', $data->id, $data->course);
        $data->coursemodule = $cm->id;
    }
    // Data start calendar events.
    $event = new stdClass();
    if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'data', 'instance' => $data->id, 'eventtype' => 'open'))) {
        if ($data->timeavailablefrom > 0) {
            // Calendar event exists so update it.
            $event->name = get_string('calendarstart', 'data', $data->name);
            $event->description = format_module_intro('data', $data, $data->coursemodule);
            $event->timestart = $data->timeavailablefrom;
            $event->visible = instance_is_visible('data', $data);
            $event->timeduration = 0;
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->update($event);
        } else {
            // Calendar event is on longer needed.
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->delete();
        }
    } else {
        // Event doesn't exist so create one.
        if (isset($data->timeavailablefrom) && $data->timeavailablefrom > 0) {
            $event->name = get_string('calendarstart', 'data', $data->name);
            $event->description = format_module_intro('data', $data, $data->coursemodule);
            $event->courseid = $data->course;
            $event->groupid = 0;
            $event->userid = 0;
            $event->modulename = 'data';
            $event->instance = $data->id;
            $event->eventtype = 'open';
            $event->timestart = $data->timeavailablefrom;
            $event->visible = instance_is_visible('data', $data);
            $event->timeduration = 0;
            calendar_event::create($event);
        }
    }
    // Data end calendar events.
    $event = new stdClass();
    if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'data', 'instance' => $data->id, 'eventtype' => 'close'))) {
        if ($data->timeavailableto > 0) {
            // Calendar event exists so update it.
            $event->name = get_string('calendarend', 'data', $data->name);
            $event->description = format_module_intro('data', $data, $data->coursemodule);
            $event->timestart = $data->timeavailableto;
            $event->visible = instance_is_visible('data', $data);
            $event->timeduration = 0;
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->update($event);
        } else {
            // Calendar event is on longer needed.
            $calendarevent = calendar_event::load($event->id);
            $calendarevent->delete();
        }
    } else {
        // Event doesn't exist so create one.
        if (isset($data->timeavailableto) && $data->timeavailableto > 0) {
            $event = new stdClass();
            $event->name = get_string('calendarend', 'data', $data->name);
            $event->description = format_module_intro('data', $data, $data->coursemodule);
            $event->courseid = $data->course;
            $event->groupid = 0;
            $event->userid = 0;
            $event->modulename = 'data';
            $event->instance = $data->id;
            $event->eventtype = 'close';
            $event->timestart = $data->timeavailableto;
            $event->visible = instance_is_visible('data', $data);
            $event->timeduration = 0;
            calendar_event::create($event);
        }
    }
}
Esempio n. 17
0
function booking_update_options($optionvalues)
{
    global $DB, $CFG;
    require_once "{$CFG->dirroot}/mod/booking/locallib.php";
    $bokingUtils = new booking_utils();
    $booking = $DB->get_record('booking', array('id' => $optionvalues->bookingid));
    $option = new stdClass();
    $option->bookingid = $optionvalues->bookingid;
    $option->text = trim($optionvalues->text);
    $option->conectedoption = $optionvalues->conectedoption;
    $option->howmanyusers = $optionvalues->howmanyusers;
    $option->removeafterminutes = $optionvalues->removeafterminutes;
    $option->notificationtext = $optionvalues->notificationtext;
    $option->disablebookingusers = $optionvalues->disablebookingusers;
    $option->sent = 0;
    $option->location = trim($optionvalues->location);
    $option->institution = trim($optionvalues->institution);
    $option->address = trim($optionvalues->address);
    $option->daystonotify = $optionvalues->daystonotify;
    $option->pollurl = $optionvalues->pollurl;
    $option->pollurlteachers = $optionvalues->pollurlteachers;
    if ($optionvalues->limitanswers == 0) {
        $option->limitanswers = 0;
        $option->maxanswers = 0;
        $option->maxoverbooking = 0;
    } else {
        $option->maxanswers = $optionvalues->maxanswers;
        $option->maxoverbooking = $optionvalues->maxoverbooking;
        $option->limitanswers = 1;
    }
    if (isset($optionvalues->restrictanswerperiod)) {
        $option->bookingclosingtime = $optionvalues->bookingclosingtime;
    } else {
        $option->bookingclosingtime = 0;
    }
    $option->courseid = $optionvalues->courseid;
    if (isset($optionvalues->startendtimeknown)) {
        $option->coursestarttime = $optionvalues->coursestarttime;
        $option->courseendtime = $optionvalues->courseendtime;
    } else {
        $option->coursestarttime = 0;
        $option->courseendtime = 0;
    }
    $option->description = $optionvalues->description;
    $option->limitanswers = $optionvalues->limitanswers;
    $option->timemodified = time();
    if (isset($optionvalues->optionid) && !empty($optionvalues->optionid) && $optionvalues->id != "add") {
        //existing booking record
        $option->id = $optionvalues->optionid;
        if (isset($optionvalues->text) && $optionvalues->text != '') {
            $event = new stdClass();
            $event->id = $DB->get_field('booking_options', 'calendarid', array('id' => $option->id));
            $groupid = $DB->get_field('booking_options', 'groupid', array('id' => $option->id));
            $coursestarttime = $DB->get_field('booking_options', 'coursestarttime', array('id' => $option->id));
            if ($coursestarttime != $optionvalues->coursestarttime) {
                $option->sent = 0;
            } else {
                $option->sent = $DB->get_field('booking_options', 'sent', array('id' => $option->id));
            }
            $option->groupid = $bokingUtils->group($booking, $option);
            $whereis = '';
            if (strlen($option->location) > 0) {
                $whereis = '<p>' . get_string('location', 'booking') . ': ' . $option->location . '</p>';
            }
            if ($event->id > 0) {
                // event exist
                if (isset($optionvalues->addtocalendar)) {
                    $event->name = $option->text;
                    $event->description = $option->description . $whereis;
                    $event->courseid = $option->courseid;
                    if ($option->courseid == 0) {
                        $event->courseid = $booking->course;
                    }
                    $event->groupid = 0;
                    $event->userid = 0;
                    $event->modulename = 'booking';
                    $event->instance = $option->bookingid;
                    $event->eventtype = 'booking';
                    $event->timestart = $option->coursestarttime;
                    $event->visible = instance_is_visible('booking', $booking);
                    $event->timeduration = $option->courseendtime - $option->coursestarttime;
                    if ($DB->record_exists("event", array('id' => $event->id))) {
                        $calendarevent = calendar_event::load($event->id);
                        $calendarevent->update($event);
                        $option->calendarid = $event->id;
                        $option->addtocalendar = $optionvalues->addtocalendar;
                    } else {
                        unset($event->id);
                        $tmpEvent = calendar_event::create($event);
                        $option->calendarid = $tmpEvent->id;
                    }
                } else {
                    // Delete event if exist
                    $event = calendar_event::load($event->id);
                    $event->delete(true);
                    $option->addtocalendar = 0;
                    $option->calendarid = 0;
                }
            } else {
                $option->addtocalendar = 0;
                $option->calendarid = 0;
                // Insert into calendar
                if (isset($optionvalues->addtocalendar)) {
                    $event = new stdClass();
                    $event->name = $option->text;
                    $event->description = $option->description . $whereis;
                    $event->courseid = $option->courseid;
                    if ($option->courseid == 0) {
                        $event->courseid = $booking->course;
                    }
                    $event->groupid = 0;
                    $event->userid = 0;
                    $event->modulename = 'booking';
                    $event->instance = $option->bookingid;
                    $event->eventtype = 'booking';
                    $event->timestart = $option->coursestarttime;
                    $event->visible = instance_is_visible('booking', $booking);
                    $event->timeduration = $option->courseendtime - $option->coursestarttime;
                    $tmpEvent = calendar_event::create($event);
                    $option->calendarid = $tmpEvent->id;
                    $option->addtocalendar = $optionvalues->addtocalendar;
                }
            }
            $DB->update_record("booking_options", $option);
            return $option->id;
        }
    } elseif (isset($optionvalues->text) && $optionvalues->text != '') {
        $option->addtocalendar = 0;
        $option->calendarid = 0;
        // Insert into calendar
        // We add a new booking_options?
        $whereis = '';
        if (strlen($option->location) > 0) {
            $whereis = '<p>' . get_string('location', 'booking') . ': ' . $option->location . '</p>';
        }
        if (isset($optionvalues->addtocalendar)) {
            $event = new stdClass();
            $event->name = $option->text;
            $event->description = $option->description . $whereis;
            $event->courseid = $option->courseid;
            if ($option->courseid == 0) {
                $event->courseid = $booking->course;
            }
            $event->groupid = 0;
            $event->userid = 0;
            $event->modulename = 'booking';
            $event->instance = $option->bookingid;
            $event->eventtype = 'booking';
            $event->timestart = $option->coursestarttime;
            $event->visible = instance_is_visible('booking', $booking);
            $event->timeduration = $option->courseendtime;
            $tmpEvent = calendar_event::create($event);
            $option->calendarid = $tmpEvent->id;
            $option->addtocalendar = $optionvalues->addtocalendar;
        }
        $option->groupid = $bokingUtils->group($booking, $option);
        return $DB->insert_record("booking_options", $option);
    }
}
function questionnaire_set_events($questionnaire)
{
    // Adding the questionnaire to the eventtable.
    global $DB;
    if ($events = $DB->get_records('event', array('modulename' => 'questionnaire', 'instance' => $questionnaire->id))) {
        foreach ($events as $event) {
            $event = calendar_event::load($event);
            $event->delete();
        }
    }
    // The open-event.
    $event = new stdClass();
    $event->description = $questionnaire->name;
    $event->courseid = $questionnaire->course;
    $event->groupid = 0;
    $event->userid = 0;
    $event->modulename = 'questionnaire';
    $event->instance = $questionnaire->id;
    $event->eventtype = 'open';
    $event->timestart = $questionnaire->opendate;
    $event->visible = instance_is_visible('questionnaire', $questionnaire);
    $event->timeduration = $questionnaire->closedate - $questionnaire->opendate;
    if ($questionnaire->closedate && $questionnaire->opendate && $event->timeduration <= QUESTIONNAIRE_MAX_EVENT_LENGTH) {
        // Single event for the whole questionnaire.
        $event->name = $questionnaire->name;
        calendar_event::create($event);
    } else {
        // Separate start and end events.
        $event->timeduration = 0;
        if ($questionnaire->opendate) {
            $event->name = $questionnaire->name . ' (' . get_string('questionnaireopens', 'questionnaire') . ')';
            calendar_event::create($event);
            unset($event->id);
            // So we can use the same object for the close event.
        }
        if ($questionnaire->closedate) {
            $event->name = $questionnaire->name . ' (' . get_string('questionnairecloses', 'questionnaire') . ')';
            $event->timestart = $questionnaire->closedate;
            $event->eventtype = 'close';
            calendar_event::create($event);
        }
    }
}
Esempio n. 19
0
/**
 * This function updates the events associated to the quiz.
 * If $override is non-zero, then it updates only the events
 * associated with the specified override.
 *
 * @uses QUIZ_MAX_EVENT_LENGTH
 * @param object $quiz the quiz object.
 * @param object optional $override limit to a specific override
 */
function quiz_update_events($quiz, $override = null) {
    global $DB;

    // Load the old events relating to this quiz.
    $conds = array('modulename'=>'quiz',
                   'instance'=>$quiz->id);
    if (!empty($override)) {
        // Only load events for this override.
        $conds['groupid'] = isset($override->groupid)?  $override->groupid : 0;
        $conds['userid'] = isset($override->userid)?  $override->userid : 0;
    }
    $oldevents = $DB->get_records('event', $conds);

    // Now make a todo list of all that needs to be updated.
    if (empty($override)) {
        // We are updating the primary settings for the quiz, so we
        // need to add all the overrides.
        $overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id));
        // As well as the original quiz (empty override).
        $overrides[] = new stdClass();
    } else {
        // Just do the one override.
        $overrides = array($override);
    }

    foreach ($overrides as $current) {
        $groupid   = isset($current->groupid)?  $current->groupid : 0;
        $userid    = isset($current->userid)? $current->userid : 0;
        $timeopen  = isset($current->timeopen)?  $current->timeopen : $quiz->timeopen;
        $timeclose = isset($current->timeclose)? $current->timeclose : $quiz->timeclose;

        // Only add open/close events for an override if they differ from the quiz default.
        $addopen  = empty($current->id) || !empty($current->timeopen);
        $addclose = empty($current->id) || !empty($current->timeclose);

        if (!empty($quiz->coursemodule)) {
            $cmid = $quiz->coursemodule;
        } else {
            $cmid = get_coursemodule_from_instance('quiz', $quiz->id, $quiz->course)->id;
        }

        $event = new stdClass();
        $event->description = format_module_intro('quiz', $quiz, $cmid);
        // Events module won't show user events when the courseid is nonzero.
        $event->courseid    = ($userid) ? 0 : $quiz->course;
        $event->groupid     = $groupid;
        $event->userid      = $userid;
        $event->modulename  = 'quiz';
        $event->instance    = $quiz->id;
        $event->timestart   = $timeopen;
        $event->timeduration = max($timeclose - $timeopen, 0);
        $event->visible     = instance_is_visible('quiz', $quiz);
        $event->eventtype   = 'open';

        // Determine the event name.
        if ($groupid) {
            $params = new stdClass();
            $params->quiz = $quiz->name;
            $params->group = groups_get_group_name($groupid);
            if ($params->group === false) {
                // Group doesn't exist, just skip it.
                continue;
            }
            $eventname = get_string('overridegroupeventname', 'quiz', $params);
        } else if ($userid) {
            $params = new stdClass();
            $params->quiz = $quiz->name;
            $eventname = get_string('overrideusereventname', 'quiz', $params);
        } else {
            $eventname = $quiz->name;
        }
        if ($addopen or $addclose) {
            if ($timeclose and $timeopen and $event->timeduration <= QUIZ_MAX_EVENT_LENGTH) {
                // Single event for the whole quiz.
                if ($oldevent = array_shift($oldevents)) {
                    $event->id = $oldevent->id;
                } else {
                    unset($event->id);
                }
                $event->name = $eventname;
                // The method calendar_event::create will reuse a db record if the id field is set.
                calendar_event::create($event);
            } else {
                // Separate start and end events.
                $event->timeduration  = 0;
                if ($timeopen && $addopen) {
                    if ($oldevent = array_shift($oldevents)) {
                        $event->id = $oldevent->id;
                    } else {
                        unset($event->id);
                    }
                    $event->name = $eventname.' ('.get_string('quizopens', 'quiz').')';
                    // The method calendar_event::create will reuse a db record if the id field is set.
                    calendar_event::create($event);
                }
                if ($timeclose && $addclose) {
                    if ($oldevent = array_shift($oldevents)) {
                        $event->id = $oldevent->id;
                    } else {
                        unset($event->id);
                    }
                    $event->name      = $eventname.' ('.get_string('quizcloses', 'quiz').')';
                    $event->timestart = $timeclose;
                    $event->eventtype = 'close';
                    calendar_event::create($event);
                }
            }
        }
    }

    // Delete any leftover events.
    foreach ($oldevents as $badevent) {
        $badevent = calendar_event::load($badevent);
        $badevent->delete();
    }
}
Esempio n. 20
0
function dimdim_print_recent_activity($course, $isteacher, $timestart)
{
    /// Given a course and a date, prints a summary of all dimdim rooms
    /// that currently have people in them.
    /// This function is called from course/lib.php: print_recent_activity()
    global $CFG;
    $timeold = time() - $CFG->dimdim_old_ping;
    $lastpingsearch = $CFG->dimdim_method == 'sockets' ? '' : 'AND cu.lastping > \'' . $timeold . '\'';
    if (!($dimdimusers = get_records_sql("SELECT u.id, cu.dimdimid, u.firstname, u.lastname\n                                        FROM {$CFG->prefix}dimdim_users as cu,\n                                             {$CFG->prefix}dimdim as ch,\n                                             {$CFG->prefix}user as u\n                                       WHERE cu.userid = u.id\n                                         AND cu.dimdimid = ch.id {$lastpingsearch}\n                                         AND ch.course = '{$course->id}'\n                                       ORDER BY cu.dimdimid ASC"))) {
        return false;
    }
    $isteacher = isteacher($course->id);
    $outputstarted = false;
    $current = 0;
    foreach ($dimdimusers as $dimdimuser) {
        if ($current != $dimdimuser->dimdimid) {
            if ($current) {
                echo '</ul></div>';
                // room
                $current = 0;
            }
            if ($dimdim = get_record('dimdim', 'id', $dimdimuser->dimdimid)) {
                if (!($isteacher or instance_is_visible('dimdim', $dimdim))) {
                    // dimdim hidden to students
                    continue;
                }
                if (!$outputstarted) {
                    print_headline(get_string('currentdimdims', 'dimdim') . ':');
                    $outputstarted = true;
                }
                echo '<div class="room"><p class="head"><a href="' . $CFG->wwwroot . '/mod/dimdim/view.php?c=' . $dimdim->id . '">' . format_string($dimdim->name, true) . '</a></p><ul>';
            }
            $current = $dimdimuser->dimdimid;
        }
        $fullname = fullname($dimdimuser, $isteacher);
        echo '<li class="info name">' . $fullname . '</li>';
    }
    if ($current) {
        echo '</ul></div>';
        // room
    }
    return true;
}
Esempio n. 21
0
/**
 * This function is called at the end of quiz_add_instance
 * and quiz_update_instance, to do the common processing.
 *
 * @param object $quiz the quiz object.
 */
function quiz_after_add_or_update($quiz)
{
    // Save the feedback
    delete_records('quiz_feedback', 'quizid', $quiz->id);
    for ($i = 0; $i <= $quiz->feedbackboundarycount; $i += 1) {
        $feedback = new stdClass();
        $feedback->quizid = $quiz->id;
        $feedback->feedbacktext = $quiz->feedbacktext[$i];
        $feedback->mingrade = $quiz->feedbackboundaries[$i];
        $feedback->maxgrade = $quiz->feedbackboundaries[$i - 1];
        if (!insert_record('quiz_feedback', $feedback, false)) {
            return "Could not save quiz feedback.";
        }
    }
    // Update the events relating to this quiz.
    // This is slightly inefficient, deleting the old events and creating new ones. However,
    // there are at most two events, and this keeps the code simpler.
    if ($events = get_records_select('event', "modulename = 'quiz' and instance = '{$quiz->id}'")) {
        foreach ($events as $event) {
            delete_event($event->id);
        }
    }
    $event = new stdClass();
    $event->description = $quiz->intro;
    $event->courseid = $quiz->course;
    $event->groupid = 0;
    $event->userid = 0;
    $event->modulename = 'quiz';
    $event->instance = $quiz->id;
    $event->timestart = $quiz->timeopen;
    $event->timeduration = $quiz->timeclose - $quiz->timeopen;
    $event->visible = instance_is_visible('quiz', $quiz);
    $event->eventtype = 'open';
    if ($quiz->timeclose and $quiz->timeopen and $event->timeduration <= QUIZ_MAX_EVENT_LENGTH) {
        // Single event for the whole quiz.
        $event->name = $quiz->name;
        add_event($event);
    } else {
        // Separate start and end events.
        $event->timeduration = 0;
        if ($quiz->timeopen) {
            $event->name = $quiz->name . ' (' . get_string('quizopens', 'quiz') . ')';
            add_event($event);
            unset($event->id);
            // So we can use the same object for the close event.
        }
        if ($quiz->timeclose) {
            $event->name = $quiz->name . ' (' . get_string('quizcloses', 'quiz') . ')';
            $event->timestart = $quiz->timeclose;
            $event->eventtype = 'close';
            add_event($event);
        }
    }
    //update related grade item
    quiz_grade_item_update(stripslashes_recursive($quiz));
}
Esempio n. 22
0
function feedback_restore_mods($mod, $restore)
{
    global $CFG;
    // $allValues = array();
    // $allTrackings = array();
    $status = true;
    $restore_userdata = restore_userdata_selected($restore, 'feedback', $mod->id);
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //check of older backupversion of feedback
        $version = intval(backup_todb($info['MOD']['#']['VERSION']['0']['#']));
        //Now, build the feedback record structure
        $feedback->course = $restore->course_id;
        $feedback->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $feedback->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
        $feedback->anonymous = backup_todb($info['MOD']['#']['ANONYMOUS']['0']['#']);
        $feedback->email_notification = backup_todb($info['MOD']['#']['EMAILNOTIFICATION']['0']['#']);
        $feedback->multiple_submit = backup_todb($info['MOD']['#']['MULTIPLESUBMIT']['0']['#']);
        $feedback->autonumbering = backup_todb($info['MOD']['#']['AUTONUMBERING']['0']['#']);
        $feedback->page_after_submit = backup_todb($info['MOD']['#']['PAGEAFTERSUB']['0']['#']);
        $feedback->site_after_submit = backup_todb($info['MOD']['#']['SITEAFTERSUB']['0']['#']);
        $feedback->publish_stats = backup_todb($info['MOD']['#']['PUBLISHSTATS']['0']['#']);
        $feedback->timeopen = backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
        $feedback->timeclose = backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
        $feedback->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the feedback
        $newid = insert_record("feedback", $feedback);
        //create events
        // the open-event
        if ($feedback->timeopen > 0) {
            $event = NULL;
            $event->name = get_string('start', 'feedback') . ' ' . $feedback->name;
            $event->description = $feedback->summary;
            $event->courseid = $feedback->course;
            $event->groupid = 0;
            $event->userid = 0;
            $event->modulename = 'feedback';
            $event->instance = $newid;
            $event->eventtype = 'open';
            $event->timestart = $feedback->timeopen;
            $event->visible = instance_is_visible('feedback', $feedback);
            if ($feedback->timeclose > 0) {
                $event->timeduration = $feedback->timeclose - $feedback->timeopen;
            } else {
                $event->timeduration = 0;
            }
            add_event($event);
        }
        // the close-event
        if ($feedback->timeclose > 0) {
            $event = NULL;
            $event->name = get_string('stop', 'feedback') . ' ' . $feedback->name;
            $event->description = $feedback->summary;
            $event->courseid = $feedback->course;
            $event->groupid = 0;
            $event->userid = 0;
            $event->modulename = 'feedback';
            $event->instance = $newid;
            $event->eventtype = 'close';
            $event->timestart = $feedback->timeclose;
            $event->visible = instance_is_visible('feedback', $feedback);
            $event->timeduration = 0;
            add_event($event);
        }
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<ul><li>" . get_string("modulename", "feedback") . " \"" . $feedback->name . "\"<br />";
        }
        backup_flush(300);
        if ($newid) {
            //Now, build the feedback_item record structure
            $items = $info['MOD']['#']['ITEMS']['0']['#']['ITEM'];
            for ($i = 0; $i < sizeof($items); $i++) {
                $item_info = $items[$i];
                $item->feedback = $newid;
                $item->template = 0;
                $item->name = backup_todb($item_info['#']['NAME']['0']['#']);
                $item->presentation = backup_todb($item_info['#']['PRESENTATION']['0']['#']);
                $item->presentation = str_replace("\n", '', $item->presentation);
                if ($version >= 1) {
                    $item->typ = backup_todb($item_info['#']['TYP']['0']['#']);
                    $item->hasvalue = backup_todb($item_info['#']['HASVALUE']['0']['#']);
                    switch ($item->typ) {
                        case 'radio':
                            $item->typ = 'multichoice';
                            $item->presentation = 'r' . FEEDBACK_MULTICHOICERESTORE_TYPE_SEP . $item->presentation;
                            break;
                        case 'check':
                            $item->typ = 'multichoice';
                            $item->presentation = 'c' . FEEDBACK_MULTICHOICERESTORE_TYPE_SEP . $item->presentation;
                            break;
                        case 'dropdown':
                            $item->typ = 'multichoice';
                            $item->presentation = 'd' . FEEDBACK_MULTICHOICERESTORE_TYPE_SEP . $item->presentation;
                            break;
                        case 'radiorated':
                            $item->typ = 'multichoicerated';
                            $item->presentation = 'r' . FEEDBACK_MULTICHOICERESTORE_TYPE_SEP . $item->presentation;
                            break;
                        case 'dropdownrated':
                            $item->typ = 'multichoicerated';
                            $item->presentation = 'd' . FEEDBACK_MULTICHOICERESTORE_TYPE_SEP . $item->presentation;
                            break;
                    }
                } else {
                    $oldtyp = intval(backup_todb($item_info['#']['TYP']['0']['#']));
                    switch ($oldtyp) {
                        case 0:
                            $item->typ = 'label';
                            $item->hasvalue = 0;
                            break;
                        case 1:
                            $item->typ = 'textfield';
                            $item->hasvalue = 1;
                            break;
                        case 2:
                            $item->typ = 'textarea';
                            $item->hasvalue = 1;
                            break;
                        case 3:
                            $item->typ = 'radio';
                            $item->hasvalue = 1;
                            break;
                        case 4:
                            $item->typ = 'check';
                            $item->hasvalue = 1;
                            break;
                        case 5:
                            $item->typ = 'dropdown';
                            $item->hasvalue = 1;
                            break;
                    }
                }
                $item->position = backup_todb($item_info['#']['POSITION']['0']['#']);
                $item->required = backup_todb($item_info['#']['REQUIRED']['0']['#']);
                //put this new item into the database
                $newitemid = insert_record('feedback_item', $item);
                //Now check if want to restore user data and do it.
                if ($restore_userdata) {
                    $values = $item_info['#']['FBVALUES']['0']['#']['FBVALUE'];
                    for ($ii = 0; $ii < sizeof($values); $ii++) {
                        $value_info = $values[$ii];
                        $value = new object();
                        $value->id = '';
                        $value->item = $newitemid;
                        $value->completed = 0;
                        $value->tmp_completed = backup_todb($value_info['#']['COMPLETED']['0']['#']);
                        $value->value = backup_todb($value_info['#']['VAL']['0']['#']);
                        $value->value = addslashes($value->value);
                        $value->course_id = backup_todb($value_info['#']['COURSE_ID']['0']['#']);
                        //put this new value into the database
                        $newvalueid = insert_record('feedback_value', $value);
                        $value->id = $newvalueid;
                        // $allValues[] = $value;
                    }
                }
            }
            //Now check if want to restore user data again and do it.
            if ($restore_userdata) {
                //restore tracking-data
                $trackings = $info['MOD']['#']['TRACKINGS']['0']['#']['TRACKING'];
                for ($i = 0; $i < sizeof($trackings); $i++) {
                    $tracking_info = $trackings[$i];
                    $tracking = new object();
                    $tracking->id = '';
                    $tracking->userid = backup_todb($tracking_info['#']['USERID']['0']['#']);
                    //have to change later
                    $tracking->feedback = $newid;
                    $tracking->completed = backup_todb($tracking_info['#']['COMPLETED']['0']['#']);
                    //have to change later
                    $tracking->count = backup_todb($tracking_info['#']['COUNT']['0']['#']);
                    if ($tracking->userid > 0) {
                        //We have to recode the userid field
                        $user = backup_getid($restore->backup_unique_code, "user", $tracking->userid);
                        if ($user) {
                            $tracking->userid = $user->new_id;
                        }
                    }
                    //save the tracking
                    $newtrackingid = insert_record('feedback_tracking', $tracking);
                    $tracking->id = $newtrackingid;
                    // $allTrackings[] = $tracking;
                }
                //restore completeds
                $completeds = $info['MOD']['#']['COMPLETEDS']['0']['#']['COMPLETED'];
                for ($i = 0; $i < sizeof($completeds); $i++) {
                    $completed_info = $completeds[$i];
                    $completed = new object();
                    $completed->feedback = $newid;
                    $completed->userid = backup_todb($completed_info['#']['USERID']['0']['#']);
                    $completed->timemodified = backup_todb($completed_info['#']['TIMEMODIFIED']['0']['#']);
                    $completed->random_response = backup_todb($completed_info['#']['RANDOMRESPONSE']['0']['#']);
                    if (!($anonymous_response = backup_todb($completed_info['#']['ANONYMOUSRESPONSE']['0']['#']))) {
                        $anonymous_response = 1;
                    }
                    $completed->anonymous_response = $anonymous_response;
                    if ($completed->userid > 0) {
                        //We have to recode the userid field
                        $user = backup_getid($restore->backup_unique_code, "user", $completed->userid);
                        if ($user) {
                            $completed->userid = $user->new_id;
                        }
                    }
                    //later this have to be changed
                    $oldcompletedid = backup_todb($completed_info['#']['ID']['0']['#']);
                    //save the completed
                    $newcompletedid = insert_record('feedback_completed', $completed);
                    //the newcompletedid have to be changed at every values
                    $tochangevals = get_records('feedback_value', 'tmp_completed', $oldcompletedid);
                    if ($tochangevals) {
                        foreach ($tochangevals as $tmpVal) {
                            $tmpVal->completed = $newcompletedid;
                            $tmpVal->tmp_completed = 0;
                            update_record('feedback_value', $tmpVal);
                        }
                    }
                    //the newcompletedid have to be changed at every tracking
                    $tochangetracks = get_records('feedback_tracking', 'completed', $oldcompletedid);
                    if ($tochangetracks) {
                        foreach ($tochangetracks as $tmpTrack) {
                            $tmpTrack->completed = $newcompletedid;
                            $tmpTrack->tmp_completed = 0;
                            update_record('feedback_tracking', $tmpTrack);
                        }
                    }
                }
            }
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
        } else {
            $status = false;
        }
        if (!defined('RESTORE_SILENTLY')) {
            //Finalize ul
            echo "</ul>";
        }
    } else {
        $status = false;
    }
    return $status;
}
Esempio n. 23
0
/** 
 *  This creates new events given as timeopen and closeopen by $feedback.
 *  @param object $feedback
 *  @return void
 */
function feedback_set_events($feedback)
{
    // adding the feedback to the eventtable (I have seen this at quiz-module)
    delete_records('event', 'modulename', 'feedback', 'instance', $feedback->id);
    // the open-event
    if ($feedback->timeopen > 0) {
        $event = NULL;
        $event->name = get_string('start', 'feedback') . ' ' . $feedback->name;
        $event->description = $feedback->summary;
        $event->courseid = $feedback->course;
        $event->groupid = 0;
        $event->userid = 0;
        $event->modulename = 'feedback';
        $event->instance = $feedbackid;
        $event->eventtype = 'open';
        $event->timestart = $feedback->timeopen;
        $event->visible = instance_is_visible('feedback', $feedback);
        if ($feedback->timeclose > 0) {
            $event->timeduration = $feedback->timeclose - $feedback->timeopen;
        } else {
            $event->timeduration = 0;
        }
        add_event($event);
    }
    // the close-event
    if ($feedback->timeclose > 0) {
        $event = NULL;
        $event->name = get_string('stop', 'feedback') . ' ' . $feedback->name;
        $event->description = $feedback->summary;
        $event->courseid = $feedback->course;
        $event->groupid = 0;
        $event->userid = 0;
        $event->modulename = 'feedback';
        $event->instance = $feedbackid;
        $event->eventtype = 'close';
        $event->timestart = $feedback->timeclose;
        $event->visible = instance_is_visible('feedback', $feedback);
        $event->timeduration = 0;
        add_event($event);
    }
}
Esempio n. 24
0
function elluminate_update_events($elluminate)
{
    global $DB;
    if ($elluminate->sessiontype == 0 || $elluminate->sessiontype == 1) {
        $oldevents = $DB->get_records('event', array('modulename' => 'elluminate', 'instance' => $elluminate->id));
    } else {
        if ($elluminate->sessiontype == 2) {
            $oldevents = $DB->get_records('event', array('modulename' => 'elluminate', 'instance' => $elluminate->groupparentid, 'groupid' => $elluminate->groupid));
        } else {
            if ($elluminate->sessiontype == 3) {
                if ($elluminate->groupmode != 0) {
                    $oldevents = $DB->get_records('event', array('modulename' => 'elluminate', 'instance' => $elluminate->groupparentid, 'groupid' => $elluminate->groupid));
                } else {
                    $oldevents = $DB->get_records('event', array('modulename' => 'elluminate', 'instance' => $elluminate->id));
                }
            }
        }
    }
    $event = new stdClass();
    foreach ($oldevents as $oldevent) {
        $event = $oldevent;
    }
    $event->description = $elluminate->description;
    $event->courseid = $elluminate->course;
    // Events module won't show user events when the courseid is nonzero
    if ($elluminate->sessiontype == 0 || $elluminate->sessiontype == 1) {
        //course private
        $event->groupid = 0;
        $event->eventtype = 'open';
        $event->name = $elluminate->name;
        $event->instance = $elluminate->id;
    } else {
        if ($elluminate->sessiontype == 3) {
            //grouping
            if ($elluminate->groupmode != 0) {
                //Seperate or Visible groups
                $event->groupid = $elluminate->groupid;
                $event->eventtype = 'group';
                $event->name = $elluminate->sessionname;
                $event->instance = $elluminate->groupparentid;
            } else {
                //No groups
                $event->groupid = 0;
                $event->eventtype = 'open';
                $event->name = $elluminate->sessionname;
                $event->instance = $elluminate->id;
            }
        } else {
            //group
            $event->groupid = $elluminate->groupid;
            $event->eventtype = 'group';
            $event->name = $elluminate->sessionname;
            $event->instance = $elluminate->groupparentid;
        }
    }
    $event->modulename = 'elluminate';
    $event->timestart = $elluminate->timestart;
    $event->timeduration = max($elluminate->timeend - $elluminate->timestart, 0);
    $event->visible = instance_is_visible('elluminate', $elluminate);
    calendar_event::create($event);
}
Esempio n. 25
0
/**
 * Are RSS feeds enabled for the supplied module instance?
 *
 * @param string   $modname        The name of the module to be checked
 * @param stdClass $instance       An instance of an activity module ie $forum, $glossary.
 * @param bool     $hasrsstype     Should there be a rsstype member variable?
 * @param bool     $hasrssarticles Should there be a rssarticles member variable?
 * @return bool whether or not RSS is enabled for the module
 */
function rss_enabled_for_mod($modname, $instance = null, $hasrsstype = true, $hasrssarticles = true)
{
    if ($hasrsstype) {
        if (empty($instance->rsstype) || $instance->rsstype == 0) {
            return false;
        }
    }
    //have they set the RSS feed to return 0 results?
    if ($hasrssarticles) {
        if (empty($instance->rssarticles) || $instance->rssarticles == 0) {
            return false;
        }
    }
    if (!empty($instance) && !instance_is_visible($modname, $instance)) {
        return false;
    }
    return true;
}
Esempio n. 26
0
/**
 * Prints any recent dialogue activity since a given time
 * @param   object  $course
 * @param   bool    $viewfullnames capability
 * @param   timestamp   $timestart
 * @return  bool    success
 */
function dialogue_print_recent_activity($course, $viewfullnames, $timestart)
{
    global $CFG;
    // have a look for new entries
    $addentrycontent = false;
    $tempmod = new object();
    // Create a temp valid module structure (only need courseid, moduleid)
    $tempmod->course = $course->id;
    if ($logs = dialogue_get_add_entry_logs($course, $timestart)) {
        // got some, see if any belong to a visible module
        foreach ($logs as $log) {
            $tempmod->id = $log->dialogueid;
            //Obtain the visible property from the instance
            if (instance_is_visible('dialogue', $tempmod)) {
                $addentrycontent = true;
                break;
            }
        }
        // if we got some "live" ones then output them
        if ($addentrycontent) {
            print_headline(get_string('newdialogueentries', 'dialogue') . ':');
            foreach ($logs as $log) {
                $tempmod->id = $log->dialogueid;
                $user = get_record('user', 'id', $log->userid);
                //Obtain the visible property from the instance
                if (instance_is_visible('dialogue', $tempmod)) {
                    print_recent_activity_note($log->time, $user, $log->subject, $CFG->wwwroot . '/mod/dialogue/' . str_replace('&', '&amp;', $log->url));
                }
            }
        }
    }
    // have a look for open conversations
    $opencontent = false;
    if ($logs = dialogue_get_open_conversations($course)) {
        // got some, see if any belong to a visible module
        foreach ($logs as $log) {
            // Create a temp valid module structure (only need courseid, moduleid)
            $tempmod->id = $log->dialogueid;
            //Obtain the visible property from the instance
            if (instance_is_visible('dialogue', $tempmod)) {
                $opencontent = true;
                break;
            }
        }
        // if we got some 'live' ones then output them
        if ($opencontent) {
            print_headline(get_string('opendialogueentries', 'dialogue') . ':');
            foreach ($logs as $log) {
                //Create a temp valid module structure (only need courseid, moduleid)
                $tempmod->id = $log->dialogueid;
                $user = get_record('user', 'id', $log->userid);
                //Obtain the visible property from the instance
                if (instance_is_visible('dialogue', $tempmod)) {
                    print_recent_activity_note($log->time, $user, $log->name, $CFG->wwwroot . '/mod/dialogue/' . str_replace('&', '&amp;', $log->url));
                }
            }
        }
    }
    return $addentrycontent or $opencontent;
}
Esempio n. 27
0
function workshop_is_recent_activity($course, $isteacher, $timestart)
{
    //jlw1 added for adding mark to courses with activity in My Moodle
    global $CFG;
    // have a look for agreed assessments for this user (agree)
    $agreecontent = false;
    if (!$isteacher) {
        // teachers only need to see submissions
        if ($logs = workshop_get_agree_logs($course, $timestart)) {
            // got some, see if any belong to a visible module
            foreach ($logs as $log) {
                // Create a temp valid module structure (only need courseid, moduleid)
                $tempmod->course = $course->id;
                $tempmod->id = $log->workshopid;
                //Obtain the visible property from the instance
                if (instance_is_visible("workshop", $tempmod)) {
                    $agreecontent = true;
                    break;
                }
            }
        }
    }
    return false;
}
Esempio n. 28
0
/**
 * This function updates the events associated to the offlinequiz.
 * If $override is non-zero, then it updates only the events
 * associated with the specified override.
 *
 * @uses OFFLINEQUIZ_MAX_EVENT_LENGTH
 * @param object $offlinequiz the offlinequiz object.
 * @param object optional $override limit to a specific override
 */
function offlinequiz_update_events($offlinequiz)
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/calendar/lib.php';
    // Load the old events relating to this offlinequiz.
    $conds = array('modulename' => 'offlinequiz', 'instance' => $offlinequiz->id);
    if (!empty($override)) {
        // Only load events for this override.
        $conds['groupid'] = isset($override->groupid) ? $override->groupid : 0;
        $conds['userid'] = isset($override->userid) ? $override->userid : 0;
    }
    $oldevents = $DB->get_records('event', $conds);
    $groupid = 0;
    $userid = 0;
    $timeopen = $offlinequiz->timeopen;
    $timeclose = $offlinequiz->timeclose;
    if ($offlinequiz->time) {
        $timeopen = $offlinequiz->time;
    }
    // Only add open/close events if they differ from the offlinequiz default.
    if (!empty($offlinequiz->coursemodule)) {
        $cmid = $offlinequiz->coursemodule;
    } else {
        $cmid = get_coursemodule_from_instance('offlinequiz', $offlinequiz->id, $offlinequiz->course)->id;
    }
    if (!empty($timeopen)) {
        $event = new stdClass();
        $event->name = $offlinequiz->name;
        $event->description = format_module_intro('offlinequiz', $offlinequiz, $cmid);
        // Events module won't show user events when the courseid is nonzero.
        $event->courseid = $userid ? 0 : $offlinequiz->course;
        $event->groupid = $groupid;
        $event->userid = $userid;
        $event->modulename = 'offlinequiz';
        $event->instance = $offlinequiz->id;
        $event->timestart = $timeopen;
        $event->timeduration = max($timeclose - $timeopen, 0);
        $event->visible = instance_is_visible('offlinequiz', $offlinequiz);
        if ($timeopen == $offlinequiz->time) {
            $event->name = $offlinequiz->name;
        }
        if ($timeopen == $offlinequiz->timeopen) {
            $event->name = $offlinequiz->name . ' (' . get_string('reportstarts', 'offlinequiz') . ')';
        }
        calendar_event::create($event);
    }
    // Delete any leftover events.
    foreach ($oldevents as $badevent) {
        $badevent = calendar_event::load($badevent);
        $badevent->delete();
    }
}
Esempio n. 29
0
/**
 * This creates new events given as timeopen and closeopen by $feedback.
 *
 * @global object
 * @param object $feedback
 * @return void
 */
function feedback_set_events($feedback) {
    global $DB;

    // adding the feedback to the eventtable (I have seen this at quiz-module)
    $DB->delete_records('event', array('modulename'=>'feedback', 'instance'=>$feedback->id));

    if (!isset($feedback->coursemodule)) {
        $cm = get_coursemodule_from_id('feedback', $feedback->id);
        $feedback->coursemodule = $cm->id;
    }

    // the open-event
    if ($feedback->timeopen > 0) {
        $event = new stdClass();
        $event->name         = get_string('start', 'feedback').' '.$feedback->name;
        $event->description  = format_module_intro('feedback', $feedback, $feedback->coursemodule);
        $event->courseid     = $feedback->course;
        $event->groupid      = 0;
        $event->userid       = 0;
        $event->modulename   = 'feedback';
        $event->instance     = $feedback->id;
        $event->eventtype    = 'open';
        $event->timestart    = $feedback->timeopen;
        $event->visible      = instance_is_visible('feedback', $feedback);
        if ($feedback->timeclose > 0) {
            $event->timeduration = ($feedback->timeclose - $feedback->timeopen);
        } else {
            $event->timeduration = 0;
        }

        calendar_event::create($event);
    }

    // the close-event
    if ($feedback->timeclose > 0) {
        $event = new stdClass();
        $event->name         = get_string('stop', 'feedback').' '.$feedback->name;
        $event->description  = format_module_intro('feedback', $feedback, $feedback->coursemodule);
        $event->courseid     = $feedback->course;
        $event->groupid      = 0;
        $event->userid       = 0;
        $event->modulename   = 'feedback';
        $event->instance     = $feedback->id;
        $event->eventtype    = 'close';
        $event->timestart    = $feedback->timeclose;
        $event->visible      = instance_is_visible('feedback', $feedback);
        $event->timeduration = 0;

        calendar_event::create($event);
    }
}
Esempio n. 30
0
/**
 * Runs any processes that must be run
 * after a lesson insert/update
 *
 * @global object
 * @param object $lesson Lesson form data
 * @return void
 **/
function lesson_process_post_save(&$lesson)
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/calendar/lib.php';
    require_once $CFG->dirroot . '/mod/lesson/locallib.php';
    if ($events = $DB->get_records('event', array('modulename' => 'lesson', 'instance' => $lesson->id))) {
        foreach ($events as $event) {
            $event = calendar_event::load($event->id);
            $event->delete();
        }
    }
    $event = new stdClass();
    $event->description = $lesson->name;
    $event->courseid = $lesson->course;
    $event->groupid = 0;
    $event->userid = 0;
    $event->modulename = 'lesson';
    $event->instance = $lesson->id;
    $event->eventtype = 'open';
    $event->timestart = $lesson->available;
    $event->visible = instance_is_visible('lesson', $lesson);
    $event->timeduration = $lesson->deadline - $lesson->available;
    if ($lesson->deadline and $lesson->available and $event->timeduration <= LESSON_MAX_EVENT_LENGTH) {
        // Single event for the whole lesson.
        $event->name = $lesson->name;
        calendar_event::create(clone $event);
    } else {
        // Separate start and end events.
        $event->timeduration = 0;
        if ($lesson->available) {
            $event->name = $lesson->name . ' (' . get_string('lessonopens', 'lesson') . ')';
            calendar_event::create(clone $event);
        }
        if ($lesson->deadline) {
            $event->name = $lesson->name . ' (' . get_string('lessoncloses', 'lesson') . ')';
            $event->timestart = $lesson->deadline;
            $event->eventtype = 'close';
            calendar_event::create(clone $event);
        }
    }
}