diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index a51eaf1528..8b7c50ab1f 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3591,6 +3591,15 @@ class CourseManager { Database::delete($table_user_course_vote, array('c_id = ? AND session_id = ? AND url_id = ?' => $params)); } } + + function return_hot_courses($limit = 5) { + $table_course_ranking = Database::get_main_table(TABLE_STATISTIC_TRACK_COURSE_RANKING); + $params['url_id'] = api_get_current_access_url_id(); + + $result = Database::select('c_id, accesses, points, users', $table_course_ranking, array('where' => array('url_id = ?' => $params), 'order' => array('accesses DESC, users DESC, points DESC'), 'limit' => $limit), 'all', true); + return $result; + + } } //end class CourseManager \ No newline at end of file diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 0d889eb389..8b72165ede 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -1170,7 +1170,7 @@ class Database { } $sql = "SELECT $clean_columns FROM $table_name $conditions"; - //echo $sql.'
'; + //echo $sql.'
'; $result = self::query($sql); $array = array(); //if (self::num_rows($result) > 0 ) { @@ -1237,28 +1237,47 @@ class Database { $return_value = " WHERE $where_return" ; } break; - case 'order': - $order_array = explode(' ', $condition_data); - if (!empty($order_array)) { - if (count($order_array) > 1 && !empty($order_array[0])) { - $order_array[0] = self::escape_string($order_array[0]); - if (!empty($order_array[1])) { - $order_array[1] = strtolower($order_array[1]); - $order = 'desc'; - if (in_array($order_array[1], array('desc', 'asc'))) { - $order = $order_array[1]; + case 'order': + $order_array = $condition_data; + + if (!empty($order_array)) { + if (count($order_array) >= 1 && !empty($order_array[0])) { + $order_array = self::escape_string($order_array[0]); + + $new_order_array = explode(',', $order_array); + + $temp_value = array(); + + foreach($new_order_array as $element) { + $element = explode(' ', $element); + $element = array_filter($element); + $element = array_values($element); + + if (!empty($element[1])) { + $element[1] = strtolower($element[1]); + $order = 'DESC'; + if (in_array($element[1], array('desc', 'asc'))) { + $order = $element[1]; + } + $temp_value[]= $element[0].' '.$order.' '; + } else { + //by default DESC + $temp_value[]= $element[0].' DESC '; } } - $return_value .= ' ORDER BY '.$order_array[0].' '.$order; - } else { - $return_value .= ' ORDER BY '.$order_array[0].' DESC '; + if (!empty($temp_value)) { + $return_value .= ' ORDER BY '.implode(', ', $temp_value); + } else { + //$return_value .= ''; + } } } break; case 'limit': $limit_array = explode(',', $condition_data); + if (!empty($limit_array)) { - if (count($limit_array) > 1) { + if (count($limit_array) > 1) { $return_value .= ' LIMIT '.intval($limit_array[0]).' , '.intval($limit_array[1]); } else { $return_value .= ' LIMIT '.intval($limit_array[0]); diff --git a/main/inc/lib/database.mysqli.lib.php b/main/inc/lib/database.mysqli.lib.php index 253572c096..fd4564b791 100644 --- a/main/inc/lib/database.mysqli.lib.php +++ b/main/inc/lib/database.mysqli.lib.php @@ -1156,23 +1156,40 @@ class Database { } break; case 'order': - $order_array = explode(' ', $condition_data); - - if (!empty($order_array)) { - if (count($order_array) > 1) { - $order_array[0] = self::escape_string($order_array[0]); - if (!empty($order_array[1])) { - $order_array[1] = strtolower($order_array[1]); - $order = 'desc'; - if (in_array($order_array[1], array('desc', 'asc'))) { - $order = $order_array[1]; + $order_array = $condition_data; + + if (!empty($order_array)) { + if (count($order_array) >= 1 && !empty($order_array[0])) { + $order_array = self::escape_string($order_array[0]); + + $new_order_array = explode(',', $order_array); + + $temp_value = array(); + + foreach($new_order_array as $element) { + $element = explode(' ', $element); + $element = array_filter($element); + $element = array_values($element); + + if (!empty($element[1])) { + $element[1] = strtolower($element[1]); + $order = 'DESC'; + if (in_array($element[1], array('desc', 'asc'))) { + $order = $element[1]; + } + $temp_value[]= $element[0].' '.$order.' '; + } else { + //by default DESC + $temp_value[]= $element[0].' DESC '; } } - $return_value .= ' ORDER BY '.$order_array[0].' '.$order; - } else { - $return_value .= ' ORDER BY '.$order_array[0].' DESC '; + if (!empty($temp_value)) { + $return_value .= ' ORDER BY '.implode(', ', $temp_value); + } else { + //$return_value .= ''; + } } - } + } break; case 'limit': diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 8faca658f0..baf212448a 100644 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -1325,7 +1325,7 @@ class IndexManager { } } - function return_hot_courses() { - Course::manager - } + function return_hot_courses() { + return CourseManager::return_hot_courses(); + } } diff --git a/main/template/default/layout/layout_2_col.tpl b/main/template/default/layout/layout_2_col.tpl index 365a67e046..d6c992edeb 100644 --- a/main/template/default/layout/layout_2_col.tpl +++ b/main/template/default/layout/layout_2_col.tpl @@ -16,13 +16,25 @@ {$message} {$content} {$announcements_block} + + {if !(empty($hot_courses)) } +

Hottest courses

+ {foreach $hot_courses as $hot_course} +
+
+ Course id: {$hot_course.c_id} +
+
+ {/foreach} + {/if}