Fix and remove E_NOTICE when search_enabled is true - refs BT#10979

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 15d1cb9dda
commit bdb5a042a5
  1. 5
      main/inc/lib/search/search_widget.js
  2. 2
      main/inc/lib/search/search_widget.php
  3. 41
      main/inc/lib/search/tool_processors/quiz_processor.class.php
  4. 4
      main/newscorm/lp_list_search.php
  5. 25
      main/search/search_suggestions.php

@ -8,12 +8,13 @@ $(document).ready(function() {
$('#tags-clean').click(function() { $('#tags-clean').click(function() {
// clear multiple select // clear multiple select
$('select option:selected').each(function () { $('select option:selected').each(function () {
$(this).attr('selected', ''); $(this).prop('selected', false);
}); });
return false; return false;
}); });
/* ajax suggestions */ /* ajax suggestions */
$('#query').autocomplete('search_suggestions.php', { $('#query').autocomplete({
source: 'search_suggestions.php',
multiple: false, multiple: false,
selectFirst: false, selectFirst: false,
mustMatch: false, mustMatch: false,

@ -20,7 +20,7 @@ require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
*/ */
function search_widget_prepare(&$htmlHeadXtra) { function search_widget_prepare(&$htmlHeadXtra) {
$htmlHeadXtra[] = ' $htmlHeadXtra[] = '
<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.autocomplete.js"></script> <!-- script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.autocomplete.js"></script -->
<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'search/search_widget.js"></script> <script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'search/search_widget.js"></script>
<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.autocomplete.css" /> <link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_LIBRARY_PATH).'search/search_widget.css" />'; <link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_LIBRARY_PATH).'search/search_widget.css" />';

@ -32,10 +32,10 @@ class quiz_processor extends search_processor {
$item = array( $item = array(
'courseid' => $courseid, 'courseid' => $courseid,
'question' => $question, 'question' => $question,
'score' => $row_val['score'], 'total_score' => $row_val['score'],
'row_id' => $row_id, 'row_id' => $row_id,
); );
$this->exercises[$courseid][$exercise_id][] = $item; $this->exercises[$courseid][$exercise_id] = $item;
$this->exercises[$courseid][$exercise_id]['total_score'] += $row_val['score']; $this->exercises[$courseid][$exercise_id]['total_score'] += $row_val['score'];
break; break;
case SE_DOCTYPE_EXERCISE_QUESTION: case SE_DOCTYPE_EXERCISE_QUESTION:
@ -45,10 +45,10 @@ class quiz_processor extends search_processor {
$item = array( $item = array(
'courseid' => $courseid, 'courseid' => $courseid,
'question' => $question, 'question' => $question,
'score' => $row_val['score'], 'total_score' => $row_val['score'],
'row_id' => $row_id, 'row_id' => $row_id,
); );
$this->exercises[$courseid][$exercise_id][] = $item; $this->exercises[$courseid][$exercise_id] = $item;
$this->exercises[$courseid][$exercise_id]['total_score'] += $row_val['score']; $this->exercises[$courseid][$exercise_id]['total_score'] += $row_val['score'];
} }
} }
@ -74,7 +74,7 @@ class quiz_processor extends search_processor {
$url = sprintf($url, $courseid, $exercise_id); $url = sprintf($url, $courseid, $exercise_id);
$result = array( $result = array(
'toolid' => TOOL_QUIZ, 'toolid' => TOOL_QUIZ,
'score' => $exercise['total_score'] / (count($exercise) - 1), // not count total_score array item 'total_score' => $exercise['total_score'] / (count($exercise) - 1), // not count total_score array item
'url' => $url, 'url' => $url,
'thumbnail' => $thumbnail, 'thumbnail' => $thumbnail,
'image' => $image, 'image' => $image,
@ -96,7 +96,7 @@ class quiz_processor extends search_processor {
// get information to sort // get information to sort
foreach ($results as $key => $row) { foreach ($results as $key => $row) {
$score[$key] = $row['score']; $score[$key] = $row['total_score'];
} }
// Sort results with score descending // Sort results with score descending
array_multisort($score, SORT_DESC, $results); array_multisort($score, SORT_DESC, $results);
@ -111,24 +111,35 @@ class quiz_processor extends search_processor {
$course_information = api_get_course_info($courseCode); $course_information = api_get_course_info($courseCode);
$course_id = $course_information['real_id']; $course_id = $course_information['real_id'];
$em = Database::getManager();
if (!empty($course_information)) { if (!empty($course_information)) {
$exercise_table = Database::get_course_table(TABLE_QUIZ_TEST);
$exercise_id = intval($exercise_id); $exercise_id = intval($exercise_id);
$sql = "SELECT * FROM $exercise_table WHERE id = $exercise_id AND c_id = $course_id LIMIT 1"; $dk_result = $em
$dk_result = Database::query($sql); ->getRepository('ChamiloCourseBundle:CQuiz')
->findOneBy([
'id' => $exercise_id,
'cId' => $course_id
]);
$name = ''; $name = '';
if ($row = Database::fetch_array($dk_result)) { if ($dk_result) {
// Get the image path // Get the image path
$thumbnail = Display::returnIconPath('quiz.png'); $thumbnail = Display::returnIconPath('quiz.png');
$image = $thumbnail; //FIXME: use big images $image = $thumbnail; //FIXME: use big images
$name = $row['title']; $name = $dk_result->getTitle();
// get author // get author
$author = ''; $author = '';
$item_result = Database::query($sql); $item_result = $em
if ($item_result !== false && $row = Database::fetch_array($item_result)) { ->getRepository('ChamiloCourseBundle:CItemProperty')
$user_data = api_get_user_info($row['insert_user_id']); ->findOneBy([
$author = api_get_person_name($user_data['firstName'], $user_data['lastName']); 'ref' => $exercise_id,
'tool' => TOOL_QUIZ,
'course' => $course_id
]);
if ($item_result) {
$author = $item_result->getInsertUser()->getCompleteName();
} }
} }
return array($thumbnail, $image, $name, $author); return array($thumbnail, $image, $name, $author);

@ -147,12 +147,12 @@ if ($count > 0) {
if ($mode == 'gallery') { if ($mode == 'gallery') {
$title = $a_prefix.str_replace('_',' ',$result['title']). $a_sufix; $title = $a_prefix.str_replace('_',' ',$result['title']). $a_sufix;
$blocks[] = array( $blocks[] = array(1 =>
$a_prefix .'<img src="'.$result['thumbnail'].'" />'. $a_sufix .'<br />'.$title.'<br />'.$result['author'], $a_prefix .'<img src="'.$result['thumbnail'].'" />'. $a_sufix .'<br />'.$title.'<br />'.$result['author'],
); );
} else { } else {
$title = '<div style="text-align:left;">'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author']) ? ' '.$result['author'] : '').'<div>'; $title = '<div style="text-align:left;">'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author']) ? ' '.$result['author'] : '').'<div>';
$blocks[] = array($title); $blocks[] = array(1 => $title);
} }
} }
} }

@ -10,8 +10,10 @@ require_once dirname(__FILE__) . '/../inc/global.inc.php';
function get_suggestions_from_search_engine($q) function get_suggestions_from_search_engine($q)
{ {
if (strlen($q)<2) { return null;} // if (strlen($q)<2) { return null;}
global $charset; global $charset;
$json = [];
$table_sfv = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES); $table_sfv = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$q = Database::escape_string($q); $q = Database::escape_string($q);
$cid = api_get_course_id(); $cid = api_get_course_id();
@ -25,7 +27,12 @@ function get_suggestions_from_search_engine($q)
$data = array(); $data = array();
$i = 0; $i = 0;
while ($row = Database::fetch_array($sql_result)) { while ($row = Database::fetch_array($sql_result)) {
echo api_convert_encoding($row['value'],'UTF-8',$charset)."| value\n"; $json[] = [
'id' => api_convert_encoding($row['value'],'UTF-8',$charset),
'value' => api_convert_encoding($row['value'],'UTF-8',$charset),
'label' => api_convert_encoding($row['value'],'UTF-8',$charset)
];
if ($i<20) { if ($i<20) {
$data[ $row['course_code'] ] [ $row['tool_id'] ] [ $row['ref_id'] ] = 1; $data[ $row['course_code'] ] [ $row['tool_id'] ] [ $row['ref_id'] ] = 1;
} }
@ -90,20 +97,24 @@ function get_suggestions_from_search_engine($q)
} }
foreach ($output as $i=>$out) { foreach ($output as $i=>$out) {
if (api_stristr($out,$q) === false) {continue;} if (api_stristr($out,$q) === false) {continue;}
$s = api_convert_encoding(substr($out,0,-3),'UTF-8',$charset) . "| value\n"; $s = api_convert_encoding(substr($out, 0, -3), 'UTF-8', $charset);
if (!in_array($s,$more_sugg)) { if (!in_array($s,$more_sugg)) {
$more_sugg[] = $s; $more_sugg[] = $s;
$json[] = [
'id' => $s,
'value' => $s,
'label' => $s
];
} }
} }
} }
} }
} }
foreach ($more_sugg as $sugg) {
echo $sugg; echo json_encode($json);
}
} }
$q = strtolower($_GET["q"]); $q = strtolower($_GET["term"]);
if (!$q) return; if (!$q) return;
//echo $q . "| value\n"; //echo $q . "| value\n";
get_suggestions_from_search_engine($q); get_suggestions_from_search_engine($q);

Loading…
Cancel
Save