示例#1
0
function calendar_get_sideblock_upcoming($events, $linkhref = NULL)
{
    $content = '';
    $lines = count($events);
    if (!$lines) {
        return $content;
    }
    for ($i = 0; $i < $lines; ++$i) {
        if (!isset($events[$i]->time)) {
            // Just for robustness
            continue;
        }
        $events[$i] = calendar_add_event_metadata($events[$i]);
        $content .= '<div class="event"><span class="icon c0">' . $events[$i]->icon . '</span> ';
        if (!empty($events[$i]->referer)) {
            // That's an activity event, so let's provide the hyperlink
            $content .= $events[$i]->referer;
        } else {
            if (!empty($linkhref)) {
                $ed = usergetdate($events[$i]->timestart);
                $href = calendar_get_link_href(CALENDAR_URL . $linkhref, $ed['mday'], $ed['mon'], $ed['year']);
                $content .= '<a href="' . $href . '#event_' . $events[$i]->id . '">' . $events[$i]->name . '</a>';
            } else {
                $content .= $events[$i]->name;
            }
        }
        $events[$i]->time = str_replace('&raquo;', '<br />&raquo;', $events[$i]->time);
        $content .= '<div class="date">' . $events[$i]->time . '</div></div>';
        if ($i < $lines - 1) {
            $content .= '<hr />';
        }
    }
    return $content;
}
示例#2
0
 /**
  * Displays an event
  *
  * @param calendar_event $event
  * @param bool $showactions
  * @return string
  */
 public function event(calendar_event $event, $showactions = true)
 {
     global $CFG;
     $event = calendar_add_event_metadata($event);
     $context = $event->context;
     $anchor = html_writer::tag('a', '', array('name' => 'event_' . $event->id));
     $table = new html_table();
     $table->attributes = array('class' => 'event', 'cellspacing' => '0');
     $table->data = array(0 => new html_table_row(), 1 => new html_table_row());
     if (!empty($event->icon)) {
         $table->data[0]->cells[0] = new html_table_cell($anchor . $event->icon);
     } else {
         $table->data[0]->cells[0] = new html_table_cell($anchor . $this->output->spacer(array('height' => 16, 'width' => 16, 'br' => true)));
     }
     $table->data[0]->cells[0]->attributes['class'] .= ' picture';
     $table->data[0]->cells[1] = new html_table_cell();
     $table->data[0]->cells[1]->attributes['class'] .= ' topic';
     if (!empty($event->referer)) {
         $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->referer, array('class' => 'referer'));
     } else {
         $table->data[0]->cells[1]->text .= html_writer::tag('div', format_string($event->name, false, array('context' => $context)), array('class' => 'name'));
     }
     if (!empty($event->courselink)) {
         $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->courselink, array('class' => 'course'));
     }
     // Show subscription source if needed.
     if (!empty($event->subscription) && $CFG->calendar_showicalsource) {
         if (!empty($event->subscription->url)) {
             $source = html_writer::link($event->subscription->url, get_string('subsource', 'calendar', $event->subscription));
         } else {
             // File based ical.
             $source = get_string('subsource', 'calendar', $event->subscription);
         }
         $table->data[0]->cells[1]->text .= html_writer::tag('div', $source, array('class' => 'subscription'));
     }
     if (!empty($event->time)) {
         $table->data[0]->cells[1]->text .= html_writer::tag('span', $event->time, array('class' => 'date'));
     } else {
         $table->data[0]->cells[1]->text .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class' => 'date'));
     }
     $table->data[1]->cells[0] = new html_table_cell('&nbsp;');
     $table->data[1]->cells[0]->attributes['class'] .= 'side';
     $table->data[1]->cells[1] = new html_table_cell(format_text($event->description, $event->format, array('context' => $context)));
     $table->data[1]->cells[1]->attributes['class'] .= ' description';
     if (isset($event->cssclass)) {
         $table->data[1]->cells[1]->attributes['class'] .= ' ' . $event->cssclass;
     }
     if (calendar_edit_event_allowed($event) && $showactions) {
         if (empty($event->cmid)) {
             $editlink = new moodle_url(CALENDAR_URL . 'event.php', array('action' => 'edit', 'id' => $event->id));
             $deletelink = new moodle_url(CALENDAR_URL . 'delete.php', array('id' => $event->id));
             if (!empty($event->calendarcourseid)) {
                 $editlink->param('course', $event->calendarcourseid);
                 $deletelink->param('course', $event->calendarcourseid);
             }
         } else {
             $editlink = new moodle_url('/course/mod.php', array('update' => $event->cmid, 'return' => true, 'sesskey' => sesskey()));
             $deletelink = null;
         }
         $commands = html_writer::start_tag('div', array('class' => 'commands'));
         $commands .= html_writer::start_tag('a', array('href' => $editlink));
         $commands .= html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'alt' => get_string('tt_editevent', 'calendar'), 'title' => get_string('tt_editevent', 'calendar')));
         $commands .= html_writer::end_tag('a');
         if ($deletelink != null) {
             $commands .= html_writer::start_tag('a', array('href' => $deletelink));
             $commands .= html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/delete'), 'alt' => get_string('tt_deleteevent', 'calendar'), 'title' => get_string('tt_deleteevent', 'calendar')));
             $commands .= html_writer::end_tag('a');
         }
         $commands .= html_writer::end_tag('div');
         $table->data[1]->cells[1]->text .= $commands;
     }
     return html_writer::table($table);
 }
示例#3
0
 /**
  * Displays an event
  *
  * @param calendar_event $event
  * @param bool $showactions
  * @return string
  */
 public function event(calendar_event $event, $showactions = true)
 {
     global $CFG;
     $event = calendar_add_event_metadata($event);
     $context = $event->context;
     $output = '';
     if (!empty($event->icon)) {
         $output .= $event->icon;
     } else {
         $output .= $this->output->spacer(array('height' => 16, 'width' => 16));
     }
     if (!empty($event->referer)) {
         $output .= $this->output->heading($event->referer, 3, array('class' => 'referer'));
     } else {
         $output .= $this->output->heading(format_string($event->name, false, array('context' => $context)), 3, array('class' => 'name'));
     }
     if (!empty($event->courselink)) {
         $output .= html_writer::tag('div', $event->courselink, array('class' => 'course'));
     }
     // Show subscription source if needed.
     if (!empty($event->subscription) && $CFG->calendar_showicalsource) {
         if (!empty($event->subscription->url)) {
             $source = html_writer::link($event->subscription->url, get_string('subsource', 'calendar', $event->subscription));
         } else {
             // File based ical.
             $source = get_string('subsource', 'calendar', $event->subscription);
         }
         $output .= html_writer::tag('div', $source, array('class' => 'subscription'));
     }
     if (!empty($event->time)) {
         $output .= html_writer::tag('span', $event->time, array('class' => 'date'));
     } else {
         $output .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class' => 'date'));
     }
     $eventdetailshtml = '';
     $eventdetailsclasses = '';
     $eventdetailshtml .= format_text($event->description, $event->format, array('context' => $context));
     $eventdetailsclasses .= 'description';
     if (isset($event->cssclass)) {
         $eventdetailsclasses .= ' ' . $event->cssclass;
     }
     $output .= html_writer::tag('div', $eventdetailshtml, array('class' => $eventdetailsclasses));
     if (calendar_edit_event_allowed($event) && $showactions) {
         if (empty($event->cmid)) {
             $editlink = new moodle_url(CALENDAR_URL . 'event.php', array('action' => 'edit', 'id' => $event->id));
             $deletelink = new moodle_url(CALENDAR_URL . 'delete.php', array('id' => $event->id));
             if (!empty($event->calendarcourseid)) {
                 $editlink->param('course', $event->calendarcourseid);
                 $deletelink->param('course', $event->calendarcourseid);
             }
         } else {
             $editlink = new moodle_url('/course/mod.php', array('update' => $event->cmid, 'return' => true, 'sesskey' => sesskey()));
             $deletelink = null;
         }
         $commands = html_writer::start_tag('div', array('class' => 'commands'));
         $commands .= html_writer::start_tag('a', array('href' => $editlink));
         $commands .= html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'alt' => get_string('tt_editevent', 'calendar'), 'title' => get_string('tt_editevent', 'calendar')));
         $commands .= html_writer::end_tag('a');
         if ($deletelink != null) {
             $commands .= html_writer::start_tag('a', array('href' => $deletelink));
             $commands .= html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/delete'), 'alt' => get_string('tt_deleteevent', 'calendar'), 'title' => get_string('tt_deleteevent', 'calendar')));
             $commands .= html_writer::end_tag('a');
         }
         $commands .= html_writer::end_tag('div');
         $output .= $commands;
     }
     return html_writer::tag('div', $output, array('class' => 'event', 'id' => 'event_' . $event->id));
 }
示例#4
0
/**
 * Get the upcoming event block
 *
 * @param array $events list of events
 * @param moodle_url|string $linkhref link to event referer
 * @param boolean $showcourselink whether links to courses should be shown
 * @return string|null $content html block content
 */
function calendar_get_block_upcoming($events, $linkhref = NULL, $showcourselink = false)
{
    $content = '';
    $lines = count($events);
    if (!$lines) {
        return $content;
    }
    for ($i = 0; $i < $lines; ++$i) {
        if (!isset($events[$i]->time)) {
            // Just for robustness
            continue;
        }
        $events[$i] = calendar_add_event_metadata($events[$i]);
        $content .= '<div class="event"><span class="icon c0">' . $events[$i]->icon . '</span>';
        if (!empty($events[$i]->referer)) {
            // That's an activity event, so let's provide the hyperlink
            $content .= $events[$i]->referer;
        } else {
            if (!empty($linkhref)) {
                $href = calendar_get_link_href(new moodle_url(CALENDAR_URL . $linkhref), 0, 0, 0, $events[$i]->timestart);
                $href->set_anchor('event_' . $events[$i]->id);
                $content .= html_writer::link($href, $events[$i]->name);
            } else {
                $content .= $events[$i]->name;
            }
        }
        $events[$i]->time = str_replace('&raquo;', '<br />&raquo;', $events[$i]->time);
        if ($showcourselink && !empty($events[$i]->courselink)) {
            $content .= html_writer::div($events[$i]->courselink, 'course');
        }
        $content .= '<div class="date">' . $events[$i]->time . '</div></div>';
        if ($i < $lines - 1) {
            $content .= '<hr />';
        }
    }
    return $content;
}
示例#5
0
 */
 calendar_set_referring_course($courseshown);
 // Be VERY careful with the format for default courses arguments!
 // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
 calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
 $restrictions = '';
 $restrictions .= 'timestart + timeduration >= ' . $from_date;
 $restrictions .= ' AND timestart <= ' . $to_date;
 $restrictions .= ' AND ( (userid = ' . $USER->id . ' AND courseid = 0 AND groupid = 0)';
 $restrictions .= ' OR (groupid = 0 AND courseid IN (1,' . $courseshown . ')))';
 $restrictions .= ' AND visible = 1';
 $events = get_records_select('event', $restrictions, 'timestart');
 $return_events = array();
 foreach ($events as $event) {
     if (function_exists(calendar_add_event_metadata)) {
         calendar_add_event_metadata($event);
     }
     $new_event = array();
     $new_event["id"] = $event->id;
     $new_event["name"] = $event->name;
     $new_event["description"] = $event->description;
     //$new_event["format"] = $event->format;
     $new_event["modulename"] = $event->modulename;
     $new_event["instance"] = $event->instance;
     $new_event["eventtype"] = $event->eventtype;
     $new_event["timestart"] = $event->timestart;
     $new_event["timeduration"] = $event->timeduration;
     $new_event["user_id"] = $event->userid;
     $new_event["group_id"] = $event->groupid;
     $new_event["course_id"] = $event->courseid;
     $new_event["visible"] = $event->visible;