当前位置: 首页>>代码示例>>PHP>>正文


PHP message_search函数代码示例

本文整理汇总了PHP中message_search函数的典型用法代码示例。如果您正苦于以下问题:PHP message_search函数的具体用法?PHP message_search怎么用?PHP message_search使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了message_search函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_message_search

 /**
  * Test message_search.
  */
 public function test_message_search()
 {
     global $USER;
     // 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'));
     // Send few messages, real (read).
     message_post_message($user1, $USER, 'Message 1', FORMAT_PLAIN);
     message_post_message($USER, $user1, 'Message 2', FORMAT_PLAIN);
     message_post_message($USER, $user2, 'Message 3', FORMAT_PLAIN);
     $this->assertCount(2, message_search(array('Message'), true, false));
     $this->assertCount(3, message_search(array('Message'), true, true));
     // Send fake message (not-read).
     $this->send_fake_message($USER, $user1, 'Message 4');
     $this->send_fake_message($user1, $USER, 'Message 5');
     $this->assertCount(3, message_search(array('Message'), true, false));
     $this->assertCount(5, message_search(array('Message'), true, true));
     // If courseid given then should be 0.
     $this->assertEquals(false, message_search(array('Message'), true, true, ''));
     $this->assertEquals(false, message_search(array('Message'), true, true, 2));
     $this->assertCount(5, message_search(array('Message'), true, true, SITEID));
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:27,代码来源:messagelib_test.php

示例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));
//.........这里部分代码省略.........
开发者ID:nfreear,项目名称:moodle,代码行数:101,代码来源:lib.php

示例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');
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:lib.php


注:本文中的message_search函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。