upgrade
This commit is contained in:
105
main/inc/lib/search/tool_processors/document_processor.class.php
Normal file
105
main/inc/lib/search/tool_processors/document_processor.class.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Process documents before pass it to search listing scripts.
|
||||
*
|
||||
* @package chamilo.include.search
|
||||
*/
|
||||
class document_processor extends search_processor
|
||||
{
|
||||
public function __construct($rows)
|
||||
{
|
||||
$this->rows = $rows;
|
||||
}
|
||||
|
||||
public function process()
|
||||
{
|
||||
$results = [];
|
||||
foreach ($this->rows as $row_val) {
|
||||
$search_show_unlinked_results = (api_get_setting('search_show_unlinked_results') == 'true');
|
||||
$course_visible_for_user = api_is_course_visible_for_user(null, $row_val['courseid']);
|
||||
// can view course?
|
||||
if ($course_visible_for_user || $search_show_unlinked_results) {
|
||||
// is visible?
|
||||
$visibility = api_get_item_visibility(api_get_course_info($row_val['courseid']), TOOL_DOCUMENT, $row_val['xapian_data'][SE_DATA]['doc_id']);
|
||||
if ($visibility) {
|
||||
list($thumbnail, $image, $name, $author, $url) = $this->get_information($row_val['courseid'], $row_val['xapian_data'][SE_DATA]['doc_id']);
|
||||
$result = [
|
||||
'toolid' => TOOL_DOCUMENT,
|
||||
'score' => $row_val['score'],
|
||||
'url' => $url,
|
||||
'thumbnail' => $thumbnail,
|
||||
'image' => $image,
|
||||
'title' => $name,
|
||||
'author' => $author,
|
||||
];
|
||||
if ($course_visible_for_user) {
|
||||
$results[] = $result;
|
||||
} else { // course not visible for user
|
||||
if ($search_show_unlinked_results) {
|
||||
$result['url'] = '';
|
||||
$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, $doc_id)
|
||||
{
|
||||
$course_information = api_get_course_info($course_id);
|
||||
$course_id = $course_information['real_id'];
|
||||
$course_path = $course_information['path'];
|
||||
if (!empty($course_information)) {
|
||||
$item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
|
||||
$doc_table = Database::get_course_table(TABLE_DOCUMENT);
|
||||
|
||||
$doc_id = intval($doc_id);
|
||||
$sql = "SELECT * FROM $doc_table
|
||||
WHERE $doc_table.id = $doc_id AND c_id = $course_id
|
||||
LIMIT 1";
|
||||
$dk_result = Database::query($sql);
|
||||
|
||||
$sql = "SELECT insert_user_id FROM $item_property_table
|
||||
WHERE ref = $doc_id AND tool = '".TOOL_DOCUMENT."' AND c_id = $course_id
|
||||
LIMIT 1";
|
||||
$name = '';
|
||||
if ($row = Database::fetch_array($dk_result)) {
|
||||
$name = $row['title'];
|
||||
$url = api_get_path(WEB_COURSE_PATH).'%s/document%s';
|
||||
$url = sprintf($url, $course_path, $row['path']);
|
||||
// Get the image path
|
||||
$icon = choose_image(basename($row['path']));
|
||||
$thumbnail = Display::returnIconPath($icon);
|
||||
$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 [$thumbnail, $image, $name, $author, $url]; // FIXME: is it posible to get an author here?
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
6
main/inc/lib/search/tool_processors/index.html
Normal file
6
main/inc/lib/search/tool_processors/index.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Process learning paths before pass it to search listing scripts.
|
||||
*
|
||||
* @package chamilo.include.search
|
||||
*/
|
||||
class learnpath_processor extends search_processor
|
||||
{
|
||||
public $learnpaths = [];
|
||||
|
||||
public function __construct($rows)
|
||||
{
|
||||
$this->rows = $rows;
|
||||
// group by learning path
|
||||
foreach ($rows as $row_id => $row_val) {
|
||||
$lp_id = $row_val['xapian_data'][SE_DATA]['lp_id'];
|
||||
$lp_item = $row_val['xapian_data'][SE_DATA]['lp_item'];
|
||||
$document_id = $row_val['xapian_data'][SE_DATA]['document_id'];
|
||||
$courseid = $row_val['courseid'];
|
||||
$item = [
|
||||
'courseid' => $courseid,
|
||||
'lp_item' => $lp_item,
|
||||
'score' => $row_val['score'],
|
||||
'row_id' => $row_id,
|
||||
];
|
||||
$this->learnpaths[$courseid][$lp_id][] = $item;
|
||||
$this->learnpaths[$courseid][$lp_id]['total_score'] += $row_val['score'];
|
||||
$this->learnpaths[$courseid][$lp_id]['has_document_id'] = is_numeric($document_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$results = [];
|
||||
foreach ($this->learnpaths as $courseid => $learnpaths) {
|
||||
$search_show_unlinked_results = api_get_setting('search_show_unlinked_results') == 'true';
|
||||
$course_visible_for_user = api_is_course_visible_for_user(null, $courseid);
|
||||
// can view course?
|
||||
if ($course_visible_for_user || $search_show_unlinked_results) {
|
||||
foreach ($learnpaths as $lp_id => $lp) {
|
||||
// is visible?
|
||||
$visibility = api_get_item_visibility(
|
||||
api_get_course_info($courseid),
|
||||
TOOL_LEARNPATH,
|
||||
$lp_id
|
||||
);
|
||||
if ($visibility) {
|
||||
list($thumbnail, $image, $name, $author) = $this->get_information($courseid, $lp_id, $lp['has_document_id']);
|
||||
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?cidReq=%s&action=view&lp_id=%s';
|
||||
$url = sprintf($url, $courseid, $lp_id);
|
||||
$result = [
|
||||
'toolid' => TOOL_LEARNPATH,
|
||||
'score' => $lp['total_score'] / (count($lp) - 1), // not count total_score array item
|
||||
'url' => $url,
|
||||
'thumbnail' => $thumbnail,
|
||||
'image' => $image,
|
||||
'title' => $name,
|
||||
'author' => $author,
|
||||
];
|
||||
if ($course_visible_for_user) {
|
||||
$results[] = $result;
|
||||
} else { // course not visible for user
|
||||
if ($search_show_unlinked_results) {
|
||||
$result['url'] = '';
|
||||
$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 learning path information.
|
||||
*/
|
||||
private function get_information($course_id, $lp_id, $has_document_id = true)
|
||||
{
|
||||
$course_information = api_get_course_info($course_id);
|
||||
$course_id = $course_information['real_id'];
|
||||
$course_path = $course_information['path'];
|
||||
|
||||
if (!empty($course_information)) {
|
||||
$lpi_table = Database::get_course_table(TABLE_LP_ITEM);
|
||||
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
|
||||
$doc_table = Database::get_course_table(TABLE_DOCUMENT);
|
||||
|
||||
$lp_id = intval($lp_id);
|
||||
|
||||
if ($has_document_id) {
|
||||
$sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author, $doc_table.path
|
||||
FROM $lp_table, $lpi_table
|
||||
INNER JOIN $doc_table ON $lpi_table.path = $doc_table.id AND $lpi_table.c_id = $course_id
|
||||
WHERE $lpi_table.c_id = $course_id AND
|
||||
$doc_table.c_id = $course_id AND
|
||||
$lpi_table.lp_id = $lp_id AND
|
||||
$lpi_table.display_order = 1 AND
|
||||
$lp_table.id = $lpi_table.lp_id
|
||||
LIMIT 1";
|
||||
} else {
|
||||
$sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author
|
||||
FROM $lp_table, $lpi_table
|
||||
WHERE
|
||||
$lpi_table.c_id = $course_id AND
|
||||
$lp_table.c_id = $course_id AND
|
||||
$lpi_table.lp_id = $lp_id AND
|
||||
$lpi_table.display_order = 1 AND
|
||||
$lp_table.id = $lpi_table.lp_id
|
||||
LIMIT 1";
|
||||
}
|
||||
|
||||
$dk_result = Database::query($sql);
|
||||
|
||||
$path = '';
|
||||
$name = '';
|
||||
if ($row = Database::fetch_array($dk_result)) {
|
||||
// Get the image path
|
||||
$img_location = api_get_path(WEB_COURSE_PATH).$course_path."/document/";
|
||||
$thumbnail_path = str_replace('.png.html', '_thumb.png', $row['path']);
|
||||
$big_img_path = str_replace('.png.html', '.png', $row['path']);
|
||||
$thumbnail = '';
|
||||
if (!empty($thumbnail_path)) {
|
||||
$thumbnail = $img_location.$thumbnail_path;
|
||||
}
|
||||
$image = '';
|
||||
if (!empty($big_img_path)) {
|
||||
$image = $img_location.$big_img_path;
|
||||
}
|
||||
$name = $row['name'];
|
||||
}
|
||||
|
||||
return [$thumbnail, $image, $name, $row['author']];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
122
main/inc/lib/search/tool_processors/link_processor.class.php
Normal file
122
main/inc/lib/search/tool_processors/link_processor.class.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Process links before pass it to search listing scripts.
|
||||
*
|
||||
* @package chamilo.include.search
|
||||
*/
|
||||
class link_processor extends search_processor
|
||||
{
|
||||
public $links = [];
|
||||
|
||||
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 = [
|
||||
'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 = [];
|
||||
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 = [
|
||||
'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 [$thumbnail, $image, $name, $author, $url];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
141
main/inc/lib/search/tool_processors/quiz_processor.class.php
Normal file
141
main/inc/lib/search/tool_processors/quiz_processor.class.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CourseBundle\Entity\CQuiz;
|
||||
|
||||
/**
|
||||
* Process exercises before pass it to search listing scripts.
|
||||
*
|
||||
* @package chamilo.include.search
|
||||
*/
|
||||
class quiz_processor extends search_processor
|
||||
{
|
||||
public $exercices = [];
|
||||
|
||||
public function __construct($rows)
|
||||
{
|
||||
$this->rows = $rows;
|
||||
// group by exercise
|
||||
foreach ($rows as $row_id => $row_val) {
|
||||
$courseid = $row_val['courseid'];
|
||||
$se_data = $row_val['xapian_data'][SE_DATA];
|
||||
switch ($row_val['xapian_data'][SE_DATA]['type']) {
|
||||
case SE_DOCTYPE_EXERCISE_EXERCISE:
|
||||
$exercise_id = $se_data['exercise_id'];
|
||||
$question = null;
|
||||
$item = [
|
||||
'courseid' => $courseid,
|
||||
'question' => $question,
|
||||
'total_score' => $row_val['score'],
|
||||
'row_id' => $row_id,
|
||||
];
|
||||
$this->exercises[$courseid][$exercise_id] = $item;
|
||||
$this->exercises[$courseid][$exercise_id]['total_score'] += $row_val['score'];
|
||||
break;
|
||||
case SE_DOCTYPE_EXERCISE_QUESTION:
|
||||
if (is_array($se_data['exercise_ids'])) {
|
||||
foreach ($se_data['exercise_ids'] as $exercise_id) {
|
||||
$question = $se_data['question_id'];
|
||||
$item = [
|
||||
'courseid' => $courseid,
|
||||
'question' => $question,
|
||||
'total_score' => $row_val['score'],
|
||||
'row_id' => $row_id,
|
||||
];
|
||||
$this->exercises[$courseid][$exercise_id] = $item;
|
||||
$this->exercises[$courseid][$exercise_id]['total_score'] += $row_val['score'];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function process()
|
||||
{
|
||||
$results = [];
|
||||
foreach ($this->exercises as $courseid => $exercises) {
|
||||
$search_show_unlinked_results = (api_get_setting('search_show_unlinked_results') == 'true');
|
||||
$course_visible_for_user = api_is_course_visible_for_user(null, $courseid);
|
||||
// can view course?
|
||||
if ($course_visible_for_user || $search_show_unlinked_results) {
|
||||
foreach ($exercises as $exercise_id => $exercise) {
|
||||
// is visible?
|
||||
$visibility = api_get_item_visibility(api_get_course_info($courseid), TOOL_QUIZ, $exercise_id);
|
||||
if ($visibility) {
|
||||
list($thumbnail, $image, $name, $author) = $this->get_information($courseid, $exercise_id);
|
||||
$url = api_get_path(WEB_CODE_PATH).'exercise/exercise_submit.php?cidReq=%s&exerciseId=%s';
|
||||
$url = sprintf($url, $courseid, $exercise_id);
|
||||
$result = [
|
||||
'toolid' => TOOL_QUIZ,
|
||||
'total_score' => $exercise['total_score'] / (count($exercise) - 1), // not count total_score array item
|
||||
'url' => $url,
|
||||
'thumbnail' => $thumbnail,
|
||||
'image' => $image,
|
||||
'title' => $name,
|
||||
'author' => $author,
|
||||
];
|
||||
if ($course_visible_for_user) {
|
||||
$results[] = $result;
|
||||
} else { // course not visible for user
|
||||
if ($search_show_unlinked_results) {
|
||||
$result['url'] = '';
|
||||
$results[] = $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get information to sort
|
||||
foreach ($results as $key => $row) {
|
||||
$score[$key] = $row['total_score'];
|
||||
}
|
||||
// Sort results with score descending
|
||||
array_multisort($score, SORT_DESC, $results);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get learning path information.
|
||||
*/
|
||||
private function get_information($courseCode, $exercise_id)
|
||||
{
|
||||
$course_information = api_get_course_info($courseCode);
|
||||
$course_id = $course_information['real_id'];
|
||||
|
||||
$em = Database::getManager();
|
||||
|
||||
if (!empty($course_information)) {
|
||||
$exercise_id = intval($exercise_id);
|
||||
$dk_result = $em->find(CQuiz::class, $exercise_id);
|
||||
|
||||
$name = '';
|
||||
if ($dk_result) {
|
||||
// Get the image path
|
||||
$thumbnail = Display::returnIconPath('quiz.png');
|
||||
$image = $thumbnail; //FIXME: use big images
|
||||
$name = $dk_result->getTitle();
|
||||
// get author
|
||||
$author = '';
|
||||
$item_result = $em
|
||||
->getRepository('ChamiloCourseBundle:CItemProperty')
|
||||
->findOneBy([
|
||||
'ref' => $exercise_id,
|
||||
'tool' => TOOL_QUIZ,
|
||||
'course' => $course_id,
|
||||
]);
|
||||
|
||||
if ($item_result) {
|
||||
$author = UserManager::formatUserFullName($item_result->getInsertUser());
|
||||
}
|
||||
}
|
||||
|
||||
return [$thumbnail, $image, $name, $author];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* @package chamilo.include.search
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class to make tool processors.
|
||||
*
|
||||
* This processor have to prepare the raw data from the search engine api to
|
||||
* make it usable by search. See some implementations of these classes if you
|
||||
* want to make one.
|
||||
*
|
||||
* Classes that extends this one should be named like: TOOL_<toolname> on
|
||||
* TOOL_<toolname>.class.php
|
||||
* See lp_list_search for an example of calling the process.
|
||||
*
|
||||
* @package chamilo.include.search
|
||||
*/
|
||||
abstract class search_processor
|
||||
{
|
||||
/**
|
||||
* Search engine api results.
|
||||
*/
|
||||
protected $rows = [];
|
||||
|
||||
/**
|
||||
* Process the data sorted by the constructor.
|
||||
*/
|
||||
abstract protected function process();
|
||||
}
|
||||
Reference in New Issue
Block a user