Minor - Format code, add docs, remove globals

1.10.x
Julio Montoya 10 years ago
parent 20dd96739d
commit e75574fb95
  1. 4
      main/inc/lib/api.lib.php
  2. 151
      main/inc/lib/app_view.php
  3. 47
      main/inc/lib/banner.lib.php
  4. 17
      main/inc/lib/career.lib.php
  5. 1
      main/inc/lib/course_description.lib.php
  6. 2
      main/inc/lib/course_home.lib.php

@ -6089,8 +6089,8 @@ function api_global_admin_can_edit_admin($admin_id_to_check, $my_user_id = null,
$my_user_id = api_get_user_id(); $my_user_id = api_get_user_id();
} }
$iam_a_global_admin = api_is_global_platform_admin($my_user_id); $iam_a_global_admin = api_is_global_platform_admin($my_user_id);
$user_is_global_admin = api_is_global_platform_admin($admin_id_to_check); $user_is_global_admin = api_is_global_platform_admin($admin_id_to_check);
if ($iam_a_global_admin) { if ($iam_a_global_admin) {
// Global admin can edit everything // Global admin can edit everything

@ -8,87 +8,92 @@
*/ */
class ViewException extends Exception {} class ViewException extends Exception {}
class View { class View
{
private $data; private $data;
private $template; private $template;
private $layout; private $layout;
private $tool_path; private $tool_path;
/** /**
* Constructor, init tool path for rendering * Constructor, init tool path for rendering
* @param string tool name (optional) * @param string tool name (optional)
*/ */
public function __construct($toolname = '', $template_path=null) { public function __construct($toolname = '', $template_path=null)
if (!empty($toolname)) { {
if (!empty($toolname)) {
if (isset($template_path)) { if (isset($template_path)) {
$path = $template_path.$toolname.'/'; $path = $template_path.$toolname.'/';
} else { } else {
$path = api_get_path(SYS_CODE_PATH).$toolname.'/'; $path = api_get_path(SYS_CODE_PATH).$toolname.'/';
} }
if (is_dir($path)) { if (is_dir($path)) {
$this->tool_path = $path; $this->tool_path = $path;
} else { } else {
throw new ViewException('View::__construct() $path directory does not exist ' . $path); throw new ViewException('View::__construct() $path directory does not exist ' . $path);
} }
} }
} }
/** /**
* Set data sent from a controller * Set data sent from a controller
* @param array data * @param array data
*/ */
public function set_data($data) { public function set_data($data)
if (!is_array($data)) { {
throw new ViewException('View::set_data() $data must to be an array, you have sent a' . gettype( $data )); if (!is_array($data)) {
} throw new ViewException('View::set_data() $data must to be an array, you have sent a' . gettype( $data ));
$this->data = $data; }
} $this->data = $data;
}
/**
* Set layout view sent from a controller
* @param string layout view
*/
public function set_layout( $layout )
{
$this->layout = $layout;
}
/**
* Set template view sent from a controller
* @param string template view
*/
public function set_template($template)
{
$this->template = $template;
}
/** /**
* Set layout view sent from a controller * Render data to the template and layout views
* @param string layout view */
*/ public function render()
public function set_layout( $layout ) { {
$this->layout = $layout; $content = $this->render_template();
} $target = $this->tool_path.$this->layout.'.php';
if (file_exists($target)) {
/** require_once $target;
* Set template view sent from a controller } else {
* @param string template view throw new ViewException('View::render() invalid file path '.$target);
*/ }
public function set_template($template) { }
$this->template = $template;
}
/**
* Render data to the template and layout views
*/
public function render() {
$content = $this->render_template();
$target = $this->tool_path.$this->layout.'.php';
if (file_exists($target)) {
require_once $target;
} else {
throw new ViewException('View::render() invalid file path '.$target);
}
}
/** /**
* It's used into render method for rendering data in the template and layout views * It's used into render method for rendering data in the template and layout views
* @return String Rendered template (as HTML, most of the time) * @return String Rendered template (as HTML, most of the time)
*/ */
private function render_template() { private function render_template()
$target = $this->tool_path.$this->template.'.php'; {
if (file_exists($target)) { $target = $this->tool_path.$this->template.'.php';
ob_start(); if (file_exists($target)) {
@extract($this->data, EXTR_OVERWRITE); //pass the $this->data array into local scope ob_start();
require_once $target; @extract($this->data, EXTR_OVERWRITE); //pass the $this->data array into local scope
$content = ob_get_clean(); require_once $target;
return $content; $content = ob_get_clean();
} else { return $content;
throw new ViewException('View::render_template() invalid file path '.$target); } else {
} throw new ViewException('View::render_template() invalid file path '.$target);
} }
}
} }
?>

@ -16,7 +16,7 @@
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/ */
function get_tabs() { function get_tabs() {
global $_course; $_course = api_get_course_info();
$navigation = array(); $navigation = array();
@ -27,7 +27,7 @@ function get_tabs() {
// My Courses // My Courses
if(api_is_allowed_to_create_course()) { if (api_is_allowed_to_create_course()) {
// Link to my courses for teachers // Link to my courses for teachers
$navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true'; $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true';
} else { } else {
@ -48,17 +48,17 @@ function get_tabs() {
// Gradebook // Gradebook
if (api_get_setting('gradebook_enable') == 'true') { if (api_get_setting('gradebook_enable') == 'true') {
$navigation['mygradebook']['url'] = api_get_path(WEB_CODE_PATH).'gradebook/gradebook.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '' ); $navigation['mygradebook']['url'] = api_get_path(WEB_CODE_PATH).'gradebook/gradebook.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '' );
$navigation['mygradebook']['title'] = get_lang('MyGradebook'); $navigation['mygradebook']['title'] = get_lang('MyGradebook');
$navigation['mygradebook']['key'] = 'gradebook'; $navigation['mygradebook']['key'] = 'gradebook';
} }
// Reporting // Reporting
if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) { if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
// Link to my space // Link to my space
$navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/'.(api_is_drh()?'session.php':''); $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/'.(api_is_drh()?'session.php':'');
$navigation['session_my_space']['title'] = get_lang('MySpace'); $navigation['session_my_space']['title'] = get_lang('MySpace');
$navigation['session_my_space']['key'] = 'my-space'; $navigation['session_my_space']['key'] = 'my-space';
} else if (api_is_student_boss()) { } else if (api_is_student_boss()) {
$navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH) . 'mySpace/student.php'; $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH) . 'mySpace/student.php';
$navigation['session_my_space']['title'] = get_lang('MySpace'); $navigation['session_my_space']['title'] = get_lang('MySpace');
@ -74,22 +74,22 @@ function get_tabs() {
$navigation['session_my_progress']['url'] .= 'auth/my_progress.php'; $navigation['session_my_progress']['url'] .= 'auth/my_progress.php';
} }
$navigation['session_my_progress']['title'] = get_lang('MyProgress'); $navigation['session_my_progress']['title'] = get_lang('MyProgress');
$navigation['session_my_progress']['key'] = 'my-progress'; $navigation['session_my_progress']['key'] = 'my-progress';
} }
// Social // Social
if (api_get_setting('allow_social_tool')=='true') { if (api_get_setting('allow_social_tool')=='true') {
$navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php'; $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
$navigation['social']['title'] = get_lang('SocialNetwork'); $navigation['social']['title'] = get_lang('SocialNetwork');
$navigation['social']['key'] = 'social-network'; $navigation['social']['key'] = 'social-network';
} }
// Dashboard // Dashboard
if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) { if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
$navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php'; $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
$navigation['dashboard']['title'] = get_lang('Dashboard'); $navigation['dashboard']['title'] = get_lang('Dashboard');
$navigation['dashboard']['key'] = 'dashboard'; $navigation['dashboard']['key'] = 'dashboard';
} }
// Reports // Reports
@ -121,6 +121,7 @@ function get_tabs() {
$navigation['platform_admin']['title'] = get_lang('PlatformAdmin'); $navigation['platform_admin']['title'] = get_lang('PlatformAdmin');
$navigation['platform_admin']['key'] = 'admin'; $navigation['platform_admin']['key'] = 'admin';
} }
return $navigation; return $navigation;
} }
@ -129,7 +130,8 @@ function get_tabs() {
* *
* @return array * @return array
*/ */
function getCustomTabs() { function getCustomTabs()
{
$tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$sql = "SELECT * FROM $tableSettingsCurrent $sql = "SELECT * FROM $tableSettingsCurrent
WHERE variable = 'show_tabs' AND WHERE variable = 'show_tabs' AND
@ -144,7 +146,8 @@ function getCustomTabs() {
return $customTabs; return $customTabs;
} }
function return_logo($theme) { function return_logo($theme)
{
$_course = api_get_course_info(); $_course = api_get_course_info();
$html = ''; $html = '';
$logo = api_get_path(SYS_CSS_PATH).'themes/'.$theme.'/images/header-logo.png'; $logo = api_get_path(SYS_CSS_PATH).'themes/'.$theme.'/images/header-logo.png';
@ -369,7 +372,11 @@ function return_navigation_array()
} }
} }
return array('menu_navigation' => $menu_navigation, 'navigation' => $navigation, 'possible_tabs' => $possible_tabs); return array(
'menu_navigation' => $menu_navigation,
'navigation' => $navigation,
'possible_tabs' => $possible_tabs,
);
} }
function return_menu() function return_menu()

@ -30,7 +30,12 @@ class Career extends Model
*/ */
public function get_count() public function get_count()
{ {
$row = Database::select('count(*) as count', $this->table, array(),'first'); $row = Database::select(
'count(*) as count',
$this->table,
array(),
'first'
);
return $row['count']; return $row['count'];
} }
@ -40,7 +45,11 @@ class Career extends Model
*/ */
public function get_all($where_conditions = array()) public function get_all($where_conditions = array())
{ {
return Database::select('*',$this->table, array('where'=>$where_conditions,'order' =>'name ASC')); return Database::select(
'*',
$this->table,
array('where' => $where_conditions, 'order' => 'name ASC')
);
} }
/** /**
@ -85,8 +94,8 @@ class Career extends Model
/** /**
* Returns a Form validator Obj * Returns a Form validator Obj
* @todo the form should be auto generated * @todo the form should be auto generated
* @param string url * @param string $url
* @param string action add, edit * @param string $action add, edit
* @return obj form validator obj * @return obj form validator obj
*/ */
public function return_form($url, $action) public function return_form($url, $action)

@ -1,5 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* This file contains a class used like library provides functions for * This file contains a class used like library provides functions for
* course description tool. It's also used like model to * course description tool. It's also used like model to

@ -14,7 +14,7 @@ class CourseHome
*/ */
public static function show_tool_3column($cat) public static function show_tool_3column($cat)
{ {
global $_user; $_user = api_get_user_info();
$TBL_ACCUEIL = Database :: get_course_table(TABLE_TOOL_LIST); $TBL_ACCUEIL = Database :: get_course_table(TABLE_TOOL_LIST);
$TABLE_TOOLS = Database :: get_main_table(TABLE_MAIN_COURSE_MODULE); $TABLE_TOOLS = Database :: get_main_table(TABLE_MAIN_COURSE_MODULE);

Loading…
Cancel
Save