コード例 #1
0
/**
 * Search through course users
 *
 * If $coursid specifies the site course then this function searches
 * through all undeleted and confirmed users
 * @param int $courseid The course in question.
 * @param string $searchtext the text to search for
 * @param string $sort the column name to order by
 * @param string $exceptions comma separated list of user IDs to exclude
 * @return array  An array of {@link $USER} records.
 */
function message_search_users($courseid, $searchtext, $sort = '', $exceptions = '')
{
    global $CFG, $USER, $DB;
    $fullname = $DB->sql_fullname();
    if (!empty($exceptions)) {
        $except = ' AND u.id NOT IN (' . $exceptions . ') ';
    } else {
        $except = '';
    }
    if (!empty($sort)) {
        $order = ' ORDER BY ' . $sort;
    } else {
        $order = '';
    }
    $ufields = user_picture::fields('u');
    if (!$courseid or $courseid == SITEID) {
        $params = array($USER->id, "%{$searchtext}%");
        $users = $DB->get_records_sql("SELECT {$ufields}, mc.id as contactlistid, mc.blocked\n                                       FROM {user} u\n                                       LEFT JOIN {message_contacts} mc\n                                            ON mc.contactid = u.id AND mc.userid = ?\n                                      WHERE u.deleted = '0' AND u.confirmed = '1'\n                                            AND (" . $DB->sql_like($fullname, '?', false) . ")\n                                            {$except}\n                                     {$order}", $params);
    } else {
        //TODO: add enabled enrolment join here (skodak)
        $context = get_context_instance(CONTEXT_COURSE, $courseid);
        $contextlists = get_related_contexts_string($context);
        // everyone who has a role assignment in this course or higher
        $params = array($USER->id, "%{$searchtext}%");
        $users = $DB->get_records_sql("SELECT {$ufields}, mc.id as contactlistid, mc.blocked\n                                         FROM {user} u\n                                         JOIN {role_assignments} ra ON ra.userid = u.id\n                                         LEFT JOIN {message_contacts} mc\n                                              ON mc.contactid = u.id AND mc.userid = ?\n                                        WHERE u.deleted = '0' AND u.confirmed = '1'\n                                              AND ra.contextid {$contextlists}\n                                              AND (" . $DB->sql_like($fullname, '?', false) . ")\n                                              {$except}\n                                       {$order}", $params);
    }
    foreach ($users as $user) {
        if (isguestusercorrect($user)) {
            $key = array_search($user, $users, TRUE);
            unset($users[$key]);
        }
    }
    return $users;
}
コード例 #2
0
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * A page displaying the user's contacts and messages
 *
 * @package   moodlecore
 * @copyright 2010 Andrew Davis
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../config.php';
require_once 'lib.php';
require_once 'send_form.php';
require_login(0, false);
if (isguestusercorrect()) {
    redirect($CFG->wwwroot);
}
if (empty($CFG->messaging)) {
    print_error('disabled', 'message');
}
//'viewing' is the preferred URL parameter but we'll still accept usergroup in case its referenced externally
$usergroup = optional_param('usergroup', MESSAGE_VIEW_UNREAD_MESSAGES, PARAM_ALPHANUMEXT);
$viewing = optional_param('viewing', $usergroup, PARAM_ALPHANUMEXT);
$history = optional_param('history', MESSAGE_HISTORY_SHORT, PARAM_INT);
$search = optional_param('search', '', PARAM_CLEAN);
//TODO: use PARAM_RAW, but make sure we use s() and p() properly
//the same param as 1.9 and the param we have been logging. Use this parameter.
$user1id = optional_param('user1', $USER->id, PARAM_INT);
//2.0 shipped using this param. Retaining it only for compatibility. It should be removed.
$user1id = optional_param('user', $user1id, PARAM_INT);