Procházet zdrojové kódy

Adding a new function to get the course URL api_get_course_url() seze BT#2066

Julio Montoya před 14 roky
rodič
revize
f321c01f96
2 změnil soubory, kde provedl 43 přidání a 9 odebrání
  1. 36 6
      main/inc/lib/main_api.lib.php
  2. 7 3
      main/inc/lib/tracking.lib.php

+ 36 - 6
main/inc/lib/main_api.lib.php

@@ -909,7 +909,7 @@ function api_get_user_info($user_id = '') {
  * Finds all the information about a user from username instead of user id
  * @param $username (string): the username
  * @return $user_info (array): user_id, lastname, firstname, username, email, ...
- * @author Yannick Warnier <yannick.warnier@dokeos.com>
+ * @author Yannick Warnier <yannick.warnier@beeznest.com>
  */
 function api_get_user_info_from_username($username = '') {
     if (empty($username)) { return false; }
@@ -952,7 +952,7 @@ function api_get_course_int_id() {
  * This function relies on api_get_course_info()
  * @param string    The course code - optional (takes it from session if not given)
  * @return string   The directory where the course is located inside the Chamilo "courses" directory
- * @author Yannick Warnier <yannick.warnier@dokeos.com>
+ * @author Yannick Warnier <yannick.warnier@beeznest.com>
  */
 function api_get_course_path($course_code = null) {
     $info = !empty($course_code) ? api_get_course_info($course_code) : api_get_course_info();
@@ -1457,7 +1457,7 @@ function api_get_last_failure() {
  * from functions or objects. This strengthens encupsalation principle
  *
  * @author Hugues Peeters <hugues.peeters@claroline.net>
- * @package dokeos.library
+ * @package chamilo.library
  */
 class api_failure {
 
@@ -4178,7 +4178,7 @@ function api_get_status_of_user_in_course ($user_id, $course_code) {
  *
  * @param string        The course code - optional (takes it from session if not given)
  * @return boolean
- * @author Yannick Warnier <yannick.warnier@dokeos.com>
+ * @author Yannick Warnier <yannick.warnier@beeznest.com>
  */
 function api_is_in_course($course_code = null) {
     if (isset($_SESSION['_course']['sysCode'])) {
@@ -4241,7 +4241,7 @@ function api_get_encrypted_password($password, $salt = '') {
 /**
  * Checks whether a secret key is valid
  * @param string $original_key_secret  - secret key from (webservice) client
- * @param string $security_key - security key from dokeos
+ * @param string $security_key - security key from Chamilo
  * @return boolean - true if secret key is valid, false otherwise
  */
 function api_is_valid_secret_key($original_key_secret, $security_key) {
@@ -4824,4 +4824,34 @@ function api_get_jquery_libraries_js($libraries, $include_jquery = true) {
         $js .= '<link rel="stylesheet" href="'.$js_path.'jquery-ui/default.css" type="text/css">';
     } 
     return $js;	
-}
+}
+
+
+/**
+ * Returns the course's URL 
+ *
+ * This function relies on api_get_course_info() 
+ * @param 	string  The course code - optional (takes it from session if not given)
+ * @param 	int		The session id  - optional (takes it from session if not given)
+ * @return 	mixed 	The URL of the course or null if something does not work  
+ * @author 	Julio Montoya <gugli100@gmail.com>
+ */
+
+function api_get_course_url($course_code = null, $session_id = null) {
+    $session_url = '';
+    if (empty($course_code)) {
+        $course_info = api_get_course_info();
+    } else {
+        $course_info = api_get_course_info($course_code);
+    }
+    if (empty($session_id)) {
+        if (api_get_session_id() != 0)
+        $session_url = '?id_session='.api_get_session_id();        
+    } else {
+        $session_url = '?id_session='.intval($session_id);
+    }
+    if (!empty($course_info['path'])) {
+        return api_get_path(WEB_COURSE_PATH).$course_info['path'].'/'.$session_url;
+    }
+    return null;
+} 

+ 7 - 3
main/inc/lib/tracking.lib.php

@@ -1945,8 +1945,9 @@ class Tracking {
                     } else {
                         $html .= '<tr class="row_even">';
                     }
-                    
-                    $html .= '<td>'.$enreg['title'].'</td>';
+                    $url = api_get_course_url($enreg['code'], $session_id);
+                    $course_url = Display::url($enreg['title'], $url, array('target'=>'_blank'));
+                    $html .= '<td>'.$course_url.'</td>';
                     
                     $html .= '<td align="center">'.$time.'</td>';
                     $html .= '<td align="center">'.$progress.'%</td>';
@@ -2053,7 +2054,10 @@ class Tracking {
                         $html .= '<tr  class="row_even">';
                     }
                     
-                    $html .= Display::tag('td', $enreg['title']);/*
+                    $url = api_get_course_url($enreg['code'], $key);
+                    $course_url = Display::url($enreg['title'], $url, array('target'=>'_blank'));
+                    
+                    $html .= Display::tag('td', $course_url);/*
                     //All exercises in the course
                     $exercises = get_all_exercises($enreg, $key);
                     //Count of user results