123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- *
- * @package chamilo.include.search
- */
- include_once __DIR__.'/../../../global.inc.php';
- require_once __DIR__.'/search_processor.class.php';
- /**
- * Process links before pass it to search listing scripts
- * @package chamilo.include.search
- */
- class link_processor extends search_processor
- {
- public $links = array();
- public function __construct($rows)
- {
- $this->rows = $rows;
- // group all links together
- foreach ($rows as $row_id => $row_val) {
- $link_id = $row_val['xapian_data'][SE_DATA]['link_id'];
- $courseid = $row_val['courseid'];
- $item = array(
- 'courseid' => $courseid,
- 'score' => $row_val['score'],
- 'link_id' => $link_id,
- 'row_id' => $row_id,
- );
- $this->links[$courseid]['links'][] = $item;
- $this->links[$courseid]['total_score'] += $row_val['score'];
- }
- }
- public function process()
- {
- $results = array();
- foreach ($this->links as $courseCode => $one_course_links) {
- $course_info = api_get_course_info($courseCode);
- $search_show_unlinked_results = (api_get_setting('search_show_unlinked_results') == 'true');
- $course_visible_for_user = api_is_course_visible_for_user(NULL, $courseCode);
- // can view course?
- if ($course_visible_for_user || $search_show_unlinked_results) {
- $result = NULL;
- foreach ($one_course_links['links'] as $one_link) {
- // is visible?
- $visibility = api_get_item_visibility($course_info, TOOL_LINK, $one_link['link_id']);
- if ($visibility) {
- // if one is visible let show the result for a course
- // also asume all data of this item like the data of the whole group of links(Ex. author)
- list($thumbnail, $image, $name, $author, $url) = $this->get_information($courseCode, $one_link['link_id']);
- $result_tmp = array(
- 'toolid' => TOOL_LINK,
- 'score' => $one_course_links['total_score'] / (count($one_course_links) - 1), // not count total_score array item
- 'url' => $url,
- 'thumbnail' => $thumbnail,
- 'image' => $image,
- 'title' => $name,
- 'author' => $author,
- );
- if ($course_visible_for_user) {
- $result = $result_tmp;
- } else { // course not visible for user
- if ($search_show_unlinked_results) {
- $result_tmp['url'] = '';
- $result = $result_tmp;
- }
- }
- break;
- }
- }
- if (!is_null($result)) {
- // if there is at least one link item found show link to course Links tool page
- $results[] = $result;
- }
- }
- }
- // get information to sort
- foreach ($results as $key => $row) {
- $score[$key] = $row['score'];
- }
- // Sort results with score descending
- array_multisort($score, SORT_DESC, $results);
- return $results;
- }
- /**
- * Get document information
- */
- private function get_information($course_id, $link_id)
- {
- $course_information = api_get_course_info($course_id);
- $course_id = $course_information['real_id'];
- $course_id_alpha = $course_information['id'];
- if (!empty($course_information)) {
- $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $link_id = intval($link_id);
- $sql = "SELECT insert_user_id FROM $item_property_table
- WHERE ref = $link_id AND tool = '".TOOL_LINK."' AND c_id = $course_id
- LIMIT 1";
- $name = get_lang('Links');
- $url = api_get_path(WEB_PATH).'main/link/link.php?cidReq=%s';
- $url = sprintf($url, $course_id_alpha);
- // Get the image path
- $thumbnail = Display::returnIconPath('link.png');
- $image = $thumbnail; //FIXME: use big images
- // get author
- $author = '';
- $item_result = Database::query($sql);
- if ($row = Database::fetch_array($item_result)) {
- $user_data = api_get_user_info($row['insert_user_id']);
- $author = api_get_person_name($user_data['firstName'], $user_data['lastName']);
- }
- return array($thumbnail, $image, $name, $author, $url);
- } else {
- return array();
- }
- }
- }
|