function dialogue_get_available_users($dialogue, $context, $editconversationid)
{
    static $displaystudentindication = false;
    // display Student indication in multi select lstbox ?
    if (!($course = get_record("course", "id", $dialogue->course))) {
        error("Course is misconfigured");
    }
    $hascapopen = has_capability('mod/dialogue:participate', $context);
    $hascapmanage = has_capability('mod/dialogue:manage', $context);
    switch ($dialogue->dialoguetype) {
        case DIALOGUETYPE_TEACHERSTUDENT:
            // teacher to student
            if ($hascapmanage) {
                return dialogue_get_available_students($dialogue, $context, $editconversationid);
            } else {
                return dialogue_get_available_teachers($dialogue, $context, $editconversationid);
            }
        case DIALOGUETYPE_STUDENTSTUDENT:
            // student to student
            if (!$hascapmanage && $hascapopen) {
                return dialogue_get_available_students($dialogue, $context, $editconversationid);
            } else {
                return;
            }
        case DIALOGUETYPE_EVERYONE:
            // everyone
            if ($teachers = dialogue_get_available_teachers($dialogue, $context, $editconversationid)) {
                foreach ($teachers as $userid => $name) {
                    $names[$userid] = $name;
                    // ." (".get_string('teacher','dialogue') . ")";
                }
                $names[-1] = "-------------";
            }
            if ($students = dialogue_get_available_students($dialogue, $context, $editconversationid)) {
                foreach ($students as $userid => $name) {
                    //$names[$userid] = (is_numeric($userid) && $displaystudentindication) ? $name." (".get_string('student','dialogue') . ")" : $name;
                    $names[$userid] = $name;
                }
            }
            if (isset($names)) {
                return $names;
            }
            return;
    }
}
Exemplo n.º 2
0
/**
 * Return a list of users that the current user is able to open a dialogue with
 * 
 * Makes calls to dialogue_get_available_students() and dialogue_get_available_teachers()
 * depending on the capability and type of dialogue
 * @param   object  $dialogue
 * @param   object  $context    for a user in this activity
 * @param   int     $editconversationid
 * @return  array   usernames and ids
 */
function dialogue_get_available_users($dialogue, $context, $editconversationid)
{
    if (!($course = get_record('course', 'id', $dialogue->course))) {
        error('Course is misconfigured');
    }
    $hascapopen = has_capability('mod/dialogue:participate', $context);
    $hascapmanage = has_capability('mod/dialogue:manage', $context);
    switch ($dialogue->dialoguetype) {
        case DIALOGUETYPE_TEACHERSTUDENT:
            // teacher to student
            if ($hascapmanage) {
                return dialogue_get_available_students($dialogue, $context, $editconversationid);
            } else {
                return dialogue_get_available_teachers($dialogue, $context, $editconversationid);
            }
        case DIALOGUETYPE_STUDENTSTUDENT:
            // student to student
            if (!$hascapmanage && $hascapopen) {
                return dialogue_get_available_students($dialogue, $context, $editconversationid);
            } else {
                return;
                // dont return any students if this is a teacher, ie has manage capability
            }
        case DIALOGUETYPE_EVERYONE:
            // everyone
            if ($teachers = dialogue_get_available_teachers($dialogue, $context, $editconversationid)) {
                foreach ($teachers as $userid => $name) {
                    $names[$userid] = $name;
                }
                $names[-1] = '-------------';
            }
            if ($students = dialogue_get_available_students($dialogue, $context, $editconversationid)) {
                foreach ($students as $userid => $name) {
                    $names[$userid] = $name;
                }
            }
            if (isset($names)) {
                return $names;
            }
            return;
    }
}