function definition()
 {
     global $COURSE;
     $mform =& $this->_form;
     $mform->addElement('text', 'name', get_string('groupselectname', 'groupselect'), array('size' => '64'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addElement('htmleditor', 'intro', get_string('intro', 'groupselect'));
     $mform->setType('intro', PARAM_RAW);
     $mform->addRule('intro', get_string('required'), 'required', null, 'client');
     $mform->setHelpButton('intro', array('questions', 'richtext'), false, 'editorhelpbutton');
     $options = array();
     $options[0] = get_string('fromallgroups', 'groupselect');
     if ($groupings = groups_get_all_groupings($COURSE->id)) {
         foreach ($groupings as $grouping) {
             $options[$grouping->id] = format_string($grouping->name);
         }
     }
     $mform->addElement('select', 'targetgrouping', get_string('targetgrouping', 'groupselect'), $options);
     $mform->addElement('passwordunmask', 'password', get_string('password', 'groupselect'), 'maxlength="254" size="24"');
     $mform->setType('password', PARAM_RAW);
     $mform->addElement('text', 'maxmembers', get_string('maxmembers', 'groupselect'), array('size' => '4'));
     $mform->setType('maxmembers', PARAM_INT);
     $mform->setDefault('maxmembers', 0);
     $mform->addElement('date_time_selector', 'timeavailable', get_string('timeavailable', 'groupselect'), array('optional' => true));
     $mform->setDefault('timeavailable', 0);
     $mform->addElement('date_time_selector', 'timedue', get_string('timedue', 'groupselect'), array('optional' => true));
     $mform->setDefault('timedue', 0);
     $features = array('groups' => true, 'groupings' => true, 'groupmembersonly' => true, 'outcomes' => false, 'gradecat' => false, 'idnumber' => false);
     $this->standard_coursemodule_elements($features);
     //-------------------------------------------------------------------------------
     // buttons
     $this->add_action_buttons();
 }
 /**
  * Definition of administration form
  */
 protected function definition()
 {
     global $CFG, $DB, $PAGE;
     $mform = $this->_form;
     $mform->addElement('hidden', 'id');
     $mform->setDefault('id', $this->_customdata['id']);
     $mform->setType('id', PARAM_INT);
     $this->context = \context_module::instance($this->_customdata['id']);
     $cm = get_coursemodule_from_id('grouptool', $this->_customdata['id']);
     $course = $DB->get_record('course', array('id' => $cm->course));
     $grouptool = $DB->get_record('grouptool', array('id' => $cm->instance), '*', MUST_EXIST);
     $coursecontext = \context_course::instance($cm->course);
     foreach ($this->_customdata['selected'] as $select) {
         $mform->addElement('hidden', 'selected[' . $select . ']');
         $mform->setDefault('selected[' . $select . ']', $select);
         $mform->setType('selected[' . $select . ']', PARAM_INT);
     }
     $mform->addElement('hidden', 'tab');
     $mform->setDefault('tab', 'group_admin');
     $mform->setType('tab', PARAM_TEXT);
     $mform->addElement('hidden', 'courseid');
     $mform->setDefault('courseid', $course->id);
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'bulkaction');
     $mform->setDefault('bulkaction', 'grouping');
     $mform->setType('bulkaction', PARAM_TEXT);
     $mform->addElement('hidden', 'start_bulkaction');
     $mform->setDefault('start_bulkaction', 1);
     $mform->setType('start_bulkaction', PARAM_BOOL);
     $groupingel = $mform->createElement('selectgroups', 'target', get_string('groupingselect', 'grouptool'));
     $options = array('' => get_string('choose', 'grouptool'));
     $options['-1'] = get_string('onenewgrouping', 'grouptool');
     $options['-2'] = get_string('onenewgroupingpergroup', 'grouptool');
     $groupingel->addOptGroup("", $options);
     if ($groupings = groups_get_all_groupings($course->id)) {
         $options = array();
         foreach ($groupings as $grouping) {
             $options[$grouping->id] = strip_tags(format_string($grouping->name));
         }
         $groupingel->addOptGroup("————————————————————————", $options);
     }
     $mform->addElement($groupingel);
     $mform->addHelpButton('target', 'groupingselect', 'grouptool');
     $mform->addElement('text', 'name', get_string('groupingname', 'group'));
     $mform->setType('name', PARAM_MULTILANG);
     $mform->disabledif('name', 'target', 'noteq', '-1');
     $grp = array();
     $grp[] = $mform->createElement('submit', 'createGroupings', get_string('create_assign_groupings', 'grouptool'));
     $grp[] = $mform->createElement('cancel');
     $mform->addGroup($grp, 'actionbuttons', '', array(' '), false);
     $mform->setType('actionbuttons', PARAM_RAW);
 }
 function definition()
 {
     global $DB, $PAGE, $OUTPUT;
     $id = optional_param('id', 0, PARAM_INT);
     $a = optional_param('a', 0, PARAM_INT);
     if ($id) {
         if (!($cm = get_coursemodule_from_id('blended', $id))) {
             print_error("Course Module ID was incorrect");
         }
         if (!($course = get_course($cm->course))) {
             print_error("Course is misconfigured");
         }
         if (!($blended = $DB->get_record('blended', array('id' => $cm->instance)))) {
             print_error("Course module is incorrect");
         }
         if (!($context = context_course::instance($course->id))) {
             print_error("Context ID is incorrect");
         }
     } else {
         if (!($blended = $DB->get_record('blended', array('id' => $a)))) {
             print_error("Course module is incorrect");
         }
         if (!($course = $DB->get_record('course', array('id' => $blended->course)))) {
             print_error("Course is misconfigured");
         }
         if (!($cm = get_coursemodule_from_instance("blended", $blended->id, $course->id))) {
             print_error("Course Module ID was incorrect");
         }
         if (!($context = context_course::instance($course->id))) {
             print_error("Context ID is incorrect");
         }
     }
     $form =& $this->_form;
     $t = 0;
     $agrupamientos = array();
     $agrupamientos[$t] = 'Eliga';
     if ($groups = groups_get_all_groupings($course->id)) {
         foreach ($groups as $group) {
             $t++;
             $agrupamientos[$t] = $group->name;
         }
     }
     //Select Elements
     $form->addElement('select', 'grouping', get_string('select_grouping', 'blended'), $agrupamientos);
 }
/**
 * Get all FN Site Groups. If a course is specified, and the course is using the FN Site
 * Groups enrolment plug-in, then return the groups currently in use in the course.
 *
 * @param int    $courseid   The id of the requested course
 * @param int    $userid     The id of the requested user or all.
 * @param int    $groupingid The id of the requested grouping or all.
 * @param string $fields     The fields to return or all.
 * @return array
 */
function fn_sg_get_all_groups($courseid = SITEID, $userid = 0, $groupingid = 0, $fields = 'g.*')
{
    global $CFG;
    if (!($course = get_record('course', 'id', $courseid, null, null, null, null, 'id,enrol'))) {
        return false;
    }
    if ($courseid != SITEID && fn_sg_course_uses_sgenrol($course)) {
        /// Get site groups used in course.
        $agroups = false;
    } else {
        $agroups = groups_get_all_groups(SITEID, $userid, $groupingid, $fields);
    }
    if (!is_array($agroups)) {
        $agroups = array();
    }
    if (!($groupings = groups_get_all_groupings(SITEID))) {
        $groupings = array();
    }
    $groups = array();
    foreach ($groupings as $groupingid => $grouping) {
        $groups['g_' . $groupingid] = $grouping;
        if ($ggroups = groups_get_all_groups(SITEID, $userid, $groupingid, $fields)) {
            foreach ($ggroups as $ggroupid => $ggroup) {
                $ggroup->name = ' - ' . $ggroup->name;
                $groups[$ggroupid] = $ggroup;
                unset($agroups[$ggroupid]);
            }
        }
    }
    $nogrouping = new Object();
    $nogrouping->id = 0;
    $nogrouping->name = 'NOT IN GROUPING';
    foreach ($agroups as $agroup) {
        $agroup->name = ' - ' . $agroup->name;
    }
    if (!empty($agroups)) {
        $groups = $groups + array('g_0' => $nogrouping) + $agroups;
    }
    return $groups;
}
/**
 * Prints a section full of activity modules
 * @Overrides course/lib.php=>print_section
 */
function ss_print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false) {
	#print_r($mods);
	
	global $CFG, $USER, $DB, $PAGE, $OUTPUT;

    static $initialised;

    static $groupbuttons;
    static $groupbuttonslink;
    static $isediting;
    static $ismoving;
    static $strmovehere;
    static $strmovefull;
    static $strunreadpostsone;
    static $usetracking;
    static $groupings;

    if (!isset($initialised)) {
        $groupbuttons     = ($course->groupmode or (!$course->groupmodeforce));
        $groupbuttonslink = (!$course->groupmodeforce);
        $isediting        = $PAGE->user_is_editing();
        $ismoving         = $isediting && ismoving($course->id);
        if ($ismoving) {
            $strmovehere  = get_string("movehere");
            $strmovefull  = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
        }
        include_once($CFG->dirroot.'/mod/forum/lib.php');
        if ($usetracking = forum_tp_can_track_forums()) {
            $strunreadpostsone = get_string('unreadpostsone', 'forum');
        }
        $initialised = true;
    }

    $labelformatoptions = new stdClass();
    $labelformatoptions->noclean = true;
    $labelformatoptions->overflowdiv = true;

/// Casting $course->modinfo to string prevents one notice when the field is null
    $modinfo = get_fast_modinfo($course);
    $completioninfo = new completion_info($course);

    //Accessibility: replace table with list <ul>, but don't output empty list.
    if (!empty($section->sequence)) {

        // Fix bug #5027, don't want style=\"width:$width\".
        echo "<ul class=\"section img-text\">\n";
        $sectionmods = explode(",", $section->sequence);

        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }

            $mod = $mods[$modnumber];
            
            if ($ismoving and $mod->id == $USER->activitycopy) {
                // do not display moving mod
                continue;
            }

            if (isset($modinfo->cms[$modnumber])) {
                // We can continue (because it will not be displayed at all)
                // if:
                // 1) The activity is not visible to users
                // and
                // 2a) The 'showavailability' option is not set (if that is set,
                //     we need to display the activity so we can show
                //     availability info)
                // or
                // 2b) The 'availableinfo' is empty, i.e. the activity was
                //     hidden in a way that leaves no info, such as using the
                //     eye icon.
                if (!$modinfo->cms[$modnumber]->uservisible &&
                    (empty($modinfo->cms[$modnumber]->showavailability) ||
                      empty($modinfo->cms[$modnumber]->availableinfo))) {
                    // visibility shortcut
                    continue;
                }
            } else {
                if (!file_exists("$CFG->dirroot/mod/$mod->modname/lib.php")) {
                    // module not installed
                    continue;
                }
                if (!coursemodule_visible_for_user($mod) &&
                    empty($mod->showavailability)) {
                    // full visibility check
                    continue;
                }
            }

            // In some cases the activity is visible to user, but it is
            // dimmed. This is done if viewhiddenactivities is true and if:
            // 1. the activity is not visible, or
            // 2. the activity has dates set which do not include current, or
            // 3. the activity has any other conditions set (regardless of whether
            //    current user meets them)
            $canviewhidden = has_capability(
                'moodle/course:viewhiddenactivities',
                get_context_instance(CONTEXT_MODULE, $mod->id));
            $accessiblebutdim = false;
            if ($canviewhidden) {
                $accessiblebutdim = !$mod->visible;
                if (!empty($CFG->enableavailability)) {
                    $accessiblebutdim = $accessiblebutdim ||
                        $mod->availablefrom > time() ||
                        ($mod->availableuntil && $mod->availableuntil < time()) ||
                        count($mod->conditionsgrade) > 0 ||
                        count($mod->conditionscompletion) > 0;
                }
            }

            $liclasses = array();
            $liclasses[] = 'activity';
            $liclasses[] = $mod->modname;
            $liclasses[] = 'modtype_'.$mod->modname;
            
            
            echo html_writer::start_tag('li', array('class'=>join(' ', $liclasses), 'id'=>'module-'.$modnumber));
            if ($ismoving) {
                echo '<a title="'.$strmovefull.'"'.
                     ' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
                     '<img class="movetarget" src="'.$OUTPUT->pix_url('movehere') . '" '.
                     ' alt="'.$strmovehere.'" /></a><br />
                     ';
            }

            $classes = array('mod-indent');
            if (!empty($mod->indent)) {
                $classes[] = 'mod-indent-'.$mod->indent;
                if ($mod->indent > 15) {
                    $classes[] = 'mod-indent-huge';
                }
            }
            echo html_writer::start_tag('div', array('class'=>join(' ', $classes)));

            $extra = '';
            if (!empty($modinfo->cms[$modnumber]->extra)) {
                $extra = $modinfo->cms[$modnumber]->extra;
            }
            
            if ($mod->modname == "label") {
                if ($accessiblebutdim || !$mod->uservisible) {
                    echo '<div class="dimmed_text"><span class="accesshide">'.
                        get_string('hiddenfromstudents').'</span>';
                } else {
                    echo '<div>';
                }
                echo format_text($extra, FORMAT_HTML, $labelformatoptions);
                echo "</div>";
                if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(".format_string($groupings[$mod->groupingid]->name).')</span>';
                }

            } else { // Normal activity
                $instancename = format_string($modinfo->cms[$modnumber]->name, true,  $course->id);
              #  echo format_string($modinfo->cms[$modnumber]->intro, true,  $course->id);
              #  echo format_string($modinfo->cms[$modnumber]->name, true,  $course->id);
              #  print_r($modinfo->cms[$modnumber]);

                $customicon = $modinfo->cms[$modnumber]->icon;
                if (!empty($customicon)) {
                    if (substr($customicon, 0, 4) === 'mod/') {
                        list($modname, $iconname) = explode('/', substr($customicon, 4), 2);
                        $icon = $OUTPUT->pix_url($iconname, $modname);
                    } else {
                        $icon = $OUTPUT->pix_url($customicon);
                    }
                } else {
                    $icon = $OUTPUT->pix_url('icon', $mod->modname);
                }

                //Accessibility: for files get description via icon, this is very ugly hack!
                $altname = '';
                $altname = $mod->modfullname;
                if (!empty($customicon)) {
                    $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
                    if ($archetype == MOD_ARCHETYPE_RESOURCE) {
                        $mimetype = mimeinfo_from_icon('type', $customicon);
                        $altname = get_mimetype_description($mimetype);
                    }
                }
                // Avoid unnecessary duplication.
                if (false !== stripos($instancename, $altname)) {
                    $altname = '';
                }
                // File type after name, for alphabetic lists (screen reader).
                if ($altname) {
                    $altname = get_accesshide(' '.$altname);
                }

                // We may be displaying this just in order to show information
                // about visibility, without the actual link
                if ($mod->uservisible) {
                    // Display normal module link
                    if (!$accessiblebutdim) {
                        $linkcss = '';
                        $accesstext  ='';
                    } else {
                        $linkcss = ' class="dimmed" ';
                        $accesstext = '<span class="accesshide">'.
                            get_string('hiddenfromstudents').': </span>';
                    }

                    echo '<a '.$linkcss.' '.$extra.
                         ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
                         '<img src="'.$icon.'" class="activityicon" alt="'.get_string('modulename',$mod->modname).'" /> '.
                         $accesstext.'<span class="instancename">'.$instancename.$altname.'</span></a>';

                    if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                        if (!isset($groupings)) {
                            $groupings = groups_get_all_groupings($course->id);
                        }
                        echo " <span class=\"groupinglabel\">(".format_string($groupings[$mod->groupingid]->name).')</span>';
                    }
                } else {
                    // Display greyed-out text of link
                    echo '<span class="dimmed_text" '.$extra.' ><span class="accesshide">'.
                        get_string('notavailableyet','condition').': </span>'.
                        '<img src="'.$icon.'" class="activityicon" alt="'.get_string('modulename', $mod->modname).'" /> <span>'.
                        $instancename.$altname.'</span></span>';
                }
            }
            if ($usetracking && $mod->modname == 'forum') {
                if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) {
                    echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">';
                    if ($unread == 1) {
                        echo $strunreadpostsone;
                    } else {
                        print_string('unreadpostsnumber', 'forum', $unread);
                    }
                    echo '</a></span>';
                }
            }

            if ($isediting) {
                if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
                    if (! $mod->groupmodelink = $groupbuttonslink) {
                        $mod->groupmode = $course->groupmode;
                    }

                } else {
                    $mod->groupmode = false;
                }
                echo '&nbsp;&nbsp;';
                echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
                hook_make_edit_icon_button($mod, $OUTPUT);
                
            }

            // Completion
            $completion = $hidecompletion
                ? COMPLETION_TRACKING_NONE
                : $completioninfo->is_enabled($mod);
            if ($completion!=COMPLETION_TRACKING_NONE && isloggedin() &&
                !isguestuser() && $mod->uservisible) {
                $completiondata = $completioninfo->get_data($mod,true);
                $completionicon = '';
                if ($isediting) {
                    switch ($completion) {
                        case COMPLETION_TRACKING_MANUAL :
                            $completionicon = 'manual-enabled'; break;
                        case COMPLETION_TRACKING_AUTOMATIC :
                            $completionicon = 'auto-enabled'; break;
                        default: // wtf
                    }
                } else if ($completion==COMPLETION_TRACKING_MANUAL) {
                    switch($completiondata->completionstate) {
                        case COMPLETION_INCOMPLETE:
                            $completionicon = 'manual-n'; break;
                        case COMPLETION_COMPLETE:
                            $completionicon = 'manual-y'; break;
                    }
                } else { // Automatic
                    switch($completiondata->completionstate) {
                        case COMPLETION_INCOMPLETE:
                            $completionicon = 'auto-n'; break;
                        case COMPLETION_COMPLETE:
                            $completionicon = 'auto-y'; break;
                        case COMPLETION_COMPLETE_PASS:
                            $completionicon = 'auto-pass'; break;
                        case COMPLETION_COMPLETE_FAIL:
                            $completionicon = 'auto-fail'; break;
                    }
                }
                if ($completionicon) {
                    $imgsrc = $OUTPUT->pix_url('i/completion-'.$completionicon);
                    $imgalt = s(get_string('completion-alt-'.$completionicon, 'completion'));
                    if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting) {
                        $imgtitle = s(get_string('completion-title-'.$completionicon, 'completion'));
                        $newstate =
                            $completiondata->completionstate==COMPLETION_COMPLETE
                            ? COMPLETION_INCOMPLETE
                            : COMPLETION_COMPLETE;
                        // In manual mode the icon is a toggle form...

                        // If this completion state is used by the
                        // conditional activities system, we need to turn
                        // off the JS.
                        if (!empty($CFG->enableavailability) &&
                            condition_info::completion_value_used_as_condition($course, $mod)) {
                            $extraclass = ' preventjs';
                        } else {
                            $extraclass = '';
                        }
                        echo "
<form class='togglecompletion$extraclass' method='post' action='togglecompletion.php'><div>
<input type='hidden' name='id' value='{$mod->id}' />
<input type='hidden' name='sesskey' value='".sesskey()."' />
<input type='hidden' name='completionstate' value='$newstate' />
<input type='image' src='$imgsrc' alt='$imgalt' title='$imgtitle' />
</div></form>";
                    } else {
                        // In auto mode, or when editing, the icon is just an image
                        echo "<span class='autocompletion'>";
                        echo "<img src='$imgsrc' alt='$imgalt' title='$imgalt' /></span>";
                    }
                }
            }

            // Show availability information (for someone who isn't allowed to
            // see the activity itself, or for staff)
            if (!$mod->uservisible) {
                echo '<div class="availabilityinfo">'.$mod->availableinfo.'</div>';
            } else if ($canviewhidden && !empty($CFG->enableavailability)) {
                $ci = new condition_info($mod);
                $fullinfo = $ci->get_full_information();
                if($fullinfo) {
                    echo '<div class="availabilityinfo">'.get_string($mod->showavailability
                        ? 'userrestriction_visible'
                        : 'userrestriction_hidden','condition',
                        $fullinfo).'</div>';
                }
            }

            echo hook_show_activity_intro($mod);
            echo html_writer::end_tag('div');
            echo html_writer::end_tag('li')."\n";
        }

    } elseif ($ismoving) {
        echo "<ul class=\"section\">\n";
    }

    if ($ismoving) {
        echo '<li><a title="'.$strmovefull.'"'.
             ' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
             '<img class="movetarget" src="'.$OUTPUT->pix_url('movehere') . '" '.
             ' alt="'.$strmovehere.'" /></a></li>
             ';
    }
    if (!empty($section->sequence) || $ismoving) {
        echo "</ul><!--class='section'-->\n\n";
    }
}
Example #6
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;
 }
 /**
  * Form Definition
  */
 function definition()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     $mform->addElement('header', 'autogroup', get_string('general'));
     $mform->addElement('text', 'namingscheme', get_string('namingscheme', 'group'));
     $mform->addHelpButton('namingscheme', 'namingscheme', 'group');
     $mform->addRule('namingscheme', get_string('required'), 'required', null, 'client');
     $mform->setType('namingscheme', PARAM_TEXT);
     // There must not be duplicate group names in course.
     $template = get_string('grouptemplate', 'group');
     $gname = groups_parse_name($template, 0);
     if (!groups_get_group_by_name($COURSE->id, $gname)) {
         $mform->setDefault('namingscheme', $template);
     }
     $options = array('groups' => get_string('numgroups', 'group'), 'members' => get_string('nummembers', 'group'));
     $mform->addElement('select', 'groupby', get_string('groupby', 'group'), $options);
     $mform->addElement('text', 'number', get_string('number', 'group'), 'maxlength="4" size="4"');
     $mform->setType('number', PARAM_INT);
     $mform->addRule('number', null, 'numeric', null, 'client');
     $mform->addRule('number', get_string('required'), 'required', null, 'client');
     $mform->addElement('header', 'groupmembershdr', get_string('groupmembers', 'group'));
     $mform->setExpanded('groupmembershdr', true);
     $options = array(0 => get_string('all'));
     $options += $this->_customdata['roles'];
     $mform->addElement('select', 'roleid', get_string('selectfromrole', 'group'), $options);
     $student = get_archetype_roles('student');
     $student = reset($student);
     if ($student and array_key_exists($student->id, $options)) {
         $mform->setDefault('roleid', $student->id);
     }
     if ($cohorts = cohort_get_available_cohorts(context_course::instance($COURSE->id), COHORT_WITH_ENROLLED_MEMBERS_ONLY)) {
         $options = array(0 => get_string('anycohort', 'cohort'));
         foreach ($cohorts as $c) {
             $options[$c->id] = format_string($c->name, true, context::instance_by_id($c->contextid));
         }
         $mform->addElement('select', 'cohortid', get_string('selectfromcohort', 'cohort'), $options);
         $mform->setDefault('cohortid', '0');
     } else {
         $mform->addElement('hidden', 'cohortid');
         $mform->setType('cohortid', PARAM_INT);
         $mform->setConstant('cohortid', '0');
     }
     if ($groupings = groups_get_all_groupings($COURSE->id)) {
         $options = array();
         $options[0] = get_string('none');
         foreach ($groupings as $grouping) {
             $options[$grouping->id] = format_string($grouping->name);
         }
         $mform->addElement('select', 'groupingid', get_string('selectfromgrouping', 'group'), $options);
         $mform->setDefault('groupingid', 0);
         $mform->disabledIf('groupingid', 'notingroup', 'checked');
     } else {
         $mform->addElement('hidden', 'groupingid');
         $mform->setType('groupingid', PARAM_INT);
         $mform->setConstant('groupingid', 0);
     }
     if ($groups = groups_get_all_groups($COURSE->id)) {
         $options = array();
         $options[0] = get_string('none');
         foreach ($groups as $group) {
             $options[$group->id] = format_string($group->name);
         }
         $mform->addElement('select', 'groupid', get_string('selectfromgroup', 'group'), $options);
         $mform->setDefault('groupid', 0);
         $mform->disabledIf('groupid', 'notingroup', 'checked');
     } else {
         $mform->addElement('hidden', 'groupid');
         $mform->setType('groupid', PARAM_INT);
         $mform->setConstant('groupid', 0);
     }
     $options = array('no' => get_string('noallocation', 'group'), 'random' => get_string('random', 'group'), 'firstname' => get_string('byfirstname', 'group'), 'lastname' => get_string('bylastname', 'group'), 'idnumber' => get_string('byidnumber', 'group'));
     $mform->addElement('select', 'allocateby', get_string('allocateby', 'group'), $options);
     $mform->setDefault('allocateby', 'random');
     $mform->addElement('checkbox', 'nosmallgroups', get_string('nosmallgroups', 'group'));
     $mform->disabledIf('nosmallgroups', 'groupby', 'noteq', 'members');
     $mform->addElement('checkbox', 'notingroup', get_string('notingroup', 'group'));
     $mform->disabledIf('notingroup', 'groupingid', 'neq', 0);
     $mform->disabledIf('notingroup', 'groupid', 'neq', 0);
     $mform->addElement('header', 'groupinghdr', get_string('grouping', 'group'));
     $options = array('0' => get_string('nogrouping', 'group'), '-1' => get_string('newgrouping', 'group'));
     if ($groupings = groups_get_all_groupings($COURSE->id)) {
         foreach ($groupings as $grouping) {
             $options[$grouping->id] = strip_tags(format_string($grouping->name));
         }
     }
     $mform->addElement('select', 'grouping', get_string('createingrouping', 'group'), $options);
     if ($groupings) {
         $mform->setDefault('grouping', '-1');
     }
     $mform->addElement('text', 'groupingname', get_string('groupingname', 'group'), $options);
     $mform->setType('groupingname', PARAM_TEXT);
     $mform->disabledIf('groupingname', 'grouping', 'noteq', '-1');
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'seed');
     $mform->setType('seed', PARAM_INT);
     $buttonarray = array();
     $buttonarray[] =& $mform->createElement('submit', 'preview', get_string('preview'));
     $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('submit'));
     $buttonarray[] =& $mform->createElement('cancel');
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
Example #8
0
 /**
  * Renders html to display a name with the link to the course module on a course page
  *
  * If module is unavailable for user but still needs to be displayed
  * in the list, just the name is returned without a link
  *
  * Note, that for course modules that never have separate pages (i.e. labels)
  * this function return an empty string
  *
  * @param cm_info $mod
  * @param array $displayoptions
  * @return string
  */
 public function course_section_cm_name(cm_info $mod, $displayoptions = array())
 {
     global $CFG;
     $output = '';
     if (!$mod->uservisible && (empty($mod->showavailability) || empty($mod->availableinfo))) {
         // nothing to be displayed to the user
         return $output;
     }
     $url = $mod->get_url();
     if (!$url) {
         return $output;
     }
     //Accessibility: for files get description via icon, this is very ugly hack!
     $instancename = $mod->get_formatted_name();
     $altname = $mod->modfullname;
     // Avoid unnecessary duplication: if e.g. a forum name already
     // includes the word forum (or Forum, etc) then it is unhelpful
     // to include that in the accessible description that is added.
     if (false !== strpos(core_text::strtolower($instancename), core_text::strtolower($altname))) {
         $altname = '';
     }
     // File type after name, for alphabetic lists (screen reader).
     if ($altname) {
         $altname = get_accesshide(' ' . $altname);
     }
     // For items which are hidden but available to current user
     // ($mod->uservisible), we show those as dimmed only if the user has
     // viewhiddenactivities, so that teachers see 'items which might not
     // be available to some students' dimmed but students do not see 'item
     // which is actually available to current student' dimmed.
     $linkclasses = '';
     $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) {
             $linkclasses .= ' dimmed';
             $textclasses .= ' dimmed_text';
             if ($conditionalhidden) {
                 $linkclasses .= ' conditionalhidden';
                 $textclasses .= ' conditionalhidden';
             }
             // Show accessibility note only if user can access the module himself.
             $accesstext = get_accesshide(get_string('hiddenfromstudents') . ':' . $mod->modfullname);
         }
     } else {
         $linkclasses .= ' dimmed';
         $textclasses .= ' dimmed_text';
     }
     // Get on-click attribute value if specified and decode the onclick - it
     // has already been encoded for display (puke).
     $onclick = htmlspecialchars_decode($mod->get_on_click(), ENT_QUOTES);
     $groupinglabel = '';
     if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', context_course::instance($mod->course))) {
         $groupings = groups_get_all_groupings($mod->course);
         $groupinglabel = html_writer::tag('span', '(' . format_string($groupings[$mod->groupingid]->name) . ')', array('class' => 'groupinglabel ' . $textclasses));
     }
     // Display link itself.
     $activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(), 'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation')) . $accesstext . html_writer::tag('span', $instancename . $altname, array('class' => 'instancename'));
     if ($mod->uservisible) {
         $output .= html_writer::link($url, $activitylink, array('class' => $linkclasses, 'onclick' => $onclick)) . $groupinglabel;
     } else {
         // We may be displaying this just in order to show information
         // about visibility, without the actual link ($mod->uservisible)
         $output .= html_writer::tag('div', $activitylink, array('class' => $textclasses)) . $groupinglabel;
     }
     return $output;
 }
function print_section_newsroom($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%")
{
    /// Prints a section full of activity modules
    global $CFG, $USER;
    static $initialised;
    static $groupbuttons;
    static $groupbuttonslink;
    static $isediting;
    static $ismoving;
    static $strmovehere;
    static $strmovefull;
    static $strunreadpostsone;
    static $usetracking;
    static $groupings;
    if (!isset($initialised)) {
        $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
        $groupbuttonslink = !$course->groupmodeforce;
        $isediting = isediting($course->id);
        $ismoving = $isediting && ismoving($course->id);
        if ($ismoving) {
            $strmovehere = get_string("movehere");
            $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
        }
        include_once $CFG->dirroot . '/mod/forum/lib.php';
        if ($usetracking = forum_tp_can_track_forums()) {
            $strunreadpostsone = get_string('unreadpostsone', 'forum');
        }
        $initialised = true;
    }
    $labelformatoptions = new object();
    $labelformatoptions->noclean = true;
    /// Casting $course->modinfo to string prevents one notice when the field is null
    $modinfo = get_fast_modinfo($course);
    //Acccessibility: replace table with list <ul>, but don't output empty list.
    if (!empty($section->sequence)) {
        // Fix bug #5027, don't want style=\"width:$width\".
        echo "<ul class=\"section img-text\">\n";
        $sectionmods = explode(",", $section->sequence);
        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }
            $mod = $mods[$modnumber];
            if ($ismoving and $mod->id == $USER->activitycopy) {
                // do not display moving mod
                continue;
            }
            if (isset($modinfo->cms[$modnumber])) {
                if (!$modinfo->cms[$modnumber]->uservisible) {
                    // visibility shortcut
                    continue;
                }
            } else {
                if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
                    // module not installed
                    continue;
                }
                if (!coursemodule_visible_for_user($mod)) {
                    // full visibility check
                    continue;
                }
            }
            // The magic! ... if indent == 1 then ... hide module
            if ($mod->indent == 1) {
                $hiddemodule = 'hidden';
            } else {
                $hiddemodule = '';
            }
            echo '<li class="activity ' . $mod->modname . ' ' . $hiddemodule . '" id="module-' . $modnumber . '">';
            // Unique ID
            if ($ismoving) {
                echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br />
                     ';
            }
            if ($mod->indent) {
                print_spacer(12, 20 * $mod->indent, false);
            }
            $extra = '';
            if (!empty($modinfo->cms[$modnumber]->extra)) {
                $extra = $modinfo->cms[$modnumber]->extra;
            }
            if ($mod->modname == "label") {
                echo "<span class=\"";
                if (!$mod->visible) {
                    echo 'dimmed_text';
                } else {
                    echo 'label';
                }
                echo '">';
                echo format_text($extra, FORMAT_HTML, $labelformatoptions);
                echo "</span>";
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            } else {
                // Normal activity
                $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id);
                if (!empty($modinfo->cms[$modnumber]->icon)) {
                    $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon;
                } else {
                    $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif";
                }
                //Accessibility: for files get description via icon.
                $altname = '';
                if ('resource' == $mod->modname) {
                    if (!empty($modinfo->cms[$modnumber]->icon)) {
                        $possaltname = $modinfo->cms[$modnumber]->icon;
                        $mimetype = mimeinfo_from_icon('type', $possaltname);
                        $altname = get_mimetype_description($mimetype);
                    } else {
                        $altname = $mod->modfullname;
                    }
                } else {
                    $altname = $mod->modfullname;
                }
                // Avoid unnecessary duplication.
                if (false !== stripos($instancename, $altname)) {
                    $altname = '';
                }
                // File type after name, for alphabetic lists (screen reader).
                if ($altname) {
                    $altname = get_accesshide(' ' . $altname);
                }
                $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>';
                //echo " $mod->modname ";
                // Special NEWSPAPER magic ... show summry from resource and blog's 200 chars from each post OUBlog (nadavkav)
                if ($mod->modname == 'resource') {
                    $article = get_record('resource', 'id', $mod->instance);
                    //print_r($article );
                    echo "{$article->summary}";
                }
                if ($mod->modname == 'oublog') {
                    require_once $CFG->dirroot . '/mod/oublog/locallib.php';
                    $oublog = get_record('oublog', 'id', $mod->instance);
                    if (!($oublogcm = get_coursemodule_from_instance('oublog', $oublog->id))) {
                        //error("Course module ID was incorrect");
                    }
                    $oublogcontext = get_context_instance(CONTEXT_MODULE, $oublogcm->id);
                    //oublog_check_view_permissions($oublog, $oublogcontext, $oublogcm);
                    $currentgroup = oublog_get_activity_group($oublogcm, true);
                    echo '<br/>';
                    /// Get Posts
                    list($posts, $recordcount) = oublog_get_posts($oublog, $oublogcontext, 0, $oublogcm, $currentgroup);
                    //, -1, $oubloguser->id, $tag, $canaudit);
                    $i = 0;
                    foreach ($posts as $post) {
                        if ($i < 3) {
                            echo '<a href="' . $CFG->wwwroot . '/mod/oublog/viewpost.php?blog=' . $oublog->id . '&post=' . $post->id . '">' . $post->title . '</a><br/>';
                            $summaryformatoptions->noclean = false;
                            echo mb_substr(format_text($post->message, FORMAT_HTML, $summaryformatoptions), 1, 600) . "<hr/>";
                        }
                        if ($i > 2 and $i < 6) {
                            echo '<a href="' . $CFG->wwwroot . '/mod/oublog/viewpost.php?blog=' . $oublog->id . '&post=' . $post->id . '">' . $post->title . '</a><br/>';
                        }
                        $i++;
                    }
                    //print_r($article );
                    //echo "$article->summary";
                    echo '<br/><a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . get_string('more', 'format_newsroom') . '</span></a>';
                }
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            }
            if ($usetracking && $mod->modname == 'forum') {
                if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) {
                    echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">';
                    if ($unread == 1) {
                        echo $strunreadpostsone;
                    } else {
                        print_string('unreadpostsnumber', 'forum', $unread);
                    }
                    echo '</a></span>';
                }
            }
            if ($isediting) {
                // TODO: we must define this as mod property!
                if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
                    if (!($mod->groupmodelink = $groupbuttonslink)) {
                        $mod->groupmode = $course->groupmode;
                    }
                } else {
                    $mod->groupmode = false;
                }
                echo '&nbsp;&nbsp;';
                echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
            }
            echo "</li>\n";
        }
    } elseif ($ismoving) {
        echo "<ul class=\"section\">\n";
    }
    if ($ismoving) {
        echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li>
             ';
    }
    if (!empty($section->sequence) || $ismoving) {
        echo "</ul><!--class='section'-->\n\n";
    }
}
}
// END UCLA MOD - CCLE-2769
// Trigger mod_created event with information about this module.
$eventdata = new stdClass();
$eventdata->modulename = $data->modulename;
$eventdata->name = $data->name;
$eventdata->cmid = $data->coursemodule;
$eventdata->courseid = $course->id;
$eventdata->userid = $USER->id;
events_trigger('mod_created', $eventdata);
add_to_log($course->id, "course", "add mod", "../mod/{$data->modulename}/view.php?id={$data->coursemodule}", "{$data->modulename} {$data->instance}");
add_to_log($course->id, $data->modulename, "add", "view.php?id={$data->coursemodule}", "{$data->instance}", $data->coursemodule);
rebuild_course_cache($course->id);
$resp = new stdClass();
$resp->error = 0;
$resp->icon = $icon;
$resp->name = $displayname;
$resp->link = new moodle_url("/mod/{$data->modulename}/view.php", array('id' => $data->coursemodule)) . '';
$resp->elementid = 'module-' . $data->coursemodule;
// START UCLA MOD - CCLE-2769 - Drag and drop file upload block on M2
// get name of grouping (if any)
if (!empty($groupingid)) {
    $groupings = groups_get_all_groupings($course->id);
    $resp->groupname = format_string($groupings[$groupingid]->name);
}
// END UCLA MOD - CCLE-2769
$data->id = $data->coursemodule;
$data->groupmodelink = false;
// Resources never have group modes
$resp->commands = make_editing_buttons($data, true, true, 0, $section);
echo json_encode($resp);
Example #11
0
    /**
     * Called to define this moodle form
     *
     * @return void
     */
    function definition() {
        global $CFG, $DB, $PAGE;
        $mform = $this->_form;

        $mform->addElement('header', 'general', get_string('general', 'form'));

        $mform->addElement('text', 'name', get_string('assignmentname', 'assign'), array('size'=>'64'));
        if (!empty($CFG->formatstringstriptags)) {
            $mform->setType('name', PARAM_TEXT);
        } else {
            $mform->setType('name', PARAM_CLEANHTML);
        }
        $mform->addRule('name', null, 'required', null, 'client');

        $this->add_intro_editor(true, get_string('description', 'assign'));

        $ctx = null;
        if ($this->current && $this->current->coursemodule) {
            $cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
            $ctx = context_module::instance($cm->id);
        }
        $assignment = new assign($ctx, null, null);
        if ($this->current && $this->current->course) {
            if (!$ctx) {
                $ctx = context_course::instance($this->current->course);
            }
            $assignment->set_course($DB->get_record('course', array('id'=>$this->current->course), '*', MUST_EXIST));
        }

        $config = get_config('assign');

        $mform->addElement('header', 'general', get_string('settings', 'assign'));
        $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', get_string('allowsubmissionsfromdate', 'assign'), array('optional'=>true));
        $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
        $mform->setDefault('allowsubmissionsfromdate', time());
        $mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'assign'), array('optional'=>true));
        $mform->addHelpButton('duedate', 'duedate', 'assign');
        $mform->setDefault('duedate', time()+7*24*3600);
        $mform->addElement('date_time_selector', 'cutoffdate', get_string('cutoffdate', 'assign'), array('optional'=>true));
        $mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign');
        $mform->setDefault('cutoffdate', time()+7*24*3600);
        $mform->addElement('selectyesno', 'alwaysshowdescription', get_string('alwaysshowdescription', 'assign'));
        $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign');
        $mform->setDefault('alwaysshowdescription', 1);
        $mform->addElement('selectyesno', 'submissiondrafts', get_string('submissiondrafts', 'assign'));
        $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign');
        $mform->setDefault('submissiondrafts', 0);
        // submission statement
        if (empty($config->requiresubmissionstatement)) {
            $mform->addElement('selectyesno', 'requiresubmissionstatement', get_string('requiresubmissionstatement', 'assign'));
            $mform->setDefault('requiresubmissionstatement', 0);
            $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'assign');
        } else {
            $mform->addElement('hidden', 'requiresubmissionstatement', 1);
        }

        $mform->addElement('selectyesno', 'sendnotifications', get_string('sendnotifications', 'assign'));
        $mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign');
        $mform->setDefault('sendnotifications', 1);
        $mform->addElement('selectyesno', 'sendlatenotifications', get_string('sendlatenotifications', 'assign'));
        $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign');
        $mform->setDefault('sendlatenotifications', 1);
        $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1);
        $mform->addElement('selectyesno', 'teamsubmission', get_string('teamsubmission', 'assign'));
        $mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign');
        $mform->setDefault('teamsubmission', 0);
        $mform->addElement('selectyesno', 'requireallteammemberssubmit', get_string('requireallteammemberssubmit', 'assign'));
        $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
        $mform->setDefault('requireallteammemberssubmit', 0);
        $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
        $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);

        $groupings = groups_get_all_groupings($assignment->get_course()->id);
        $options = array();
        $options[0] = get_string('none');
        foreach ($groupings as $grouping) {
            $options[$grouping->id] = $grouping->name;
        }
        $mform->addElement('select', 'teamsubmissiongroupingid', get_string('teamsubmissiongroupingid', 'assign'), $options);
        $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign');
        $mform->setDefault('teamsubmissiongroupingid', 0);
        $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);

        $mform->addElement('selectyesno', 'blindmarking', get_string('blindmarking', 'assign'));
        $mform->addHelpButton('blindmarking', 'blindmarking', 'assign');
        $mform->setDefault('blindmarking', 0);
        if ($assignment->has_submissions_or_grades() ) {
            $mform->freeze('blindmarking');
        }


        // plagiarism enabling form
        if (!empty($CFG->enableplagiarism)) {
            /** Include plagiarismlib.php */
            require_once($CFG->libdir . '/plagiarismlib.php');
            plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign');
        }

        $assignment->add_all_plugin_settings($mform);
        $this->standard_grading_coursemodule_elements();
        $this->standard_coursemodule_elements();

        $this->add_action_buttons();

        // Add warning popup/noscript tag, if grades are changed by user.
        if ($mform->elementExists('grade') && !empty($this->_instance) && $DB->record_exists_select('assign_grades', 'assignment = ? AND grade <> -1', array($this->_instance))) {
            $module = array(
                'name' => 'mod_assign',
                'fullpath' => '/mod/assign/module.js',
                'requires' => array('node', 'event'),
                'strings' => array(array('changegradewarning', 'mod_assign'))
                );
            $PAGE->requires->js_init_call('M.mod_assign.init_grade_change', null, false, $module);

            // Add noscript tag in case
            $noscriptwarning = $mform->createElement('static', 'warning', null,  html_writer::tag('noscript', get_string('changegradewarning', 'mod_assign')));
            $mform->insertElementBefore($noscriptwarning, 'grade');
        }
    }
 /**
  * Renders HTML to display one course module in a course section
  *
  * This includes link, content, availability, completion info and additional information
  * that module type wants to display (i.e. number of unread forum posts)
  *
  * This function calls:
  * {@link core_course_renderer::course_section_cm_name()}
  * {@link cm_info::get_after_link()}
  * {@link core_course_renderer::course_section_cm_text()}
  * {@link core_course_renderer::course_section_cm_availability()}
  * {@link core_course_renderer::course_section_cm_completion()}
  * {@link course_get_cm_edit_actions()}
  * {@link core_course_renderer::course_section_cm_edit_actions()}
  *
  * @param \stdClass $course
  * @param \completion_info $completioninfo
  * @param \cm_info $mod
  * @param int|null $sectionreturn
  * @param array $displayoptions
  * @return string
  */
 public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array())
 {
     global $COURSE;
     $output = '';
     // We return empty string (because course module will not be displayed at all)
     // if:
     // 1) The activity is not visible to users
     // and
     // 2) The 'availableinfo' is empty, i.e. the activity was
     // hidden in a way that leaves no info, such as using the
     // eye icon.
     if (!$mod->uservisible && empty($mod->availableinfo)) {
         return $output;
     }
     $output .= '<div class="asset-wrapper">';
     // TODO - add if can edit.
     // Drop section notice.
     $output .= '<a class="snap-move-note" href="#">' . get_string('movehere', 'theme_snap') . '</a>';
     // Start the div for the activity content.
     $output .= "<div class='activityinstance'>";
     // Display the link to the module (or do nothing if module has no url).
     $cmname = $this->course_section_cm_name($mod, $displayoptions);
     $assetlink = '';
     // SHAME - For moodles ajax show/hide call to work it needs activityinstance > a to add a class of dimmed to.
     // This dimmed class is of course inaccessible junk.
     if (!empty($cmname)) {
         $assetlink = '<a></a><h4 class="snap-asset-link">' . $cmname . '</h4>';
     }
     // Asset content.
     $contentpart = $this->course_section_cm_text($mod, $displayoptions);
     // Activity/resource type.
     $snapmodtype = $this->get_mod_type($mod)[0];
     $assetmeta = "<span class='snap-assettype'>" . $snapmodtype . "</span>";
     // Groups, Restriction and all that jazz metadata.
     // Completion tracking.
     $completiontracking = $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
     // Due date, feedback available and all the nice snap things.
     $snapcompletiondata = $this->module_meta_html($mod);
     $assetcompletionmeta = "<div class='snap-completion-meta'>" . $completiontracking . $snapcompletiondata . "</div>";
     // Draft status - always output, shown via css of parent.
     $assetrestrictions = "<div class='draft-tag text text-warning'>" . get_string('draft', 'theme_snap') . "</div>";
     $canmanagegroups = has_capability('moodle/course:managegroups', context_course::instance($mod->course));
     if ($canmanagegroups && $mod->effectivegroupmode != NOGROUPS) {
         if ($mod->effectivegroupmode == VISIBLEGROUPS) {
             $groupinfo = get_string('groupsvisible');
         } else {
             if ($mod->effectivegroupmode == SEPARATEGROUPS) {
                 $groupinfo = get_string('groupsseparate');
             }
         }
         $assetrestrictions .= "<div class='text'>{$groupinfo}</div>";
     }
     // TODO - ask what this is...
     if (!empty($mod->groupingid) && $canmanagegroups) {
         // Grouping label.
         $groupings = groups_get_all_groupings($mod->course);
         $assetrestrictions .= "<div class='text text-danger'>" . format_string($groupings[$mod->groupingid]->name) . "</div>";
         // TBD - add a title to show this is the Grouping...
     }
     $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $mod->context);
     // If the module isn't available, or we are a teacher (can view hidden activities) then get availability
     // info.
     $availabilityinfo = '';
     if (!$mod->available || $canviewhidden) {
         $availabilityinfo = $this->course_section_cm_availability($mod, $displayoptions);
     }
     if ($availabilityinfo !== '') {
         $conditionalinfo = get_string('conditional', 'theme_snap');
         $assetrestrictions .= "<div class='text text-danger'>{$conditionalinfo}.{$availabilityinfo}</div>";
     }
     $assetrestrictions = "<div class='snap-restrictions-meta'>{$assetrestrictions}</div>";
     $assetmeta .= $assetcompletionmeta . $assetrestrictions;
     // Build output.
     $postcontent = '<div class="snap-asset-meta" data-cmid="' . $mod->id . '">' . $mod->afterlink . $assetmeta . '</div>';
     $output .= $assetlink . $contentpart . $postcontent;
     // Bail at this point if we aren't using a supported format. (Folder view is only partially supported).
     $supported = ['folderview', 'topics', 'weeks', 'site'];
     if (!in_array($COURSE->format, $supported)) {
         return parent::course_section_cm($course, $completioninfo, $mod, $sectionreturn, $displayoptions) . $assetmeta;
     }
     // Build up edit actions.
     $actions = '';
     $actionsadvanced = array();
     $coursecontext = context_course::instance($mod->course);
     $modcontext = context_module::instance($mod->id);
     $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
     if (has_capability('moodle/course:update', $modcontext)) {
         $str = get_strings(array('delete', 'move', 'duplicate', 'hide', 'show', 'roles'), 'moodle');
         // TODO - add snap strings here.
         // Move, Edit, Delete.
         if (has_capability('moodle/course:manageactivities', $modcontext)) {
             $movealt = get_string('move', 'theme_snap', $mod->get_formatted_name());
             $moveicon = "<img title='{$movealt}' aria-hidden='true' class='svg-icon' src='" . $this->output->pix_url('move', 'theme') . "' />";
             $editalt = get_string('edit', 'theme_snap', $mod->get_formatted_name());
             $editicon = "<img title='{$editalt}' alt='{$editalt}' class='svg-icon' src='" . $this->output->pix_url('edit', 'theme') . "'/>";
             $actions .= "<input id='snap-move-mod-{$mod->id}' class='js-snap-asset-move sr-only' type='checkbox'><label class='snap-asset-move' for='snap-move-mod-{$mod->id}'><span class='sr-only'>{$movealt}</span>{$moveicon}</label>";
             $actions .= "<a class='snap-edit-asset' href='" . new moodle_url($baseurl, array('update' => $mod->id)) . "'>{$editicon}</a>";
             $actionsadvanced[] = "<a href='" . new moodle_url($baseurl, array('delete' => $mod->id)) . "'>{$str->delete}</a>";
         }
         // Hide/Show.
         if (has_capability('moodle/course:activityvisibility', $modcontext)) {
             $actionsadvanced[] = "<a href='" . new moodle_url($baseurl, array('hide' => $mod->id)) . "' class='editing_hide js_snap_hide'>{$str->hide}</a>";
             $actionsadvanced[] = "<a href='" . new moodle_url($baseurl, array('show' => $mod->id)) . "' class='editing_show js_snap_show'>{$str->show}</a>";
             // AX click to change.
         }
         // Duplicate.
         $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport');
         if (has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2) && plugin_supports('mod', $mod->modname, 'duplicate', true)) {
             $actionsadvanced[] = "<a href='" . new moodle_url($baseurl, array('duplicate' => $mod->id)) . "' class='js_snap_duplicate'>{$str->duplicate}</a>";
         }
         // Asign roles.
         if (has_capability('moodle/role:assign', $modcontext)) {
             $actionsadvanced[] = "<a href='" . new moodle_url('/admin/roles/assign.php', array('contextid' => $modcontext->id)) . "'>{$str->roles}</a>";
         }
         // Give local plugins a chance to add icons.
         $localplugins = array();
         foreach (get_plugin_list_with_function('local', 'extend_module_editing_buttons') as $function) {
             $localplugins = array_merge($localplugins, $function($mod));
         }
         // TODO - pld string is far too long....
         $locallinks = '';
         foreach ($localplugins as $localplugin) {
             $url = $localplugin->url;
             $text = $localplugin->text;
             $class = $localplugin->attributes['class'];
             $actionsadvanced[] = "<a href='{$url}' class='{$class}'>{$text}</a>";
         }
     }
     $advancedactions = '';
     if (!empty($actionsadvanced)) {
         $moreicon = "<img title='" . get_string('more', 'theme_snap') . "' alt='" . get_string('more', 'theme_snap') . "' class='svg-icon' src='" . $this->output->pix_url('more', 'theme') . "'/>";
         $advancedactions = "<div class='dropdown snap-edit-more-dropdown'>\n                      <a href='#' class='dropdown-toggle snap-edit-asset-more' data-toggle='dropdown' aria-expanded='false' aria-haspopup='true'>{$moreicon}</a>\n                      <ul class='dropdown-menu'>";
         foreach ($actionsadvanced as $action) {
             $advancedactions .= "<li>{$action}</li>";
         }
         $advancedactions .= "</ul></div>";
     }
     // Add actions menu.
     if ($actions) {
         $output .= "<div class='snap-asset-actions' role='region' aria-label='actions'>";
         $output .= $actions . $advancedactions;
         $output .= "</div>";
     }
     $output .= "</div>";
     // Close .activityinstance.
     $output .= "</div>";
     // Close .asset-wrapper.
     return $output;
 }
 /**
  * Gets a grouping array for display
  *
  * @return array
  */
 protected function get_groupings()
 {
     // get the courseid from the module's course context
     if (get_class($this->context) == 'context_course') {
         // if the context defined for the form is a context course just get its id
         $courseid = $this->context->instanceid;
     } else {
         $cmcontext = context_module::instance($this->_cm->id);
         $coursecontext = $cmcontext->get_course_context(false);
         $courseid = $coursecontext->instanceid;
     }
     $groupings = groups_get_all_groupings($courseid);
     // create an array with just the grouping id and name
     $retgroupings = array();
     $retgroupings[''] = get_string('none');
     foreach ($groupings as $grouping) {
         $retgroupings[$grouping->id] = $grouping->name;
     }
     return $retgroupings;
 }
Example #14
0
 /**
  * get_sql_filter
  *
  * @param xxx $data
  * @return xxx
  */
 function get_sql_filter($data)
 {
     global $DB, $hotpot;
     $filter = '';
     $params = array();
     if (($value = $data['value']) && ($operator = $data['operator'])) {
         $userids = array();
         if (substr($value, 0, 5) == 'group') {
             if (substr($value, 5, 3) == 'ing') {
                 $gids = groups_get_all_groupings($hotpot->course->id);
                 $gid = intval(substr($value, 8));
                 if ($gids && array_key_exists($gid, $gids) && ($members = groups_get_grouping_members($gid))) {
                     $userids = array_keys($members);
                 }
             } else {
                 $gids = groups_get_all_groups($hotpot->course->id);
                 $gid = intval(substr($value, 5));
                 if ($gids && array_key_exists($gid, $gids) && ($members = groups_get_members($gid))) {
                     $userids = array_keys($members);
                 }
             }
         }
         if (count($userids)) {
             switch ($operator) {
                 case 1:
                     // is equal to
                     list($filter, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, '', true);
                     break;
                 case 2:
                     // isn't equal to
                     list($filter, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, '', false);
                     break;
             }
             if ($filter) {
                 $filter = 'id ' . $filter;
             }
         }
     }
     // no userids found
     return array($filter, $params);
 }
    echo '<div class="ui-widget" style="text-align:center;"><div style="display:inline-block; padding-left:10px; padding-right:10px;" class="ui-state-highlight ui-corner-all"><p>' . $feedback . '</p></div></div>';
} else {
    echo <<<HTML
<div id="predicate">
</div>
<div style="text-align:center;margin:10px;"><button type="button" onclick="addNewCriterion();">Add New Criterion</button>&nbsp;<button type="button" onclick="buildTeams();"><strong>Build Teams</strong></button>&nbsp;<button type="button" onclick="resetTeams();">Reset Teams</button></div>
<div style="text-align:center;margin:10px;">Number of teams: <span class="stepper">2</span></div>
<div style="text-align:center;">Prioritize: <select id="prioritise"><option value="numbers" selected="selected">equal team numbers</option><option value="criteria">most criteria met</option></select></div>
<div id="unassigned"><h2>Unassigned to teams</h2><button type="button" onclick="assignRandomly();">Assign Randomly</button><div class="sortable">
HTML;
    foreach ($students as $s) {
        $answeredstate = !isset($responses[$s->id]) || empty($responses[$s->id]) ? 'unanswered' : 'answered';
        echo "<div id=\"student-{$s->id}\" class=\"student ui-state-default {$answeredstate}\">{$s->firstname}&nbsp;{$s->lastname}</div>";
    }
    $groupings = "";
    foreach (groups_get_all_groupings($course->id) as $grping) {
        $groupings .= "<option value=\"{$grping->id}\">{$grping->name}</option>";
    }
    echo <<<HTML
</div></div><div id="teams"></div>
<div style="text-align:center;margin:15px 50px 0px;border-top:1px solid black;padding-top:15px;">
    <button type="button" onclick="\$('#createGroupsForm').slideDown(300);" style="font-size:1.5em;font-weight:bold;">Create Groups</button>
    <div style="display:none" id="createGroupsForm"><p>Are you sure you want to create your groups now? This action cannot be undone.</p>
        <table style="margin:auto;">
            <tr><th scope="row"><label for="groupingName">Grouping Name</label></th><td><input type="text" id="groupingName"></td></tr>
            <tr><td colspan="2" style="text-align:center;font-size:0.8em">or...</td></tr>
            <tr><th scope="row"><label for="groupingSelect">Add To Grouping</label></th><td><select id="groupingSelect">{$groupings}</select></td></tr>
            <tr><th scope="row"><label for="inheritGroupingName">Prefix Team Names with Grouping Name</label></th><td style="text-align:left;"><input type="checkbox" checked="checked" name="inheritGroupingName" id="inheritGroupingName" value="1" /></td></tr>
            <tr><td colspan="2" style="text-align:center;font-size:0.8em">or...</td></tr>
            <tr><th scope="row"><label for="nogrouping">Don't assign groups to a Grouping</label></th><td style="text-align:left;"><input type="checkbox" name="nogrouping" id="nogrouping" value="1" /></td></tr>
        </table>
Example #16
0
 /**
  * Constructs object from database information plus extra required data.
  * @param object $data Array entry from cached sectioncache
  * @param int $number Section number (array key)
  * @param int $courseid Course ID
  * @param int $sequence Sequence of course-module ids contained within
  * @param course_modinfo $modinfo Owner (needed for checking availability)
  * @param int $userid User ID
  */
 public function __construct($data, $number, $courseid, $sequence, $modinfo, $userid)
 {
     global $CFG;
     // Data that is always present
     $this->_id = $data->id;
     $defaults = self::$sectioncachedefaults + array('conditionscompletion' => array(), 'conditionsgrade' => array(), 'conditionsfield' => array());
     // Data that may use default values to save cache size
     foreach ($defaults as $field => $value) {
         if (isset($data->{$field})) {
             $this->{'_' . $field} = $data->{$field};
         } else {
             $this->{'_' . $field} = $value;
         }
     }
     // cached course format data
     $formatoptionsdef = course_get_format($courseid)->section_format_options();
     foreach ($formatoptionsdef as $field => $option) {
         if (!empty($option['cache'])) {
             if (isset($data->{$field})) {
                 $this->cachedformatoptions[$field] = $data->{$field};
             } else {
                 if (array_key_exists('cachedefault', $option)) {
                     $this->cachedformatoptions[$field] = $option['cachedefault'];
                 }
             }
         }
     }
     // Other data from other places
     $this->_course = $courseid;
     $this->_section = $number;
     $this->_sequence = $sequence;
     // Availability data
     if (!empty($CFG->enableavailability)) {
         // Get availability information
         $ci = new condition_info_section($this);
         $this->_available = $ci->is_available($this->_availableinfo, true, $userid, $modinfo);
         // Display grouping info if available & not already displaying
         // (it would already display if current user doesn't have access)
         // for people with managegroups - same logic/class as grouping label
         // on individual activities.
         $context = context_course::instance($courseid);
         if ($this->_availableinfo === '' && $this->_groupingid && has_capability('moodle/course:managegroups', $context)) {
             $groupings = groups_get_all_groupings($courseid);
             $this->_availableinfo = html_writer::tag('span', '(' . format_string($groupings[$this->_groupingid]->name, true, array('context' => $context)) . ')', array('class' => 'groupinglabel'));
         }
     } else {
         $this->_available = true;
     }
     // Update visibility for current user
     $this->update_user_visible($userid);
 }
Example #17
0
 /**
  * Called to define this moodle form
  *
  * @return void
  */
 public function definition()
 {
     global $CFG, $DB, $PAGE;
     $mform = $this->_form;
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('assignmentname', 'assign'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEANHTML);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $this->add_intro_editor(true, get_string('description', 'assign'));
     $ctx = null;
     if ($this->current && $this->current->coursemodule) {
         $cm = get_coursemodule_from_instance('assign', $this->current->id, 0, false, MUST_EXIST);
         $ctx = context_module::instance($cm->id);
     }
     $assignment = new assign($ctx, null, null);
     if ($this->current && $this->current->course) {
         if (!$ctx) {
             $ctx = context_course::instance($this->current->course);
         }
         $course = $DB->get_record('course', array('id' => $this->current->course), '*', MUST_EXIST);
         $assignment->set_course($course);
     }
     $config = get_config('assign');
     $mform->addElement('header', 'availability', get_string('availability', 'assign'));
     $mform->setExpanded('availability', true);
     $name = get_string('allowsubmissionsfromdate', 'assign');
     $options = array('optional' => true);
     $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options);
     $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'assign');
     $name = get_string('duedate', 'assign');
     $mform->addElement('date_time_selector', 'duedate', $name, array('optional' => true));
     $mform->addHelpButton('duedate', 'duedate', 'assign');
     $name = get_string('cutoffdate', 'assign');
     $mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional' => true));
     $mform->addHelpButton('cutoffdate', 'cutoffdate', 'assign');
     $name = get_string('alwaysshowdescription', 'assign');
     $mform->addElement('checkbox', 'alwaysshowdescription', $name);
     $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'assign');
     $mform->disabledIf('alwaysshowdescription', 'allowsubmissionsfromdate[enabled]', 'notchecked');
     $assignment->add_all_plugin_settings($mform);
     $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'assign'));
     $name = get_string('submissiondrafts', 'assign');
     $mform->addElement('selectyesno', 'submissiondrafts', $name);
     $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'assign');
     $name = get_string('requiresubmissionstatement', 'assign');
     $mform->addElement('selectyesno', 'requiresubmissionstatement', $name);
     $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'assign');
     $mform->setType('requiresubmissionstatement', PARAM_BOOL);
     $options = array(ASSIGN_ATTEMPT_REOPEN_METHOD_NONE => get_string('attemptreopenmethod_none', 'mod_assign'), ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL => get_string('attemptreopenmethod_manual', 'mod_assign'), ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS => get_string('attemptreopenmethod_untilpass', 'mod_assign'));
     $mform->addElement('select', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_assign'), $options);
     $mform->addHelpButton('attemptreopenmethod', 'attemptreopenmethod', 'mod_assign');
     $options = array(ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_assign'));
     $options += array_combine(range(1, 30), range(1, 30));
     $mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_assign'), $options);
     $mform->addHelpButton('maxattempts', 'maxattempts', 'assign');
     $mform->disabledIf('maxattempts', 'attemptreopenmethod', 'eq', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE);
     $mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign'));
     $name = get_string('teamsubmission', 'assign');
     $mform->addElement('selectyesno', 'teamsubmission', $name);
     $mform->addHelpButton('teamsubmission', 'teamsubmission', 'assign');
     if ($assignment->has_submissions_or_grades()) {
         $mform->freeze('teamsubmission');
     }
     $name = get_string('requireallteammemberssubmit', 'assign');
     $mform->addElement('selectyesno', 'requireallteammemberssubmit', $name);
     $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
     $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
     $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);
     $groupings = groups_get_all_groupings($assignment->get_course()->id);
     $options = array();
     $options[0] = get_string('none');
     foreach ($groupings as $grouping) {
         $options[$grouping->id] = $grouping->name;
     }
     $name = get_string('teamsubmissiongroupingid', 'assign');
     $mform->addElement('select', 'teamsubmissiongroupingid', $name, $options);
     $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign');
     $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);
     if ($assignment->has_submissions_or_grades()) {
         $mform->freeze('teamsubmissiongroupingid');
     }
     $mform->addElement('header', 'notifications', get_string('notifications', 'assign'));
     $name = get_string('sendnotifications', 'assign');
     $mform->addElement('selectyesno', 'sendnotifications', $name);
     $mform->addHelpButton('sendnotifications', 'sendnotifications', 'assign');
     $name = get_string('sendlatenotifications', 'assign');
     $mform->addElement('selectyesno', 'sendlatenotifications', $name);
     $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'assign');
     $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1);
     $name = get_string('sendstudentnotificationsdefault', 'assign');
     $mform->addElement('selectyesno', 'sendstudentnotifications', $name);
     $mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'assign');
     // Plagiarism enabling form.
     if (!empty($CFG->enableplagiarism)) {
         require_once $CFG->libdir . '/plagiarismlib.php';
         plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_assign');
     }
     $this->standard_grading_coursemodule_elements();
     $name = get_string('blindmarking', 'assign');
     $mform->addElement('selectyesno', 'blindmarking', $name);
     $mform->addHelpButton('blindmarking', 'blindmarking', 'assign');
     if ($assignment->has_submissions_or_grades()) {
         $mform->freeze('blindmarking');
     }
     $name = get_string('markingworkflow', 'assign');
     $mform->addElement('selectyesno', 'markingworkflow', $name);
     $mform->addHelpButton('markingworkflow', 'markingworkflow', 'assign');
     $name = get_string('markingallocation', 'assign');
     $mform->addElement('selectyesno', 'markingallocation', $name);
     $mform->addHelpButton('markingallocation', 'markingallocation', 'assign');
     $mform->disabledIf('markingallocation', 'markingworkflow', 'eq', 0);
     $this->standard_coursemodule_elements();
     $this->apply_admin_defaults();
     $this->add_action_buttons();
     // Add warning popup/noscript tag, if grades are changed by user.
     $hasgrade = false;
     if (!empty($this->_instance)) {
         $hasgrade = $DB->record_exists_select('assign_grades', 'assignment = ? AND grade <> -1', array($this->_instance));
     }
     if ($mform->elementExists('grade') && $hasgrade) {
         $module = array('name' => 'mod_assign', 'fullpath' => '/mod/assign/module.js', 'requires' => array('node', 'event'), 'strings' => array(array('changegradewarning', 'mod_assign')));
         $PAGE->requires->js_init_call('M.mod_assign.init_grade_change', null, false, $module);
         // Add noscript tag in case.
         $noscriptwarning = $mform->createElement('static', 'warning', null, html_writer::tag('noscript', get_string('changegradewarning', 'mod_assign')));
         $mform->insertElementBefore($noscriptwarning, 'grade');
     }
 }
Example #18
0
function autoattend_choose_grouping($courseid, $url, $url_options)
{
    global $OUTPUT;
    $options = array();
    $groupings = groups_get_all_groupings($courseid);
    if ($groupings) {
        $popupurl = $url . $url_options;
        foreach ($groupings as $grouping) {
            $options[$grouping->id] = $grouping->name;
        }
        $options[0] = get_string('allgrouping', 'block_autoattend');
    }
    return $options;
}
 /**
  * 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;
 }
 /**
  * view userlist tab
  */
 public function view_userlist()
 {
     global $PAGE, $OUTPUT;
     $groupid = optional_param('groupid', 0, PARAM_INT);
     $groupingid = optional_param('groupingid', 0, PARAM_INT);
     $orientation = optional_param('orientation', 0, PARAM_BOOL);
     $url = new moodle_url($PAGE->url, array('sesskey' => sesskey(), 'groupid' => $groupid, 'groupingid' => $groupingid, 'orientation' => $orientation));
     $groupings = groups_get_all_groupings($this->course->id);
     $options = array(0 => get_string('all'));
     if (count($groupings)) {
         foreach ($groupings as $grouping) {
             $options[$grouping->id] = $grouping->name;
         }
     }
     $groupingselect = new single_select($url, 'groupingid', $options, $groupingid, false);
     $groups = $this->get_active_groups(false, false, 0, 0, $groupingid);
     $options = array(0 => get_string('all'));
     if (count($groups)) {
         foreach ($groups as $group) {
             $options[$group->id] = $group->name;
         }
     }
     if (!key_exists($groupid, $options)) {
         $groupid = 0;
         $url->param('groupid', 0);
         echo $OUTPUT->box($OUTPUT->notification(get_string('group_not_in_grouping', 'grouptool') . html_writer::empty_tag('br') . get_string('switched_to_all_groups', 'grouptool'), 'notifyproblem'), 'generalbox centered');
     }
     $groupselect = new single_select($url, 'groupid', $options, $groupid, false);
     $options = array(0 => get_string('portrait', 'grouptool'), 1 => get_string('landscape', 'grouptool'));
     $orientationselect = new single_select($url, 'orientation', $options, $orientation, false);
     echo html_writer::tag('div', get_string('grouping', 'group') . '&nbsp;' . $OUTPUT->render($groupingselect), array('class' => 'centered grouptool_userlist_filter')) . html_writer::tag('div', get_string('group', 'group') . '&nbsp;' . $OUTPUT->render($groupselect), array('class' => 'centered grouptool_userlist_filter')) . html_writer::tag('div', get_string('orientation', 'grouptool') . '&nbsp;' . $OUTPUT->render($orientationselect), array('class' => 'centered grouptool_userlist_filter'));
     flush();
     $this->userlist_table($groupingid, $groupid);
 }
 /**
  * Form Definition
  */
 function definition()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     $mform->addElement('header', 'autogroup', get_string('autocreategroups', 'group'));
     $options = array(0 => get_string('all'));
     $options += $this->_customdata['roles'];
     $mform->addElement('select', 'roleid', get_string('selectfromrole', 'group'), $options);
     $student = get_archetype_roles('student');
     $student = reset($student);
     if ($student and array_key_exists($student->id, $options)) {
         $mform->setDefault('roleid', $student->id);
     }
     $context = context_course::instance($COURSE->id);
     if (has_capability('moodle/cohort:view', $context)) {
         $options = cohort_get_visible_list($COURSE);
         if ($options) {
             $options = array(0 => get_string('anycohort', 'cohort')) + $options;
             $mform->addElement('select', 'cohortid', get_string('selectfromcohort', 'cohort'), $options);
             $mform->setDefault('cohortid', '0');
         } else {
             $mform->addElement('hidden', 'cohortid');
             $mform->setType('cohortid', PARAM_INT);
             $mform->setConstant('cohortid', '0');
         }
     } else {
         $mform->addElement('hidden', 'cohortid');
         $mform->setType('cohortid', PARAM_INT);
         $mform->setConstant('cohortid', '0');
     }
     $options = array('groups' => get_string('numgroups', 'group'), 'members' => get_string('nummembers', 'group'));
     $mform->addElement('select', 'groupby', get_string('groupby', 'group'), $options);
     $mform->addElement('text', 'number', get_string('number', 'group'), 'maxlength="4" size="4"');
     $mform->setType('number', PARAM_INT);
     $mform->addRule('number', null, 'numeric', null, 'client');
     $mform->addRule('number', get_string('required'), 'required', null, 'client');
     $mform->addElement('checkbox', 'nosmallgroups', get_string('nosmallgroups', 'group'));
     $mform->disabledIf('nosmallgroups', 'groupby', 'noteq', 'members');
     $mform->setAdvanced('nosmallgroups');
     $options = array('no' => get_string('noallocation', 'group'), 'random' => get_string('random', 'group'), 'firstname' => get_string('byfirstname', 'group'), 'lastname' => get_string('bylastname', 'group'), 'idnumber' => get_string('byidnumber', 'group'));
     $mform->addElement('select', 'allocateby', get_string('allocateby', 'group'), $options);
     $mform->setDefault('allocateby', 'random');
     $mform->setAdvanced('allocateby');
     $mform->addElement('text', 'namingscheme', get_string('namingscheme', 'group'));
     $mform->addHelpButton('namingscheme', 'namingscheme', 'group');
     $mform->addRule('namingscheme', get_string('required'), 'required', null, 'client');
     $mform->setType('namingscheme', PARAM_TEXT);
     // there must not be duplicate group names in course
     $template = get_string('grouptemplate', 'group');
     $gname = groups_parse_name($template, 0);
     if (!groups_get_group_by_name($COURSE->id, $gname)) {
         $mform->setDefault('namingscheme', $template);
     }
     $options = array('0' => get_string('no'), '-1' => get_string('newgrouping', 'group'));
     if ($groupings = groups_get_all_groupings($COURSE->id)) {
         foreach ($groupings as $grouping) {
             $options[$grouping->id] = strip_tags(format_string($grouping->name));
         }
     }
     $mform->addElement('select', 'grouping', get_string('createingrouping', 'group'), $options);
     if ($groupings) {
         $mform->setDefault('grouping', '-1');
     }
     $mform->addElement('text', 'groupingname', get_string('groupingname', 'group'), $options);
     $mform->setType('groupingname', PARAM_TEXT);
     $mform->disabledIf('groupingname', 'grouping', 'noteq', '-1');
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'seed');
     $mform->setType('seed', PARAM_INT);
     $buttonarray = array();
     $buttonarray[] =& $mform->createElement('submit', 'preview', get_string('preview'));
     $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('submit'));
     $buttonarray[] =& $mform->createElement('cancel');
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
 /**
  * Called to define this moodle form
  *
  * @return void
  */
 public function definition()
 {
     global $CFG, $COURSE, $DB, $PAGE;
     $mform = $this->_form;
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('select', 'state', 'State/Province: ');
     $mform->addElement('text', 'name', get_string('seplmentname', 'sepl'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEANHTML);
     }
     $se_problems = new SphereEngine\Api("dadeea82cdd4b840cbde18858d9f17d6fb11a957", "v3", "problems");
     $problemsClient = $se_problems->getProblemsClient();
     #$client = (new SphereEngine\Api("dadeea82cdd4b840cbde18858d9f17d6fb11a957", "v3", "problems"))->getProblemsClient();
     #$result = $problemsClient->problems->all();
     #$mform->addElement('select', 'problem', 'Problem: ',$result);//, $state);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "http://problems.sphere-engine.com/api/v3/problems?access_token=dadeea82cdd4b840cbde18858d9f17d6fb11a957");
     curl_setopt($ch, CURLOPT_POST, 1);
     #curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
     // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $server_output2 = curl_exec($ch);
     curl_close($ch);
     $client = (new SphereEngine\Api("dadeea82cdd4b840cbde18858d9f17d6fb11a957", "v3", "endpoint"))->getProblemsClient();
     var_dump($user);
     #var_dump(
     #$client->problems->all(['items']);
     var_dump($server_output2);
     $result2 = json_decode($server_output2, true);
     var_dump($result2);
     $mform->addElement('select', 'problem', 'Problem: ', $result2);
     //, $state);
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $this->standard_intro_elements(get_string('description', 'sepl'));
     $mform->addElement('filemanager', 'introattachments', get_string('introattachments', 'sepl'), null, array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes));
     $mform->addHelpButton('introattachments', 'introattachments', 'sepl');
     $ctx = null;
     if ($this->current && $this->current->coursemodule) {
         $cm = get_coursemodule_from_instance('sepl', $this->current->id, 0, false, MUST_EXIST);
         $ctx = context_module::instance($cm->id);
     }
     $seplment = new sepl($ctx, null, null);
     if ($this->current && $this->current->course) {
         if (!$ctx) {
             $ctx = context_course::instance($this->current->course);
         }
         $course = $DB->get_record('course', array('id' => $this->current->course), '*', MUST_EXIST);
         $seplment->set_course($course);
     }
     $config = get_config('sepl');
     $mform->addElement('header', 'availability', get_string('availability', 'sepl'));
     $mform->setExpanded('availability', true);
     $name = get_string('allowsubmissionsfromdate', 'sepl');
     $options = array('optional' => true);
     $mform->addElement('date_time_selector', 'allowsubmissionsfromdate', $name, $options);
     $mform->addHelpButton('allowsubmissionsfromdate', 'allowsubmissionsfromdate', 'sepl');
     $name = get_string('duedate', 'sepl');
     $mform->addElement('date_time_selector', 'duedate', $name, array('optional' => true));
     $mform->addHelpButton('duedate', 'duedate', 'sepl');
     $name = get_string('cutoffdate', 'sepl');
     $mform->addElement('date_time_selector', 'cutoffdate', $name, array('optional' => true));
     $mform->addHelpButton('cutoffdate', 'cutoffdate', 'sepl');
     $name = get_string('alwaysshowdescription', 'sepl');
     $mform->addElement('checkbox', 'alwaysshowdescription', $name);
     $mform->addHelpButton('alwaysshowdescription', 'alwaysshowdescription', 'sepl');
     $mform->disabledIf('alwaysshowdescription', 'allowsubmissionsfromdate[enabled]', 'notchecked');
     $seplment->add_all_plugin_settings($mform);
     $mform->addElement('header', 'submissionsettings', get_string('submissionsettings', 'sepl'));
     $name = get_string('submissiondrafts', 'sepl');
     $mform->addElement('selectyesno', 'submissiondrafts', $name);
     $mform->addHelpButton('submissiondrafts', 'submissiondrafts', 'sepl');
     $name = get_string('requiresubmissionstatement', 'sepl');
     $mform->addElement('selectyesno', 'requiresubmissionstatement', $name);
     $mform->addHelpButton('requiresubmissionstatement', 'requiresubmissionstatement', 'sepl');
     $mform->setType('requiresubmissionstatement', PARAM_BOOL);
     $options = array(ASSIGN_ATTEMPT_REOPEN_METHOD_NONE => get_string('attemptreopenmethod_none', 'mod_sepl'), ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL => get_string('attemptreopenmethod_manual', 'mod_sepl'), ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS => get_string('attemptreopenmethod_untilpass', 'mod_sepl'));
     $mform->addElement('select', 'attemptreopenmethod', get_string('attemptreopenmethod', 'mod_sepl'), $options);
     $mform->addHelpButton('attemptreopenmethod', 'attemptreopenmethod', 'mod_sepl');
     $options = array(ASSIGN_UNLIMITED_ATTEMPTS => get_string('unlimitedattempts', 'mod_sepl'));
     $options += array_combine(range(1, 30), range(1, 30));
     $mform->addElement('select', 'maxattempts', get_string('maxattempts', 'mod_sepl'), $options);
     $mform->addHelpButton('maxattempts', 'maxattempts', 'sepl');
     $mform->disabledIf('maxattempts', 'attemptreopenmethod', 'eq', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE);
     $mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'sepl'));
     $name = get_string('teamsubmission', 'sepl');
     $mform->addElement('selectyesno', 'teamsubmission', $name);
     $mform->addHelpButton('teamsubmission', 'teamsubmission', 'sepl');
     if ($seplment->has_submissions_or_grades()) {
         $mform->freeze('teamsubmission');
     }
     $name = get_string('preventsubmissionnotingroup', 'sepl');
     $mform->addElement('selectyesno', 'preventsubmissionnotingroup', $name);
     $mform->addHelpButton('preventsubmissionnotingroup', 'preventsubmissionnotingroup', 'sepl');
     $mform->setType('preventsubmissionnotingroup', PARAM_BOOL);
     $mform->disabledIf('preventsubmissionnotingroup', 'teamsubmission', 'eq', 0);
     $name = get_string('requireallteammemberssubmit', 'sepl');
     $mform->addElement('selectyesno', 'requireallteammemberssubmit', $name);
     $mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'sepl');
     $mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
     $mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);
     $groupings = groups_get_all_groupings($seplment->get_course()->id);
     $options = array();
     $options[0] = get_string('none');
     foreach ($groupings as $grouping) {
         $options[$grouping->id] = $grouping->name;
     }
     $name = get_string('teamsubmissiongroupingid', 'sepl');
     $mform->addElement('select', 'teamsubmissiongroupingid', $name, $options);
     $mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'sepl');
     $mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);
     if ($seplment->has_submissions_or_grades()) {
         $mform->freeze('teamsubmissiongroupingid');
     }
     $mform->addElement('header', 'notifications', get_string('notifications', 'sepl'));
     $name = get_string('sendnotifications', 'sepl');
     $mform->addElement('selectyesno', 'sendnotifications', $name);
     $mform->addHelpButton('sendnotifications', 'sendnotifications', 'sepl');
     $name = get_string('sendlatenotifications', 'sepl');
     $mform->addElement('selectyesno', 'sendlatenotifications', $name);
     $mform->addHelpButton('sendlatenotifications', 'sendlatenotifications', 'sepl');
     $mform->disabledIf('sendlatenotifications', 'sendnotifications', 'eq', 1);
     $name = get_string('sendstudentnotificationsdefault', 'sepl');
     $mform->addElement('selectyesno', 'sendstudentnotifications', $name);
     $mform->addHelpButton('sendstudentnotifications', 'sendstudentnotificationsdefault', 'sepl');
     // Plagiarism enabling form.
     if (!empty($CFG->enableplagiarism)) {
         require_once $CFG->libdir . '/plagiarismlib.php';
         plagiarism_get_form_elements_module($mform, $ctx->get_course_context(), 'mod_sepl');
     }
     $this->standard_grading_coursemodule_elements();
     $name = get_string('blindmarking', 'sepl');
     $mform->addElement('selectyesno', 'blindmarking', $name);
     $mform->addHelpButton('blindmarking', 'blindmarking', 'sepl');
     if ($seplment->has_submissions_or_grades()) {
         $mform->freeze('blindmarking');
     }
     $name = get_string('markingworkflow', 'sepl');
     $mform->addElement('selectyesno', 'markingworkflow', $name);
     $mform->addHelpButton('markingworkflow', 'markingworkflow', 'sepl');
     $name = get_string('markingallocation', 'sepl');
     $mform->addElement('selectyesno', 'markingallocation', $name);
     $mform->addHelpButton('markingallocation', 'markingallocation', 'sepl');
     $mform->disabledIf('markingallocation', 'markingworkflow', 'eq', 0);
     $this->standard_coursemodule_elements();
     $this->apply_admin_defaults();
     $this->add_action_buttons();
     // Add warning popup/noscript tag, if grades are changed by user.
     $hasgrade = false;
     if (!empty($this->_instance)) {
         $hasgrade = $DB->record_exists_select('sepl_grades', 'seplment = ? AND grade <> -1', array($this->_instance));
     }
     if ($mform->elementExists('grade') && $hasgrade) {
         $module = array('name' => 'mod_sepl', 'fullpath' => '/mod/sepl/module.js', 'requires' => array('node', 'event'), 'strings' => array(array('changegradewarning', 'mod_sepl')));
         $PAGE->requires->js_init_call('M.mod_sepl.init_grade_change', null, false, $module);
         // Add noscript tag in case.
         $noscriptwarning = $mform->createElement('static', 'warning', null, html_writer::tag('noscript', get_string('changegradewarning', 'mod_sepl')));
         $mform->insertElementBefore($noscriptwarning, 'grade');
     }
 }
Example #23
0
 /**
  * Returns the availability text shown next to the section on course page.
  *
  * @return string
  */
 private function get_availableinfo() {
     // Make sure $this->_available has been calculated, it may also fill the _availableinfo property.
     $this->get_available();
     $userid = $this->modinfo->get_user_id();
     if ($this->_availableinfo !== null || $userid == -1) {
         // It has been already calculated or does not need calculation.
         return $this->_availableinfo;
     }
     $this->_availableinfo = '';
     // Display grouping info if available & not already displaying
     // (it would already display if current user doesn't have access)
     // for people with managegroups - same logic/class as grouping label
     // on individual activities.
     $context = context_course::instance($this->get_course());
     if ($this->_groupingid && has_capability('moodle/course:managegroups', $context, $userid)) {
         $groupings = groups_get_all_groupings($this->get_course());
         $this->_availableinfo = html_writer::tag('span', '(' . format_string(
                 $groupings[$this->_groupingid]->name, true, array('context' => $context)) .
                 ')', array('class' => 'groupinglabel'));
     }
     return $this->_availableinfo;
 }
Example #24
0
 /**
  * @param string $textclasses additionnal classes for grouping label
  * @return string An empty string or HTML grouping label span tag
  */
 public function get_grouping_label($textclasses = '')
 {
     $groupinglabel = '';
     if (!empty($this->groupingid) && has_capability('moodle/course:managegroups', context_course::instance($this->course))) {
         $groupings = groups_get_all_groupings($this->course);
         $groupinglabel = html_writer::tag('span', '(' . format_string($groupings[$this->groupingid]->name) . ')', array('class' => 'groupinglabel ' . $textclasses));
     }
     return $groupinglabel;
 }
 function definition()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     $mform->addElement('header', 'autogroup', get_string('autocreategroups', 'group'));
     $options = array(0 => get_string('all'));
     $options += $this->_customdata['roles'];
     $mform->addElement('select', 'roleid', get_string('selectfromrole', 'group'), $options);
     if (!empty($COURSE->defaultrole) and array_key_exists($COURSE->defaultrole, $options)) {
         $mform->setDefault('roleid', $COURSE->defaultrole);
     } else {
         if (!empty($CFG->defaultcourseroleid) and array_key_exists($CFG->defaultcourseroleid, $options)) {
             $mform->setDefault('roleid', $CFG->defaultcourseroleid);
         }
     }
     $options = array('groups' => get_string('numgroups', 'group'), 'members' => get_string('nummembers', 'group'));
     $mform->addElement('select', 'groupby', get_string('groupby', 'group'), $options);
     $mform->addElement('text', 'number', get_string('number', 'group'), 'maxlength="4" size="4"');
     $mform->setType('number', PARAM_INT);
     $mform->addRule('number', null, 'numeric', null, 'client');
     $mform->addRule('number', get_string('required'), 'required', null, 'client');
     $mform->addElement('checkbox', 'nosmallgroups', get_string('nosmallgroups', 'group'));
     $mform->disabledIf('nosmallgroups', 'groupby', 'noteq', 'members');
     $mform->setAdvanced('nosmallgroups');
     $options = array('no' => get_string('noallocation', 'group'), 'random' => get_string('random', 'group'), 'firstname' => get_string('byfirstname', 'group'), 'lastname' => get_string('bylastname', 'group'), 'idnumber' => get_string('byidnumber', 'group'));
     $mform->addElement('select', 'allocateby', get_string('allocateby', 'group'), $options);
     $mform->setDefault('allocateby', 'random');
     $mform->setAdvanced('allocateby');
     $mform->addElement('text', 'namingscheme', get_string('namingscheme', 'group'));
     $mform->setHelpButton('namingscheme', array(false, get_string('namingschemehelp', 'group'), false, true, false, get_string('namingschemehelp', 'group')));
     $mform->addRule('namingscheme', get_string('required'), 'required', null, 'client');
     $mform->setType('namingscheme', PARAM_MULTILANG);
     // there must not be duplicate group names in course
     $template = get_string('grouptemplate', 'group');
     $gname = groups_parse_name($template, 0);
     if (!groups_get_group_by_name($COURSE->id, $gname)) {
         $mform->setDefault('namingscheme', $template);
     }
     if (!empty($CFG->enablegroupings)) {
         $options = array('0' => get_string('no'), '-1' => get_string('newgrouping', 'group'));
         if ($groupings = groups_get_all_groupings($COURSE->id)) {
             foreach ($groupings as $grouping) {
                 $options[$grouping->id] = strip_tags(format_string($grouping->name));
             }
         }
         $mform->addElement('select', 'grouping', get_string('createingrouping', 'group'), $options);
         if ($groupings) {
             $mform->setDefault('grouping', '-1');
         }
         $mform->addElement('text', 'groupingname', get_string('groupingname', 'group'), $options);
         $mform->setType('groupingname', PARAM_MULTILANG);
         $mform->disabledIf('groupingname', 'grouping', 'noteq', '-1');
     }
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'seed');
     $mform->setType('seed', PARAM_INT);
     $buttonarray = array();
     $buttonarray[] =& $mform->createElement('submit', 'preview', get_string('preview'), 'xx');
     $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('submit'));
     $buttonarray[] =& $mform->createElement('cancel');
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
/**
 * Own function to print one section in a tree way
 */
function print_topicstree_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%")
{
    /// Prints a section full of activity modules
    global $CFG, $USER;
    static $initialised;
    static $groupbuttons;
    static $groupbuttonslink;
    static $strmovehere;
    static $strmovefull;
    static $strunreadpostsone;
    static $usetracking;
    static $groupings;
    $spacer = '&nbsp;&nbsp;&nbsp;';
    if (!isset($initialised)) {
        $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
        $groupbuttonslink = !$course->groupmodeforce;
        include_once $CFG->dirroot . '/mod/forum/lib.php';
        if ($usetracking = forum_tp_can_track_forums()) {
            $strunreadpostsone = get_string('unreadpostsone', 'forum');
        }
        $initialised = true;
    }
    $labelformatoptions = new object();
    $labelformatoptions->noclean = true;
    /// Casting $course->modinfo to string prevents one notice when the field is null
    $modinfo = get_fast_modinfo($course);
    //Acccessibility: replace table with list <ul>, but don't output empty list.
    if (!empty($section->sequence)) {
        $collapsablename = "collapsable-{$course->id}-{$section->id}";
        echo '<script type="text/javascript">';
        echo "//<![CDATA[\n";
        /**
         * Can use both:
         * call a function: addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
         * execute code: addLoadEvent(function() {
         *               // more code to run on page load 
         *           });
         */
        echo "addLoadEvent(function() {";
        echo "    compactMenu('{$collapsablename}',false,'{$spacer}&plusmn; ');";
        echo "    stateToFromStr('{$collapsablename}', retrieveCookie('{$collapsablename}'));";
        echo '});';
        echo "addUnloadEvent(function() {";
        echo "    setCookie('{$collapsablename}',stateToFromStr('{$collapsablename}'));";
        echo '});';
        echo "//]]>\n";
        echo '</script>';
        // Fix bug #5027, don't want style=\"width:$width\".
        echo "<ul id=\"{$collapsablename}\" class=\"section img-text treesection\">\n";
        $sectionmods = explode(",", $section->sequence);
        /// Preprocess all the mods, adding the necessary stuff to be able to
        /// output nested lists later
        preprocessmods4topicstree($sectionmods, $mods, $modinfo);
        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }
            $mod = $mods[$modnumber];
            if (isset($modinfo->cms[$modnumber])) {
                if (!$modinfo->cms[$modnumber]->uservisible) {
                    // visibility shortcut
                    continue;
                }
            } else {
                if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
                    // module not installed
                    continue;
                }
                if (!coursemodule_visible_for_user($mod)) {
                    // full visibility check
                    continue;
                }
            }
            $lastcss = '';
            /// Close levels if necessary
            if (!empty($mod->closelevel)) {
                for ($n = 0; $n < $mod->closelevel; $n++) {
                    echo '</ul></li>' . "\n";
                }
            }
            if (!empty($mod->islast)) {
                $lastcss = 'last ';
            }
            echo '<li class="activity treeactivity ' . $lastcss . $mod->modname . '" id="module-' . $modnumber . '">';
            // Unique ID
            /// Add spacer for activities without collapse/expand button
            if (empty($mod->openlevel)) {
                echo $spacer;
            }
            $extra = '';
            if (!empty($modinfo->cms[$modnumber]->extra)) {
                $extra = $modinfo->cms[$modnumber]->extra;
            }
            if ($mod->modname == "label") {
                if (!$mod->visible) {
                    echo "<span class=\"dimmed_text\">";
                }
                echo format_text($extra, FORMAT_HTML, $labelformatoptions);
                if (!$mod->visible) {
                    echo "</span>";
                }
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            } else {
                // Normal activity
                $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id);
                if (!empty($modinfo->cms[$modnumber]->icon)) {
                    $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon;
                } else {
                    $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif";
                }
                //Accessibility: for files get description via icon.
                $altname = '';
                if ('resource' == $mod->modname) {
                    if (!empty($modinfo->cms[$modnumber]->icon)) {
                        $possaltname = $modinfo->cms[$modnumber]->icon;
                        $mimetype = mimeinfo_from_icon('type', $possaltname);
                        $altname = get_mimetype_description($mimetype);
                    } else {
                        $altname = $mod->modfullname;
                    }
                } else {
                    $altname = $mod->modfullname;
                }
                // Avoid unnecessary duplication.
                if (false !== stripos($instancename, $altname)) {
                    $altname = '';
                }
                // File type after name, for alphabetic lists (screen reader).
                if ($altname) {
                    $altname = get_accesshide(' ' . $altname);
                }
                $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>';
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            }
            if ($usetracking && $mod->modname == 'forum') {
                if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) {
                    echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">';
                    if ($unread == 1) {
                        echo $strunreadpostsone;
                    } else {
                        print_string('unreadpostsnumber', 'forum', $unread);
                    }
                    echo '</a></span>';
                }
            }
            /// Open new level if necessary, else print end of li
            if (isset($mod->openlevel)) {
                echo '<ul class="treelevel-' . ($mod->openlevel + 1) . '">' . "\n";
            } else {
                echo "</li>\n";
            }
        }
        /// End modules iterator
        /// Close remaining levels if necessary
        if (!empty($mod->indent)) {
            for ($n = 0; $n < $mod->indent; $n++) {
                echo '</ul></li>' . "\n";
            }
        }
    }
    if (!empty($section->sequence)) {
        echo "</ul><!--class='section'-->\n\n";
    }
}
 /**
  * Get all groupings in the specified course
  *
  * @param int $courseid id of course
  * @return array of grouping objects (id, courseid, name, enrolmentkey)
  * @since Moodle 2.3
  */
 public static function get_course_groupings($courseid)
 {
     global $CFG;
     require_once "{$CFG->dirroot}/group/lib.php";
     require_once "{$CFG->libdir}/filelib.php";
     $params = self::validate_parameters(self::get_course_groupings_parameters(), array('courseid' => $courseid));
     // Now security checks.
     $context = context_course::instance($params['courseid']);
     try {
         self::validate_context($context);
     } catch (Exception $e) {
         $exceptionparam = new stdClass();
         $exceptionparam->message = $e->getMessage();
         $exceptionparam->courseid = $params['courseid'];
         throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
     }
     require_capability('moodle/course:managegroups', $context);
     $gs = groups_get_all_groupings($params['courseid']);
     $groupings = array();
     foreach ($gs as $grouping) {
         list($grouping->description, $grouping->descriptionformat) = external_format_text($grouping->description, $grouping->descriptionformat, $context->id, 'grouping', 'description', $grouping->id);
         $groupings[] = (array) $grouping;
     }
     return $groupings;
 }
 /**
  * Renders HTML to display one course module in a course section
  *
  * This includes link, content, availability, completion info and additional information
  * that module type wants to display (i.e. number of unread forum posts)
  *
  * This function calls:
  * {@link core_course_renderer::course_section_cm_name()}
  * {@link cm_info::get_after_link()}
  * {@link core_course_renderer::course_section_cm_text()}
  * {@link core_course_renderer::course_section_cm_availability()}
  * {@link core_course_renderer::course_section_cm_completion()}
  * {@link course_get_cm_edit_actions()}
  * {@link core_course_renderer::course_section_cm_edit_actions()}
  *
  * @param stdClass $course
  * @param completion_info $completioninfo
  * @param cm_info $mod
  * @param int|null $sectionreturn
  * @param array $displayoptions
  * @return string
  */
 public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array())
 {
     $output = '';
     // We return empty string (because course module will not be displayed at all)
     // if:
     // 1) The activity is not visible to users
     // and
     // 2) The 'availableinfo' is empty, i.e. the activity was
     //     hidden in a way that leaves no info, such as using the
     //     eye icon.
     if (!$mod->uservisible && empty($mod->availableinfo)) {
         return $output;
     }
     $output .= "<div class='asset-wrapper'>";
     // Start the div for the activity content.
     $output .= "<div class='activityinstance'>";
     // Display the link to the module (or do nothing if module has no url).
     $cmname = $this->course_section_cm_name($mod, $displayoptions);
     $assetlink = '';
     // SHAME - For moodles ajax show/hide call to work it needs activityinstance > a to add a class of dimmed to.
     // This dimmed class is of course inaccessible junk.
     if (!empty($cmname)) {
         $assetlink = "<a></a><h4 class='snap-asset-link'>" . $cmname . "</h4>";
     }
     // Meta.
     $assetmeta = "<div class='snap-meta'>";
     // Activity/resource type.
     $snapmodtype = $this->get_mod_type($mod)[0];
     $assetmeta .= "<span class='snap-assettype'>" . $snapmodtype . "</span>";
     if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', context_course::instance($mod->course))) {
         // Grouping label.
         $groupings = groups_get_all_groupings($mod->course);
         $assetmeta .= "<span class='snap-groupinglabel'>" . format_string($groupings[$mod->groupingid]->name) . "</span>";
         // TBD - add a title to show this is the Grouping...
     }
     // Draft status - always output, shown via css of parent.
     $assetmeta .= "<span class='draft_info'>" . get_string('draft', 'theme_snap') . "</span>";
     $availabilityinfo = $this->course_section_cm_availability($mod, $displayoptions);
     if ($availabilityinfo !== '') {
         $conditionalinfo = get_string('conditional', 'theme_snap');
         $assetmeta .= "<span class='conditional_info'>{$conditionalinfo}</span>";
         $assetmeta .= "<div class='availabilityinfo'>{$availabilityinfo}</div>";
     }
     $assetmeta .= "</div>";
     // Close asset-meta.
     $contentpart = $this->course_section_cm_text($mod, $displayoptions);
     // Build output.
     $output .= $assetlink . $assetmeta . $contentpart;
     if (!empty($cmname)) {
         // Module can put text after the link (e.g. forum unread).
         $output .= $mod->afterlink;
     }
     $output .= "</div>";
     // Close activity instance.
     // Build up edit icons.
     $modicons = '';
     if ($this->page->user_is_editing()) {
         $editactions = $this->course_get_cm_edit_actions($mod, $sectionreturn);
         $modicons .= $this->course_section_cm_edit_actions($editactions, $mod, $displayoptions);
         $modicons .= $mod->afterediticons;
         $modicons .= course_get_cm_move($mod, $sectionreturn);
     }
     if (!$this->page->user_is_editing()) {
         $modicons .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
     }
     // Add actions menu.
     if ($modicons) {
         $output .= "<div class='actions' role='region' aria-label='actions'>";
         $output .= $modicons;
         $output .= "</div>";
     }
     $output .= "</div>";
     // Close clearfix.
     return $output;
 }
Example #29
0
/**
 * Prints a section full of activity modules
 */
function print_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%", $hidecompletion = false)
{
    global $CFG, $USER, $DB, $PAGE, $OUTPUT;
    static $initialised;
    static $groupbuttons;
    static $groupbuttonslink;
    static $isediting;
    static $ismoving;
    static $strmovehere;
    static $strmovefull;
    static $strunreadpostsone;
    static $groupings;
    static $modulenames;
    if (!isset($initialised)) {
        $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
        $groupbuttonslink = !$course->groupmodeforce;
        $isediting = $PAGE->user_is_editing();
        $ismoving = $isediting && ismoving($course->id);
        if ($ismoving) {
            $strmovehere = get_string("movehere");
            $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
        }
        $modulenames = array();
        $initialised = true;
    }
    $modinfo = get_fast_modinfo($course);
    $completioninfo = new completion_info($course);
    //Accessibility: replace table with list <ul>, but don't output empty list.
    if (!empty($section->sequence)) {
        // Fix bug #5027, don't want style=\"width:$width\".
        echo "<ul class=\"section img-text\">\n";
        $sectionmods = explode(",", $section->sequence);
        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }
            /**
             * @var cm_info
             */
            $mod = $mods[$modnumber];
            if ($ismoving and $mod->id == $USER->activitycopy) {
                // do not display moving mod
                continue;
            }
            if (isset($modinfo->cms[$modnumber])) {
                // We can continue (because it will not be displayed at all)
                // if:
                // 1) The activity is not visible to users
                // and
                // 2a) The 'showavailability' option is not set (if that is set,
                //     we need to display the activity so we can show
                //     availability info)
                // or
                // 2b) The 'availableinfo' is empty, i.e. the activity was
                //     hidden in a way that leaves no info, such as using the
                //     eye icon.
                if (!$modinfo->cms[$modnumber]->uservisible && (empty($modinfo->cms[$modnumber]->showavailability) || empty($modinfo->cms[$modnumber]->availableinfo))) {
                    // visibility shortcut
                    continue;
                }
            } else {
                if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
                    // module not installed
                    continue;
                }
                if (!coursemodule_visible_for_user($mod) && empty($mod->showavailability)) {
                    // full visibility check
                    continue;
                }
            }
            if (!isset($modulenames[$mod->modname])) {
                $modulenames[$mod->modname] = get_string('modulename', $mod->modname);
            }
            $modulename = $modulenames[$mod->modname];
            // In some cases the activity is visible to user, but it is
            // dimmed. This is done if viewhiddenactivities is true and if:
            // 1. the activity is not visible, or
            // 2. the activity has dates set which do not include current, or
            // 3. the activity has any other conditions set (regardless of whether
            //    current user meets them)
            $canviewhidden = has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id));
            $accessiblebutdim = false;
            if ($canviewhidden) {
                $accessiblebutdim = !$mod->visible;
                if (!empty($CFG->enableavailability)) {
                    $accessiblebutdim = $accessiblebutdim || $mod->availablefrom > time() || $mod->availableuntil && $mod->availableuntil < time() || count($mod->conditionsgrade) > 0 || count($mod->conditionscompletion) > 0;
                }
            }
            $liclasses = array();
            $liclasses[] = 'activity';
            $liclasses[] = $mod->modname;
            $liclasses[] = 'modtype_' . $mod->modname;
            $extraclasses = $mod->get_extra_classes();
            if ($extraclasses) {
                $liclasses = array_merge($liclasses, explode(' ', $extraclasses));
            }
            echo html_writer::start_tag('li', array('class' => join(' ', $liclasses), 'id' => 'module-' . $modnumber));
            if ($ismoving) {
                echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a><br />
                     ';
            }
            $classes = array('mod-indent');
            if (!empty($mod->indent)) {
                $classes[] = 'mod-indent-' . $mod->indent;
                if ($mod->indent > 15) {
                    $classes[] = 'mod-indent-huge';
                }
            }
            echo html_writer::start_tag('div', array('class' => join(' ', $classes)));
            // Get data about this course-module
            list($content, $instancename) = get_print_section_cm_text($modinfo->cms[$modnumber], $course);
            //Accessibility: for files get description via icon, this is very ugly hack!
            $altname = '';
            $altname = $mod->modfullname;
            if (!empty($customicon)) {
                $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
                if ($archetype == MOD_ARCHETYPE_RESOURCE) {
                    $mimetype = mimeinfo_from_icon('type', $customicon);
                    $altname = get_mimetype_description($mimetype);
                }
            }
            // Avoid unnecessary duplication: if e.g. a forum name already
            // includes the word forum (or Forum, etc) then it is unhelpful
            // to include that in the accessible description that is added.
            if (false !== strpos(textlib::strtolower($instancename), textlib::strtolower($altname))) {
                $altname = '';
            }
            // File type after name, for alphabetic lists (screen reader).
            if ($altname) {
                $altname = get_accesshide(' ' . $altname);
            }
            // We may be displaying this just in order to show information
            // about visibility, without the actual link
            $contentpart = '';
            if ($mod->uservisible) {
                // Nope - in this case the link is fully working for user
                $linkclasses = '';
                $textclasses = '';
                if ($accessiblebutdim) {
                    $linkclasses .= ' dimmed';
                    $textclasses .= ' dimmed_text';
                    $accesstext = '<span class="accesshide">' . get_string('hiddenfromstudents') . ': </span>';
                } else {
                    $accesstext = '';
                }
                if ($linkclasses) {
                    $linkcss = 'class="' . trim($linkclasses) . '" ';
                } else {
                    $linkcss = '';
                }
                if ($textclasses) {
                    $textcss = 'class="' . trim($textclasses) . '" ';
                } else {
                    $textcss = '';
                }
                // Get on-click attribute value if specified
                $onclick = $mod->get_on_click();
                if ($onclick) {
                    $onclick = ' onclick="' . $onclick . '"';
                }
                if ($url = $mod->get_url()) {
                    // Display link itself
                    echo '<a ' . $linkcss . $mod->extra . $onclick . ' href="' . $url . '"><img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> ' . $accesstext . '<span class="instancename">' . $instancename . $altname . '</span></a>';
                    // If specified, display extra content after link
                    if ($content) {
                        $contentpart = '<div class="' . trim('contentafterlink' . $textclasses) . '">' . $content . '</div>';
                    }
                } else {
                    // No link, so display only content
                    $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>';
                }
                if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            } else {
                $textclasses = $extraclasses;
                $textclasses .= ' dimmed_text';
                if ($textclasses) {
                    $textcss = 'class="' . trim($textclasses) . '" ';
                } else {
                    $textcss = '';
                }
                $accesstext = '<span class="accesshide">' . get_string('notavailableyet', 'condition') . ': </span>';
                if ($url = $mod->get_url()) {
                    // Display greyed-out text of link
                    echo '<div ' . $textcss . $mod->extra . ' >' . '<img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> <span>' . $instancename . $altname . '</span></div>';
                    // Do not display content after link when it is greyed out like this.
                } else {
                    // No link, so display only content (also greyed)
                    $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>';
                }
            }
            // Module can put text after the link (e.g. forum unread)
            echo $mod->get_after_link();
            // If there is content but NO link (eg label), then display the
            // content here (BEFORE any icons). In this case cons must be
            // displayed after the content so that it makes more sense visually
            // and for accessibility reasons, e.g. if you have a one-line label
            // it should work similarly (at least in terms of ordering) to an
            // activity.
            if (empty($url)) {
                echo $contentpart;
            }
            if ($isediting) {
                if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
                    if (!($mod->groupmodelink = $groupbuttonslink)) {
                        $mod->groupmode = $course->groupmode;
                    }
                } else {
                    $mod->groupmode = false;
                }
                echo '&nbsp;&nbsp;';
                echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
                echo $mod->get_after_edit_icons();
            }
            // Completion
            $completion = $hidecompletion ? COMPLETION_TRACKING_NONE : $completioninfo->is_enabled($mod);
            if ($completion != COMPLETION_TRACKING_NONE && isloggedin() && !isguestuser() && $mod->uservisible) {
                $completiondata = $completioninfo->get_data($mod, true);
                $completionicon = '';
                if ($isediting) {
                    switch ($completion) {
                        case COMPLETION_TRACKING_MANUAL:
                            $completionicon = 'manual-enabled';
                            break;
                        case COMPLETION_TRACKING_AUTOMATIC:
                            $completionicon = 'auto-enabled';
                            break;
                        default:
                            // wtf
                    }
                } else {
                    if ($completion == COMPLETION_TRACKING_MANUAL) {
                        switch ($completiondata->completionstate) {
                            case COMPLETION_INCOMPLETE:
                                $completionicon = 'manual-n';
                                break;
                            case COMPLETION_COMPLETE:
                                $completionicon = 'manual-y';
                                break;
                        }
                    } else {
                        // Automatic
                        switch ($completiondata->completionstate) {
                            case COMPLETION_INCOMPLETE:
                                $completionicon = 'auto-n';
                                break;
                            case COMPLETION_COMPLETE:
                                $completionicon = 'auto-y';
                                break;
                            case COMPLETION_COMPLETE_PASS:
                                $completionicon = 'auto-pass';
                                break;
                            case COMPLETION_COMPLETE_FAIL:
                                $completionicon = 'auto-fail';
                                break;
                        }
                    }
                }
                if ($completionicon) {
                    $imgsrc = $OUTPUT->pix_url('i/completion-' . $completionicon);
                    $imgalt = s(get_string('completion-alt-' . $completionicon, 'completion', $mod->name));
                    if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting) {
                        $imgtitle = s(get_string('completion-title-' . $completionicon, 'completion', $mod->name));
                        $newstate = $completiondata->completionstate == COMPLETION_COMPLETE ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE;
                        // In manual mode the icon is a toggle form...
                        // If this completion state is used by the
                        // conditional activities system, we need to turn
                        // off the JS.
                        if (!empty($CFG->enableavailability) && condition_info::completion_value_used_as_condition($course, $mod)) {
                            $extraclass = ' preventjs';
                        } else {
                            $extraclass = '';
                        }
                        echo "\n<form class='togglecompletion{$extraclass}' method='post' action='" . $CFG->wwwroot . "/course/togglecompletion.php'><div>\n<input type='hidden' name='id' value='{$mod->id}' />\n<input type='hidden' name='modulename' value='" . s($mod->name) . "' />\n<input type='hidden' name='sesskey' value='" . sesskey() . "' />\n<input type='hidden' name='completionstate' value='{$newstate}' />\n<input type='image' src='{$imgsrc}' alt='{$imgalt}' title='{$imgtitle}' />\n</div></form>";
                    } else {
                        // In auto mode, or when editing, the icon is just an image
                        echo "<span class='autocompletion'>";
                        echo "<img src='{$imgsrc}' alt='{$imgalt}' title='{$imgalt}' /></span>";
                    }
                }
            }
            // If there is content AND a link, then display the content here
            // (AFTER any icons). Otherwise it was displayed before
            if (!empty($url)) {
                echo $contentpart;
            }
            // Show availability information (for someone who isn't allowed to
            // see the activity itself, or for staff)
            if (!$mod->uservisible) {
                echo '<div class="availabilityinfo">' . $mod->availableinfo . '</div>';
            } else {
                if ($canviewhidden && !empty($CFG->enableavailability)) {
                    $ci = new condition_info($mod);
                    $fullinfo = $ci->get_full_information();
                    if ($fullinfo) {
                        echo '<div class="availabilityinfo">' . get_string($mod->showavailability ? 'userrestriction_visible' : 'userrestriction_hidden', 'condition', $fullinfo) . '</div>';
                    }
                }
            }
            echo html_writer::end_tag('div');
            echo html_writer::end_tag('li') . "\n";
        }
    } elseif ($ismoving) {
        echo "<ul class=\"section\">\n";
    }
    if ($ismoving) {
        echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a></li>
             ';
    }
    if (!empty($section->sequence) || $ismoving) {
        echo "</ul><!--class='section'-->\n\n";
    }
}
Example #30
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->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', $mod->context);
            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->url) {
            if ($content) {
                // If specified, display extra content after link.
                $output = html_writer::tag('div', $content, array('class' =>
                        trim('contentafterlink ' . $textclasses)));
            }
        } else {
            $groupinglabel = '';
            if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', context_course::instance($mod->course))) {
                $groupings = groups_get_all_groupings($mod->course);
                $groupinglabel = html_writer::tag('span', '('.format_string($groupings[$mod->groupingid]->name).')',
                        array('class' => 'groupinglabel '.$textclasses));
            }

            // No link, so display only content.
            $output = html_writer::tag('div', $accesstext . $content . $groupinglabel,
                    array('class' => 'contentwithoutlink ' . $textclasses));
        }
        return $output;
    }