Minor - format code.

pull/2487/head
jmontoyaa 8 years ago
parent b223b1033d
commit 1c335a8101
  1. 90
      main/inc/lib/geometry.lib.php
  2. 153
      main/inc/lib/myspace.lib.php

@ -12,9 +12,13 @@ define('DEBUG', false);
* @param max[y] Y resolution
* @returns an array such as: for all i in [0..max[x][ : for all j in [0..max[y][ : array[i][j] = FALSE
*/
function poly_init($max) {
return array_fill(0, $max["x"] - 1,
array_fill(0, $max["y"] - 1, FALSE));
function poly_init($max)
{
return array_fill(
0,
$max["x"] - 1,
array_fill(0, $max["y"] - 1, false)
);
}
@ -41,7 +45,8 @@ function poly_init($max) {
* @returns an array such as: for all i in [0..max[x][ : for all j in [0..max[y][ : array[i][j] = in_poly(poly, i,j)
* in_poly(poly,i,j) = true iff (i,j) is inside the polygon defined by poly
*/
function poly_compile($poly, $max, $test = false) {
function poly_compile($poly, $max, $test = false)
{
$res = poly_init($max);
// looking for EDGES
@ -56,9 +61,9 @@ function poly_compile($poly, $max, $test = false) {
* for all j in [O..max[y][ : for all i in bords[$j] :
* (i,j) is a point inside an edge of the polygone
*/
$bord_lenght = $max['x'];
$bord_lenght = $max['x'];
if ($max['y'] > $bord_lenght) {
$bord_lenght = $max['y'];
$bord_lenght = $max['y'];
}
//$bords = array_fill(0, $bord_lenght-1, array()); // building this array
@ -66,7 +71,7 @@ function poly_compile($poly, $max, $test = false) {
/* adding the first point of the polygone */
if (is_array($bords[$poly[0]['y']])) //avoid warning
array_push($bords[$poly[0]['y']], $poly[0]['x']);
array_push($bords[$poly[0]['y']], $poly[0]['x']);
$i = 1; // we re-use $i and $old_pente bellow the loop
$old_pente = 0;
@ -78,14 +83,14 @@ function poly_compile($poly, $max, $test = false) {
if ($poly[$i - 1]['x'] == $poly[$i]['x'])
continue; // twice the same point
else { // infinite elevation of the edge
if (is_array($bords[$poly[$i]['y']]))
array_push($bords[$poly[$i]['y']], $poly[$i]['x']);
if (is_array($bords[$poly[$i]['y']]))
array_push($bords[$poly[$i]['y']], $poly[$i]['x']);
$old_pente = 0;
continue;
}
}
//echo 'point:'.$poly[$i]['y']; bug here
//echo 'point:'.$poly[$i]['y']; bug here
// adding the point as a part of an edge
if (is_array($bords[$poly[$i]['y']])) //avoid warning
array_push($bords[$poly[$i]['y']], $poly[$i]['x']);
@ -102,13 +107,13 @@ function poly_compile($poly, $max, $test = false) {
if ($i > 1)
if (($old_pente < 0 && $pente > 0)
|| ($old_pente > 0 && $pente < 0)) {
if (is_array($bords[$poly[$i]['y']])) //avoid warning
array_push($bords[$poly[$i]['y']], $poly[$i]['x']);
if (is_array($bords[$poly[$i]['y']])) //avoid warning
array_push($bords[$poly[$i]['y']], $poly[$i]['x']);
if (DEBUG)
echo '*('.$poly[$i]['x'].
';'.$poly[$i]['y'].') ';
}
}
/* detect the direction of the elevation in Y */
$dy_inc = ($poly[$i]['y'] - $poly[$i - 1]['y']) > 0 ? 1 : -1;
@ -137,9 +142,9 @@ function poly_compile($poly, $max, $test = false) {
// elevation between $poly[0]['x'] and $poly[1]['x'])
$rest = $poly[0]['y'] - $poly[1]['y'];
if ($rest != 0)
$pente1 = ($poly[0]['x'] - $poly[1]['x']) / ($rest);
$pente1 = ($poly[0]['x'] - $poly[1]['x']) / ($rest);
else
$pente1 = 0;
$pente1 = 0;
// elevation between $poly[$i-1]['x'] and $poly[0]['x'])
$pente = ($poly[$i - 1]['x'] - $poly[0]['x']) /
@ -151,14 +156,14 @@ function poly_compile($poly, $max, $test = false) {
// doubling the first point if needed (see above)
if (($pente1 < 0 && $pente > 0) || ($pente1 > 0 && $pente < 0)) {
if (is_array($bords[$poly[$i - 1]['y']]))
array_push($bords[$poly[$i - 1]['y']], round($poly[$i - 1]['x']));
if (is_array($bords[$poly[$i - 1]['y']]))
array_push($bords[$poly[$i - 1]['y']], round($poly[$i - 1]['x']));
//if (DEBUG) echo '('.$poly[$i-1]['x'].';'.$poly[$i-1]['y'].') ';
}
// doubling the last point if neededd
if (($old_pente < 0 && $pente > 0) || ($old_pente > 0 && $pente < 0)) {
if (is_array($bords[$poly[$i - 1]['y']])) //avoid warning
array_push($bords[$poly[$i - 1]['y']], round($poly[$i - 1]['x']));
if (is_array($bords[$poly[$i - 1]['y']])) //avoid warning
array_push($bords[$poly[$i - 1]['y']], round($poly[$i - 1]['x']));
//if (DEBUG) echo '*('.$poly[$i-1]['x'].';'.$poly[$i-1]['y'].') ';
}
@ -185,7 +190,7 @@ function poly_compile($poly, $max, $test = false) {
for ($i = 0; $i < $n; $i++) { // Y
//error_log(__FILE__.' - Border Num '.$i,0);
if (is_array($bords[$i])) {
sort($bords[$i]);
sort($bords[$i]);
}
for ($j = 0; $j < sizeof($bords[$i]); $j += 2) { // bords
@ -196,15 +201,15 @@ function poly_compile($poly, $max, $test = false) {
for ($k = round($bords[$i][$j]); $k <= $bords[$i][$j + 1]; $k++) {
$res[$k][$i] = true; //filling the array with trues
if ($test == 1) {
/*how to draw the polygon in a human way:
In ubuntu : sudo apt-get install gnuplot
Create an empty file with all points with the result of this echos (No commas, no point, no headers)
In gnuplot:
For 1 polygon: plot "/home/jmontoya/test"
For 2 polygons: plot "/home/jmontoya/test", "/home/jmontoya/test2"
A new window will appear with the plot
*/
echo $k.' '.$i; echo '<br />';
/*how to draw the polygon in a human way:
In ubuntu : sudo apt-get install gnuplot
Create an empty file with all points with the result of this echos (No commas, no point, no headers)
In gnuplot:
For 1 polygon: plot "/home/jmontoya/test"
For 2 polygons: plot "/home/jmontoya/test", "/home/jmontoya/test2"
A new window will appear with the plot
*/
echo $k.' '.$i; echo '<br />';
}
}
}
@ -222,7 +227,8 @@ function poly_compile($poly, $max, $test = false) {
*
* @return string html code of the representation of the polygone image
*/
function poly_dump(&$poly, $max, $format = 'raw') {
function poly_dump(&$poly, $max, $format = 'raw')
{
if ($format == 'html') {
$s = "<div style='font-size: 8px; line-height:3px'><pre>\n";
}
@ -247,7 +253,8 @@ function poly_dump(&$poly, $max, $format = 'raw') {
*
* @returns (see below, UTSL)
*/
function poly_result(&$poly1, &$poly2, $max) {
function poly_result(&$poly1, &$poly2, $max)
{
$onlyIn1 = 0;
$surfaceOf1 = 0;
$surfaceOf2 = 0;
@ -280,8 +287,8 @@ function poly_result(&$poly1, &$poly2, $max) {
*
* @returns (see below, UTSL)
*/
function poly_touch(&$poly1, &$poly2, $max) {
function poly_touch(&$poly1, &$poly2, $max)
{
for ($i = 0; $i < $max['x']; $i++) {
for ($j = 0; $j < $max['y']; $j++) {
if (isset($poly1[$i][$j]) && ($poly1[$i][$j] == true)
@ -301,14 +308,15 @@ function poly_touch(&$poly1, &$poly2, $max) {
* @return array An array of points in the right format to use with the
* local functions
*/
function convert_coordinates($coords, $sep = '|') {
function convert_coordinates($coords, $sep = '|')
{
$points = array();
$pairs = explode($sep, $coords);
foreach ($pairs as $idx => $pcoord) {
list($x, $y) = explode(';', $pcoord);
$points[] = array('x'=>$x, 'y'=>$y);
}
return $points;
return $points;
}
/**
@ -317,15 +325,16 @@ function convert_coordinates($coords, $sep = '|') {
* @param array Coordinates of one polygon
* @return array ('x'=>val,'y'=>val)
*/
function poly_get_max(&$coords1, &$coords2) {
function poly_get_max(&$coords1, &$coords2)
{
$mx = 0;
$my = 0;
foreach ($coords1 as $coord) {
if ($coord['x'] > $mx) {
if ($coord['x'] > $mx) {
$mx = $coord['x'];
}
}
if ($coord['y'] > $my) {
$my = $coord['y'];
$my = $coord['y'];
}
}
foreach ($coords2 as $coord) {
@ -461,7 +470,8 @@ class Geometry
* @param array $point The point properties
* @return boolean
*/
public static function pointIsInPolygon($properties, $point) {
public static function pointIsInPolygon($properties, $point)
{
$points = $properties;
$isInside = false;

@ -126,8 +126,11 @@ class MySpace
* @param int $sessionId Session id (optional, default = 0)
* @return array Connections
*/
public static function get_connections_to_course($userId, $courseInfo, $sessionId = 0)
{
public static function get_connections_to_course(
$userId,
$courseInfo,
$sessionId = 0
) {
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
// protect data
@ -438,7 +441,6 @@ class MySpace
}
$result_coaches = Database::query($sqlCoachs);
//$total_no_coaches = Database::num_rows($result_coaches);
$global_coaches = array();
while ($coach = Database::fetch_array($result_coaches)) {
$global_coaches[$coach['user_id']] = $coach;
@ -552,6 +554,9 @@ class MySpace
$table -> display();
}
/**
* @return mixed
*/
public static function count_coaches()
{
global $total_no_coaches;
@ -572,8 +577,12 @@ class MySpace
* Display a sortable table that contains an overview off all the progress of the user in a session
* @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
*/
public static function display_tracking_lp_progress_overview($sessionId = '', $courseId = '', $date_from, $date_to)
{
public static function display_tracking_lp_progress_overview(
$sessionId = '',
$courseId = '',
$date_from,
$date_to
) {
$course = api_get_course_info_by_id($courseId);
/**
* Column name
@ -679,7 +688,8 @@ class MySpace
* @param int $sessionId The session ID
* @param int $courseId The course ID
* @param int $exerciseId The quiz ID
* @param int $answer Answer status (0 = incorrect, 1 = correct, 2 = both)
* @param $date_from
* @param $date_to
* @return string HTML array of results formatted for gridJS
* @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
*/
@ -740,7 +750,16 @@ class MySpace
$extra_params['height'] = 'auto';
$tableId = 'exerciseProgressOverview';
$table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), '', true);
$table = Display::grid_js(
$tableId,
$url,
$columns,
$column_model,
$extra_params,
array(),
'',
true
);
$return = '<script>$(function() {'.$table.
'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
@ -753,6 +772,7 @@ class MySpace
});
});</script>';
$return .= Display::grid_html($tableId);
return $return;
}
@ -830,7 +850,11 @@ class MySpace
if (!empty($_SESSION['additional_export_fields'])) {
echo Display::return_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>', 'confirm', false);
} else {
echo Display::return_message(get_lang('NoAdditionalFieldsWillBeExported'), 'confirm', false);
echo Display::return_message(
get_lang('NoAdditionalFieldsWillBeExported'),
'confirm',
false
);
}
} else {
$form->display();
@ -901,8 +925,12 @@ class MySpace
* @param string $direction Order direction
* @return array Results
*/
public static function get_course_data_tracking_overview($from, $numberItems, $column, $direction)
{
public static function get_course_data_tracking_overview(
$from,
$numberItems,
$column,
$direction
) {
$courses = CourseManager::get_courses_list(
$from,
$numberItems,
@ -967,18 +995,44 @@ class MySpace
$total_questions_answered = 0;
while ($row = Database::fetch_object($result)) {
// get time spent in the course and session
$time_spent += Tracking::get_time_spent_on_the_course($row->user_id, $courseInfo['real_id']);
$progress_tmp = Tracking::get_avg_student_progress($row->user_id, $course_code, array(), null, true);
$time_spent += Tracking::get_time_spent_on_the_course(
$row->user_id,
$courseInfo['real_id']
);
$progress_tmp = Tracking::get_avg_student_progress(
$row->user_id,
$course_code,
array(),
null,
true
);
$progress += $progress_tmp[0];
$nb_progress_lp += $progress_tmp[1];
$score_tmp = Tracking::get_avg_student_score($row->user_id, $course_code, array(), null, true);
$score_tmp = Tracking::get_avg_student_score(
$row->user_id,
$course_code,
array(),
null,
true
);
if (is_array($score_tmp)) {
$score += $score_tmp[0];
$nb_score_lp += $score_tmp[1];
}
$nb_messages += Tracking::count_student_messages($row->user_id, $course_code);
$nb_assignments += Tracking::count_student_assignments($row->user_id, $course_code);
$last_login_date_tmp = Tracking::get_last_connection_date_on_the_course($row->user_id, $courseInfo, null, false);
$nb_messages += Tracking::count_student_messages(
$row->user_id,
$course_code
);
$nb_assignments += Tracking::count_student_assignments(
$row->user_id,
$course_code
);
$last_login_date_tmp = Tracking::get_last_connection_date_on_the_course(
$row->user_id,
$courseInfo,
null,
false
);
if ($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned
$last_login_date = $last_login_date_tmp;
} else if ($last_login_date_tmp != false && $last_login_date != false) { // TODO: Repeated previous condition. To be cleaned.
@ -1004,7 +1058,11 @@ class MySpace
$avg_score = '-';
}
if ($last_login_date) {
$last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
$last_login_date = api_convert_and_format_date(
$last_login_date,
DATE_FORMAT_SHORT,
date_default_timezone_get()
);
} else {
$last_login_date = '-';
}
@ -1121,19 +1179,45 @@ class MySpace
$total_questions_answered = 0;
while ($row = Database::fetch_object($result)) {
// get time spent in the course and session
$time_spent += Tracking::get_time_spent_on_the_course($row->user_id, $courseId);
$progress_tmp = Tracking::get_avg_student_progress($row->user_id, $course_code, array(), null, true);
$time_spent += Tracking::get_time_spent_on_the_course(
$row->user_id,
$courseId
);
$progress_tmp = Tracking::get_avg_student_progress(
$row->user_id,
$course_code,
array(),
null,
true
);
$progress += $progress_tmp[0];
$nb_progress_lp += $progress_tmp[1];
$score_tmp = Tracking::get_avg_student_score($row->user_id, $course_code, array(), null, true);
$score_tmp = Tracking::get_avg_student_score(
$row->user_id,
$course_code,
array(),
null,
true
);
if (is_array($score_tmp)) {
$score += $score_tmp[0];
$nb_score_lp += $score_tmp[1];
}
$nb_messages += Tracking::count_student_messages($row->user_id, $course_code);
$nb_assignments += Tracking::count_student_assignments($row->user_id, $course_code);
$nb_messages += Tracking::count_student_messages(
$row->user_id,
$course_code
);
$nb_assignments += Tracking::count_student_assignments(
$row->user_id,
$course_code
);
$last_login_date_tmp = Tracking::get_last_connection_date_on_the_course($row->user_id, $courseInfo, null, false);
$last_login_date_tmp = Tracking::get_last_connection_date_on_the_course(
$row->user_id,
$courseInfo,
null,
false
);
if ($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned.
$last_login_date = $last_login_date_tmp;
} else if ($last_login_date_tmp != false && $last_login_date == false) { // TODO: Repeated previous condition. To be cleaned.
@ -1159,7 +1243,11 @@ class MySpace
$avg_score = '-';
}
if ($last_login_date) {
$last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
$last_login_date = api_convert_and_format_date(
$last_login_date,
DATE_FORMAT_SHORT,
date_default_timezone_get()
);
} else {
$last_login_date = '-';
}
@ -1246,8 +1334,12 @@ class MySpace
* @param string $direction Order direction
* @return array Results
*/
public static function get_session_data_tracking_overview($from, $numberItems, $column, $direction)
{
public static function get_session_data_tracking_overview(
$from,
$numberItems,
$column,
$direction
) {
$from = (int) $from;
$numberItems = (int) $numberItems;
$direction = Database::escape_string($direction);
@ -1277,7 +1369,7 @@ class MySpace
/**
* Fills in session reporting data
*
* @param integer $user_id the id of the user
* @param int $session_id the id of the user
* @param array $url_params additonal url parameters
* @param array $row the row information (the other columns)
* @return string html code
@ -1659,7 +1751,12 @@ class MySpace
$direction = 'ASC';
}
$user_data = self::get_user_data_tracking_overview($from, 1000, $orderby, $direction);
$user_data = self::get_user_data_tracking_overview(
$from,
1000,
$orderby,
$direction
);
// the first line of the csv file with the column headers
$csv_row = array();

Loading…
Cancel
Save