This is a major issue as if there are no other courses with similar name then, the same course is listed under similar courses. & in second scenario non related courses are also shown if just the course name is matching somehow, although one course is of be cooking category & other of engineering category.
This is not logical
Similar courses/related courses should list other courses from the same category.
I zeroed down to the components\com_splms\models\courses.php
->public function getRelatedCourses
public function getRelatedCourses($course_name, $course_id, $cat_id, $limit = 3) {
$search = preg_replace('#\xE3\x80\x80#s', " ", htmlspecialchars(trim($course_name)));
$search_array = explode(" ", $search);
$str_tag_ids = implode(' OR ', array_map(function ($entry) {
return "a.title LIKE '%" . $entry . "%'";
}, $search_array));
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select( array('a.id', 'a.title', 'a.alias', 'a.level', 'a.course_sub_title', 'a.course_time', 'a.image', 'a.price', 'a.sale_price') );
$query->select($db->quoteName('b.title', 'category_name'));
$query->from($db->quoteName('#__splms_courses', 'a'));
$query->join('LEFT', $db->quoteName('#__splms_coursescategories', 'b') . ' ON (' . $db->quoteName('a.coursecategory_id') . ' = ' . $db->quoteName('b.id') . ')');
$query->where($db->quoteName('a.id')." != ".$db->quote($course_id));
$query->where($db->quoteName('a.published')." = ".$db->quote('1'));
if ($str_tag_ids) {
$query->where($str_tag_ids);
}
$query->setLimit($limit);
$db->setQuery($query);
$relatedCourses = $db->loadObjectList();
foreach ($relatedCourses as &$relatedCourse) {
$relatedCourse->thumbnail = SplmsHelper::getThumbnail($relatedCourse->image);
$relatedCourse->url = JRoute::_('index.php?option=com_splms&view=course&id=' . $relatedCourse->id . ':' . $relatedCourse->alias . SplmsHelper::getItemId('courses'));
}
return $relatedCourses;
}
Can you please help me to simplify this function so that it only returns courses from same category.
regards