本文整理汇总了PHP中message_search_users函数的典型用法代码示例。如果您正苦于以下问题:PHP message_search_users函数的具体用法?PHP message_search_users怎么用?PHP message_search_users使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了message_search_users函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search_contacts
/**
* Search contacts.
*
* @param string $searchtext query string.
* @param bool $onlymycourses limit the search to the user's courses only.
* @return external_description
* @since Moodle 2.5
*/
public static function search_contacts($searchtext, $onlymycourses = false)
{
global $CFG, $USER, $PAGE;
require_once $CFG->dirroot . '/user/lib.php';
// Check if messaging is enabled.
if (!$CFG->messaging) {
throw new moodle_exception('disabled', 'message');
}
require_once $CFG->libdir . '/enrollib.php';
$params = array('searchtext' => $searchtext, 'onlymycourses' => $onlymycourses);
$params = self::validate_parameters(self::search_contacts_parameters(), $params);
// Extra validation, we do not allow empty queries.
if ($params['searchtext'] === '') {
throw new moodle_exception('querystringcannotbeempty');
}
$courseids = array();
if ($params['onlymycourses']) {
$mycourses = enrol_get_my_courses(array('id'));
foreach ($mycourses as $mycourse) {
$courseids[] = $mycourse->id;
}
} else {
$courseids[] = SITEID;
}
// Retrieving the users matching the query.
$users = message_search_users($courseids, $params['searchtext']);
$results = array();
foreach ($users as $user) {
$results[$user->id] = $user;
}
// Reorganising information.
foreach ($results as &$user) {
$newuser = array('id' => $user->id, 'fullname' => fullname($user));
// Avoid undefined property notice as phone not specified.
$user->phone1 = null;
$user->phone2 = null;
$userpicture = new user_picture($user);
$userpicture->size = 1;
// Size f1.
$newuser['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);
$userpicture->size = 0;
// Size f2.
$newuser['profileimageurlsmall'] = $userpicture->get_url($PAGE)->out(false);
$user = $newuser;
}
return $results;
}
示例2: message_print_search_results
/**
* Print the results of a message search
* @param mixed $frm submitted form data
* @param bool $showicontext show text next to action icons?
* @param object $user1 the current user
*/
function message_print_search_results($frm, $showicontext=false, $user1=null) {
global $USER, $DB, $OUTPUT;
if (empty($user1)) {
$user1 = $USER;
}
echo html_writer::start_tag('div', array('class' => 'mdl-left'));
$personsearch = false;
$personsearchstring = null;
if (!empty($frm->personsubmit) and !empty($frm->name)) {
$personsearch = true;
$personsearchstring = $frm->name;
} else if (!empty($frm->combinedsubmit) and !empty($frm->combinedsearch)) {
$personsearch = true;
$personsearchstring = $frm->combinedsearch;
}
/// search for person
if ($personsearch) {
if (optional_param('mycourses', 0, PARAM_BOOL)) {
$users = array();
$mycourses = enrol_get_my_courses();
foreach ($mycourses as $mycourse) {
if (is_array($susers = message_search_users($mycourse->id, $personsearchstring))) {
foreach ($susers as $suser) $users[$suser->id] = $suser;
}
}
} else {
$users = message_search_users(SITEID, $personsearchstring);
}
if (!empty($users)) {
echo html_writer::start_tag('p', array('class' => 'heading searchresultcount'));
echo get_string('userssearchresults', 'message', count($users));
echo html_writer::end_tag('p');
echo html_writer::start_tag('table', array('class' => 'messagesearchresults'));
foreach ($users as $user) {
if ( $user->contactlistid ) {
if ($user->blocked == 0) { /// not blocked
$strcontact = message_contact_link($user->id, 'remove', true, null, $showicontext);
$strblock = message_contact_link($user->id, 'block', true, null, $showicontext);
} else { // blocked
$strcontact = message_contact_link($user->id, 'add', true, null, $showicontext);
$strblock = message_contact_link($user->id, 'unblock', true, null, $showicontext);
}
} else {
$strcontact = message_contact_link($user->id, 'add', true, null, $showicontext);
$strblock = message_contact_link($user->id, 'block', true, null, $showicontext);
}
//should we show just the icon or icon and text?
$histicontext = 'icon';
if ($showicontext) {
$histicontext = 'both';
}
$strhistory = message_history_link($USER->id, $user->id, true, '', '', $histicontext);
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('class' => 'pix'));
echo $OUTPUT->user_picture($user, array('size' => 20, 'courseid' => SITEID));
echo html_writer::end_tag('td');
echo html_writer::start_tag('td',array('class' => 'contact'));
$action = null;
$link = new moodle_url("/message/index.php?id=$user->id");
echo $OUTPUT->action_link($link, fullname($user), $action, array('title' => get_string('sendmessageto', 'message', fullname($user))));
echo html_writer::end_tag('td');
echo html_writer::tag('td', $strcontact, array('class' => 'link'));
echo html_writer::tag('td', $strblock, array('class' => 'link'));
echo html_writer::tag('td', $strhistory, array('class' => 'link'));
echo html_writer::end_tag('tr');
}
echo html_writer::end_tag('table');
} else {
echo html_writer::start_tag('p', array('class' => 'heading searchresultcount'));
echo get_string('userssearchresults', 'message', 0).'<br /><br />';
echo html_writer::end_tag('p');
}
}
// search messages for keywords
$messagesearch = false;
$messagesearchstring = null;
if (!empty($frm->keywords)) {
$messagesearch = true;
$messagesearchstring = clean_text(trim($frm->keywords));
//.........这里部分代码省略.........
示例3: message_print_search_results
function message_print_search_results($frm)
{
global $USER, $CFG;
echo '<div align="center">';
/// search for person
if (!empty($frm->personsubmit) and !empty($frm->name)) {
if (optional_param('mycourses', 0, PARAM_BOOL)) {
$users = array();
$mycourses = get_my_courses($USER->id);
foreach ($mycourses as $mycourse) {
if (is_array($susers = message_search_users($mycourse->id, $frm->name))) {
foreach ($susers as $suser) {
$users[$suser->id] = $suser;
}
}
}
} else {
$users = message_search_users(SITEID, $frm->name);
}
if (!empty($users)) {
echo '<strong>' . get_string('userssearchresults', 'message', count($users)) . '</strong>';
echo '<table class="message_users">';
foreach ($users as $user) {
if ($user->contactlistid) {
if ($user->blocked == 0) {
/// not blocked
$strcontact = message_contact_link($user->id, 'remove', true);
$strblock = message_contact_link($user->id, 'block', true);
} else {
// blocked
$strcontact = message_contact_link($user->id, 'add', true);
$strblock = message_contact_link($user->id, 'unblock', true);
}
} else {
$strcontact = message_contact_link($user->id, 'add', true);
$strblock = message_contact_link($user->id, 'block', true);
}
$strhistory = message_history_link($user->id, 0, true, '', '', 'icon');
echo '<tr><td class="pix">';
print_user_picture($user, SITEID, $user->picture, 20, false, true, 'userwindow');
echo '</td>';
echo '<td class="contact">';
link_to_popup_window("/message/discussion.php?id={$user->id}", "message_{$user->id}", fullname($user), 500, 500, get_string('sendmessageto', 'message', fullname($user)), 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500');
echo '</td>';
echo '<td class="link">' . $strcontact . '</td>';
echo '<td class="link">' . $strblock . '</td>';
echo '<td class="link">' . $strhistory . '</td>';
echo '</tr>';
}
echo '</table>';
} else {
notify(get_string('nosearchresults', 'message'));
}
/// search messages for keywords
} else {
if (!empty($frm->keywordssubmit) and !empty($frm->keywords)) {
$keywordstring = clean_text(trim($frm->keywords));
$keywords = explode(' ', $keywordstring);
$tome = false;
$fromme = false;
$courseid = 'none';
switch ($frm->keywordsoption) {
case 'tome':
$tome = true;
break;
case 'fromme':
$fromme = true;
break;
case 'allmine':
$tome = true;
$fromme = true;
break;
case 'allusers':
$courseid = SITEID;
break;
case 'courseusers':
$courseid = $frm->courseid;
break;
default:
$tome = true;
$fromme = true;
}
if (($messages = message_search($keywords, $fromme, $tome, $courseid)) !== false) {
/// get a list of contacts
if (($contacts = get_records('message_contacts', 'userid', $USER->id, '', 'contactid, blocked')) === false) {
$contacts = array();
}
/// print heading with number of results
echo '<p class="heading">' . get_string('keywordssearchresults', 'message', count($messages)) . ' ("' . s($keywordstring) . '")</p>';
/// print table headings
echo '<table class="searchresults" cellspacing="0">';
echo '<tr>';
echo '<td><strong>' . get_string('from') . '</strong></td>';
echo '<td><strong>' . get_string('to') . '</strong></td>';
echo '<td><strong>' . get_string('message', 'message') . '</strong></td>';
echo '<td><strong>' . get_string('timesent', 'message') . '</strong></td>';
echo "</tr>\n";
$blockedcount = 0;
$dateformat = get_string('strftimedatetimeshort');
$strcontext = get_string('context', 'message');
//.........这里部分代码省略.........
示例4: test_message_search_users
/**
* Test message_search_users.
*/
public function test_message_search_users()
{
// Set this user as the admin.
$this->setAdminUser();
// Create a user to add to the admin's contact list.
$user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'user1'));
$user2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'user2'));
// Add users to the admin's contact list.
message_add_contact($user1->id);
message_add_contact($user2->id);
// Add blocked contact.
$this->assertCount(1, message_search_users(0, 'Test1'));
$this->assertCount(2, message_search_users(0, 'Test'));
$this->assertCount(1, message_search_users(0, 'user1'));
$this->assertCount(2, message_search_users(0, 'user'));
}
示例5: search_contacts
/**
* Search contacts.
*
* @param string $searchtext query string.
* @param bool $onlymycourses limit the search to the user's courses only.
* @return external_description
* @since 2.5
*/
public static function search_contacts($searchtext, $onlymycourses = false) {
global $CFG, $USER;
require_once($CFG->libdir . '/enrollib.php');
$params = array('searchtext' => $searchtext, 'onlymycourses' => $onlymycourses);
$params = self::validate_parameters(self::search_contacts_parameters(), $params);
// Extra validation, we do not allow empty queries.
if ($params['searchtext'] === '') {
throw new moodle_exception('querystringcannotbeempty');
}
$courseids = array();
if ($params['onlymycourses']) {
$mycourses = enrol_get_my_courses(array('id'));
foreach ($mycourses as $mycourse) {
$courseids[] = $mycourse->id;
}
} else {
$courseids[] = SITEID;
}
// Retrieving the users matching the query.
$users = message_search_users($courseids, $params['searchtext']);
$results = array();
foreach ($users as $user) {
$results[$user->id] = $user;
}
// Reorganising information.
foreach ($results as &$user) {
$newuser = array(
'id' => $user->id,
'fullname' => fullname($user)
);
// Avoid undefined property notice as phone not specified.
$user->phone1 = null;
$user->phone2 = null;
// Try to get the user picture, but sometimes this method can return null.
$userdetails = user_get_user_details($user, null, array('profileimageurl', 'profileimageurlsmall'));
if (!empty($userdetails)) {
$newuser['profileimageurl'] = $userdetails['profileimageurl'];
$newuser['profileimageurlsmall'] = $userdetails['profileimageurlsmall'];
}
$user = $newuser;
}
return $results;
}