/**
  * Cosntructor.
  *
  * @param \stdClass $collaborate
  * @param \stdClass $cm
  * @param \context_module $context
  * @param \mod_collaborate_renderer $renderer
  */
 public function __construct(\stdClass $collaborate, \cm_info $cm, \context_module $context, \mod_collaborate_renderer $renderer)
 {
     $this->collaborate = $collaborate;
     $this->cm = $cm;
     $this->context = $context;
     $this->renderer = $renderer;
     $this->course = $cm->get_course();
 }
 /**
  * Constructor
  *
  * @param \stdClass $collaborate
  * @param \cm_info $cm
  * @param \context_module $context;
  * @param \stdClass $user;
  * @throws \coding_exception
  * @throws \require_login_exception
  */
 public function __construct(\stdClass $collaborate, \cm_info $cm, \context_module $context, \stdClass $user)
 {
     global $DB;
     $this->collaborate = $collaborate;
     $this->course = $cm->get_course();
     $this->cm = $cm;
     $this->id = $cm->instance;
     $this->context = $context;
     $this->user = $user;
     $this->collaborate = $DB->get_record('collaborate', array('id' => $this->id), '*', MUST_EXIST);
     $this->api = api::get_api();
 }
/**
 *
 * @param cm_info $cm
 * @param stdClass $stopwatch
 * @param int $duration
 */
function mod_stopwatch_update_timer(cm_info $cm, $stopwatch, $duration)
{
    global $USER, $DB, $CFG;
    require_once $CFG->libdir . '/completionlib.php';
    $record = $DB->get_record('stopwatch_user', array('stopwatchid' => $cm->instance, 'courseid' => $cm->course, 'userid' => $USER->id));
    if ($record) {
        $data = array('id' => $record->id, 'timemodified' => time(), 'duration' => $duration);
        $DB->update_record('stopwatch_user', $data);
    } else {
        $data = array('courseid' => $cm->course, 'stopwatchid' => $cm->instance, 'userid' => $USER->id, 'timecreated' => time(), 'timemodified' => time(), 'duration' => $duration);
        $DB->insert_record('stopwatch_user', $data);
    }
    // Update completion state
    $completion = new completion_info($cm->get_course());
    if ($completion->is_enabled($cm) && $stopwatch->completiontimed) {
        $completion->update_state($cm, COMPLETION_COMPLETE);
    }
}
/**
 * @param cm_info $cm
 * @return bool
 */
function navbuttons_mod_assignment_showbuttons($cm)
{
    global $DB, $CFG, $USER;
    if (!($assignment = $DB->get_record('assignment', array('id' => $cm->instance)))) {
        return true;
        // Not quite sure what went wrong
    }
    $type = $assignment->assignmenttype;
    if ($type == 'offline') {
        return true;
        // Cannot track 'offline' assignments
    }
    require_once $CFG->dirroot . '/mod/assignment/type/' . $type . '/assignment.class.php';
    $class = 'assignment_' . $type;
    /** @var assignment_base $instance */
    $instance = new $class($cm->id, $assignment, $cm, $cm->get_course());
    if (!($submission = $instance->get_submission($USER->id))) {
        return false;
        // No submission
    }
    if ($type == 'upload' || $type == 'uploadpdf') {
        if ($instance->drafts_tracked()) {
            if ($instance->is_finalized($submission)) {
                return true;
                // Upload submission is 'finalised'
            } else {
                return false;
            }
        }
    }
    if ($submission->timemodified > 0) {
        return true;
        // Submission has a 'modified' time
    }
    return false;
}
Exemplo n.º 5
0
/**
 * Returns whether the discussion group is visible by the current user or not.
 *
 * @since Moodle 2.8, 2.7.1, 2.6.4
 * @param cm_info $cm The discussion course module
 * @param int $discussiongroupid The discussion groupid
 * @return bool
 */
function forum_is_user_group_discussion(cm_info $cm, $discussiongroupid)
{
    if ($discussiongroupid == -1 || $cm->effectivegroupmode != SEPARATEGROUPS) {
        return true;
    }
    if (isguestuser()) {
        return false;
    }
    if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id)) || in_array($discussiongroupid, $cm->get_modinfo()->get_groups($cm->groupingid))) {
        return true;
    }
    return false;
}
Exemplo n.º 6
0
/**
 * Overwrites the content in the course-module object with the folder files list
 * if folder.display == FOLDER_DISPLAY_INLINE
 *
 * @param cm_info $cm
 */
function folder_cm_info_view(cm_info $cm)
{
    global $PAGE;
    if ($cm->uservisible && $cm->get_custom_data() && has_capability('mod/folder:view', $cm->context)) {
        // Restore folder object from customdata.
        // Note the field 'customdata' is not empty IF AND ONLY IF we display contens inline.
        // Otherwise the content is default.
        $folder = $cm->get_custom_data();
        $folder->id = (int) $cm->instance;
        $folder->course = (int) $cm->course;
        $folder->display = FOLDER_DISPLAY_INLINE;
        $folder->name = $cm->name;
        if (empty($folder->intro)) {
            $folder->intro = '';
        }
        if (empty($folder->introformat)) {
            $folder->introformat = FORMAT_MOODLE;
        }
        // display folder
        $renderer = $PAGE->get_renderer('mod_folder');
        $cm->set_content($renderer->display_folder($folder));
    }
}
Exemplo n.º 7
0
 /**
  * Constructor for the base assign class.
  *
  * Note: For $coursemodule you can supply a stdclass if you like, but it
  * will be more efficient to supply a cm_info object.
  *
  * @param mixed $coursemodulecontext context|null the course module context
  *                                   (or the course context if the coursemodule has not been
  *                                   created yet).
  * @param mixed $coursemodule the current course module if it was already loaded,
  *                            otherwise this class will load one from the context as required.
  * @param mixed $course the current course  if it was already loaded,
  *                      otherwise this class will load one from the context as required.
  */
 public function __construct($coursemodulecontext, $coursemodule, $course)
 {
     $this->context = $coursemodulecontext;
     $this->course = $course;
     // Ensure that $this->coursemodule is a cm_info object (or null).
     $this->coursemodule = cm_info::create($coursemodule);
     // Temporary cache only lives for a single request - used to reduce db lookups.
     $this->cache = array();
     $this->submissionplugins = $this->load_plugins('assignsubmission');
     $this->feedbackplugins = $this->load_plugins('assignfeedback');
 }
 /**
  * Tests the function for constructing a cm_info from mixed data.
  */
 public function test_create()
 {
     global $CFG, $DB;
     $this->resetAfterTest();
     // Create a course and an activity.
     $generator = $this->getDataGenerator();
     $course = $generator->create_course();
     $page = $generator->create_module('page', array('course' => $course->id, 'name' => 'Annie'));
     // Null is passed through.
     $this->assertNull(cm_info::create(null));
     // Stdclass object turns into cm_info.
     $cm = cm_info::create((object) array('id' => $page->cmid, 'course' => $course->id));
     $this->assertInstanceOf('cm_info', $cm);
     $this->assertEquals('Annie', $cm->name);
     // A cm_info object stays as cm_info.
     $this->assertSame($cm, cm_info::create($cm));
     // Invalid object (missing fields) causes error.
     try {
         cm_info::create((object) array('id' => $page->cmid));
         $this->fail();
     } catch (Exception $e) {
         $this->assertInstanceOf('coding_exception', $e);
     }
     // Create a second hidden activity.
     $hiddenpage = $generator->create_module('page', array('course' => $course->id, 'name' => 'Annie', 'visible' => 0));
     // Create 2 user accounts, one is a manager who can see everything.
     $user = $generator->create_user();
     $generator->enrol_user($user->id, $course->id);
     $manager = $generator->create_user();
     $generator->enrol_user($manager->id, $course->id, $DB->get_field('role', 'id', array('shortname' => 'manager'), MUST_EXIST));
     // User can see the normal page but not the hidden one.
     $cm = cm_info::create((object) array('id' => $page->cmid, 'course' => $course->id), $user->id);
     $this->assertTrue($cm->uservisible);
     $cm = cm_info::create((object) array('id' => $hiddenpage->cmid, 'course' => $course->id), $user->id);
     $this->assertFalse($cm->uservisible);
     // Manager can see the hidden one too.
     $cm = cm_info::create((object) array('id' => $hiddenpage->cmid, 'course' => $course->id), $manager->id);
     $this->assertTrue($cm->uservisible);
 }
Exemplo n.º 9
0
/**
 * Returns the move action.
 *
 * @param cm_info $mod The module to produce a move button for
 * @param int $sr The section to link back to (used for creating the links)
 * @return The markup for the move action, or an empty string if not available.
 */
function course_get_cm_move(cm_info $mod, $sr = null)
{
    global $OUTPUT;
    static $str;
    static $baseurl;
    $modcontext = context_module::instance($mod->id);
    $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
    if (!isset($str)) {
        $str = get_strings(array('move'));
    }
    if (!isset($baseurl)) {
        $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
        if ($sr !== null) {
            $baseurl->param('sr', $sr);
        }
    }
    if ($hasmanageactivities) {
        $pixicon = 'i/dragdrop';
        if (!course_ajax_enabled($mod->get_course())) {
            // Override for course frontpage until we get drag/drop working there.
            $pixicon = 't/move';
        }
        return html_writer::link(new moodle_url($baseurl, array('copy' => $mod->id)), $OUTPUT->pix_icon($pixicon, $str->move, 'moodle', array('class' => 'iconsmall', 'title' => '')), array('class' => 'editing_move', 'data-action' => 'move'));
    }
    return '';
}
Exemplo n.º 10
0
/**
 * Returns the rename action.
 *
 * @deprecated since 3.1
 * @param cm_info $mod The module to produce editing buttons for
 * @param int $sr The section to link back to (used for creating the links)
 * @return The markup for the rename action, or an empty string if not available.
 */
function course_get_cm_rename_action(cm_info $mod, $sr = null)
{
    global $COURSE, $OUTPUT;
    static $str;
    static $baseurl;
    debugging('Function course_get_cm_rename_action() is deprecated. Please use inplace_editable ' . 'https://docs.moodle.org/dev/Inplace_editable', DEBUG_DEVELOPER);
    $modcontext = context_module::instance($mod->id);
    $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
    if (!isset($str)) {
        $str = get_strings(array('edittitle'));
    }
    if (!isset($baseurl)) {
        $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
    }
    if ($sr !== null) {
        $baseurl->param('sr', $sr);
    }
    // AJAX edit title.
    if ($mod->has_view() && $hasmanageactivities && course_ajax_enabled($COURSE) && ($mod->course == $COURSE->id || $mod->course == SITEID)) {
        // we will not display link if we are on some other-course page (where we should not see this module anyway)
        return html_writer::span(html_writer::link(new moodle_url($baseurl, array('update' => $mod->id)), $OUTPUT->pix_icon('t/editstring', '', 'moodle', array('class' => 'iconsmall visibleifjs', 'title' => '')), array('class' => 'editing_title', 'data-action' => 'edittitle', 'title' => $str->edittitle)));
    }
    return '';
}
Exemplo n.º 11
0
/**
 * Obtains shared data that is used in print_section when displaying a
 * course-module entry.
 *
 * Calls format_text or format_string as appropriate, and obtains the correct icon.
 *
 * This data is also used in other areas of the code.
 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
 * @param object $course Moodle course object
 * @return array An array with the following values in this order:
 *   $content (optional extra content for after link),
 *   $instancename (text of link)
 */
function get_print_section_cm_text(cm_info $cm, $course)
{
    global $OUTPUT;
    // Get course context
    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
    // Get content from modinfo if specified. Content displays either
    // in addition to the standard link (below), or replaces it if
    // the link is turned off by setting ->url to null.
    if (($content = $cm->get_content()) !== '') {
        $labelformatoptions = new stdClass();
        $labelformatoptions->noclean = true;
        $labelformatoptions->overflowdiv = true;
        $labelformatoptions->context = $coursecontext;
        $content = format_text($content, FORMAT_HTML, $labelformatoptions);
    } else {
        $content = '';
    }
    $stringoptions = new stdClass();
    $stringoptions->context = $coursecontext;
    $instancename = format_string($cm->name, true, $stringoptions);
    return array($content, $instancename);
}
Exemplo n.º 12
0
/**
 * Retrieves the completion status of the LO for an specific user (100 if this is completed and 0 if not), returns NULL if completion tracking is not enabled for that LO (or the entire course) and if the LO corresponds to a section or course LO
 * @author elever
 * @param cm_info $coursemodule_info : Moodle object with information of a module in a course
 * @param int $userid : moodle identifier of the user
 * @return int $completion_status | null
 */
function block_intuitel_get_completion_status(\cm_info $coursemodule_info, $userid)
{
    $completion = new \completion_info($coursemodule_info->get_course());
    if ($completion->is_enabled($coursemodule_info) > 0) {
        //check if completion is enabled for a particular course and activity, returns 0 if it is not enabled, 1 if completion is enabled and is manual and 2 if automatic
        $completion_status = $completion->get_data($coursemodule_info, false, $userid);
        //this object has also information about viewed...is the row of the related table in the database
        $completion_status = $completion_status->completionstate;
        if ($completion_status > 0) {
            $completion_status = 100;
            // moodle completion system retrieves 0 when the activity is not completed, 1 when the activity is completed (regardless of mark), 2 when the activity is completed with a passed mark, 3 when the activity is completed but with a fail mark
        }
    } else {
        $completion_status = null;
    }
    return $completion_status;
}
Exemplo n.º 13
0
/**
 * Overwrites the content in the course-module object with the Dataform view content
 * if dataform.inlineview is not empty
 *
 * @param cm_info $cm
 */
function dataform_cm_info_view(cm_info $cm)
{
    global $PAGE, $CFG, $OUTPUT;
    if (!$cm->uservisible) {
        return;
    }
    // Default content if not displaying inline view.
    if (!($dataform = $cm->customdata) or empty($dataform->inlineview)) {
        return;
    }
    if (!empty($dataform->embedded)) {
        $content = mod_dataform_dataform::get_content_embedded($dataform->id, $dataform->inlineview);
    } else {
        $content = mod_dataform_dataform::get_content_inline($dataform->id, $dataform->inlineview);
    }
    if (!empty($content)) {
        $cm->set_content($content);
    }
}
Exemplo n.º 14
0
 /**
  * Send the details of the newly created activity back to the client browser
  *
  * @param cm_info $mod details of the mod just created
  */
 protected function send_response($mod)
 {
     global $OUTPUT, $PAGE;
     $courserenderer = $PAGE->get_renderer('core', 'course');
     $resp = new stdClass();
     $resp->error = self::ERROR_OK;
     $resp->icon = $mod->get_icon_url()->out();
     $resp->name = $mod->name;
     if ($mod->has_view()) {
         $resp->link = $mod->get_url()->out();
     } else {
         $resp->link = null;
     }
     $resp->content = $mod->get_content();
     $resp->elementid = 'module-' . $mod->id;
     $actions = course_get_cm_edit_actions($mod, 0, $mod->sectionnum);
     $resp->commands = ' ' . $courserenderer->course_section_cm_edit_actions($actions);
     $resp->onclick = $mod->get_on_click();
     $resp->visible = $mod->visible;
     // if using groupings, then display grouping name
     if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', $this->context)) {
         $groupings = groups_get_all_groupings($this->course->id);
         $resp->groupingname = format_string($groupings[$mod->groupingid]->name);
     }
     echo $OUTPUT->header();
     echo json_encode($resp);
     die;
 }
Exemplo n.º 15
0
function opencast_cm_info_view(cm_info $cm) {
   
    $details = $cm->customdata;
    if ($details) {
        $cm->set_after_link(' ' . html_writer::tag('span', $details,
                array('class' => 'resourcelinkdetails')));
    }
}
Exemplo n.º 16
0
 /**
  * Renders HTML to show course module availability information (for someone who isn't allowed
  * to see the activity itself, or for staff)
  *
  * @param cm_info $mod
  * @param array $displayoptions
  * @return string
  */
 public function course_section_cm_availability(cm_info $mod, $displayoptions = array())
 {
     global $CFG;
     if (!$mod->uservisible) {
         // this is a student who is not allowed to see the module but might be allowed
         // to see availability info (i.e. "Available from ...")
         if (!empty($mod->availableinfo)) {
             $formattedinfo = \core_availability\info::format_info($mod->availableinfo, $mod->get_course());
             $output = html_writer::tag('div', $formattedinfo, array('class' => 'availabilityinfo'));
         }
         return $output;
     }
     // this is a teacher who is allowed to see module but still should see the
     // information that module is not available to all/some students
     $modcontext = context_module::instance($mod->id);
     $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext);
     if ($canviewhidden && !empty($CFG->enableavailability)) {
         // Don't add availability information if user is not editing and activity is hidden.
         if ($mod->visible || $this->page->user_is_editing()) {
             $hidinfoclass = '';
             if (!$mod->visible) {
                 $hidinfoclass = 'hide';
             }
             $ci = new \core_availability\info_module($mod);
             $fullinfo = $ci->get_full_information();
             if ($fullinfo) {
                 $formattedinfo = \core_availability\info::format_info($fullinfo, $mod->get_course());
                 return html_writer::div($formattedinfo, 'availabilityinfo ' . $hidinfoclass);
             }
         }
     }
     return '';
 }
Exemplo n.º 17
0
/**
 * Obtains shared data that is used in print_section when displaying a
 * course-module entry.
 *
 * Deprecated. Instead of:
 * list($content, $name) = get_print_section_cm_text($cm, $course);
 * use:
 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
 * $name = $cm->get_formatted_name();
 *
 * @deprecated since 2.5
 * @see cm_info::get_formatted_content()
 * @see cm_info::get_formatted_name()
 *
 * This data is also used in other areas of the code.
 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
 * @param object $course (argument not used)
 * @return array An array with the following values in this order:
 *   $content (optional extra content for after link),
 *   $instancename (text of link)
 */
function get_print_section_cm_text(cm_info $cm, $course)
{
    debugging('Function get_print_section_cm_text() is deprecated. Please use ' . 'cm_info::get_formatted_content() and cm_info::get_formatted_name()', DEBUG_DEVELOPER);
    return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)), $cm->get_formatted_name());
}
Exemplo n.º 18
0
/**
 * This will provide summary info about the user's grade in the subcourse below the link on
 * the course/view.php page
 *
 * @param cm_info $cm
 * @return void
 */
function mod_subcourse_cm_info_view(cm_info $cm)
{
    global $USER, $CFG;
    $html = '';
    require_once $CFG->dirroot . '/grade/querylib.php';
    $currentgrade = grade_get_course_grade($USER->id, $cm->course);
    $html .= html_writer::empty_tag('br');
    $html .= html_writer::start_tag('span');
    $html .= get_string('currentgrade', 'subcourse') . ' ' . $currentgrade->str_grade;
    $html .= html_writer::end_tag('span');
    $cm->set_after_link($html);
}
Exemplo n.º 19
0
 /**
  * Constructor for the base assign class.
  *
  * Note: For $coursemodule you can supply a stdclass if you like, but it
  * will be more efficient to supply a cm_info object.
  *
  * @param mixed $coursemodulecontext context|null the course module context
  *                                   (or the course context if the coursemodule has not been
  *                                   created yet).
  * @param mixed $coursemodule the current course module if it was already loaded,
  *                            otherwise this class will load one from the context as required.
  * @param mixed $course the current course  if it was already loaded,
  *                      otherwise this class will load one from the context as required.
  */
 public function __construct($coursemodulecontext, $coursemodule, $course)
 {
     global $SESSION;
     $this->context = $coursemodulecontext;
     $this->course = $course;
     // Ensure that $this->coursemodule is a cm_info object (or null).
     $this->coursemodule = cm_info::create($coursemodule);
     // Temporary cache only lives for a single request - used to reduce db lookups.
     $this->cache = array();
     $this->submissionplugins = $this->load_plugins('assignsubmission');
     $this->feedbackplugins = $this->load_plugins('assignfeedback');
     // Extra entropy is required for uniqid() to work on cygwin.
     $this->useridlistid = clean_param(uniqid('', true), PARAM_ALPHANUM);
     if (!isset($SESSION->mod_assign_useridlist)) {
         $SESSION->mod_assign_useridlist = [];
     }
 }
Exemplo n.º 20
0
/**
 * Checks if the current user can see the glossary entry.
 *
 * @since Moodle 3.1
 * @param stdClass $entry
 * @param cm_info  $cminfo
 * @return bool
 */
function glossary_can_view_entry($entry, $cminfo) {
    global $USER;

    $cm = $cminfo->get_course_module_record();
    $context = \context_module::instance($cm->id);

    // Recheck uservisible although it should have already been checked in core_search.
    if ($cminfo->uservisible === false) {
        return false;
    }

    // Check approval.
    if (empty($entry->approved) && $entry->userid != $USER->id && !has_capability('mod/glossary:approve', $context)) {
        return false;
    }

    return true;
}
Exemplo n.º 21
0
 /**
  * Send the details of the newly created activity back to the client browser
  *
  * @param cm_info $mod details of the mod just created
  */
 protected function send_response($mod)
 {
     global $OUTPUT;
     $resp = new stdClass();
     $resp->error = self::ERROR_OK;
     $resp->icon = $mod->get_icon_url()->out();
     $resp->name = $mod->name;
     $resp->link = $mod->get_url()->out();
     $resp->elementid = 'module-' . $mod->id;
     $resp->commands = make_editing_buttons($mod, true, true, 0, $mod->sectionnum);
     $resp->onclick = $mod->get_on_click();
     // if using groupings, then display grouping name
     if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', $this->context)) {
         $groupings = groups_get_all_groupings($this->course->id);
         $resp->groupingname = format_string($groupings[$mod->groupingid]->name);
     }
     echo $OUTPUT->header();
     echo json_encode($resp);
     die;
 }
Exemplo n.º 22
0
/**
 * Returns the list of all editing actions that current user can perform on the module
 *
 * @param cm_info $mod The module to produce editing buttons for
 * @param int $indent The current indenting (default -1 means no move left-right actions)
 * @param int $sr The section to link back to (used for creating the links)
 * @return array array of action_link or pix_icon objects
 */
function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null)
{
    global $COURSE, $SITE;
    static $str;
    $coursecontext = context_course::instance($mod->course);
    $modcontext = context_module::instance($mod->id);
    $editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign');
    $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
    // no permission to edit anything
    if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) {
        return array();
    }
    $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
    if (!isset($str)) {
        $str = get_strings(array('delete', 'move', 'moveright', 'moveleft', 'update', 'duplicate', 'hide', 'show', 'edittitle'), 'moodle');
        $str->assign = get_string('assignroles', 'role');
        $str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone"));
        $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate"));
        $str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible"));
        $str->forcedgroupsnone = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsnone"));
        $str->forcedgroupsseparate = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsseparate"));
        $str->forcedgroupsvisible = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsvisible"));
    }
    $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
    if ($sr !== null) {
        $baseurl->param('sr', $sr);
    }
    $actions = array();
    // AJAX edit title
    if ($mod->has_view() && $hasmanageactivities && ($mod->course == $COURSE->id && course_ajax_enabled($COURSE) || $mod->course == SITEID && course_ajax_enabled($SITE))) {
        // we will not display link if we are on some other-course page (where we should not see this module anyway)
        $actions['title'] = new action_link(new moodle_url($baseurl, array('update' => $mod->id)), new pix_icon('t/editstring', $str->edittitle, 'moodle', array('class' => 'iconsmall visibleifjs', 'title' => '')), null, array('class' => 'editing_title', 'title' => $str->edittitle));
    }
    // leftright
    if ($hasmanageactivities) {
        if (right_to_left()) {
            // Exchange arrows on RTL
            $rightarrow = 't/left';
            $leftarrow = 't/right';
        } else {
            $rightarrow = 't/right';
            $leftarrow = 't/left';
        }
        if ($indent > 0) {
            $actions['moveleft'] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')), new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_moveleft', 'title' => $str->moveleft));
        }
        if ($indent >= 0) {
            $actions['moveright'] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')), new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_moveright', 'title' => $str->moveright));
        }
    }
    // move
    if ($hasmanageactivities) {
        $actions['move'] = new action_link(new moodle_url($baseurl, array('copy' => $mod->id)), new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_move', 'title' => $str->move));
    }
    // Update
    if ($hasmanageactivities) {
        $actions['update'] = new action_link(new moodle_url($baseurl, array('update' => $mod->id)), new pix_icon('t/edit', $str->update, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_update', 'title' => $str->update));
    }
    // Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php)
    // note that restoring on front page is never allowed
    if ($mod->course != SITEID && has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) {
        $actions['duplicate'] = new action_link(new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_duplicate', 'title' => $str->duplicate));
    }
    // Delete
    if ($hasmanageactivities) {
        $actions['delete'] = new action_link(new moodle_url($baseurl, array('delete' => $mod->id)), new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_delete', 'title' => $str->delete));
    }
    // hideshow
    if (has_capability('moodle/course:activityvisibility', $modcontext)) {
        if ($mod->visible) {
            $actions['hide'] = new action_link(new moodle_url($baseurl, array('hide' => $mod->id)), new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_hide', 'title' => $str->hide));
        } else {
            $actions['show'] = new action_link(new moodle_url($baseurl, array('show' => $mod->id)), new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_show', 'title' => $str->show));
        }
    }
    // groupmode
    if ($hasmanageactivities and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
        if ($mod->coursegroupmodeforce) {
            $modgroupmode = $mod->coursegroupmode;
        } else {
            $modgroupmode = $mod->groupmode;
        }
        if ($modgroupmode == SEPARATEGROUPS) {
            $groupmode = NOGROUPS;
            $grouptitle = $str->groupsseparate;
            $forcedgrouptitle = $str->forcedgroupsseparate;
            $actionname = 'groupsseparate';
            $groupimage = 't/groups';
        } else {
            if ($modgroupmode == VISIBLEGROUPS) {
                $groupmode = SEPARATEGROUPS;
                $grouptitle = $str->groupsvisible;
                $forcedgrouptitle = $str->forcedgroupsvisible;
                $actionname = 'groupsvisible';
                $groupimage = 't/groupv';
            } else {
                $groupmode = VISIBLEGROUPS;
                $grouptitle = $str->groupsnone;
                $forcedgrouptitle = $str->forcedgroupsnone;
                $actionname = 'groupsnone';
                $groupimage = 't/groupn';
            }
        }
        if (!$mod->coursegroupmodeforce) {
            $actions[$actionname] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $groupmode)), new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_' . $actionname, 'title' => $grouptitle));
        } else {
            $actions[$actionname] = new pix_icon($groupimage, $forcedgrouptitle, 'moodle', array('title' => $forcedgrouptitle, 'class' => 'iconsmall'));
        }
    }
    // Assign
    if (has_capability('moodle/role:assign', $modcontext)) {
        $actions['assign'] = new action_link(new moodle_url('/admin/roles/assign.php', array('contextid' => $modcontext->id)), new pix_icon('t/assignroles', $str->assign, 'moodle', array('class' => 'iconsmall', 'title' => '')), null, array('class' => 'editing_assign', 'title' => $str->assign));
    }
    return $actions;
}
Exemplo n.º 23
0
/**
 * Obtains shared data that is used in print_section when displaying a
 * course-module entry.
 *
 * Calls format_text or format_string as appropriate, and obtains the correct icon.
 *
 * This data is also used in other areas of the code.
 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
 * @param object $course Moodle course object
 * @return array An array with the following values in this order:
 *   $content (optional extra content for after link),
 *   $instancename (text of link)
 */
function get_print_section_cm_text(cm_info $cm, $course)
{
    global $OUTPUT;
    // Get content from modinfo if specified. Content displays either
    // in addition to the standard link (below), or replaces it if
    // the link is turned off by setting ->url to null.
    if (($content = $cm->get_content()) !== '') {
        // Improve filter performance by preloading filter setttings for all
        // activities on the course (this does nothing if called multiple
        // times)
        filter_preload_activities($cm->get_modinfo());
        // Get module context
        $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        $labelformatoptions = new stdClass();
        $labelformatoptions->noclean = true;
        $labelformatoptions->overflowdiv = true;
        $labelformatoptions->context = $modulecontext;
        $content = format_text($content, FORMAT_HTML, $labelformatoptions);
    } else {
        $content = '';
    }
    // Get course context
    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
    $stringoptions = new stdClass();
    $stringoptions->context = $coursecontext;
    $instancename = format_string($cm->name, true, $stringoptions);
    return array($content, $instancename);
}
Exemplo n.º 24
0
 /**
  * Constructs based on course.
  * Note: This constructor should not usually be called directly.
  * Use get_fast_modinfo($course) instead as this maintains a cache.
  * @param object $course Moodle course object, which may include modinfo
  * @param int $userid User ID
  */
 public function __construct($course, $userid)
 {
     global $CFG, $DB;
     // Set initial values
     $this->courseid = $course->id;
     $this->userid = $userid;
     $this->sections = array();
     $this->cms = array();
     $this->instances = array();
     $this->groups = null;
     $this->course = $course;
     // Check modinfo field is set. If not, build and load it.
     if (empty($course->modinfo)) {
         rebuild_course_cache($course->id);
         $course->modinfo = $DB->get_field('course', 'modinfo', array('id' => $course->id));
     }
     // Load modinfo field into memory as PHP object and check it's valid
     $info = unserialize($course->modinfo);
     if (!is_array($info)) {
         // hmm, something is wrong - lets try to fix it
         rebuild_course_cache($course->id);
         $course->modinfo = $DB->get_field('course', 'modinfo', array('id' => $course->id));
         $info = unserialize($course->modinfo);
         if (!is_array($info)) {
             // If it still fails, abort
             debugging('Problem with "modinfo" data for this course');
             return;
         }
     }
     // If we haven't already preloaded contexts for the course, do it now
     preload_course_contexts($course->id);
     // Loop through each piece of module data, constructing it
     $modexists = array();
     foreach ($info as $mod) {
         if (empty($mod->name)) {
             // something is wrong here
             continue;
         }
         // Skip modules which don't exist
         if (empty($modexists[$mod->mod])) {
             if (!file_exists("{$CFG->dirroot}/mod/{$mod->mod}/lib.php")) {
                 continue;
             }
             $modexists[$mod->mod] = true;
         }
         // Construct info for this module
         $cm = new cm_info($this, $course, $mod, $info);
         // Store module in instances and cms array
         if (!isset($this->instances[$cm->modname])) {
             $this->instances[$cm->modname] = array();
         }
         $this->instances[$cm->modname][$cm->instance] = $cm;
         $this->cms[$cm->id] = $cm;
         // Reconstruct sections. This works because modules are stored in order
         if (!isset($this->sections[$cm->sectionnum])) {
             $this->sections[$cm->sectionnum] = array();
         }
         $this->sections[$cm->sectionnum][] = $cm->id;
     }
     // We need at least 'dynamic' data from each course-module (this is basically the remaining
     // data which was always present in previous version of get_fast_modinfo, so it's required
     // for BC). Creating it in a second pass is necessary because obtain_dynamic_data sometimes
     // needs to be able to refer to a 'complete' (with basic data) modinfo.
     foreach ($this->cms as $cm) {
         $cm->obtain_dynamic_data();
     }
 }
Exemplo n.º 25
0
/**
 * Called when viewing course page.
 *
 * @param cm_info $coursemodule
 */
function facetoface_cm_info_view(cm_info $coursemodule) {
    global $USER, $DB;

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

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

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

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

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

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

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

                $sessiondates = '';

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            $table .= html_writer::start_tag('tr')
                .html_writer::tag('td', ($iseditor || ($coursemodule->visible && $coursemodule->available)) ? $htmlviewallsessions : $strviewallsessions, array('colspan' => '2'))
                .html_writer::end_tag('tr')
                .html_writer::end_tag('table');
        } else {
            // Show only name if session display is set to zero.
            $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname f2fonepointfive'));
            $coursemodule->set_content($content);
            return;
        }
    } else if (has_capability('mod/facetoface:viewemptyactivities', $contextmodule)) {
        $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname f2fonepointfive'));
        $coursemodule->set_content($content);
        return;
    } else {
        // Nothing to display to this user.
        $coursemodule->set_content('');
        return;
    }
    $coursemodule->set_content($table);
}
Exemplo n.º 26
0
 /**
  * Renders html to display the module content on the course page (i.e. text of the labels)
  *
  * @param cm_info $mod
  * @param array $displayoptions
  * @return string
  */
 public function course_section_cm_text(cm_info $mod, $displayoptions = array())
 {
     $output = '';
     if (!$mod->uservisible && (empty($mod->showavailability) || empty($mod->availableinfo))) {
         // nothing to be displayed to the user
         return $output;
     }
     $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
     $accesstext = '';
     $textclasses = '';
     if ($mod->uservisible) {
         $conditionalhidden = $this->is_cm_conditionally_hidden($mod);
         $accessiblebutdim = (!$mod->visible || $conditionalhidden) && has_capability('moodle/course:viewhiddenactivities', context_course::instance($mod->course));
         if ($accessiblebutdim) {
             $textclasses .= ' dimmed_text';
             if ($conditionalhidden) {
                 $textclasses .= ' conditionalhidden';
             }
             // Show accessibility note only if user can access the module himself.
             $accesstext = get_accesshide(get_string('hiddenfromstudents') . ':' . $mod->modfullname);
         }
     } else {
         $textclasses .= ' dimmed_text';
     }
     if ($mod->get_url()) {
         if ($content) {
             // If specified, display extra content after link.
             $output = html_writer::tag('div', $content, array('class' => trim('contentafterlink ' . $textclasses)));
         }
     } else {
         // No link, so display only content.
         $output = html_writer::tag('div', $accesstext . $content, array('class' => 'contentwithoutlink ' . $textclasses));
     }
     return $output;
 }
Exemplo n.º 27
0
 /**
  * Adds a course module to the navigation node
  *
  * This is basically copied from function global_navigation::load_section_activities()
  * because it is not accessible from outside.
  *
  * @param navigation_node $node
  * @param cm_info $cm
  * @return null|navigation_node
  */
 protected function navigation_add_activity(navigation_node $node, $cm)
 {
     if (!$cm->uservisible) {
         return null;
     }
     $action = $cm->get_url();
     if (!$action) {
         // Do not add to navigation activity without url (i.e. labels).
         return null;
     }
     $activityname = format_string($cm->name, true, array('context' => context_module::instance($cm->id)));
     if ($cm->icon) {
         $icon = new pix_icon($cm->icon, $cm->modfullname, $cm->iconcomponent);
     } else {
         $icon = new pix_icon('icon', $cm->modfullname, $cm->modname);
     }
     $activitynode = $node->add($activityname, $action, navigation_node::TYPE_ACTIVITY, null, $cm->id, $icon);
     if (global_navigation::module_extends_navigation($cm->modname)) {
         $activitynode->nodetype = navigation_node::NODETYPE_BRANCH;
     } else {
         $activitynode->nodetype = navigation_node::NODETYPE_LEAF;
     }
     return $activitynode;
 }
Exemplo n.º 28
0
/**
 * Used by course/lib.php to display a few sessions besides the
 * facetoface activity on the course page
 *
 * @param object $cm the cm_info object for the F2F instance
 * @global class $USER used to get the current userid
 * @global class $CFG used to get the path to the module
 */
function facetoface_cm_info_view(cm_info $cm)
{
    global $CFG, $USER, $DB, $OUTPUT;
    $contextmodule = context_module::instance($cm->id);
    if (!has_capability('mod/facetoface:view', $contextmodule)) {
        return '';
        // Not allowed to view this activity.
    }
    $timenow = time();
    $facetoface = $DB->get_record('facetoface', array('id' => $cm->instance));
    if (!$facetoface) {
        error_log("mod/facetoface: ask to print coursemodule info for a non-existent activity ({$cm->instance})");
        return '';
    }
    // View all sessions link.
    $htmlviewallsessions = html_writer::link(new moodle_url('/mod/facetoface/view.php', array('f' => $facetoface->id)), get_string('viewallsessions', 'facetoface'), array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => get_string('viewallsessions', 'facetoface')));
    $table = new html_table();
    $table->attributes['class'] = 'table90 inlinetable';
    $table->data[] = array(html_writer::empty_tag('hr'));
    if ($submissions = facetoface_get_user_submissions($facetoface->id, $USER->id)) {
        $submission = array_shift($submissions);
        // First submission.
        // User has signedup for the instance.
        if ($session = facetoface_get_session($submission->sessionid)) {
            $sessiondate = '';
            $sessiontime = '';
            if ($session->datetimeknown) {
                foreach ($session->sessiondates as $date) {
                    if (!empty($sessiondate)) {
                        $sessiondate .= html_writer::empty_tag('br');
                    }
                    $sessiondate .= userdate($date->timestart, get_string('strftimedate'));
                    if (!empty($sessiontime)) {
                        $sessiontime .= html_writer::empty_tag('br');
                    }
                    $sessiontime .= userdate($date->timestart, get_string('strftimetime')) . ' - ' . userdate($date->timefinish, get_string('strftimetime'));
                }
            } else {
                $sessiondate = get_string('wait-listed', 'facetoface');
                $sessiontime = get_string('wait-listed', 'facetoface');
            }
            $location = ' ';
            $customfielddata = facetoface_get_customfielddata($session->id);
            if (!empty($customfielddata['location'])) {
                $location = ' ' . $customfielddata['location']->data;
            }
            $venue = ' ';
            if (!empty($customfielddata['venue'])) {
                $venue = ' ' . $customfielddata['venue']->data;
            }
            // Don't include the link to view attendees if user is lacking capability.
            $attendeeslink = '';
            if (has_capability('mod/facetoface:viewattendees', context_course::instance($cm->course))) {
                $strattendees = get_string('seeattendees', 'facetoface');
                $attendeesurl = new moodle_url('/mod/facetoface/attendees.php', array('s' => $session->id));
                $attendeeslink = ' ' . html_writer::link($attendeesurl, $strattendees, array('class' => 'f2fsessionlinks f2fviewattendees', 'title' => $strattendees));
            }
            // Don't include the link to cancel a session if it has already occurred.
            $cancellink = '';
            if (!facetoface_has_session_started($session, $timenow)) {
                $strcancel = get_string('cancelbooking', 'facetoface');
                $cancelurl = new moodle_url('/mod/facetoface/cancelsignup.php', array('s' => $session->id));
                $cancellink = ' ' . html_writer::link($cancelurl, $strcancel, array('class' => 'f2fsessionlinks f2fcancel', 'title' => $strcancel));
            }
            // Add table data.
            $table->data[] = array(get_string('bookingstatus', 'facetoface') . ': ');
            $table->data[] = array($location, $venue, $sessiondate, $sessiontime);
            $table->data[] = array(html_writer::tag('span', get_string('options', 'facetoface') . ': ' . html_writer::link(new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)), get_string('moreinfo', 'facetoface'), array('class' => 'f2fsessionlinks f2fsessioninfolink', 'title' => get_string('moreinfo', 'facetoface'))) . "{$attendeeslink}{$cancellink}"));
            $table->data[] = array($htmlviewallsessions);
        }
    } else {
        if ($facetoface->display > 0 && ($sessions = facetoface_get_sessions($facetoface->id))) {
            $table->data[] = array(get_string('signupforsession', 'facetoface'));
            $count = 0;
            foreach ($sessions as $session) {
                // Don't display past or in-progress sessions.
                if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) {
                    continue;
                }
                // Don't diisplay full sessions.
                if (!facetoface_session_has_capacity($session, $contextmodule)) {
                    continue;
                }
                // Check display count.
                $count++;
                if ($count > $facetoface->display) {
                    break;
                }
                $multiday = '';
                $sessiondate = '';
                $sessiontime = '';
                if ($session->datetimeknown) {
                    if (empty($session->sessiondates)) {
                        $sessiondate = get_string('unknowndate', 'facetoface');
                        $sessiontime = get_string('unknowntime', 'facetoface');
                    } else {
                        $sessiondate = userdate($session->sessiondates[0]->timestart, get_string('strftimedate'));
                        $sessiontime = userdate($session->sessiondates[0]->timestart, get_string('strftimetime')) . ' - ' . userdate($session->sessiondates[0]->timefinish, get_string('strftimetime'));
                        if (count($session->sessiondates) > 1) {
                            $multiday = ' (' . get_string('multiday', 'facetoface') . ')';
                        }
                    }
                } else {
                    $sessiondate = get_string('wait-listed', 'facetoface');
                }
                $locationstr = '';
                $customfielddata = facetoface_get_customfielddata($session->id);
                if (!empty($customfielddata['location']) && trim($customfielddata['location']->data) != '') {
                    $locationstr = $customfielddata['location']->data . ', ';
                }
                if ($cm->uservisible) {
                    $signupurl = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id));
                    $row = array(html_writer::link($signupurl, "{$locationstr} {$sessiondate} {$sessiontime} {$multiday}", array('class' => 'f2fsessiontime')));
                } else {
                    $row = array(html_writer::tag('span', "{$locationstr} {$sessiondate} {$sessiontime} {$multiday}", array('class' => 'f2fsessiontime')));
                }
                // Add to table.
                $table->data[] = $row;
            }
            if ($cm->uservisible) {
                $table->data[] = array($htmlviewallsessions);
            } else {
                $table->data[] = array($strviewallsessions);
            }
        } else {
            // Nothing to display to this user.
            return;
        }
    }
    $cm->set_after_link(html_writer::table($table));
}
Exemplo n.º 29
0
 /**
  * Adds a course module to the navigation node
  *
  * @param navigation_node $node
  * @param cm_info $cm
  * @return null|navigation_node
  */
 protected function navigation_add_activity(navigation_node $node, $cm)
 {
     if (!$cm->uservisible || !$cm->has_view()) {
         return null;
     }
     $activityname = $cm->get_formatted_name();
     $action = $cm->url;
     if ($cm->icon) {
         $icon = new pix_icon($cm->icon, $cm->modfullname, $cm->iconcomponent);
     } else {
         $icon = new pix_icon('icon', $cm->modfullname, $cm->modname);
     }
     $activitynode = $node->add($activityname, $action, navigation_node::TYPE_ACTIVITY, null, $cm->id, $icon);
     if (global_navigation::module_extends_navigation($cm->modname)) {
         $activitynode->nodetype = navigation_node::NODETYPE_BRANCH;
     } else {
         $activitynode->nodetype = navigation_node::NODETYPE_LEAF;
     }
     return $activitynode;
 }
Exemplo n.º 30
0
 /**
  * Checks if an activity is visible to the given user.
  *
  * Unlike other checks in the availability system, this check includes the
  * $cm->visible flag. It is equivalent to $cm->uservisible.
  *
  * If you have already checked (or do not care whether) the user has access
  * to the course, you can set $checkcourse to false to save it checking
  * course access.
  *
  * When checking for the current user, you should generally not call
  * this function. Instead, use get_fast_modinfo to get a cm_info object,
  * then simply check the $cm->uservisible flag. This function is intended
  * to obtain that information for a separate course-module object that
  * wasn't loaded with get_fast_modinfo, or for a different user.
  *
  * This function has a performance cost unless the availability system is
  * disabled, and you supply a $cm object with necessary fields, and you
  * don't check course access.
  *
  * @param int|\stdClass|\cm_info $cmorid Object or id representing activity
  * @param int $userid User id (0 = current user)
  * @param bool $checkcourse If true, checks whether the user has course access
  * @return bool True if the activity is visible to the specified user
  * @throws \moodle_exception If the cmid doesn't exist
  */
 public static function is_user_visible($cmorid, $userid = 0, $checkcourse = true)
 {
     global $USER, $DB, $CFG;
     // Evaluate user id.
     if (!$userid) {
         $userid = $USER->id;
     }
     // If this happens to be already called with a cm_info for the right user
     // then just return uservisible.
     if ($cmorid instanceof \cm_info && $cmorid->get_modinfo()->userid == $userid) {
         return $cmorid->uservisible;
     }
     // If the $cmorid isn't an object or doesn't have required fields, load it.
     if (is_object($cmorid) && isset($cmorid->course) && isset($cmorid->visible)) {
         $cm = $cmorid;
     } else {
         if (is_object($cmorid)) {
             $cmorid = $cmorid->id;
         }
         $cm = $DB->get_record('course_modules', array('id' => $cmorid));
         if (!$cm) {
             // In some error cases, the course module may not exist.
             debugging('info_module::is_user_visible called with invalid cmid ' . $cmorid, DEBUG_DEVELOPER);
             return false;
         }
     }
     // If requested, check user can access the course.
     if ($checkcourse) {
         $coursecontext = \context_course::instance($cm->course);
         if (!is_enrolled($coursecontext, $userid, '', true) && !has_capability('moodle/course:view', $coursecontext, $userid)) {
             return false;
         }
     }
     // If availability is disabled, then all we need to do is check the visible flag.
     if (!$CFG->enableavailability && $cm->visible) {
         return true;
     }
     // When availability is enabled, access can depend on 3 things:
     // 1. $cm->visible
     // 2. $cm->availability
     // 3. $section->availability (for activity section and possibly for
     //    parent sections)
     // As a result we cannot take short cuts any longer and must get
     // standard modinfo.
     $modinfo = get_fast_modinfo($cm->course, $userid);
     $cms = $modinfo->get_cms();
     if (!isset($cms[$cm->id])) {
         // In some cases this might get called with a cmid that is no longer
         // available, for example when a module is hidden at system level.
         debugging('info_module::is_user_visible called with invalid cmid ' . $cm->id, DEBUG_DEVELOPER);
         return false;
     }
     return $cms[$cm->id]->uservisible;
 }