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


PHP get_courses_search函数代码示例

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


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

示例1: search_courses

 public static function search_courses($options)
 {
     $params = self::validate_parameters(self::search_courses_parameters(), array('options' => $options));
     $searchquery = array();
     foreach ($params as $param) {
         $searchquery[] = $param['query'];
     }
     $results = get_courses_search($searchquery);
     $resultcourses = array();
     if ($results) {
         foreach ($results as $result) {
             $resultcourses[] = array('id' => $result->id, 'fullname' => $result->fullname, 'shortname' => $result->shortname, 'summary' => $result->summary);
         }
     }
     return $resultcourses;
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:16,代码来源:externallib.php

示例2: search_courses

 /**
  * Searches courses
  *
  * List of found course ids is cached for 10 minutes. Cache may be purged prior
  * to this when somebody edits courses or categories, however it is very
  * difficult to keep track of all possible changes that may affect list of courses.
  *
  * @param array $search contains search criterias, such as:
  *     - search - search string
  *     - blocklist - id of block (if we are searching for courses containing specific block0
  *     - modulelist - name of module (if we are searching for courses containing specific module
  *     - tagid - id of tag
  * @param array $options display options, same as in get_courses() except 'recursive' is ignored -
  *                       search is always category-independent
  * @return course_in_list[]
  */
 public static function search_courses($search, $options = array())
 {
     global $DB;
     $offset = !empty($options['offset']) ? $options['offset'] : 0;
     $limit = !empty($options['limit']) ? $options['limit'] : null;
     $sortfields = !empty($options['sort']) ? $options['sort'] : array('sortorder' => 1);
     $coursecatcache = cache::make('core', 'coursecat');
     $cachekey = 's-' . serialize($search + array('sort' => $sortfields));
     $cntcachekey = 'scnt-' . serialize($search);
     $ids = $coursecatcache->get($cachekey);
     if ($ids !== false) {
         // We already cached last search result.
         $ids = array_slice($ids, $offset, $limit);
         $courses = array();
         if (!empty($ids)) {
             list($sql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'id');
             $records = self::get_course_records("c.id " . $sql, $params, $options);
             // Preload course contacts if necessary - saves DB queries later to do it for each course separately.
             if (!empty($options['coursecontacts'])) {
                 self::preload_course_contacts($records);
             }
             // If option 'idonly' is specified no further action is needed, just return list of ids.
             if (!empty($options['idonly'])) {
                 return array_keys($records);
             }
             // Prepare the list of course_in_list objects.
             foreach ($ids as $id) {
                 $courses[$id] = new course_in_list($records[$id]);
             }
         }
         return $courses;
     }
     $preloadcoursecontacts = !empty($options['coursecontacts']);
     unset($options['coursecontacts']);
     if (!empty($search['search'])) {
         // Search courses that have specified words in their names/summaries.
         $searchterms = preg_split('|\\s+|', trim($search['search']), 0, PREG_SPLIT_NO_EMPTY);
         $searchterms = array_filter($searchterms, create_function('$v', 'return strlen($v) > 1;'));
         $courselist = get_courses_search($searchterms, 'c.sortorder ASC', 0, 9999999, $totalcount);
         self::sort_records($courselist, $sortfields);
         $coursecatcache->set($cachekey, array_keys($courselist));
         $coursecatcache->set($cntcachekey, $totalcount);
         $records = array_slice($courselist, $offset, $limit, true);
     } else {
         if (!empty($search['blocklist'])) {
             // Search courses that have block with specified id.
             $blockname = $DB->get_field('block', 'name', array('id' => $search['blocklist']));
             $where = 'ctx.id in (SELECT distinct bi.parentcontextid FROM {block_instances} bi
                 WHERE bi.blockname = :blockname)';
             $params = array('blockname' => $blockname);
         } else {
             if (!empty($search['modulelist'])) {
                 // Search courses that have module with specified name.
                 $where = "c.id IN (SELECT DISTINCT module.course " . "FROM {" . $search['modulelist'] . "} module)";
                 $params = array();
             } else {
                 if (!empty($search['tagid'])) {
                     // Search courses that are tagged with the specified tag.
                     $where = "c.id IN (SELECT t.itemid " . "FROM {tag_instance} t WHERE t.tagid = :tagid AND t.itemtype = :itemtype)";
                     $params = array('tagid' => $search['tagid'], 'itemtype' => 'course');
                 } else {
                     debugging('No criteria is specified while searching courses', DEBUG_DEVELOPER);
                     return array();
                 }
             }
         }
         $courselist = self::get_course_records($where, $params, $options, true);
         self::sort_records($courselist, $sortfields);
         $coursecatcache->set($cachekey, array_keys($courselist));
         $coursecatcache->set($cntcachekey, count($courselist));
         $records = array_slice($courselist, $offset, $limit, true);
     }
     // Preload course contacts if necessary - saves DB queries later to do it for each course separately.
     if (!empty($preloadcoursecontacts)) {
         self::preload_course_contacts($records);
     }
     // If option 'idonly' is specified no further action is needed, just return list of ids.
     if (!empty($options['idonly'])) {
         return array_keys($records);
     }
     // Prepare the list of course_in_list objects.
     $courses = array();
     foreach ($records as $record) {
         $courses[$record->id] = new course_in_list($record);
//.........这里部分代码省略.........
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:101,代码来源:coursecatlib.php

示例3: foreach

foreach ($cat_courses as $ccourse) {
    if ($ccourse->id != $course->id && $ccourse->id != SITEID) {
        $options[$ccourse->id] = format_string($ccourse->fullname);
    }
}
$cat = get_record("course_categories", "id", $course->category);
if (count($options) > 0) {
    $mform_post = new course_import_activities_form_1($CFG->wwwroot . '/course/import/activities/index.php', array('options' => $options, 'courseid' => $course->id, 'text' => get_string('coursescategory')));
    $mform_post->display();
}
if (!empty($creator)) {
    $mform_post = new course_import_activities_form_2($CFG->wwwroot . '/course/import/activities/index.php', array('courseid' => $course->id));
    $mform_post->display();
}
if (!empty($fromcoursesearch) && !empty($creator)) {
    $totalcount = 0;
    $courses = get_courses_search(explode(" ", $fromcoursesearch), "fullname ASC", $page, 50, $totalcount);
    if (is_array($courses) and count($courses) > 0) {
        $table->data[] = array('<b>' . get_string('searchresults') . '</b>', '', '');
        foreach ($courses as $scourse) {
            if ($course->id != $scourse->id) {
                $table->data[] = array('', format_string($scourse->fullname), '<a href="' . $CFG->wwwroot . '/course/import/activities/index.php?id=' . $course->id . '&amp;fromcourse=' . $scourse->id . '">' . get_string('usethiscourse') . '</a>');
            }
        }
    } else {
        $table->data[] = array('', get_string('noresults'), '');
    }
}
if (!empty($table)) {
    print_table($table);
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:31,代码来源:mod.php

示例4: foreach

    if (!empty($courselist)) {
        $firstcourse = $page * $perpage;
        $lastcourse = $page * $perpage + $perpage - 1;
        $i = 0;
        foreach ($courselist as $course) {
            if ($i >= $firstcourse && $i <= $lastcourse) {
                $courses[$course->id] = $course;
            }
            $i++;
        }
    }
    $totalcount = count($courselist);
} else {
    if (!empty($searchterm)) {
        // Donot do search for empty search request.
        $courses = get_courses_search($searchterms, "fullname ASC", $page, $perpage, $totalcount);
    }
}
$searchform = '';
// Turn editing should be visible if user have system or category level capability
if (!empty($courses) && (can_edit_in_category() || !empty($usercatlist))) {
    if ($PAGE->user_is_editing()) {
        $string = new lang_string("turneditingoff");
        $edit = "off";
    } else {
        $string = new lang_string("turneditingon");
        $edit = "on";
    }
    $params = array_merge($urlparams, array('sesskey' => sesskey(), 'edit' => $edit));
    $aurl = new moodle_url("{$CFG->wwwroot}/course/search.php", $params);
    $searchform = $OUTPUT->single_button($aurl, $string, 'get');
开发者ID:vinoth4891,项目名称:clinique,代码行数:31,代码来源:search.php

示例5: search_courses

    /**
     * Searches courses
     *
     * List of found course ids is cached for 10 minutes. Cache may be purged prior
     * to this when somebody edits courses or categories, however it is very
     * difficult to keep track of all possible changes that may affect list of courses.
     *
     * @param array $search contains search criterias, such as:
     *     - search - search string
     *     - blocklist - id of block (if we are searching for courses containing specific block0
     *     - modulelist - name of module (if we are searching for courses containing specific module
     *     - tagid - id of tag
     * @param array $options display options, same as in get_courses() except 'recursive' is ignored -
     *                       search is always category-independent
     * @param array $requiredcapabilites List of capabilities required to see return course.
     * @return course_in_list[]
     */
    public static function search_courses($search, $options = array(), $requiredcapabilities = array()) {
        global $DB;
        $offset = !empty($options['offset']) ? $options['offset'] : 0;
        $limit = !empty($options['limit']) ? $options['limit'] : null;
        $sortfields = !empty($options['sort']) ? $options['sort'] : array('sortorder' => 1);

        $coursecatcache = cache::make('core', 'coursecat');
        $cachekey = 's-'. serialize(
            $search + array('sort' => $sortfields) + array('requiredcapabilities' => $requiredcapabilities)
        );
        $cntcachekey = 'scnt-'. serialize($search);

        $ids = $coursecatcache->get($cachekey);
        if ($ids !== false) {
            // We already cached last search result.
            $ids = array_slice($ids, $offset, $limit);
            $courses = array();
            if (!empty($ids)) {
                list($sql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'id');
                $records = self::get_course_records("c.id ". $sql, $params, $options);
                // Preload course contacts if necessary - saves DB queries later to do it for each course separately.
                if (!empty($options['coursecontacts'])) {
                    self::preload_course_contacts($records);
                }
                // If option 'idonly' is specified no further action is needed, just return list of ids.
                if (!empty($options['idonly'])) {
                    return array_keys($records);
                }
                // Prepare the list of course_in_list objects.
                foreach ($ids as $id) {
                    $courses[$id] = new course_in_list($records[$id]);
                }
            }
            return $courses;
        }

        $preloadcoursecontacts = !empty($options['coursecontacts']);
        unset($options['coursecontacts']);

        // Empty search string will return all results.
        if (!isset($search['search'])) {
            $search['search'] = '';
        }

        if (empty($search['blocklist']) && empty($search['modulelist']) && empty($search['tagid'])) {
            // Search courses that have specified words in their names/summaries.
            $searchterms = preg_split('|\s+|', trim($search['search']), 0, PREG_SPLIT_NO_EMPTY);

            $courselist = get_courses_search($searchterms, 'c.sortorder ASC', 0, 9999999, $totalcount, $requiredcapabilities);
            self::sort_records($courselist, $sortfields);
            $coursecatcache->set($cachekey, array_keys($courselist));
            $coursecatcache->set($cntcachekey, $totalcount);
            $records = array_slice($courselist, $offset, $limit, true);
        } else {
            if (!empty($search['blocklist'])) {
                // Search courses that have block with specified id.
                $blockname = $DB->get_field('block', 'name', array('id' => $search['blocklist']));
                $where = 'ctx.id in (SELECT distinct bi.parentcontextid FROM {block_instances} bi
                    WHERE bi.blockname = :blockname)';
                $params = array('blockname' => $blockname);
            } else if (!empty($search['modulelist'])) {
                // Search courses that have module with specified name.
                $where = "c.id IN (SELECT DISTINCT module.course ".
                        "FROM {".$search['modulelist']."} module)";
                $params = array();
            } else if (!empty($search['tagid'])) {
                // Search courses that are tagged with the specified tag.
                $where = "c.id IN (SELECT t.itemid ".
                        "FROM {tag_instance} t WHERE t.tagid = :tagid AND t.itemtype = :itemtype AND t.component = :component)";
                $params = array('tagid' => $search['tagid'], 'itemtype' => 'course', 'component' => 'core');
                if (!empty($search['ctx'])) {
                    $rec = isset($search['rec']) ? $search['rec'] : true;
                    $parentcontext = context::instance_by_id($search['ctx']);
                    if ($parentcontext->contextlevel == CONTEXT_SYSTEM && $rec) {
                        // Parent context is system context and recursive is set to yes.
                        // Nothing to filter - all courses fall into this condition.
                    } else if ($rec) {
                        // Filter all courses in the parent context at any level.
                        $where .= ' AND ctx.path LIKE :contextpath';
                        $params['contextpath'] = $parentcontext->path . '%';
                    } else if ($parentcontext->contextlevel == CONTEXT_COURSECAT) {
                        // All courses in the given course category.
                        $where .= ' AND c.category = :category';
//.........这里部分代码省略.........
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:101,代码来源:coursecatlib.php

示例6: message_print_byrole

/**
 * hook for the messagebyroletab.
 * not correctly namespaced because of limitations in messaging.
 *
 * unfortunately we don't seem to be able to pass
 * parameters from the request here...
*/
function message_print_byrole()
{
    global $CFG, $USER;
    require_once $CFG->dirroot . '/local/lib/messagelib.php';
    $target = optional_param('target', 0, PARAM_INT);
    $course = optional_param('lp', 0, PARAM_INT);
    $page = optional_param('page', 0, PARAM_INT);
    $perpage = optional_param('perpage', 10, PARAM_INT);
    $sitecontext = get_context_instance(CONTEXT_COURSE, SITEID);
    $cansearch = has_capability('moodle/local:cansearchforlptomessage', $sitecontext);
    $searchform = null;
    $messageform = null;
    $courses = array();
    $totalcount = 0;
    if (!empty($course) || !empty($target)) {
        $c = get_record('course', 'id', $course);
        $targetobject = (object) tao_message_target_get($target, $c);
        if ($count = tao_message_count_recipients_by_target($targetobject, $c)) {
            $targetobject->key = $target;
            require_capability('moodle/local:' . $targetobject->capability, get_context_instance(CONTEXT_COURSE, $c->id));
            // give the message send form
            require_once $CFG->dirroot . '/local/forms.php';
            $messageform = new tao_message_send_form('', array('course' => $c, 'target' => $targetobject));
            if ($data = $messageform->get_data()) {
                // send message
                $eventdata = array('body' => $data->body, 'from' => $USER->id, 'format' => $data->format, 'course' => $c, 'target' => $targetobject);
                events_trigger('tao_message_role', $eventdata);
                echo get_string('messagequeued', 'local');
                print_continue($CFG->wwwroot . '/message/index.php?tab=byrole');
                return;
            } else {
                if (!$messageform->is_cancelled()) {
                    $messageform->display();
                    return;
                }
            }
        } else {
            notify(get_string('messagenorecipients', 'local'));
        }
    }
    if ($cansearch) {
        // set up the search form object and process any search requests
        require_capability('moodle/local:cansearchforlptomessage', $sitecontext);
        require_once $CFG->dirroot . '/local/forms.php';
        $searchform = new tao_message_lpsearch_form('', array(), 'get');
        if ($data = $searchform->get_data()) {
            $search = trim(strip_tags($data->search));
            // trim & clean raw searched string
            if ($search) {
                $searchterms = explode(" ", $search);
                // Search for words independently
                foreach ($searchterms as $key => $searchterm) {
                    if (strlen($searchterm) < 1) {
                        unset($searchterms[$key]);
                    }
                }
                $search = trim(implode(" ", $searchterms));
            }
            if (count($searchterms) > 0) {
                $courses = get_courses_search($searchterms, "fullname ASC", $page, $perpage, $totalcount);
            }
            if (empty($courses)) {
                $nosearchresults = true;
            }
        }
    }
    // print the main part of the page
    $targets = (object) tao_message_targets();
    // SITE wide message groups first
    $sitecontent = '';
    foreach ($targets->site as $key => $target) {
        $target = (object) $target;
        $target->key = $key;
        $sitecontent .= tao_print_target($target);
    }
    $lpcontent = '';
    if (empty($courses)) {
        // if we haven't come from a search, get all courses they have a direct relationship with
        if (has_capability('moodle/local:hasdirectlprelationship', $sitecontext)) {
            // Non-cached - get accessinfo
            if (isset($USER->access)) {
                $accessinfo = $USER->access;
            } else {
                $accessinfo = get_user_access_sitewide($USER->id);
            }
            $courses = get_user_courses_bycap($USER->id, 'moodle/local:hasdirectlprelationship', $accessinfo, false, 'c.fullname', array('fullname'));
        }
    }
    if ($courses) {
        // either from a search, or from the 'direct' relationships
        foreach ($courses as $course) {
            // print the targets for each course
            $coursecontent = '';
//.........这里部分代码省略.........
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:101,代码来源:lib.php

示例7: array

        } else {
            if ($showall and confirm_sesskey()) {
                $searchtext = '';
                $previoussearch = 0;
            }
        }
    }
}
/// Get all existing students and teachers for this course.
if (!($alreadycourses = get_courses_in_metacourse($course->id))) {
    $alreadycourses = array();
}
$numcourses = 0;
/// Get search results excluding any users already in this course
if ($searchtext != '' and $previoussearch and confirm_sesskey()) {
    if ($searchcourses = get_courses_search(explode(" ", $searchtext), 'fullname ASC', 0, 99999, $numcourses)) {
        foreach ($searchcourses as $tmp) {
            if (array_key_exists($tmp->id, $alreadycourses)) {
                unset($searchcourses[$tmp->id]);
            }
            if (!empty($tmp->metacourse)) {
                unset($searchcourses[$tmp->id]);
            }
        }
        if (array_key_exists($course->id, $searchcourses)) {
            unset($searchcourses[$course->id]);
        }
        $numcourses = count($searchcourses);
    }
}
/// If no search results then get potential students for this course excluding users already in course
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:importstudents.php

示例8: enrol_get_my_courses

$my_courses_flag = 0;
$total = 0;
$courses['query'] = $query;
$course_count = 10;
// Default value for course result list
if (!empty($_GET['course_count'])) {
    $course_count = $_GET['course_count'];
}
if ($_GET['my_courses_flag'] == "true") {
    $my_courses_flag = $_GET['my_courses_flag'];
    $courses['results'] = enrol_get_my_courses(array('id', 'shortname'), 'visible DESC,sortorder ASC', $course_count);
    //Once you have the results, filter the ones matching the search query
    $mycourses = array();
    foreach ($courses['results'] as $objCourse) {
        if (preg_match('/' . $query . '/i', $objCourse->fullname) != 0) {
            $mycourses[] = $objCourse;
        }
    }
    $courses['results'] = array_values($mycourses);
    echo json_encode($courses);
} else {
    $courses['results'] = array_values(get_courses_search(array($query), 'fullname ASC', 0, $course_count, $total));
    if (empty($courses['results'])) {
        $objCourse = new stdClass();
        $objCourse->id = 'na';
        $courses['results'] = array_values(array($objCourse));
        echo json_encode($courses);
    } else {
        echo json_encode($courses);
    }
}
开发者ID:nadavkav,项目名称:moodle-block_searchcourses,代码行数:31,代码来源:result.php


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