Browse Source

Some date fixes see BT#4957

Julio Montoya 12 years ago
parent
commit
ad5098849c

+ 20 - 29
plugin/dashboard/block_teacher/block_teacher.class.php

@@ -89,7 +89,7 @@ class BlockTeacher extends Block {
  	 * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  	 * @return string  content html
  	 */
-    public function get_teachers_content_html_for_platform_admin() {	 	
+    public function get_teachers_content_html_for_platform_admin() { 	
 		$content = '<div style="margin:10px;">';
 		$content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>';		 		
 		if (count($this->teachers) > 0) {
@@ -98,9 +98,7 @@ class BlockTeacher extends Block {
 									<th>'.get_lang('User').'</th>
 									<th>'.get_lang('TimeSpentOnThePlatform').'</th>			
 									<th>'.get_lang('LastConnexion').'</th>													
-								</tr>								
-							';
-	 		
+								</tr>';	 		
 	 		$i = 1;
 	 		foreach ($this->teachers as $teacher) {
 	 			
@@ -138,40 +136,36 @@ class BlockTeacher extends Block {
 	}
 	
 	public function get_teachers_content_html_for_drh() {  		
-  		
-  		$teachers = $this->teachers;
- 		$content = ''; 		
  		$content = '<div style="margin:10px;">';
  		$content .= '<h3><font color="#000">'.get_lang('YourTeachers').'</font></h3>'; 		
  		 		 		 	
- 		if (count($teachers) > 0) { 			
- 			$a_last_week = get_last_week();
- 			$last_week 	 = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
+ 		if (count($this->teachers) > 0) { 			
+ 			$a_last_week = get_last_week();            
+ 			$last_week 	 = api_convert_and_format_date($a_last_week[0], DATE_FORMAT_SHORT).' '.get_lang('Until').'<br />'.api_convert_and_format_date($a_last_week[6], DATE_FORMAT_SHORT);
  			
-	 		$teachers_table = '<table class="data_table" width:"95%">'; 		
-	 		$teachers_table .= '
-								<tr>		
+	 		$teachers_table = '<table class="data_table">'; 		
+	 		$teachers_table .= '<tr>		
 									<th>'.get_lang('User').'</th>
 									<th>'.get_lang('TimeSpentLastWeek').'<br />'.$last_week.'</th>														
-								</tr>								
-							';
-	 		
+								</tr>';		
 	 		$i = 1;
-	 		foreach ($teachers as $teacher) {
+	 		foreach ($this->teachers as $teacher) {
 	 			
 	 			$teacher_id = $teacher['user_id'];
 	 			$firstname  = $teacher['firstname'];
 	 			$lastname   = $teacher['lastname'];
 				$username	= $teacher['username'];
-	 			$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id,true));
-	 				 			
-	 			if ($i%2 == 0) $class_tr = 'row_odd';
-	    		else $class_tr = 'row_even';
+	 			$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($teacher_id, 'custom', api_get_utc_datetime($a_last_week[0]), api_get_utc_datetime($a_last_week[6])));
+                	 				 			
+	 			if ($i%2 == 0) {
+                    $class_tr = 'row_odd';
+                } else {
+                    $class_tr = 'row_even';
+                }
 	    		$teachers_table .= '<tr class="'.$class_tr.'">
 										<td>'.api_get_person_name($firstname,$lastname).' ('.$username.')</td>										
 										<td align="right">'.$time_on_platform.'</td>										
-									</tr>';
-	 			
+									</tr>';	 			
 	 			$i++;		
 	 		}
 	 		$teachers_table .= '</table>';
@@ -181,13 +175,11 @@ class BlockTeacher extends Block {
   		
   		$content .= $teachers_table;
  		
- 		if (count($teachers) > 0) {
+ 		if (count($this->teachers) > 0) {
 			$content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/teachers.php">'.get_lang('SeeMore').'</a></div>';
 		}
 		$content .= '</div>';
-
-  		return $content;	
-  		
+  		return $content;  		
   	}
  
     /**
@@ -196,6 +188,5 @@ class BlockTeacher extends Block {
 	 */
 	function get_number_of_teachers() {
 		return count($this->teachers);
-	}
-    
+	}    
 }

+ 19 - 33
plugin/dashboard/block_teacher_graph/block_teacher_graph.class.php

@@ -9,15 +9,11 @@
 /**
  * required files for getting data
  */
-require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
-require_once api_get_path(LIBRARY_PATH).'course.lib.php';
 require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
 require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
 require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
 require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
 
-
-
 /**
  * This class is used like controller for teacher graph block plugin, 
  * the class name must be registered inside path.info file (e.g: controller = "BlockTeacherGraph"), so dashboard controller will be instantiate it
@@ -65,21 +61,18 @@ class BlockTeacherGraph extends Block {
      * it's important to use the name 'get_block' for beeing used from dashboard controller 
      * @return array   column and content html
      */
-    public function get_block() {
-    	
-    	global $charset;
-    	    	
+    public function get_block() {    	
+    	global $charset;    	    	
     	$column = 1;
     	$data   = array();
 		
 		/*if (api_is_platform_admin()) {
 			$teacher_content_html = $this->get_teachers_content_html_for_platform_admin();
 		} else if (api_is_drh()) {*/
-			$teacher_information_graph = $this->get_teachers_information_graph();
+        $teacher_information_graph = $this->get_teachers_information_graph();
 		//}
 		
-		$html = '        		
-			            <li class="widget color-blue" id="intro">
+		$html = '<li class="widget color-blue" id="intro">
 			                <div class="widget-head">
 			                    <h3>'.get_lang('TeachersInformationsGraph').'</h3>
 			                    <div class="widget-actions"><a onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">'.Display::return_icon('close.gif',get_lang('Close')).'</a></div>
@@ -88,14 +81,10 @@ class BlockTeacherGraph extends Block {
 			                	<div style="padding:10px;"><strong>'.get_lang('TimeSpentOnThePlatformLastWeekByDay').'</strong></div>
 								'.$teacher_information_graph.'
 			                </div>
-			            </li>		            			    
-				'; 
-    	
+			            </li>';    	
     	$data['column'] = $column;
-    	$data['content_html'] = $html;
-    	    	    	    	
-    	return $data;    	    	
-    	
+    	$data['content_html'] = $html;    	    	    	    	
+    	return $data;    	
     }
     
     /**
@@ -103,13 +92,10 @@ class BlockTeacherGraph extends Block {
  	 * @return string  content html
  	 */
     public function get_teachers_information_graph() {
-
-	 	$teachers = $this->teachers;
 		$graph = '';
-
- 		$user_ids = array_keys($teachers); 		
+ 		$user_ids = array_keys($this->teachers); 		
  		$a_last_week = get_last_week();
-
+        
 		if (is_array($user_ids) && count($user_ids) > 0) {
 			$data_set = new pData;  		
 			foreach ($user_ids as $user_id) {
@@ -117,16 +103,19 @@ class BlockTeacherGraph extends Block {
 				$username = $teacher_info['username'];
 				$time_by_days = array();
 				foreach ($a_last_week as $day) {
-					$time_on_platform_by_day = Tracking::get_time_spent_on_the_platform($user_id, false, $day);
+                    $date = new DateTime(api_get_utc_datetime($day));
+                    $start_date = $date->format('Y-m-d').' 00:00:00';
+                    $end_date   = $date->format('Y-m-d').' 23:59:59';                    
+					$time_on_platform_by_day = Tracking::get_time_spent_on_the_platform($user_id, 'custom', $start_date, $end_date);                    
 					$hours = floor($time_on_platform_by_day / 3600);			
 					$min = floor(($time_on_platform_by_day - ($hours * 3600)) / 60);
 					$time_by_days[] = $min;					
-				}
-				$data_set->AddPoint($time_by_days,$username);	
+				}                
+				$data_set->AddPoint($time_by_days, $username);	
 				$data_set->AddSerie($username);
 			}
 	
-			$last_week 	 = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
+			$last_week 	 = date('Y-m-d', $a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
 			$days_on_week = array();			
 			foreach ($a_last_week as $weekday) {
 				$days_on_week[] = date('d/m',$weekday);
@@ -184,10 +173,8 @@ class BlockTeacherGraph extends Block {
 		} else {
 			$graph = '<p>'.api_convert_encoding(get_lang('GraphicNotAvailable'),'UTF-8').'</p>';
 		}		  
- 		return $graph; 	
- 		
-	}
-	
+ 		return $graph; 		
+	}	
  
     /**
 	 * Get number of teachers 
@@ -195,6 +182,5 @@ class BlockTeacherGraph extends Block {
 	 */
 	function get_number_of_teachers() {
 		return count($this->teachers);
-	}
-    
+	}    
 }