Minor - format code.

pull/2487/head
jmontoyaa 8 years ago
parent dc08aac0f4
commit 5cc6f0cb32
  1. 79
      main/gradebook/lib/be/category.class.php
  2. 150
      main/inc/lib/display.lib.php
  3. 143
      main/user/resume_session.php

@ -1347,8 +1347,16 @@ class Category implements GradebookItem
$crscats = self::load(null, null, $this->course_code, 0); $crscats = self::load(null, null, $this->course_code, 0);
foreach ($crscats as $cat) { foreach ($crscats as $cat) {
if ($this->can_be_moved_to_cat($cat)) { if ($this->can_be_moved_to_cat($cat)) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); $targets[] = array(
$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); $cat->get_id(),
$cat->get_name(),
$level + 1
);
$targets = $this->add_target_subcategories(
$targets,
$level + 1,
$cat->get_id()
);
} }
} }
} }
@ -1357,7 +1365,11 @@ class Category implements GradebookItem
foreach ($indcats as $cat) { foreach ($indcats as $cat) {
if ($this->can_be_moved_to_cat($cat)) { if ($this->can_be_moved_to_cat($cat)) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); $targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id()); $targets = $this->add_target_subcategories(
$targets,
$level + 1,
$cat->get_id()
);
} }
} }
@ -1470,15 +1482,33 @@ class Category implements GradebookItem
$user = api_is_platform_admin() ? null : api_get_user_id(); $user = api_is_platform_admin() ? null : api_get_user_id();
$cats = self::get_root_categories_for_teacher($user); $cats = self::get_root_categories_for_teacher($user);
foreach ($cats as $cat) { foreach ($cats as $cat) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); $targets[] = array(
$targets = self::add_subtree($targets, $level + 1, $cat->get_id(), null); $cat->get_id(),
$cat->get_name(),
$level + 1
);
$targets = self::add_subtree(
$targets,
$level + 1,
$cat->get_id(),
null
);
} }
} else { } else {
// student // student
$cats = self::get_root_categories_for_student(api_get_user_id()); $cats = self::get_root_categories_for_student(api_get_user_id());
foreach ($cats as $cat) { foreach ($cats as $cat) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1); $targets[] = array(
$targets = self::add_subtree($targets, $level + 1, $cat->get_id(), 1); $cat->get_id(),
$cat->get_name(),
$level + 1
);
$targets = self::add_subtree(
$targets,
$level + 1,
$cat->get_id(),
1
);
} }
} }
@ -1733,15 +1763,42 @@ class Category implements GradebookItem
// root // root
if ($this->id == 0) { if ($this->id == 0) {
return $this->get_root_categories_for_teacher(api_get_user_id(), $course_code, $session_id, false); return $this->get_root_categories_for_teacher(
api_get_user_id(),
$course_code,
$session_id,
false
);
// inside a course // inside a course
} elseif (!empty($this->course_code)) { } elseif (!empty($this->course_code)) {
return self::load(null, null, $this->course_code, $this->id, null, $session_id, $order); return self::load(
null,
null,
$this->course_code,
$this->id,
null,
$session_id,
$order
);
} elseif (!empty($course_code)) { } elseif (!empty($course_code)) {
return self::load(null, null, $course_code, $this->id, null, $session_id, $order); return self::load(
null,
null,
$course_code,
$this->id,
null,
$session_id,
$order
);
// course independent // course independent
} else { } else {
return self::load(null, api_get_user_id(), 0, $this->id, null); return self::load(
null,
api_get_user_id(),
0,
$this->id,
null
);
} }
} elseif (api_is_platform_admin()) { } elseif (api_is_platform_admin()) {
// platform admin // platform admin

@ -56,8 +56,11 @@ class Display
* @param string Optional help file name * @param string Optional help file name
* @param string $page_header * @param string $page_header
*/ */
public static function display_header($tool_name = '', $help = null, $page_header = null) public static function display_header(
{ $tool_name = '',
$help = null,
$page_header = null
) {
$origin = api_get_origin(); $origin = api_get_origin();
$showHeader = true; $showHeader = true;
if (isset($origin) && $origin == 'learnpath') { if (isset($origin) && $origin == 'learnpath') {
@ -106,7 +109,12 @@ class Display
public static function display_reduced_header() public static function display_reduced_header()
{ {
global $show_learnpath, $tool_name; global $show_learnpath, $tool_name;
self::$global_template = new Template($tool_name, false, false, $show_learnpath); self::$global_template = new Template(
$tool_name,
false,
false,
$show_learnpath
);
echo self::$global_template->show_header_template(); echo self::$global_template->show_header_template();
} }
@ -117,7 +125,12 @@ class Display
{ {
global $tool_name, $show_learnpath; global $tool_name, $show_learnpath;
$disable_js_and_css_files = true; $disable_js_and_css_files = true;
self::$global_template = new Template($tool_name, false, false, $show_learnpath); self::$global_template = new Template(
$tool_name,
false,
false,
$show_learnpath
);
} }
/** /**
@ -126,7 +139,12 @@ class Display
public static function set_header() public static function set_header()
{ {
global $show_learnpath, $tool_name; global $show_learnpath, $tool_name;
self::$global_template = new Template($tool_name, false, false, $show_learnpath); self::$global_template = new Template(
$tool_name,
false,
false,
$show_learnpath
);
} }
/** /**
@ -160,8 +178,10 @@ class Display
* return: $tool return a string array list with the "define" in main_api.lib * return: $tool return a string array list with the "define" in main_api.lib
* @return html code for adding an introduction * @return html code for adding an introduction
*/ */
public static function display_introduction_section($tool, $editor_config = null) public static function display_introduction_section(
{ $tool,
$editor_config = null
) {
echo self::return_introduction_section($tool, $editor_config); echo self::return_introduction_section($tool, $editor_config);
} }
@ -170,8 +190,10 @@ class Display
* @param array $editor_config * @param array $editor_config
* @return null * @return null
*/ */
public static function return_introduction_section($tool, $editor_config = null) public static function return_introduction_section(
{ $tool,
$editor_config = null
) {
$is_allowed_to_edit = api_is_allowed_to_edit(); $is_allowed_to_edit = api_is_allowed_to_edit();
$moduleId = $tool; $moduleId = $tool;
if (api_get_setting('enable_tool_introduction') == 'true' || $tool == TOOL_COURSE_HOMEPAGE) { if (api_get_setting('enable_tool_introduction') == 'true' || $tool == TOOL_COURSE_HOMEPAGE) {
@ -442,8 +464,11 @@ class Display
* *
* @return void * @return void
*/ */
public static function display_normal_message($message, $filter = true, $returnValue = false) public static function display_normal_message(
{ $message,
$filter = true,
$returnValue = false
) {
$message = self::return_message($message, 'normal', $filter); $message = self::return_message($message, 'normal', $filter);
if ($returnValue) { if ($returnValue) {
return $message; return $message;
@ -458,8 +483,11 @@ class Display
* *
* @deprecated use Display::addFlash(Display::return_message($message, 'warning')); * @deprecated use Display::addFlash(Display::return_message($message, 'warning'));
*/ */
public static function display_warning_message($message, $filter = true, $returnValue = false) public static function display_warning_message(
{ $message,
$filter = true,
$returnValue = false
) {
$message = self::return_message($message, 'warning', $filter); $message = self::return_message($message, 'warning', $filter);
if ($returnValue) { if ($returnValue) {
return $message; return $message;
@ -474,8 +502,11 @@ class Display
* @deprecated use Display::addFlash(Display::return_message($message, 'confirm')); * @deprecated use Display::addFlash(Display::return_message($message, 'confirm'));
* @return void * @return void
*/ */
public static function display_confirmation_message($message, $filter = true, $returnValue = false) public static function display_confirmation_message(
{ $message,
$filter = true,
$returnValue = false
) {
$message = self::return_message($message, 'confirm', $filter); $message = self::return_message($message, 'confirm', $filter);
if ($returnValue) { if ($returnValue) {
return $message; return $message;
@ -493,8 +524,11 @@ class Display
* *
* @return void * @return void
*/ */
public static function display_error_message($message, $filter = true, $returnValue = false) public static function display_error_message(
{ $message,
$filter = true,
$returnValue = false
) {
$message = self::return_message($message, 'error', $filter); $message = self::return_message($message, 'error', $filter);
if ($returnValue) { if ($returnValue) {
return $message; return $message;
@ -508,8 +542,11 @@ class Display
* @param string $type * @param string $type
* @param bool $filter * @param bool $filter
*/ */
public static function return_message_and_translate($message, $type = 'normal', $filter = true) public static function return_message_and_translate(
{ $message,
$type = 'normal',
$filter = true
) {
$message = get_lang($message); $message = get_lang($message);
echo self::return_message($message, $type, $filter); echo self::return_message($message, $type, $filter);
} }
@ -521,14 +558,21 @@ class Display
* @param bool $filter Whether to XSS-filter or not * @param bool $filter Whether to XSS-filter or not
* @return string Message wrapped into an HTML div * @return string Message wrapped into an HTML div
*/ */
public static function return_message($message, $type = 'normal', $filter = true) public static function return_message(
{ $message,
$type = 'normal',
$filter = true
) {
if (empty($message)) { if (empty($message)) {
return ''; return '';
} }
if ($filter) { if ($filter) {
$message = api_htmlentities($message, ENT_QUOTES, api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()); $message = api_htmlentities(
$message,
ENT_QUOTES,
api_is_xml_http_request() ? 'UTF-8' : api_get_system_encoding()
);
} }
$class = ''; $class = '';
@ -560,8 +604,11 @@ class Display
* @param string optional, class from stylesheet * @param string optional, class from stylesheet
* @return string encrypted mailto hyperlink * @return string encrypted mailto hyperlink
*/ */
public static function encrypted_mailto_link($email, $clickable_text = null, $style_class = '') public static function encrypted_mailto_link(
{ $email,
$clickable_text = null,
$style_class = ''
) {
if (is_null($clickable_text)) { if (is_null($clickable_text)) {
$clickable_text = $email; $clickable_text = $email;
} }
@ -602,8 +649,12 @@ class Display
* @param string optional, class from stylesheet * @param string optional, class from stylesheet
* @return string encrypted mailto hyperlink * @return string encrypted mailto hyperlink
*/ */
public static function icon_mailto_link($email, $icon_file = "mail.png", $icon_size = 22, $style_class = '') public static function icon_mailto_link(
{ $email,
$icon_file = "mail.png",
$icon_size = 22,
$style_class = ''
) {
// "mailto:" already present? // "mailto:" already present?
if (substr($email, 0, 7) != 'mailto:') { if (substr($email, 0, 7) != 'mailto:') {
$email = 'mailto:'.$email; $email = 'mailto:'.$email;
@ -815,8 +866,12 @@ class Display
* @return string * @return string
* @author Julio Montoya 2010 * @author Julio Montoya 2010
*/ */
public static function img($image_path, $alt_text = '', $additional_attributes = null, $filterPath = true) public static function img(
{ $image_path,
$alt_text = '',
$additional_attributes = null,
$filterPath = true
) {
if (empty($image_path)) { if (empty($image_path)) {
// For some reason, the call to img() happened without a proper // For some reason, the call to img() happened without a proper
// image. Log the error and return an empty string to avoid // image. Log the error and return an empty string to avoid
@ -979,7 +1034,11 @@ class Display
} else { } else {
$blank_item_text = Security::remove_XSS($blank_item_text); $blank_item_text = Security::remove_XSS($blank_item_text);
} }
$html .= self::tag('option', '-- '.$blank_item_text.' --', array('value' => '-1')); $html .= self::tag(
'option',
'-- '.$blank_item_text.' --',
array('value' => '-1')
);
} }
if ($values) { if ($values) {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
@ -1027,8 +1086,13 @@ class Display
* *
* @return string * @return string
*/ */
public static function tabs($headers, $items, $id = 'tabs', $attributes = array(), $ul_attributes = array()) public static function tabs(
{ $headers,
$items,
$id = 'tabs',
$attributes = array(),
$ul_attributes = array()
) {
if (empty($headers) || count($headers) == 0) { if (empty($headers) || count($headers) == 0) {
return ''; return '';
} }
@ -1055,7 +1119,15 @@ class Display
$lis .= self::tag('li', $item, $ul_attributes); $lis .= self::tag('li', $item, $ul_attributes);
$i++; $i++;
} }
$ul = self::tag('ul', $lis, ['class' => 'nav nav-tabs tabs-margin', 'role'=> 'tablist', 'id' => 'ul_'.$id]); $ul = self::tag(
'ul',
$lis,
[
'class' => 'nav nav-tabs tabs-margin',
'role' => 'tablist',
'id' => 'ul_'.$id
]
);
$i = 1; $i = 1;
$divs = ''; $divs = '';
@ -1109,7 +1181,12 @@ class Display
$lis .= self::tag('li', $item, array('class' => $class)); $lis .= self::tag('li', $item, array('class' => $class));
$i++; $i++;
} }
return self::tag('ul', $lis, array('class' => 'nav nav-tabs tabs-margin'));
return self::tag(
'ul',
$lis,
array('class' => 'nav nav-tabs tabs-margin')
);
} }
/** /**
@ -1189,12 +1266,11 @@ class Display
// encoding problems - see #6159 // encoding problems - see #6159
//$column_names = array_map("utf8_encode", $column_names); //$column_names = array_map("utf8_encode", $column_names);
$obj->colNames = $column_names; $obj->colNames = $column_names;
$obj->colModel = $column_model; $obj->colModel = $column_model;
$obj->pager = '#'.$div_id.'_pager'; $obj->pager = '#'.$div_id.'_pager';
$obj->datatype = 'json'; $obj->datatype = 'json';
$obj->viewrecords = 'true'; $obj->viewrecords = 'true';
$all_value = 10000000; $all_value = 10000000;
// Default row quantity // Default row quantity

@ -77,9 +77,13 @@ if ($allowTutors === 'true') {
if ($result) { if ($result) {
Display::addFlash( Display::addFlash(
Display::return_message( Display::return_message(
get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']), get_lang('UserAdded').' '.api_get_person_name(
'confirm' $user_info['firstname'],
)); $user_info['lastname']
),
'confirm'
)
);
} }
break; break;
case 'delete': case 'delete':
@ -120,70 +124,73 @@ if ($allowTutors === 'true') {
} }
Display::display_header($tool_name); Display::display_header($tool_name);
echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']); echo Display::page_header(
Display::return_icon(
'session.png',
get_lang('Session')
).' '.$session['name']
);
echo Display::page_subheader(get_lang('GeneralProperties').$url); echo Display::page_subheader(get_lang('GeneralProperties').$url);
?> ?>
<!-- General properties --> <!-- General properties -->
<table class="data_table"> <table class="data_table">
<tr> <tr>
<td><?php echo get_lang('GeneralCoach'); ?> :</td> <td><?php echo get_lang('GeneralCoach'); ?> :</td>
<td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td> <td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td>
</tr> </tr>
<?php if (!empty($session_category)) { ?> <?php if (!empty($session_category)) { ?>
<tr> <tr>
<td><?php echo get_lang('SessionCategory') ?></td> <td><?php echo get_lang('SessionCategory') ?></td>
<td><?php echo $session_category; ?></td> <td><?php echo $session_category; ?></td>
</tr> </tr>
<?php } ?> <?php } ?>
<tr> <tr>
<td><?php echo get_lang('Date'); ?> :</td> <td><?php echo get_lang('Date'); ?> :</td>
<td> <td>
<?php <?php
if ($session['access_start_date'] == '00-00-0000' && $session['access_end_date'] == '00-00-0000') { if ($session['access_start_date'] == '00-00-0000' && $session['access_end_date'] == '00-00-0000') {
echo get_lang('NoTimeLimits'); echo get_lang('NoTimeLimits');
} else {
if ($session['access_start_date'] != '00-00-0000') {
//$session['date_start'] = Display::tag('i', get_lang('NoTimeLimits'));
$session['access_start_date'] = get_lang('From').' '.$session['access_start_date'];
} else {
$session['access_start_date'] = '';
} }
else { if ($session['access_end_date'] == '00-00-0000') {
if ($session['access_start_date'] != '00-00-0000') { $session['access_end_date'] = '';
//$session['date_start'] = Display::tag('i', get_lang('NoTimeLimits')); } else {
$session['access_start_date'] = get_lang('From').' '.$session['access_start_date']; $session['access_end_date'] = get_lang('Until').' '.$session['access_end_date'];
} else {
$session['access_start_date'] = '';
}
if ($session['access_end_date'] == '00-00-0000') {
$session['access_end_date'] = '';
} else {
$session['access_end_date'] = get_lang('Until').' '.$session['access_end_date'];
}
echo $session['access_start_date'].' '.$session['access_end_date'];
} }
?> echo $session['access_start_date'].' '.$session['access_end_date'];
</td> } ?>
</td>
</tr> </tr>
<!-- show nb_days_before and nb_days_after only if they are different from 0 --> <!-- show nb_days_before and nb_days_after only if they are different from 0 -->
<tr> <tr>
<td> <td>
<?php echo api_ucfirst(get_lang('SessionCoachStartDate')) ?> : <?php echo api_ucfirst(get_lang('SessionCoachStartDate')) ?> :
</td> </td>
<td> <td>
<?php echo intval($session['coach_access_start_date']) ?> <?php echo intval($session['coach_access_start_date']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<?php echo api_ucfirst(get_lang('SessionCoachEndDate')) ?> : <?php echo api_ucfirst(get_lang('SessionCoachEndDate')) ?> :
</td> </td>
<td> <td>
<?php echo intval($session['coach_session_access_end_date']) ?> <?php echo intval($session['coach_session_access_end_date']) ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<?php echo api_ucfirst(get_lang('SessionVisibility')) ?> : <?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
</td> </td>
<td> <td>
<?php if ($session['visibility'] == 1) echo get_lang('ReadOnly'); elseif ($session['visibility'] == 2) echo get_lang('Visible'); elseif ($session['visibility'] == 3) echo api_ucfirst(get_lang('Invisible')) ?> <?php if ($session['visibility'] == 1) echo get_lang('ReadOnly'); elseif ($session['visibility'] == 2) echo get_lang('Visible'); elseif ($session['visibility'] == 3) echo api_ucfirst(get_lang('Invisible')) ?>
</td> </td>
</tr> </tr>
<?php <?php
@ -216,14 +223,14 @@ if ($allowTutors === 'true') {
if ($session['nbr_courses'] == 0) { if ($session['nbr_courses'] == 0) {
echo '<tr> echo '<tr>
<td colspan="4">'.get_lang('NoCoursesForThisSession').'</td> <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
</tr>'; </tr>';
} else { } else {
// select the courses // select the courses
$sql = "SELECT c.id, code,title,visual_code, nbr_users $sql = "SELECT c.id, code,title,visual_code, nbr_users
FROM $tbl_course c,$tbl_session_rel_course sc FROM $tbl_course c,$tbl_session_rel_course sc
WHERE c.id = sc.c_id WHERE c.id = sc.c_id
AND session_id='$id_session' AND session_id='$id_session'
ORDER BY title"; ORDER BY title";
$result = Database::query($sql); $result = Database::query($sql);
$courses = Database::store_result($result); $courses = Database::store_result($result);
foreach ($courses as $course) { foreach ($courses as $course) {
@ -243,21 +250,21 @@ if ($allowTutors === 'true') {
// Get coachs of the courses in session // Get coachs of the courses in session
$sql = "SELECT user.lastname,user.firstname,user.username $sql = "SELECT user.lastname,user.firstname,user.username
FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
WHERE WHERE
session_rcru.user_id = user.user_id AND session_rcru.user_id = user.user_id AND
session_rcru.session_id = '".intval($id_session)."' AND session_rcru.session_id = '".intval($id_session)."' AND
session_rcru.c_id ='".Database::escape_string($course['id'])."' AND session_rcru.c_id ='".Database::escape_string($course['id'])."' AND
session_rcru.status=2"; session_rcru.status=2";
$rs = Database::query($sql); $rs = Database::query($sql);
$coachs = array(); $coachs = array();
if (Database::num_rows($rs) > 0) { if (Database::num_rows($rs) > 0) {
while ($info_coach = Database::fetch_array($rs)) { while ($info_coach = Database::fetch_array($rs)) {
$coachs[] = api_get_person_name( $coachs[] = api_get_person_name(
$info_coach['firstname'], $info_coach['firstname'],
$info_coach['lastname'] $info_coach['lastname']
).' ('.$info_coach['username'].')'; ).' ('.$info_coach['username'].')';
} }
} else { } else {
$coach = get_lang('None'); $coach = get_lang('None');
@ -273,12 +280,12 @@ if ($allowTutors === 'true') {
//hide_course_breadcrumb the parameter has been added to hide the //hide_course_breadcrumb the parameter has been added to hide the
// name of the course, that appeared in the default $interbreadcrumb // name of the course, that appeared in the default $interbreadcrumb
echo ' echo '
<tr> <tr>
<td>'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session), '</td> <td>'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session), '</td>
<td>'.$coach.'</td> <td>'.$coach.'</td>
<td>'.$course['nbr_users'].'</td> <td>'.$course['nbr_users'].'</td>
</tr>'; </tr>';
} }
} }
?> ?>
@ -301,8 +308,8 @@ if ($allowTutors === 'true') {
if ($session['nbr_users'] == 0) { if ($session['nbr_users'] == 0) {
echo '<tr> echo '<tr>
<td colspan="2">'.get_lang('NoUsersForThisSession').'</td> <td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
</tr>'; </tr>';
} else { } else {
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname'; $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
@ -366,4 +373,4 @@ if ($allowTutors === 'true') {
api_not_allowed(); api_not_allowed();
} }
// footer // footer
Display :: display_footer(); Display::display_footer();

Loading…
Cancel
Save