Explorar o código

Adding hot courses block (partial) see #4200

Julio Montoya %!s(int64=13) %!d(string=hai) anos
pai
achega
b20c8f927a

+ 9 - 0
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

+ 34 - 15
main/inc/lib/database.lib.php

@@ -1170,7 +1170,7 @@ class Database {
         }
 
         $sql    = "SELECT $clean_columns FROM $table_name $conditions";
-	    //echo $sql.'<br />';
+	//echo $sql.'<br />';
         $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]);

+ 31 - 14
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':

+ 3 - 3
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();
+        }
 }

+ 13 - 1
main/template/default/layout/layout_2_col.tpl

@@ -16,13 +16,25 @@
 		{$message}
 		{$content}
 		{$announcements_block}
+
+                {if !(empty($hot_courses)) }	
+                     <h3>Hottest courses</h3>
+                    {foreach $hot_courses as $hot_course}
+                        <div class="categories-block-course">
+                            <div class="categories-content-course">
+                                Course id: {$hot_course.c_id}
+                            </div>
+                        </div>
+                    {/foreach}
+                {/if}
 	</div>
 	
 	<div id="menu-wrapper">
 	    
 		{if $_u.logged == 0}
 			{include file="default/layout/login_form.tpl"}
-		{/if}			
+		{/if}
+
 		{$profile_block}			
 		{$account_block}		
 		{$teacher_block}