function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $modcontext = $this->_customdata['modcontext'];
     $mform->addElement('header', 'general', get_string('export', 'quiz'));
     $mform->setHelpButton('general', array('export', get_string('export', 'quiz'), 'attforblock'));
     $groupmode = groups_get_activity_groupmode($cm);
     $groups = groups_get_activity_allowed_groups($cm, $USER->id);
     if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
         $grouplist[0] = get_string('allparticipants');
     }
     if ($groups) {
         foreach ($groups as $group) {
             $grouplist[$group->id] = $group->name;
         }
     }
     $mform->addElement('select', 'group', get_string('group'), $grouplist);
     $ident = array();
     $ident[] =& MoodleQuickForm::createElement('checkbox', 'id', '', get_string('studentid', 'attforblock'));
     $ident[] =& MoodleQuickForm::createElement('checkbox', 'uname', '', get_string('username'));
     $mform->addGroup($ident, 'ident', get_string('identifyby', 'attforblock'), array('<br />'), true);
     $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true));
     $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attforblock'), get_string('yes'));
     $mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attforblock'));
     $mform->disabledIf('sessionenddate', 'includenottaken', 'notchecked');
     $mform->addElement('select', 'format', get_string('format'), array('excel' => get_string('downloadexcel', 'attforblock'), 'ooo' => get_string('downloadooo', 'attforblock'), 'text' => get_string('downloadtext', 'attforblock')));
     // buttons
     $submit_string = get_string('ok');
     $this->add_action_buttons(false, $submit_string);
     $mform->addElement('hidden', 'id', $cm->id);
     //        $mform->addElement('hidden', 'action', 'add');
 }
 public function should_display($discussion)
 {
     global $USER;
     if (is_a($discussion, 'mod_forumng_discussion')) {
         return true;
     }
     // This is a forum.
     if (!$discussion->get_tags_enabled()) {
         return false;
     } else {
         // Need to check for capabilities.
         if (has_capability('forumngfeature/edittags:managesettags', $discussion->get_context())) {
             return true;
         } else {
             $cm = $discussion->get_course_module();
             if ($discussion->get_group_mode()) {
                 $allowedgroups = groups_get_activity_allowed_groups($cm);
                 if (!empty($allowedgroups) && has_capability('forumngfeature/edittags:editsettags', $discussion->get_context())) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
 /**
  * Called to define this moodle form
  *
  * @return void
  */
 public function definition()
 {
     global $USER;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $modcontext = $this->_customdata['modcontext'];
     $mform->addElement('header', 'general', get_string('export', 'attendance'));
     $groupmode = groups_get_activity_groupmode($cm, $course);
     $groups = groups_get_activity_allowed_groups($cm, $USER->id);
     if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
         $grouplist[0] = get_string('allparticipants');
     }
     if ($groups) {
         foreach ($groups as $group) {
             $grouplist[$group->id] = $group->name;
         }
     }
     $mform->addElement('select', 'group', get_string('group'), $grouplist);
     $ident = array();
     $ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attendance'));
     $ident[] =& $mform->createElement('checkbox', 'uname', '', get_string('username'));
     $optional = array('idnumber', 'institution', 'department');
     foreach ($optional as $opt) {
         $ident[] =& $mform->createElement('checkbox', $opt, '', get_string($opt));
         $mform->setType($opt, PARAM_NOTAGS);
     }
     $mform->addGroup($ident, 'ident', get_string('identifyby', 'attendance'), array('<br />'), true);
     $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true));
     $mform->setType('id', PARAM_INT);
     $mform->setType('uname', PARAM_INT);
     $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes'));
     $mform->setDefault('includeallsessions', true);
     $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attendance'), get_string('yes'));
     $mform->addElement('checkbox', 'includeremarks', get_string('includeremarks', 'attendance'), get_string('yes'));
     $mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod', 'attendance'));
     $mform->setDefault('sessionstartdate', $course->startdate);
     $mform->disabledIf('sessionstartdate', 'includeallsessions', 'checked');
     $mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attendance'));
     $mform->disabledIf('sessionenddate', 'includeallsessions', 'checked');
     $mform->addElement('select', 'format', get_string('format'), array('excel' => get_string('downloadexcel', 'attendance'), 'ooo' => get_string('downloadooo', 'attendance'), 'text' => get_string('downloadtext', 'attendance')));
     $submit_string = get_string('ok');
     $this->add_action_buttons(false, $submit_string);
     $mform->addElement('hidden', 'id', $cm->id);
 }
Ejemplo n.º 4
0
function bigbluebuttonbn_view_joining($bbbsession, $context, $streamline)
{
    global $CFG, $DB;
    $joining = false;
    // If user is administrator, moderator or if is viewer and no waiting is required
    if ($bbbsession['flag']['administrator'] || $bbbsession['flag']['moderator'] || !$bbbsession['flag']['wait']) {
        //
        // Join directly
        //
        $metadata = array("meta_origin" => $bbbsession['origin'], "meta_originVersion" => $bbbsession['originVersion'], "meta_originServerName" => $bbbsession['originServerName'], "meta_originServerCommonName" => $bbbsession['originServerCommonName'], "meta_originTag" => $bbbsession['originTag'], "meta_context" => $bbbsession['context'], "meta_contextActivity" => $bbbsession['contextActivity'], "meta_contextActivityDescription" => $bbbsession['contextActivityDescription'], "meta_recording" => $bbbsession['textflag']['record']);
        $response = bigbluebuttonbn_getCreateMeetingArray($bbbsession['meetingname'], $bbbsession['meetingid'], $bbbsession['welcome'], $bbbsession['modPW'], $bbbsession['viewerPW'], $bbbsession['salt'], $bbbsession['url'], $bbbsession['logoutURL'], $bbbsession['textflag']['record'], $bbbsession['timeduration'], $bbbsession['voicebridge'], $metadata);
        if (!$response) {
            // If the server is unreachable, then prompts the user of the necessary action
            if ($bbbsession['flag']['administrator']) {
                print_error('view_error_unable_join', 'streamline', $CFG->wwwroot . '/admin/settings.php?section=modsettingbigbluebuttonbn');
            } else {
                if ($bbbsession['flag']['moderator']) {
                    print_error('view_error_unable_join_teacher', 'streamline', $CFG->wwwroot . '/admin/settings.php?section=modsettingbigbluebuttonbn');
                } else {
                    print_error('view_error_unable_join_student', 'streamline', $CFG->wwwroot . '/admin/settings.php?section=modsettingbigbluebuttonbn');
                }
            }
        } else {
            if ($response['returncode'] == "FAILED") {
                // The meeting was not created
                $error_key = bigbluebuttonbn_get_error_key($response['messageKey'], 'view_error_create');
                if (!$error_key) {
                    print_error($response['message'], 'streamline');
                } else {
                    print_error($error_key, 'streamline');
                }
            } else {
                if ($response['hasBeenForciblyEnded'] == "true") {
                    print_error(get_string('index_error_forciblyended', 'streamline'));
                } else {
                    ///////////////Everything is ok /////////////////////
                    /// Moodle event logger: Create an event for meeting created
                    if ($CFG->version < '2014051200') {
                        //This is valid before v2.7
                        add_to_log($bbbsession['courseid'], 'streamline', 'meeting created', '', $streamline->name, $bbbsession['cm']->id);
                    } else {
                        //This is valid after v2.7
                        $event = \mod_streamline\event\bigbluebuttonbn_meeting_created::create(array('context' => $context, 'objectid' => $streamline->id));
                        $event->trigger();
                    }
                    /// Internal logger: Instert a record with the meeting created
                    bigbluebuttonbn_log($bbbsession, 'Create');
                    if (groups_get_activity_groupmode($bbbsession['cm']) > 0 && count(groups_get_activity_allowed_groups($bbbsession['cm'])) > 1) {
                        print "<br>" . get_string('view_groups_selection', 'streamline') . "&nbsp;&nbsp;<input type='button' onClick='M.mod_streamline.joinURL()' value='" . get_string('view_groups_selection_join', 'streamline') . "'>";
                    } else {
                        $joining = true;
                        if ($bbbsession['flag']['administrator'] || $bbbsession['flag']['moderator']) {
                            print "<br />" . get_string('view_login_moderator', 'streamline') . "<br /><br />";
                        } else {
                            print "<br />" . get_string('view_login_viewer', 'streamline') . "<br /><br />";
                        }
                        print "<center><img src='pix/loading.gif' /></center>";
                    }
                    /// Moodle event logger: Create an event for meeting joined
                    if ($CFG->version < '2014051200') {
                        //This is valid before v2.7
                        add_to_log($bbbsession['courseid'], 'streamline', 'meeting joined', '', $streamline->name, $bbbsession['cm']->id);
                    } else {
                        //This is valid after v2.7
                        $event = \mod_streamline\event\bigbluebuttonbn_meeting_joined::create(array('context' => $context, 'objectid' => $streamline->id));
                        $event->trigger();
                    }
                }
            }
        }
    } else {
        //
        // "Viewer" && Waiting for moderator is required;
        //
        $joining = true;
        print "<div align='center'>";
        if (bigbluebuttonbn_wrap_simplexml_load_file(bigbluebuttonbn_getIsMeetingRunningURL($bbbsession['meetingid'], $bbbsession['url'], $bbbsession['salt'])) == "true") {
            /// Since the meeting is already running, we just join the session
            print "<br />" . get_string('view_login_viewer', 'streamline') . "<br /><br />";
            print "<center><img src='pix/loading.gif' /></center>";
            /// Moodle event logger: Create an event for meeting joined
            if ($CFG->version < '2014051200') {
                //This is valid before v2.7
                add_to_log($bbbsession['courseid'], 'streamline', 'meeting joined', '', $streamline->name, $bbbsession['cm']->id);
            } else {
                //This is valid after v2.7
                $event = \mod_streamline\event\bigbluebuttonbn_meeting_joined::create(array('context' => $context, 'objectid' => $streamline->id));
                $event->trigger();
            }
        } else {
            /// Since the meeting is not running, the spining wheel is shown
            print "<br />" . get_string('view_wait', 'streamline') . "<br /><br />";
            print '<center><img src="pix/polling.gif"></center>';
        }
        print "</div>";
    }
    return $joining;
}
Ejemplo n.º 5
0
 /**
  * Form definition
  *
  * @return void
  */
 function definition()
 {
     global $CFG, $OUTPUT;
     $mform =& $this->_form;
     //var_dump($this->_customdata);die;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $coursecontext = $this->_customdata['coursecontext'];
     $modcontext = $this->_customdata['modcontext'];
     $twf = $this->_customdata['twf'];
     $post = $this->_customdata['post'];
     $subscribe = $this->_customdata['subscribe'];
     $edit = $this->_customdata['edit'];
     $thresholdwarning = $this->_customdata['thresholdwarning'];
     $syx_newdiscussion = $this->_customdata['syx_newdiscussion'];
     $syx_phase = $this->_customdata['syx_phase'];
     $syx_instance = $this->_customdata['syx_instance'];
     $syx_teamwork = $this->_customdata['syx_teamwork'];
     $mform->addElement('header', 'general', '');
     //fill in the data depending on page params later using set_data
     // If there is a warning message and we are not editing a post we need to handle the warning.
     if (!empty($thresholdwarning) && !$edit) {
         // Here we want to display a warning if they can still post but have reached the warning threshold.
         if ($thresholdwarning->canpost) {
             $message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
             $mform->addElement('html', $OUTPUT->notification($message));
         }
     }
     $mform->addElement('text', 'subject', get_string('subject', 'twf'), 'size="48"');
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', get_string('required'), 'required', null, 'client');
     $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     if ($syx_newdiscussion) {
         $mform->addElement('text', 'score', get_string('score', 'twf'));
         $mform->setType('score', PARAM_INT);
         $mform->addRule('score', get_string('required'), 'required', null, 'client');
         $mform->addHelpButton('score', 'score_rules', 'twf');
     }
     $mform->addElement('editor', 'message', get_string('message', 'twf'), null, self::editor_options($modcontext, empty($post->id) ? null : $post->id));
     $mform->setType('message', PARAM_RAW);
     $mform->addRule('message', get_string('required'), 'required', null, 'client');
     $manageactivities = has_capability('moodle/course:manageactivities', $coursecontext);
     if (\mod_twf\subscriptions::is_forcesubscribed($twf)) {
         $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'twf'));
         $mform->freeze('discussionsubscribe');
         $mform->setDefaults('discussionsubscribe', 0);
         $mform->addHelpButton('discussionsubscribe', 'forcesubscribed', 'twf');
     } else {
         if (\mod_twf\subscriptions::subscription_disabled($twf) && !$manageactivities) {
             $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'twf'));
             $mform->freeze('discussionsubscribe');
             $mform->setDefaults('discussionsubscribe', 0);
             $mform->addHelpButton('discussionsubscribe', 'disallowsubscription', 'twf');
         } else {
             $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'twf'));
             $mform->addHelpButton('discussionsubscribe', 'discussionsubscription', 'twf');
         }
     }
     if (!empty($twf->maxattachments) && $twf->maxbytes != 1 && has_capability('mod/twf:createattachment', $modcontext)) {
         //  1 = No attachments at all
         $mform->addElement('filemanager', 'attachments', get_string('attachment', 'twf'), null, self::attachment_options($twf));
         $mform->addHelpButton('attachments', 'attachment', 'twf');
     }
     if (empty($post->id) && $manageactivities) {
         $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'twf'));
     }
     if (!empty($CFG->twf_enabletimedposts) && !$post->parent && has_capability('mod/twf:viewhiddentimedposts', $coursecontext)) {
         // hack alert
         $mform->addElement('header', 'displayperiod', get_string('displayperiod', 'twf'));
         $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'twf'), array('optional' => true));
         $mform->addHelpButton('timestart', 'displaystart', 'twf');
         $mform->addElement('date_selector', 'timeend', get_string('displayend', 'twf'), array('optional' => true));
         $mform->addHelpButton('timeend', 'displayend', 'twf');
     } else {
         $mform->addElement('hidden', 'timestart');
         $mform->setType('timestart', PARAM_INT);
         $mform->addElement('hidden', 'timeend');
         $mform->setType('timeend', PARAM_INT);
         $mform->setConstants(array('timestart' => 0, 'timeend' => 0));
     }
     if ($groupmode = groups_get_activity_groupmode($cm, $course)) {
         $groupdata = groups_get_activity_allowed_groups($cm);
         $groupinfo = array();
         foreach ($groupdata as $groupid => $group) {
             // Check whether this user can post in this group.
             // We must make this check because all groups are returned for a visible grouped activity.
             if (twf_user_can_post_discussion($twf, $groupid, null, $cm, $modcontext)) {
                 // Build the data for the groupinfo select.
                 $groupinfo[$groupid] = $group->name;
             } else {
                 unset($groupdata[$groupid]);
             }
         }
         $groupcount = count($groupinfo);
         // Check whether a user can post to all of their own groups.
         // Posts to all of my groups are copied to each group that the user is a member of. Certain conditions must be met.
         // 1) It only makes sense to allow this when a user is in more than one group.
         // Note: This check must come before we consider adding accessallgroups, because that is not a real group.
         $canposttoowngroups = empty($post->edit) && $groupcount > 1;
         // 2) Important: You can *only* post to multiple groups for a top level post. Never any reply.
         $canposttoowngroups = $canposttoowngroups && empty($post->parent);
         // 3) You also need the canposttoowngroups capability.
         $canposttoowngroups = $canposttoowngroups && has_capability('mod/twf:canposttomygroups', $modcontext);
         if ($canposttoowngroups) {
             // This user is in multiple groups, and can post to all of their own groups.
             // Note: This is not the same as accessallgroups. This option will copy a post to all groups that a
             // user is a member of.
             $mform->addElement('checkbox', 'posttomygroups', get_string('posttomygroups', 'twf'));
             $mform->addHelpButton('posttomygroups', 'posttomygroups', 'twf');
             $mform->disabledIf('groupinfo', 'posttomygroups', 'checked');
         }
         // Check whether this user can post to all groups.
         // Posts to the 'All participants' group go to all groups, not to each group in a list.
         // It makes sense to allow this, even if there currently aren't any groups because there may be in the future.
         if (twf_user_can_post_discussion($twf, -1, null, $cm, $modcontext)) {
             // Note: We must reverse in this manner because array_unshift renumbers the array.
             $groupinfo = array_reverse($groupinfo, true);
             $groupinfo[-1] = get_string('allparticipants');
             $groupinfo = array_reverse($groupinfo, true);
             $groupcount++;
         }
         // Determine whether the user can select a group from the dropdown. The dropdown is available for several reasons.
         // 1) This is a new post (not an edit), and there are at least two groups to choose from.
         $canselectgroupfornew = empty($post->edit) && $groupcount > 1;
         // 2) This is editing of an existing post and the user is allowed to movediscussions.
         // We allow this because the post may have been moved from another twf where groups are not available.
         // We show this even if no groups are available as groups *may* have been available but now are not.
         $canselectgroupformove = $groupcount && !empty($post->edit) && has_capability('mod/twf:movediscussions', $modcontext);
         // Important: You can *only* change the group for a top level post. Never any reply.
         $canselectgroup = empty($post->parent) && ($canselectgroupfornew || $canselectgroupformove);
         if ($canselectgroup) {
             $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
             $mform->setDefault('groupinfo', $post->groupid);
             $mform->setType('groupinfo', PARAM_INT);
         } else {
             if (empty($post->groupid)) {
                 $groupname = get_string('allparticipants');
             } else {
                 $groupname = format_string($groupdata[$post->groupid]->name);
             }
             $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     if (isset($post->edit)) {
         // hack alert
         $submit_string = get_string('savechanges');
     } else {
         $submit_string = get_string('posttotwf', 'twf');
     }
     $this->add_action_buttons(true, $submit_string);
     //var_dump($syx_teamwork);die;
     $mform->addElement('hidden', 'teamwork', $syx_teamwork);
     $mform->setType('teamwork', PARAM_INT);
     $mform->addElement('hidden', 'phase', $syx_phase);
     $mform->setType('phase', PARAM_INT);
     $mform->addElement('hidden', 'instace', $syx_instance);
     $mform->setType('instace', PARAM_INT);
     $mform->addElement('hidden', 'course');
     $mform->setType('course', PARAM_INT);
     $mform->addElement('hidden', 'twf');
     $mform->setType('twf', PARAM_INT);
     $mform->addElement('hidden', 'discussion');
     $mform->setType('discussion', PARAM_INT);
     $mform->addElement('hidden', 'parent');
     $mform->setType('parent', PARAM_INT);
     $mform->addElement('hidden', 'userid');
     $mform->setType('userid', PARAM_INT);
     $mform->addElement('hidden', 'groupid');
     $mform->setType('groupid', PARAM_INT);
     $mform->addElement('hidden', 'edit');
     $mform->setType('edit', PARAM_INT);
     $mform->addElement('hidden', 'reply');
     $mform->setType('reply', PARAM_INT);
 }
Ejemplo n.º 6
0
 /**
  * Get the simple edit discussion form
  *
  * @param object $cm
  * @param int $postid
  * @param array $data Template data
  * @return string
  */
 public function simple_edit_discussion($cm, $postid = 0, array $data = array())
 {
     global $DB, $USER, $OUTPUT;
     $context = context_module::instance($cm->id);
     $forum = hsuforum_get_cm_forum($cm);
     if (!empty($postid)) {
         $params = array('edit' => $postid);
         $legend = get_string('editingpost', 'hsuforum');
         $post = $DB->get_record('hsuforum_posts', ['id' => $postid]);
         if ($post->userid != $USER->id) {
             $user = $DB->get_record('user', ['id' => $post->userid]);
             $user = hsuforum_anonymize_user($user, $forum, $post);
             $data['userpicture'] = $this->output->user_picture($user, array('link' => false, 'size' => 100));
         }
     } else {
         $params = array('forum' => $cm->instance);
         $legend = get_string('addyourdiscussion', 'hsuforum');
         $thresholdwarning = hsuforum_check_throttling($forum, $cm);
         if (!empty($thresholdwarning)) {
             $message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
             $data['thresholdwarning'] = $OUTPUT->notification($message);
             if ($thresholdwarning->canpost === false) {
                 $data['thresholdblocked'] = " hsuforum-threshold-blocked ";
             }
         }
     }
     $data += array('itemid' => 0, 'groupid' => 0, 'messageformat' => FORMAT_HTML);
     $actionurl = new moodle_url('/mod/hsuforum/route.php', array('action' => empty($postid) ? 'add_discussion' : 'update_post', 'sesskey' => sesskey(), 'edit' => $postid, 'contextid' => $context->id, 'itemid' => $data['itemid'], 'messageformat' => $data['messageformat']));
     $extrahtml = '';
     if (groups_get_activity_groupmode($cm)) {
         $groupdata = groups_get_activity_allowed_groups($cm);
         if (count($groupdata) > 1) {
             if (has_capability('moodle/site:accessallgroups', $context)) {
                 $groupinfo[0] = get_string('allparticipants');
             }
             foreach ($groupdata as $grouptemp) {
                 $groupinfo[$grouptemp->id] = $grouptemp->name;
             }
             $extrahtml = html_writer::tag('span', get_string('group'));
             $extrahtml .= html_writer::select($groupinfo, 'groupinfo', $data['groupid'], false);
             $extrahtml = html_writer::tag('label', $extrahtml);
         } else {
             $actionurl->param('groupinfo', groups_get_activity_group($cm));
         }
     }
     if ($forum->anonymous) {
         $extrahtml .= html_writer::tag('label', html_writer::checkbox('reveal', 1, !empty($data['reveal'])) . get_string('reveal', 'hsuforum'));
     }
     $data += array('postid' => $postid, 'context' => $context, 'forum' => $forum, 'actionurl' => $actionurl, 'class' => 'hsuforum-discussion', 'legend' => $legend, 'extrahtml' => $extrahtml, 'advancedurl' => new moodle_url('/mod/hsuforum/post.php', $params));
     return $this->simple_edit_template($data);
 }
Ejemplo n.º 7
0
/**
 * Determine if a given group is visible to user or not in a given context.
 *
 * @since Moodle 2.6
 * @param int      $groupid Group id to test. 0 for all groups.
 * @param stdClass $course  Course object.
 * @param stdClass $cm      Course module object.
 * @param int      $userid  user id to test against. Defaults to $USER.
 * @return boolean true if visible, false otherwise
 */
function groups_group_visible($groupid, $course, $cm = null, $userid = null)
{
    global $USER;
    if (empty($userid)) {
        $userid = $USER->id;
    }
    $groupmode = empty($cm) ? groups_get_course_groupmode($course) : groups_get_activity_groupmode($cm, $course);
    if ($groupmode == NOGROUPS || $groupmode == VISIBLEGROUPS) {
        // Groups are not used, or everything is visible, no need to go any further.
        return true;
    }
    $context = empty($cm) ? context_course::instance($course->id) : context_module::instance($cm->id);
    if (has_capability('moodle/site:accessallgroups', $context, $userid)) {
        // User can see everything. Groupid = 0 is handled here as well.
        return true;
    } else {
        if ($groupid != 0) {
            // Group mode is separate, and user doesn't have access all groups capability. Check if user can see requested group.
            $groups = empty($cm) ? groups_get_all_groups($course->id, $userid) : groups_get_activity_allowed_groups($cm, $userid);
            if (array_key_exists($groupid, $groups)) {
                // User can see the group.
                return true;
            }
        }
    }
    return false;
}
 public function can_take_session($groupid)
 {
     if (!$this->can_take()) {
         return false;
     }
     if ($groupid == attendance::SESSION_COMMON || $this->can_access_all_groups() || array_key_exists($groupid, groups_get_activity_allowed_groups($this->cm))) {
         return true;
     }
     return false;
 }
 /**
  * Called to define this moodle form
  *
  * @return void
  */
 public function definition()
 {
     global $USER, $DB, $PAGE;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $modcontext = $this->_customdata['modcontext'];
     $mform->addElement('header', 'general', get_string('export', 'attendance'));
     $groupmode = groups_get_activity_groupmode($cm, $course);
     $groups = groups_get_activity_allowed_groups($cm, $USER->id);
     if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $modcontext)) {
         $grouplist[0] = get_string('allparticipants');
     }
     if ($groups) {
         foreach ($groups as $group) {
             $grouplist[$group->id] = $group->name;
         }
     }
     $mform->addElement('select', 'group', get_string('group'), $grouplist);
     // Restrict the export to the selected users.
     $namefields = get_all_user_name_fields(true, 'u');
     $allusers = get_enrolled_users($modcontext, 'mod/attendance:canbelisted', 0, 'u.id,' . $namefields);
     $userlist = array();
     foreach ($allusers as $user) {
         $userlist[$user->id] = fullname($user);
     }
     unset($allusers);
     $tempusers = $DB->get_records('attendance_tempusers', array('courseid' => $course->id), 'studentid, fullname');
     foreach ($tempusers as $user) {
         $userlist[$user->studentid] = $user->fullname;
     }
     list($gsql, $gparams) = $DB->get_in_or_equal(array_keys($grouplist), SQL_PARAMS_NAMED);
     list($usql, $uparams) = $DB->get_in_or_equal(array_keys($userlist), SQL_PARAMS_NAMED);
     $params = array_merge($gparams, $uparams);
     $groupmembers = $DB->get_recordset_select('groups_members', "groupid {$gsql} AND userid {$usql}", $params, '', 'groupid, userid');
     $groupmappings = array();
     foreach ($groupmembers as $groupmember) {
         if (!isset($groupmappings[$groupmember->groupid])) {
             $groupmappings[$groupmember->groupid] = array();
         }
         $groupmappings[$groupmember->groupid][$groupmember->userid] = $userlist[$groupmember->userid];
     }
     if (isset($grouplist[0])) {
         $groupmappings[0] = $userlist;
     }
     $mform->addElement('selectyesno', 'selectedusers', get_string('onlyselectedusers', 'mod_attendance'));
     $sel = $mform->addElement('select', 'users', get_string('users', 'mod_attendance'), $userlist, array('size' => 12));
     $sel->setMultiple(true);
     $mform->disabledIf('users', 'selectedusers', 'eq', 0);
     $opts = array('groupmappings' => $groupmappings);
     $PAGE->requires->yui_module('moodle-mod_attendance-groupfilter', 'M.mod_attendance.groupfilter.init', array($opts));
     $ident = array();
     $ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attendance'));
     $ident[] =& $mform->createElement('checkbox', 'uname', '', get_string('username'));
     $optional = array('idnumber', 'institution', 'department');
     foreach ($optional as $opt) {
         $ident[] =& $mform->createElement('checkbox', $opt, '', get_string($opt));
         $mform->setType($opt, PARAM_NOTAGS);
     }
     $mform->addGroup($ident, 'ident', get_string('identifyby', 'attendance'), array('<br />'), true);
     $mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true));
     $mform->setType('id', PARAM_INT);
     $mform->setType('uname', PARAM_INT);
     $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes'));
     $mform->setDefault('includeallsessions', true);
     $mform->addElement('checkbox', 'includenottaken', get_string('includenottaken', 'attendance'), get_string('yes'));
     $mform->addElement('checkbox', 'includeremarks', get_string('includeremarks', 'attendance'), get_string('yes'));
     $mform->addElement('date_selector', 'sessionstartdate', get_string('startofperiod', 'attendance'));
     $mform->setDefault('sessionstartdate', $course->startdate);
     $mform->disabledIf('sessionstartdate', 'includeallsessions', 'checked');
     $mform->addElement('date_selector', 'sessionenddate', get_string('endofperiod', 'attendance'));
     $mform->disabledIf('sessionenddate', 'includeallsessions', 'checked');
     $mform->addElement('select', 'format', get_string('format'), array('excel' => get_string('downloadexcel', 'attendance'), 'ooo' => get_string('downloadooo', 'attendance'), 'text' => get_string('downloadtext', 'attendance')));
     $submitstring = get_string('ok');
     $this->add_action_buttons(false, $submitstring);
     $mform->addElement('hidden', 'id', $cm->id);
 }
Ejemplo n.º 10
0
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $coursecontext = $this->_customdata['coursecontext'];
     $modcontext = $this->_customdata['modcontext'];
     $forum = $this->_customdata['forum'];
     $post = $this->_customdata['post'];
     // if $forum->maxbytes == '0' means we should use $course->maxbytes
     if ($forum->maxbytes == '0') {
         $forum->maxbytes = $course->maxbytes;
     }
     // TODO: add max files and max size support
     $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext' => true, 'context' => $modcontext);
     $mform->addElement('header', 'general', '');
     //fill in the data depending on page params later using set_data
     $mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', get_string('required'), 'required', null, 'client');
     $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addElement('editor', 'message', get_string('message', 'forum'), null, $editoroptions);
     $mform->setType('message', PARAM_RAW);
     $mform->addRule('message', get_string('required'), 'required', null, 'client');
     if (isset($forum->id) && forum_is_forcesubscribed($forum)) {
         $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
         $mform->addElement('hidden', 'subscribe');
         $mform->setType('subscribe', PARAM_INT);
         $mform->addHelpButton('subscribemessage', 'subscription', 'forum');
     } else {
         if (isset($forum->forcesubscribe) && $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE || has_capability('moodle/course:manageactivities', $coursecontext)) {
             $options = array();
             $options[0] = get_string('subscribestop', 'forum');
             $options[1] = get_string('subscribestart', 'forum');
             $mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
             $mform->addHelpButton('subscribe', 'subscription', 'forum');
         } else {
             if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
                 $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
                 $mform->addElement('hidden', 'subscribe');
                 $mform->setType('subscribe', PARAM_INT);
                 $mform->addHelpButton('subscribemessage', 'subscription', 'forum');
             }
         }
     }
     if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) {
         //  1 = No attachments at all
         $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null, array('subdirs' => 0, 'maxbytes' => $forum->maxbytes, 'maxfiles' => $forum->maxattachments, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL));
         $mform->addHelpButton('attachments', 'attachment', 'forum');
     }
     if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) {
         // hack alert
         $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
     }
     if (!empty($CFG->forum_enabletimedposts) && !$post->parent && has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) {
         // hack alert
         $mform->addElement('header', '', get_string('displayperiod', 'forum'));
         $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional' => true));
         $mform->addHelpButton('timestart', 'displaystart', 'forum');
         $mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional' => true));
         $mform->addHelpButton('timeend', 'displayend', 'forum');
     } else {
         $mform->addElement('hidden', 'timestart');
         $mform->setType('timestart', PARAM_INT);
         $mform->addElement('hidden', 'timeend');
         $mform->setType('timeend', PARAM_INT);
         $mform->setConstants(array('timestart' => 0, 'timeend' => 0));
     }
     if (groups_get_activity_groupmode($cm, $course)) {
         // hack alert
         $groupdata = groups_get_activity_allowed_groups($cm);
         $groupcount = count($groupdata);
         $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
         $contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
         if ($contextcheck) {
             $groupinfo = array('0' => get_string('allparticipants'));
             foreach ($groupdata as $grouptemp) {
                 $groupinfo[$grouptemp->id] = $grouptemp->name;
             }
             $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
             $mform->setDefault('groupinfo', $post->groupid);
         } else {
             if (empty($post->groupid)) {
                 $groupname = get_string('allparticipants');
             } else {
                 $groupname = format_string($groupdata[$post->groupid]->name);
             }
             $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     if (isset($post->edit)) {
         // hack alert
         $submit_string = get_string('savechanges');
     } else {
         $submit_string = get_string('posttoforum', 'forum');
     }
     $this->add_action_buttons(false, $submit_string);
     $mform->addElement('hidden', 'course');
     $mform->setType('course', PARAM_INT);
     $mform->addElement('hidden', 'forum');
     $mform->setType('forum', PARAM_INT);
     $mform->addElement('hidden', 'discussion');
     $mform->setType('discussion', PARAM_INT);
     $mform->addElement('hidden', 'parent');
     $mform->setType('parent', PARAM_INT);
     $mform->addElement('hidden', 'userid');
     $mform->setType('userid', PARAM_INT);
     $mform->addElement('hidden', 'groupid');
     $mform->setType('groupid', PARAM_INT);
     $mform->addElement('hidden', 'edit');
     $mform->setType('edit', PARAM_INT);
     $mform->addElement('hidden', 'reply');
     $mform->setType('reply', PARAM_INT);
 }
Ejemplo n.º 11
0
/**
 * Determine if the current user can see at least one of the groups of the specified user.
 *
 * @param stdClass $course  Course object.
 * @param int $userid  user id to check against.
 * @param stdClass $cm Course module object. Optional, just for checking at activity level instead course one.
 * @return boolean true if visible, false otherwise
 * @since Moodle 2.9
 */
function groups_user_groups_visible($course, $userid, $cm = null)
{
    global $USER;
    $groupmode = empty($cm) ? groups_get_course_groupmode($course) : groups_get_activity_groupmode($cm, $course);
    if ($groupmode == NOGROUPS || $groupmode == VISIBLEGROUPS) {
        // Groups are not used, or everything is visible, no need to go any further.
        return true;
    }
    $context = empty($cm) ? context_course::instance($course->id) : context_module::instance($cm->id);
    if (has_capability('moodle/site:accessallgroups', $context)) {
        // User can see everything.
        return true;
    } else {
        // Group mode is separate, and user doesn't have access all groups capability.
        if (empty($cm)) {
            $usergroups = groups_get_all_groups($course->id, $userid);
            $currentusergroups = groups_get_all_groups($course->id, $USER->id);
        } else {
            $usergroups = groups_get_activity_allowed_groups($cm, $userid);
            $currentusergroups = groups_get_activity_allowed_groups($cm, $USER->id);
        }
        $samegroups = array_intersect_key($currentusergroups, $usergroups);
        if (!empty($samegroups)) {
            // We share groups!
            return true;
        }
    }
    return false;
}
Ejemplo n.º 12
0
/**
 * Prints the subwiki selector if user has access to more than one subwiki.
 * Also displays the currently-viewing subwiki.
 *
 * @param object $subwiki Current subwiki object
 * @param object $ouwiki Wiki object
 * @param object $cm Course-module object
 * @param object $context Context for permissions
 * @param object $course Course object
 */
function ouwiki_display_subwiki_selector($subwiki, $ouwiki, $cm, $context, $course, $actionurl = 'view.php')
{
    global $USER, $DB;
    if ($ouwiki->subwikis == OUWIKI_SUBWIKIS_SINGLE) {
        return '';
    }
    $choicefield = '';
    switch ($ouwiki->subwikis) {
        case OUWIKI_SUBWIKIS_GROUPS:
            $groups = groups_get_activity_allowed_groups($cm);
            uasort($groups, create_function('$a,$b', 'return strcasecmp($a->name,$b->name);'));
            $wikifor = htmlspecialchars($groups[$subwiki->groupid]->name);
            // Do they have more than one?
            if (count($groups) > 1) {
                $choicefield = 'group';
                $choices = $groups;
            }
            break;
        case OUWIKI_SUBWIKIS_INDIVIDUAL:
            $user = $DB->get_record('user', array('id' => $subwiki->userid), 'id, firstname, lastname, username');
            $wikifor = ouwiki_display_user($user, $cm->course);
            if (has_capability('mod/ouwiki:viewallindividuals', $context)) {
                // Get list of everybody...
                $choicefield = 'user';
                try {
                    $choices = $DB->get_records_sql('SELECT u.id, u.firstname, u.lastname
                            FROM {ouwiki_subwikis} sw
                            INNER JOIN {user} u ON sw.userid = u.id
                            WHERE sw.wikiid = ?
                            ORDER BY u.lastname, u.firstname', array($ouwiki->id));
                } catch (Exception $e) {
                    ouwiki_dberror($e);
                }
                foreach ($choices as $choice) {
                    $choice->name = fullname($choice);
                }
            } else {
                if (has_capability('mod/ouwiki:viewgroupindividuals', $context)) {
                    $choicefield = 'user';
                    $choices = array();
                    // User allowed to view people in same group
                    $theirgroups = groups_get_all_groups($cm->course, $USER->id, $course->defaultgroupingid);
                    if (!$theirgroups) {
                        $theirgroups = array();
                    }
                    foreach ($theirgroups as $group) {
                        $members = groups_get_members($group->id, 'u.id, u.firstname, u.lastname');
                        foreach ($members as $member) {
                            $member->name = fullname($member);
                            $choices[$member->id] = $member;
                        }
                    }
                } else {
                    // Nope, only yours
                }
            }
            break;
        default:
            ouwiki_error("Unexpected subwikis value: {$ouwiki->subwikis}");
    }
    $out = '<div class="ouw_subwiki"><label for="wikiselect">' . get_string('wikifor', 'ouwiki') . '</label>';
    if ($choicefield && count($choices) > 1) {
        $selectedid = $choicefield == 'user' ? $subwiki->userid : $subwiki->groupid;
        $out .= '<form method="get" action="' . $actionurl . '" class="ouwiki_otherwikis">
            <div><input type="hidden" name="id" value="' . $cm->id . '"/>
            <select name="' . $choicefield . '" id="wikiselect">';
        foreach ($choices as $choice) {
            $selected = $choice->id == $selectedid ? ' selected="selected"' : '';
            $out .= '<option value="' . $choice->id . '"' . $selected . '>' . htmlspecialchars($choice->name) . '</option>';
        }
        $out .= '</select> <input type="submit" value="' . get_string('changebutton', 'ouwiki') . '" /></div></form>';
    } else {
        $out .= $wikifor;
    }
    $out .= '</div>';
    return $out;
}
Ejemplo n.º 13
0
 /**
  * Form definition
  *
  * @return void
  */
 function definition()
 {
     global $CFG, $OUTPUT;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $coursecontext = $this->_customdata['coursecontext'];
     $modcontext = $this->_customdata['modcontext'];
     $forum = $this->_customdata['forum'];
     $post = $this->_customdata['post'];
     $edit = $this->_customdata['edit'];
     $thresholdwarning = $this->_customdata['thresholdwarning'];
     $mform->addElement('header', 'general', '');
     //fill in the data depending on page params later using set_data
     // If there is a warning message and we are not editing a post we need to handle the warning.
     if (!empty($thresholdwarning) && !$edit) {
         // Here we want to display a warning if they can still post but have reached the warning threshold.
         if ($thresholdwarning->canpost) {
             $message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
             $mform->addElement('html', $OUTPUT->notification($message));
         }
     }
     $mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', get_string('required'), 'required', null, 'client');
     $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addElement('editor', 'message', get_string('message', 'forum'), null, self::editor_options($modcontext, empty($post->id) ? null : $post->id));
     $mform->setType('message', PARAM_RAW);
     $mform->addRule('message', get_string('required'), 'required', null, 'client');
     if (isset($forum->id) && forum_is_forcesubscribed($forum)) {
         $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
         $mform->addElement('hidden', 'subscribe');
         $mform->setType('subscribe', PARAM_INT);
         $mform->addHelpButton('subscribemessage', 'subscription', 'forum');
     } else {
         if (isset($forum->forcesubscribe) && $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE || has_capability('moodle/course:manageactivities', $coursecontext)) {
             $options = array();
             $options[0] = get_string('subscribestop', 'forum');
             $options[1] = get_string('subscribestart', 'forum');
             $mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
             $mform->addHelpButton('subscribe', 'subscription', 'forum');
         } else {
             if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
                 $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
                 $mform->addElement('hidden', 'subscribe');
                 $mform->setType('subscribe', PARAM_INT);
                 $mform->addHelpButton('subscribemessage', 'subscription', 'forum');
             }
         }
     }
     if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) {
         //  1 = No attachments at all
         $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null, self::attachment_options($forum));
         $mform->addHelpButton('attachments', 'attachment', 'forum');
     }
     if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) {
         // hack alert
         $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
     }
     if (!empty($CFG->forum_enabletimedposts) && !$post->parent && has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) {
         // hack alert
         $mform->addElement('header', 'displayperiod', get_string('displayperiod', 'forum'));
         $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional' => true));
         $mform->addHelpButton('timestart', 'displaystart', 'forum');
         $mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional' => true));
         $mform->addHelpButton('timeend', 'displayend', 'forum');
     } else {
         $mform->addElement('hidden', 'timestart');
         $mform->setType('timestart', PARAM_INT);
         $mform->addElement('hidden', 'timeend');
         $mform->setType('timeend', PARAM_INT);
         $mform->setConstants(array('timestart' => 0, 'timeend' => 0));
     }
     if (groups_get_activity_groupmode($cm, $course)) {
         // hack alert
         $groupdata = groups_get_activity_allowed_groups($cm);
         $groupcount = count($groupdata);
         $modulecontext = context_module::instance($cm->id);
         $contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount;
         if ($contextcheck) {
             $groupinfo = array('0' => get_string('allparticipants'));
             foreach ($groupdata as $grouptemp) {
                 $groupinfo[$grouptemp->id] = $grouptemp->name;
             }
             $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
             $mform->setDefault('groupinfo', $post->groupid);
             $mform->setType('groupinfo', PARAM_INT);
         } else {
             if (empty($post->groupid)) {
                 $groupname = get_string('allparticipants');
             } else {
                 $groupname = format_string($groupdata[$post->groupid]->name);
             }
             $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     if (isset($post->edit)) {
         // hack alert
         $submit_string = get_string('savechanges');
     } else {
         $submit_string = get_string('posttoforum', 'forum');
     }
     $this->add_action_buttons(false, $submit_string);
     $mform->addElement('hidden', 'course');
     $mform->setType('course', PARAM_INT);
     $mform->addElement('hidden', 'forum');
     $mform->setType('forum', PARAM_INT);
     $mform->addElement('hidden', 'discussion');
     $mform->setType('discussion', PARAM_INT);
     $mform->addElement('hidden', 'parent');
     $mform->setType('parent', PARAM_INT);
     $mform->addElement('hidden', 'userid');
     $mform->setType('userid', PARAM_INT);
     $mform->addElement('hidden', 'groupid');
     $mform->setType('groupid', PARAM_INT);
     $mform->addElement('hidden', 'edit');
     $mform->setType('edit', PARAM_INT);
     $mform->addElement('hidden', 'reply');
     $mform->setType('reply', PARAM_INT);
 }
Ejemplo n.º 14
0
 /**
  *
  */
 public function display_edit(&$mform, $entry, array $options = null)
 {
     $field = $this->_field;
     $fieldid = $field->id;
     $entryid = $entry->id;
     $fieldname = "entry_{$entryid}_groupid";
     $selected = $entry->groupid;
     static $groupsmenu = null;
     if (is_null($groupsmenu)) {
         $groupsmenu = array(0 => get_string('choosedots'));
         if ($groups = groups_get_activity_allowed_groups($field->df->cm)) {
             foreach ($groups as $groupid => $group) {
                 $groupsmenu[$groupid] = $group->name;
             }
         }
     }
     $mform->addElement('select', $fieldname, null, $groupsmenu);
     $mform->setDefault($fieldname, $selected);
 }
Ejemplo n.º 15
0
 /**
  * Form definition
  *
  * @return void
  */
 function definition()
 {
     global $OUTPUT, $USER, $DB;
     $config = get_config('hsuforum');
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $coursecontext = $this->_customdata['coursecontext'];
     $modcontext = $this->_customdata['modcontext'];
     $forum = $this->_customdata['forum'];
     $post = $this->_customdata['post'];
     $edit = $this->_customdata['edit'];
     $thresholdwarning = $this->_customdata['thresholdwarning'];
     $mform->addElement('html', '<div class="fcontainer">');
     // If there is a warning message and we are not editing a post we need to handle the warning.
     if (!empty($thresholdwarning) && !$edit) {
         // Here we want to display a warning if they can still post but have reached the warning threshold.
         if ($thresholdwarning->canpost) {
             $message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
             $mform->addElement('html', $OUTPUT->notification($message));
         }
     }
     $mform->addElement('text', 'subject', get_string('subject', 'hsuforum'), 'size="48"');
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', get_string('required'), 'required', null, 'client');
     $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addElement('editor', 'message', get_string('message', 'hsuforum'), null, self::editor_options($modcontext, empty($post->id) ? null : $post->id));
     $mform->setType('message', PARAM_RAW);
     $mform->addRule('message', get_string('required'), 'required', null, 'client');
     if (isset($forum->id) && hsuforum_is_forcesubscribed($forum)) {
         $mform->addElement('static', 'subscribemessage', get_string('subscription', 'hsuforum'), get_string('everyoneissubscribed', 'hsuforum'));
         $mform->addElement('hidden', 'subscribe');
         $mform->setType('subscribe', PARAM_INT);
         $mform->addHelpButton('subscribemessage', 'subscription', 'hsuforum');
     } else {
         if (isset($forum->forcesubscribe) && $forum->forcesubscribe != HSUFORUM_DISALLOWSUBSCRIBE || has_capability('moodle/course:manageactivities', $coursecontext)) {
             $options = array();
             $options[0] = get_string('subscribestop', 'hsuforum');
             $options[1] = get_string('subscribestart', 'hsuforum');
             $mform->addElement('select', 'subscribe', get_string('subscription', 'hsuforum'), $options);
             $mform->addHelpButton('subscribe', 'subscription', 'hsuforum');
         } else {
             if ($forum->forcesubscribe == HSUFORUM_DISALLOWSUBSCRIBE) {
                 $mform->addElement('static', 'subscribemessage', get_string('subscription', 'hsuforum'), get_string('disallowsubscribe', 'hsuforum'));
                 $mform->addElement('hidden', 'subscribe');
                 $mform->setType('subscribe', PARAM_INT);
                 $mform->addHelpButton('subscribemessage', 'subscription', 'hsuforum');
             }
         }
     }
     if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/hsuforum:createattachment', $modcontext)) {
         //  1 = No attachments at all
         $mform->addElement('filemanager', 'attachments', get_string('attachment', 'hsuforum'), null, self::attachment_options($forum));
         $mform->addHelpButton('attachments', 'attachment', 'hsuforum');
     }
     if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) {
         // hack alert
         $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'hsuforum'));
     }
     if (!empty($config->enabletimedposts) && !$post->parent && has_capability('mod/hsuforum:viewhiddentimedposts', $coursecontext)) {
         // hack alert
         $mform->addElement('header', 'displayperiod', get_string('displayperiod', 'hsuforum'));
         $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'hsuforum'), array('optional' => true));
         $mform->addHelpButton('timestart', 'displaystart', 'hsuforum');
         $mform->addElement('date_selector', 'timeend', get_string('displayend', 'hsuforum'), array('optional' => true));
         $mform->addHelpButton('timeend', 'displayend', 'hsuforum');
     } else {
         $mform->addElement('hidden', 'timestart');
         $mform->setType('timestart', PARAM_INT);
         $mform->addElement('hidden', 'timeend');
         $mform->setType('timeend', PARAM_INT);
         $mform->setConstants(array('timestart' => 0, 'timeend' => 0));
     }
     if ($groupmode = groups_get_activity_groupmode($cm, $course)) {
         // hack alert
         $groupdata = groups_get_activity_allowed_groups($cm);
         $groupcount = count($groupdata);
         $groupinfo = array();
         $modulecontext = context_module::instance($cm->id);
         // Check whether the user has access to all groups in this forum from the accessallgroups cap.
         if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $modulecontext)) {
             // Only allow posting to all groups if the user has access to all groups.
             $groupinfo = array('0' => get_string('allparticipants'));
             $groupcount++;
         }
         $contextcheck = has_capability('mod/hsuforum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
         if ($contextcheck) {
             foreach ($groupdata as $grouptemp) {
                 $groupinfo[$grouptemp->id] = $grouptemp->name;
             }
             $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
             $mform->setDefault('groupinfo', $post->groupid);
             $mform->setType('groupinfo', PARAM_INT);
         } else {
             if (empty($post->groupid)) {
                 $groupname = get_string('allparticipants');
             } else {
                 $groupname = format_string($groupdata[$post->groupid]->name);
             }
             $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
         }
     }
     if (!empty($forum->anonymous) and $post->userid == $USER->id and has_capability('mod/hsuforum:revealpost', $modcontext)) {
         $mform->addElement('advcheckbox', 'reveal', get_string('reveal', 'hsuforum'));
         $mform->addHelpButton('reveal', 'reveal', 'hsuforum');
     }
     if (!empty($forum->allowprivatereplies) and !empty($post->parent) and has_capability('mod/hsuforum:allowprivate', $modcontext)) {
         if ($post->userid != $USER->id) {
             $mform->addElement('hidden', 'privatereply', 0);
             $mform->setType('privatereply', PARAM_INT);
         } else {
             $parentauthorid = $DB->get_field('hsuforum_posts', 'userid', array('id' => $post->parent), MUST_EXIST);
             $mform->addElement('advcheckbox', 'privatereply', get_string('privatereply', 'hsuforum'), null, null, array(0, $parentauthorid));
             $mform->addHelpButton('privatereply', 'privatereply', 'hsuforum');
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     if (isset($post->edit)) {
         // hack alert
         $submit_string = get_string('savechanges');
     } else {
         $submit_string = get_string('posttoforum', 'hsuforum');
     }
     $this->add_action_buttons(false, $submit_string);
     $mform->addElement('hidden', 'course');
     $mform->setType('course', PARAM_INT);
     $mform->addElement('hidden', 'forum');
     $mform->setType('forum', PARAM_INT);
     $mform->addElement('hidden', 'discussion');
     $mform->setType('discussion', PARAM_INT);
     $mform->addElement('hidden', 'parent');
     $mform->setType('parent', PARAM_INT);
     $mform->addElement('hidden', 'userid');
     $mform->setType('userid', PARAM_INT);
     $mform->addElement('hidden', 'groupid');
     $mform->setType('groupid', PARAM_INT);
     $mform->addElement('hidden', 'edit');
     $mform->setType('edit', PARAM_INT);
     $mform->addElement('hidden', 'reply');
     $mform->setType('reply', PARAM_INT);
     $mform->addElement('html', '</div>');
 }
Ejemplo n.º 16
0
        }
        if (!empty($popup) && $popup == 1) {
            ?>
<script type="text/javascript">
                opener.document.location.reload();
                self.close();
                </script><?php 
            die;
        } else {
            redirect('view.php?q=' . $quiz->id, $message);
        }
    }
} else {
    if (!has_capability('moodle/site:accessallgroups', $context) && groups_get_activity_groupmode($cm) == SEPARATEGROUPS) {
        // Check the users have at least one group in common.
        $teachersgroups = groups_get_activity_allowed_groups($cm);
        $studentsgroups = groups_get_all_groups($cm->course, $attempt->userid, $cm->groupingid);
        if (!($teachersgroups && $studentsgroups && array_intersect(array_keys($teachersgroups), array_keys($studentsgroups)))) {
            print_error('noreview', 'quiz', 'view.php?q=' . $quiz->id);
        }
    }
}
/// Bits needed to print a good URL for this page.
$urloptions = '';
if ($showall) {
    $urloptions .= '&amp;showall=true';
} else {
    if ($page > 0) {
        $urloptions .= '&amp;page=' . $page;
    }
}
Ejemplo n.º 17
0
function bigbluebuttonbn_view_joining($bbbsession)
{
    echo '<script type="text/javascript" >var bigbluebuttonbn_view = "join";</script>' . "\n";
    if ($bbbsession['flag']['moderator'] || !$bbbsession['flag']['wait']) {
        // If is a moderator or if is a viewer and no waiting is required
        //
        // Join directly
        //
        $response = BigBlueButtonBN::createMeetingArray($bbbsession['meetingname'], $bbbsession['meetingid'], $bbbsession['welcome'], $bbbsession['modPW'], $bbbsession['viewerPW'], $bbbsession['salt'], $bbbsession['url'], $bbbsession['logoutURL'], $bbbsession['textflag']['record'], $bbbsession['timeduration'], $bbbsession['voicebridge'], array("meta_course" => $bbbsession['coursename'], "meta_activity" => $bbbsession['meetingname'], "meta_description" => $bbbsession['description'], "meta_email" => $bbbsession['useremail'], "meta_recording" => $bbbsession['textflag']['record']));
        if (!$response) {
            // If the server is unreachable, then prompts the user of the necessary action
            if ($bbbsession['flag']['administrator']) {
                print_error('view_error_unable_join', 'bigbluebuttonbn', $CFG->wwwroot . '/admin/settings.php?section=modsettingbigbluebuttonbn');
            } else {
                if ($bbbsession['flag']['moderator']) {
                    print_error('view_error_unable_join_teacher', 'bigbluebuttonbn', $CFG->wwwroot . '/admin/settings.php?section=modsettingbigbluebuttonbn');
                } else {
                    print_error('view_error_unable_join_student', 'bigbluebuttonbn', $CFG->wwwroot . '/admin/settings.php?section=modsettingbigbluebuttonbn');
                }
            }
        } else {
            if ($response['returncode'] == "FAILED") {
                // The meeting was not created
                if ($response['messageKey'] == "checksumError") {
                    print_error(get_string('index_error_checksum', 'bigbluebuttonbn'));
                } else {
                    print_error($response['message']);
                }
            } else {
                if ($response['hasBeenForciblyEnded'] == "true") {
                    print_error(get_string('index_error_forciblyended', 'bigbluebuttonbn'));
                } else {
                    ///////////////Everything is ok /////////////////////
                    if (groups_get_activity_groupmode($bbbsession['cm']) > 0 && count(groups_get_activity_allowed_groups($bbbsession['cm'])) > 1) {
                        print '<script type="text/javascript" >var joining = "false";</script>';
                        print get_string('view_groups_selection', 'bigbluebuttonbn') . "&nbsp;&nbsp;<input type='button' onClick='bigbluebuttonbn_joinURL()' value='" . get_string('view_groups_selection_join', 'bigbluebuttonbn') . "'>";
                    } else {
                        print '<script type="text/javascript" >var joining = "true";</script>';
                        if ($bbbsession['flag']['moderator']) {
                            print "<br />" . get_string('view_login_moderator', 'bigbluebuttonbn') . "<br /><br />";
                        } else {
                            print "<br />" . get_string('view_login_viewer', 'bigbluebuttonbn') . "<br /><br />";
                        }
                        print "<center><img src='pix/loading.gif' /></center>";
                    }
                }
            }
        }
    } else {
        // "Viewer" && Waiting for moderator is required;
        echo '<script type="text/javascript" >var joining = "true";</script>' . "\n";
        print "<div align='center'>";
        if (BigBlueButtonBN::isMeetingRunning($bbbsession['meetingid'], $bbbsession['url'], $bbbsession['salt']) == "true") {
            //
            // since the meeting is already running, we just join the session
            //
            print "<br />" . get_string('view_login_viewer', 'bigbluebuttonbn') . "<br /><br />";
            print "<center><img src='pix/loading.gif' /></center>";
        } else {
            print "<br />" . get_string('view_wait', 'bigbluebuttonbn') . "<br /><br />";
            print '<center><img src="pix/polling.gif"></center>';
        }
        print "</div>";
    }
}
Ejemplo n.º 18
0
 /**
  * Capability check to make sure this grader can edit this submission.
  *
  * @param int $userid - The user whose submission is to be edited
  * @param int $graderid (optional) - The user who will do the editing (default to $USER->id).
  * @return bool
  */
 public function can_edit_submission($userid, $graderid = 0)
 {
     global $USER;
     if (empty($graderid)) {
         $graderid = $USER->id;
     }
     $instance = $this->get_instance();
     if ($userid == $graderid && $instance->teamsubmission && $instance->preventsubmissionnotingroup && $this->get_submission_group($userid) == false) {
         return false;
     }
     if ($userid == $graderid && $this->submissions_open($userid) && has_capability('mod/assign:submit', $this->context, $graderid)) {
         // User can edit their own submission.
         return true;
     }
     if (!has_capability('mod/assign:editothersubmission', $this->context, $graderid)) {
         return false;
     }
     $cm = $this->get_course_module();
     if (groups_get_activity_groupmode($cm) == SEPARATEGROUPS) {
         // These arrays are indexed by groupid.
         $studentgroups = array_keys(groups_get_activity_allowed_groups($cm, $userid));
         $gradergroups = array_keys(groups_get_activity_allowed_groups($cm, $graderid));
         return count(array_intersect($studentgroups, $gradergroups)) > 0;
     }
     return true;
 }
Ejemplo n.º 19
0
$forum = mod_forumng::get_from_cmid($cmid, $cloneid);
$course = $forum->get_course();
$cm = $forum->get_course_module();
$context = $forum->get_context(true);
// Get group id for forum.
$groupid = mod_forumng::get_activity_group($cm, true);
$fid = $forum->get_id();
// Check access.
$forum->require_view($groupid);
$managesettags = has_capability('forumngfeature/edittags:managesettags', $forum->get_context());
$editsettags = has_capability('forumngfeature/edittags:editsettags', $forum->get_context());
$groupmode = groups_get_activity_groupmode($cm, $course);
$groupsaccessto = array();
if ($managesettags || $editsettags) {
    if ($groupmode) {
        $groupsaccessto = groups_get_activity_allowed_groups($cm);
        if (!$managesettags && empty($groupsaccessto)) {
            // Nothing to show - shouldn't get button anyway so error.
            print_error('nopermissiontoshow');
        }
    }
} else {
    // Get out of here.
    print_error('nopermissiontoshow');
}
require_once 'managetags_form.php';
$urlparams = array('id' => $cmid);
if ($cloneid) {
    $urlparams['clone'] = $cloneid;
}
$groups = array();
Ejemplo n.º 20
0
 /**
  * Form definition
  *
  * @return void
  */
 function definition()
 {
     global $CFG, $OUTPUT;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $cm = $this->_customdata['cm'];
     $coursecontext = $this->_customdata['coursecontext'];
     $modcontext = $this->_customdata['modcontext'];
     $quora = $this->_customdata['quora'];
     $post = $this->_customdata['post'];
     $subscribe = $this->_customdata['subscribe'];
     $edit = $this->_customdata['edit'];
     $thresholdwarning = $this->_customdata['thresholdwarning'];
     $mform->addElement('header', 'general', '');
     //fill in the data depending on page params later using set_data
     // If there is a warning message and we are not editing a post we need to handle the warning.
     if (!empty($thresholdwarning) && !$edit) {
         // Here we want to display a warning if they can still post but have reached the warning threshold.
         if ($thresholdwarning->canpost) {
             $message = get_string($thresholdwarning->errorcode, $thresholdwarning->module, $thresholdwarning->additional);
             $mform->addElement('html', $OUTPUT->notification($message));
         }
     }
     $mform->addElement('text', 'subject', get_string('subject', 'quora'), 'size="48"');
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', get_string('required'), 'required', null, 'client');
     $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addElement('editor', 'message', get_string('message', 'quora'), null, self::editor_options($modcontext, empty($post->id) ? null : $post->id));
     $mform->setType('message', PARAM_RAW);
     $mform->addRule('message', get_string('required'), 'required', null, 'client');
     $manageactivities = has_capability('moodle/course:manageactivities', $coursecontext);
     if (\mod_quora\subscriptions::is_forcesubscribed($quora)) {
         $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'quora'));
         $mform->freeze('discussionsubscribe');
         $mform->setDefaults('discussionsubscribe', 0);
         $mform->addHelpButton('discussionsubscribe', 'forcesubscribed', 'quora');
     } else {
         if (\mod_quora\subscriptions::subscription_disabled($quora) && !$manageactivities) {
             $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'quora'));
             $mform->freeze('discussionsubscribe');
             $mform->setDefaults('discussionsubscribe', 0);
             $mform->addHelpButton('discussionsubscribe', 'disallowsubscription', 'quora');
         } else {
             $mform->addElement('checkbox', 'discussionsubscribe', get_string('discussionsubscription', 'quora'));
             $mform->addHelpButton('discussionsubscribe', 'discussionsubscription', 'quora');
         }
     }
     if (!empty($quora->maxattachments) && $quora->maxbytes != 1 && has_capability('mod/quora:createattachment', $modcontext)) {
         //  1 = No attachments at all
         $mform->addElement('filemanager', 'attachments', get_string('attachment', 'quora'), null, self::attachment_options($quora));
         $mform->addHelpButton('attachments', 'attachment', 'quora');
     }
     if (empty($post->id) && $manageactivities) {
         $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'quora'));
     }
     if (!empty($CFG->quora_enabletimedposts) && !$post->parent && has_capability('mod/quora:viewhiddentimedposts', $coursecontext)) {
         // hack alert
         $mform->addElement('header', 'displayperiod', get_string('displayperiod', 'quora'));
         $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'quora'), array('optional' => true));
         $mform->addHelpButton('timestart', 'displaystart', 'quora');
         $mform->addElement('date_selector', 'timeend', get_string('displayend', 'quora'), array('optional' => true));
         $mform->addHelpButton('timeend', 'displayend', 'quora');
     } else {
         $mform->addElement('hidden', 'timestart');
         $mform->setType('timestart', PARAM_INT);
         $mform->addElement('hidden', 'timeend');
         $mform->setType('timeend', PARAM_INT);
         $mform->setConstants(array('timestart' => 0, 'timeend' => 0));
     }
     if ($groupmode = groups_get_activity_groupmode($cm, $course)) {
         // hack alert
         $groupdata = groups_get_activity_allowed_groups($cm);
         $groupcount = count($groupdata);
         $groupinfo = array();
         $modulecontext = context_module::instance($cm->id);
         // Check whether the user has access to all groups in this quora from the accessallgroups cap.
         if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $modulecontext)) {
             // Only allow posting to all groups if the user has access to all groups.
             $groupinfo = array('0' => get_string('allparticipants'));
             $groupcount++;
         }
         $contextcheck = has_capability('mod/quora:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
         if ($contextcheck) {
             if (has_capability('mod/quora:canposttomygroups', $modulecontext) && !isset($post->edit)) {
                 $mform->addElement('checkbox', 'posttomygroups', get_string('posttomygroups', 'quora'));
                 $mform->addHelpButton('posttomygroups', 'posttomygroups', 'quora');
                 $mform->disabledIf('groupinfo', 'posttomygroups', 'checked');
             }
             foreach ($groupdata as $grouptemp) {
                 $groupinfo[$grouptemp->id] = $grouptemp->name;
             }
             $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
             $mform->setDefault('groupinfo', $post->groupid);
             $mform->setType('groupinfo', PARAM_INT);
         } else {
             if (empty($post->groupid)) {
                 $groupname = get_string('allparticipants');
             } else {
                 $groupname = format_string($groupdata[$post->groupid]->name);
             }
             $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
         }
     }
     //-------------------------------------------------------------------------------
     // buttons
     if (isset($post->edit)) {
         // hack alert
         $submit_string = get_string('savechanges');
     } else {
         $submit_string = get_string('posttoquora', 'quora');
     }
     $this->add_action_buttons(true, $submit_string);
     $mform->addElement('hidden', 'course');
     $mform->setType('course', PARAM_INT);
     $mform->addElement('hidden', 'quora');
     $mform->setType('quora', PARAM_INT);
     $mform->addElement('hidden', 'discussion');
     $mform->setType('discussion', PARAM_INT);
     $mform->addElement('hidden', 'parent');
     $mform->setType('parent', PARAM_INT);
     $mform->addElement('hidden', 'userid');
     $mform->setType('userid', PARAM_INT);
     $mform->addElement('hidden', 'groupid');
     $mform->setType('groupid', PARAM_INT);
     $mform->addElement('hidden', 'edit');
     $mform->setType('edit', PARAM_INT);
     $mform->addElement('hidden', 'reply');
     $mform->setType('reply', PARAM_INT);
 }
Ejemplo n.º 21
0
/**
 * Print a detailed representation of what a user has done with
 * a given particular instance of this module, for user activity reports.
 *
 * @return string HTML
 */
function workshop_user_complete($course, $user, $mod, $workshop) {
    global $CFG, $DB, $OUTPUT;
    require_once(dirname(__FILE__).'/locallib.php');
    require_once($CFG->libdir.'/gradelib.php');

    $workshop   = new workshop($workshop, $mod, $course);
    $grades     = grade_get_grades($course->id, 'mod', 'workshop', $workshop->id, $user->id);

    if (!empty($grades->items[0]->grades)) {
        $submissiongrade = reset($grades->items[0]->grades);
        $info = get_string('submissiongrade', 'workshop') . ': ' . $submissiongrade->str_long_grade;
        echo html_writer::tag('li', $info, array('class'=>'submissiongrade'));
    }
    if (!empty($grades->items[1]->grades)) {
        $assessmentgrade = reset($grades->items[1]->grades);
        $info = get_string('gradinggrade', 'workshop') . ': ' . $assessmentgrade->str_long_grade;
        echo html_writer::tag('li', $info, array('class'=>'gradinggrade'));
    }

    if (has_capability('mod/workshop:viewallsubmissions', $workshop->context)) {
        $canviewsubmission = true;
        if (groups_get_activity_groupmode($workshop->cm) == SEPARATEGROUPS) {
            // user must have accessallgroups or share at least one group with the submission author
            if (!has_capability('moodle/site:accessallgroups', $workshop->context)) {
                $usersgroups = groups_get_activity_allowed_groups($workshop->cm);
                $authorsgroups = groups_get_all_groups($workshop->course->id, $user->id, $workshop->cm->groupingid, 'g.id');
                $sharedgroups = array_intersect_key($usersgroups, $authorsgroups);
                if (empty($sharedgroups)) {
                    $canviewsubmission = false;
                }
            }
        }
        if ($canviewsubmission and $submission = $workshop->get_submission_by_author($user->id)) {
            $title      = format_string($submission->title);
            $url        = $workshop->submission_url($submission->id);
            $link       = html_writer::link($url, $title);
            $info       = get_string('submission', 'workshop').': '.$link;
            echo html_writer::tag('li', $info, array('class'=>'submission'));
        }
    }

    if (has_capability('mod/workshop:viewallassessments', $workshop->context)) {
        if ($assessments = $workshop->get_assessments_by_reviewer($user->id)) {
            foreach ($assessments as $assessment) {
                $a = new stdclass();
                $a->submissionurl = $workshop->submission_url($assessment->submissionid)->out();
                $a->assessmenturl = $workshop->assess_url($assessment->id)->out();
                $a->submissiontitle = s($assessment->submissiontitle);
                echo html_writer::tag('li', get_string('assessmentofsubmission', 'workshop', $a));
            }
        }
    }
}
Ejemplo n.º 22
0
 /**
  * Gets a list of groups that the user is allowed to access within the specified activity.
  *
  * @throws moodle_exception
  * @param int $cmid course module id
  * @param int $userid id of user.
  * @return array of group objects (id, name, description, format) and possible warnings.
  * @since Moodle 3.0
  */
 public static function get_activity_allowed_groups($cmid, $userid = 0)
 {
     global $USER;
     // Warnings array, it can be empty at the end but is mandatory.
     $warnings = array();
     $params = array('cmid' => $cmid, 'userid' => $userid);
     $params = self::validate_parameters(self::get_activity_allowed_groups_parameters(), $params);
     $cmid = $params['cmid'];
     $userid = $params['userid'];
     $cm = get_coursemodule_from_id(null, $cmid, 0, false, MUST_EXIST);
     // Security checks.
     $context = context_module::instance($cm->id);
     $coursecontext = context_course::instance($cm->course);
     self::validate_context($context);
     if (empty($userid)) {
         $userid = $USER->id;
     }
     $user = core_user::get_user($userid, '*', MUST_EXIST);
     core_user::require_active_user($user);
     // Check if we have permissions for retrieve the information.
     if ($user->id != $USER->id) {
         if (!has_capability('moodle/course:managegroups', $context)) {
             throw new moodle_exception('accessdenied', 'admin');
         }
         // Validate if the user is enrolled in the course.
         $course = get_course($cm->course);
         if (!can_access_course($course, $user, '', true)) {
             // We return a warning because the function does not fail for not enrolled users.
             $warning = array();
             $warning['item'] = 'course';
             $warning['itemid'] = $cm->course;
             $warning['warningcode'] = '1';
             $warning['message'] = "User {$user->id} cannot access course {$cm->course}";
             $warnings[] = $warning;
         }
     }
     $usergroups = array();
     if (empty($warnings)) {
         $groups = groups_get_activity_allowed_groups($cm, $user->id);
         foreach ($groups as $group) {
             list($group->description, $group->descriptionformat) = external_format_text($group->description, $group->descriptionformat, $coursecontext->id, 'group', 'description', $group->id);
             $group->courseid = $cm->course;
             $usergroups[] = $group;
         }
     }
     $results = array('groups' => $usergroups, 'warnings' => $warnings);
     return $results;
 }
Ejemplo n.º 23
0
<?php

// $Id$
include '../../../../config.php';
include $CFG->dirroot . "/lib/graphlib.php";
include $CFG->dirroot . "/mod/quiz/report/reportlib.php";
$quizid = required_param('id', PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT);
$quiz = $DB->get_record('quiz', array('id' => $quizid));
$course = $DB->get_record('course', array('id' => $quiz->course));
$cm = get_coursemodule_from_instance('quiz', $quizid);
require_login($course, true, $cm);
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($groupid && ($groupmode = groups_get_activity_groupmode($cm))) {
    // Groups are being used
    $groups = groups_get_activity_allowed_groups($cm);
    if (array_key_exists($groupid, $groups)) {
        $group = $groups[$groupid];
        if (!($groupusers = get_users_by_capability($modcontext, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '', $group->id, '', false))) {
            print_error('nostudentsingroup');
        } else {
            $groupusers = array_keys($groupusers);
        }
    } else {
        print_error('errorinvalidgroup', 'group', null, $groupid);
    }
} else {
    $groups = false;
    $group = false;
    $groupusers = array();
}
Ejemplo n.º 24
0
 /**
  * Is the current user allowed to review this attempt. This applies when
  * {@link is_own_attempt()} returns false.
  * @return bool whether the review should be allowed.
  */
 public function is_review_allowed()
 {
     if (!$this->has_capability('mod/quiz:viewreports')) {
         return false;
     }
     $cm = $this->get_cm();
     if ($this->has_capability('moodle/site:accessallgroups') || groups_get_activity_groupmode($cm) != SEPARATEGROUPS) {
         return true;
     }
     // Check the users have at least one group in common.
     $teachersgroups = groups_get_activity_allowed_groups($cm);
     $studentsgroups = groups_get_all_groups($cm->course, $this->attempt->userid, $cm->groupingid);
     return $teachersgroups && $studentsgroups && array_intersect(array_keys($teachersgroups), array_keys($studentsgroups));
 }
Ejemplo n.º 25
0
 /**
  * Returns IDs of the users who share group membership with the specified user.
  *
  * @param stdClass|cm_info $cm Course-module
  * @param int $userid User ID
  * @return array An array of ID of users.
  */
 public function get_shared_group_members($cm, $userid)
 {
     if (!isset($this->sharedgroupmembers[$userid])) {
         $this->sharedgroupmembers[$userid] = array();
         $groupsids = array_keys(groups_get_activity_allowed_groups($cm, $userid));
         foreach ($groupsids as $groupid) {
             $members = array_keys(groups_get_members($groupid, 'u.id'));
             $this->sharedgroupmembers[$userid] = array_merge($this->sharedgroupmembers[$userid], $members);
         }
     }
     return $this->sharedgroupmembers[$userid];
 }
Ejemplo n.º 26
0
         }
     }
     if (!empty($btnurl)) {
         echo $output->single_button($btnurl, $btntxt, 'get');
     }
     echo $output->box_end();
     print_collapsible_region_end();
 } else {
     echo "<p>Please choose a group before submitting an exercise</p>";
 }
 ///////////////////////////// end by Morteza
 if (has_capability('mod/workshopplus:viewallsubmissions', $PAGE->context)) {
     $groupmode = groups_get_activity_groupmode($workshopplus->cm);
     $groupid = groups_get_activity_group($workshopplus->cm, true);
     if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $workshopplus->context)) {
         $allowedgroups = groups_get_activity_allowed_groups($workshopplus->cm);
         if (empty($allowedgroups)) {
             echo $output->container(get_string('groupnoallowed', 'mod_workshopplus'), 'groupwidget error');
             break;
         }
         if (!in_array($groupid, array_keys($allowedgroups))) {
             echo $output->container(get_string('groupnotamember', 'core_group'), 'groupwidget error');
             break;
         }
     }
     $countsubmissions = $workshopplus->count_submissions('all', $groupid);
     $perpage = get_user_preferences('workshopplus_perpage', 10);
     $pagingbar = new paging_bar($countsubmissions, $page, $perpage, $PAGE->url, 'page');
     print_collapsible_region_start('', 'workshopplus-viewlet-allsubmissions', get_string('allsubmissions', 'workshopplus', $countsubmissions));
     echo $output->box_start('generalbox allsubmissions');
     echo $output->container(groups_print_activity_menu($workshopplus->cm, $PAGE->url, true), 'groupwidget');
Ejemplo n.º 27
0
/**
 * Prints detailed summary information about what a user has done,
 * for user activity reports.
 *
 * @param stdClass $course
 * @param stdClass $user
 * @param stdClass $mod
 * @param stdClass $wiki
 */
function ouwiki_user_complete($course, $user, $mod, $wiki)
{
    global $DB, $CFG, $OUTPUT, $USER, $PAGE;
    require_once "{$CFG->libdir}/gradelib.php";
    require_once "{$CFG->dirroot}/mod/ouwiki/locallib.php";
    $grades = grade_get_grades($course->id, 'mod', 'ouwiki', $wiki->id, $user->id);
    if (!empty($grades->items[0]->grades)) {
        $grade = reset($grades->items[0]->grades);
        if ($grade != '-') {
            echo $OUTPUT->container(get_string('grade') . ': ' . $grade->str_long_grade);
            if ($grade->str_feedback) {
                echo $OUTPUT->container(get_string('feedback') . ': ' . $grade->str_feedback);
            }
        }
    }
    $usergroups = array();
    if ($wiki->subwikis == 1) {
        $wikigroups = groups_get_activity_allowed_groups($mod);
        foreach ($wikigroups as $mygroup) {
            if (groups_is_member($mygroup->id, $user->id)) {
                $usergroups[] = $mygroup;
            }
        }
    }
    $context = context_module::instance($mod->id);
    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
    $ouwikioutput = $PAGE->get_renderer('mod_ouwiki');
    echo '<div class="ouwiki_user_complete_report">';
    if (empty($usergroups)) {
        $subwiki = ouwiki_get_subwiki($course, $wiki, $mod, $context, 0, $user->id, true);
        $canview = ouwiki_can_view_participation($course, $wiki, $subwiki, $mod, $USER->id);
        list($newuser, $changes) = ouwiki_get_user_participation($user->id, $subwiki);
        echo $ouwikioutput->ouwiki_render_user_participation($user, $changes, $mod, $course, $wiki, $subwiki, '', 0, '', $canview, $context, $fullname, false, '');
    } else {
        foreach ($usergroups as $group) {
            $subwiki = ouwiki_get_subwiki($course, $wiki, $mod, $context, $group->id, $user->id, true);
            $canview = ouwiki_can_view_participation($course, $wiki, $subwiki, $mod, $USER->id);
            list($newuser, $changes) = ouwiki_get_user_participation($user->id, $subwiki);
            echo $OUTPUT->heading(get_string('group') . ': ' . $group->name, 5);
            echo $ouwikioutput->ouwiki_render_user_participation($user, $changes, $mod, $course, $wiki, $subwiki, '', $group->id, '', $canview, $context, $fullname, false, $group->name);
        }
    }
    echo '</div>';
}
Ejemplo n.º 28
0
function get_allowed_groupids($targetforum, $aag)
{
    global $USER;
    // We don't actually have a target group, get the list of allowed
    // groups and see if there is only one option - if so we will use it.
    // Work out list of allowed groups for current user.
    $cm = $targetforum->get_course_module();
    $groups = array();
    // Need to get groups allowed for that activity - if any at all.
    $groups = groups_get_activity_allowed_groups($cm, $USER->id);
    $options = array();
    if ($groups) {
        foreach ($groups as $group) {
            $options[$group->id] = $group->id;
        }
    } else {
        if ($aag) {
            $options[0] = 0;
        }
    }
    return $options;
}
Ejemplo n.º 29
0
$userassessment = $workshop->get_assessment_of_submission_by_user($submission->id, $USER->id);
$isreviewer = !empty($userassessment);
$editable = ($cansubmit and $ownsubmission);
$ispublished = ($workshop->phase == workshop::PHASE_CLOSED and $submission->published == 1 and has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context));
if (empty($submission->id) and !$workshop->creating_submission_allowed($USER->id)) {
    $editable = false;
}
if ($submission->id and !$workshop->modifying_submission_allowed($USER->id)) {
    $editable = false;
}
if ($canviewall) {
    // check this flag against the group membership yet
    if (groups_get_activity_groupmode($workshop->cm) == SEPARATEGROUPS) {
        // user must have accessallgroups or share at least one group with the submission author
        if (!has_capability('moodle/site:accessallgroups', $workshop->context)) {
            $usersgroups = groups_get_activity_allowed_groups($workshop->cm);
            $authorsgroups = groups_get_all_groups($workshop->course->id, $submission->authorid, $workshop->cm->groupingid, 'g.id');
            $sharedgroups = array_intersect_key($usersgroups, $authorsgroups);
            if (empty($sharedgroups)) {
                $canviewall = false;
            }
        }
    }
}
if ($editable and $workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION and !has_capability('mod/workshop:manageexamples', $workshop->context)) {
    // check that all required examples have been assessed by the user
    $examples = $workshop->get_examples_for_reviewer($USER->id);
    foreach ($examples as $exampleid => $example) {
        if (is_null($example->grade)) {
            $editable = false;
            break;
    //No groups mode
    $bbbsession['meetingid'] = $bbbsession['bigbluebuttonbn']->meetingid . '-' . $bbbsession['course']->id . '-' . $bbbsession['bigbluebuttonbn']->id;
    $bbbsession['meetingname'] = $bbbsession['bigbluebuttonbn']->name;
} else {
    // Separate or visible groups mode
    echo $OUTPUT->box_start('generalbox boxaligncenter');
    echo '<br><div class="alert alert-warning">' . get_string('view_groups_selection_warning', 'bigbluebuttonbn') . '</div>';
    echo $OUTPUT->box_end();
    $bbbsession['group'] = groups_get_activity_group($bbbsession['cm'], true);
    if ($groupmode == SEPARATEGROUPS) {
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/bigbluebuttonbn/view.php?id=' . $bbbsession['cm']->id, false, true);
        if ($bbbsession['group'] == 0) {
            if ($bbbsession['administrator']) {
                $my_groups = groups_get_all_groups($bbbsession['course']->id);
            } else {
                $my_groups = groups_get_activity_allowed_groups($bbbsession['cm']);
            }
            $current_group = current($my_groups);
            $bbbsession['group'] = $current_group->id;
        }
    } else {
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/bigbluebuttonbn/view.php?id=' . $bbbsession['cm']->id);
    }
    $bbbsession['meetingid'] = $bbbsession['bigbluebuttonbn']->meetingid . '-' . $bbbsession['course']->id . '-' . $bbbsession['bigbluebuttonbn']->id . '[' . $bbbsession['group'] . ']';
    if ($bbbsession['group'] > 0) {
        $group_name = groups_get_group_name($bbbsession['group']);
    } else {
        $group_name = get_string('allparticipants');
    }
    $bbbsession['meetingname'] = $bbbsession['bigbluebuttonbn']->name . ' (' . $group_name . ')';
}