Browse Source

Minor - Format code, add docs, remove globals

Julio Montoya 9 years ago
parent
commit
e75574fb95

+ 2 - 2
main/inc/lib/api.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();
     }
 
-    $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);
+    $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);
 
     if ($iam_a_global_admin) {
         // Global admin can edit everything

+ 78 - 73
main/inc/lib/app_view.php

@@ -8,87 +8,92 @@
  */
 
 class ViewException extends Exception {}
-class View {
-	
-	private $data;
-	private $template;
-	private $layout;
+class View
+{
+    private $data;
+    private $template;
+    private $layout;
     private $tool_path;
-   
-   	/**
-   	 * Constructor, init tool path for rendering
-   	 * @param string  tool name (optional)
-   	 */
-	public function __construct($toolname = '', $template_path=null) {
-		if (!empty($toolname)) {
+
+    /**
+     * Constructor, init tool path for rendering
+     * @param string  tool name (optional)
+     */
+    public function __construct($toolname = '', $template_path=null)
+    {
+        if (!empty($toolname)) {
             if (isset($template_path)) {
                 $path = $template_path.$toolname.'/';
             } else {
                 $path = api_get_path(SYS_CODE_PATH).$toolname.'/';
             }
-			if (is_dir($path)) {
-				$this->tool_path = $path;
-			} else {
-				throw new ViewException('View::__construct() $path directory does not exist ' . $path);
-			}
-		}
-	}
-   
+            if (is_dir($path)) {
+                $this->tool_path = $path;
+            } else {
+                throw new ViewException('View::__construct() $path directory does not exist ' . $path);
+            }
+        }
+    }
+
     /**
-   	 * Set data sent from a controller 
-   	 * @param array 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 ));
-		}
-		$this->data = $data;
-	}
-   
+     * Set data sent from a controller
+     * @param array 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 ));
+        }
+        $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 
-   	 * @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;
-	}
+     * 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);
+        }
+    }
 
-	/**
-   	 * 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
-     * @return  String  Rendered template (as HTML, most of the time)   
-   	 */   
-	private function render_template() {		
-		$target = $this->tool_path.$this->template.'.php';
-		if (file_exists($target)) {           
-			ob_start();
-			@extract($this->data, EXTR_OVERWRITE); //pass the $this->data array into local scope
-			require_once $target;
-			$content = ob_get_clean();
-			return $content;
-		} else {
-			throw new ViewException('View::render_template() invalid file path '.$target);
-		}
-	}
+     * 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)
+     */
+    private function render_template()
+    {
+        $target = $this->tool_path.$this->template.'.php';
+        if (file_exists($target)) {
+            ob_start();
+            @extract($this->data, EXTR_OVERWRITE); //pass the $this->data array into local scope
+            require_once $target;
+            $content = ob_get_clean();
+            return $content;
+        } else {
+            throw new ViewException('View::render_template() invalid file path '.$target);
+        }
+    }
 }
-?>

+ 27 - 20
main/inc/lib/banner.lib.php

@@ -16,7 +16,7 @@
  * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  */
 function get_tabs() {
-    global $_course;
+    $_course = api_get_course_info();
 
     $navigation = array();
 
@@ -27,7 +27,7 @@ function get_tabs() {
 
     // My Courses
 
-    if(api_is_allowed_to_create_course()) {
+    if (api_is_allowed_to_create_course()) {
         // Link to my courses for teachers
         $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true';
     } else {
@@ -48,17 +48,17 @@ function get_tabs() {
 
 	// Gradebook
 	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']['title'] = get_lang('MyGradebook');
-            $navigation['mygradebook']['key'] = 'gradebook';
+        $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']['key'] = 'gradebook';
 	}
 
 	// Reporting
 	if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) {
-            // 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']['title'] = get_lang('MySpace');
-            $navigation['session_my_space']['key'] = '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']['title'] = get_lang('MySpace');
+        $navigation['session_my_space']['key'] = 'my-space';
     } else if (api_is_student_boss()) {
         $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH) . 'mySpace/student.php';
         $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']['title'] = get_lang('MyProgress');
-            $navigation['session_my_progress']['key'] = 'my-progress';
+        $navigation['session_my_progress']['title'] = get_lang('MyProgress');
+        $navigation['session_my_progress']['key'] = 'my-progress';
     }
 
 	// Social
 	if (api_get_setting('allow_social_tool')=='true') {
-            $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
-            $navigation['social']['title'] = get_lang('SocialNetwork');
-            $navigation['social']['key'] = 'social-network';
+        $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
+        $navigation['social']['title'] = get_lang('SocialNetwork');
+        $navigation['social']['key'] = 'social-network';
 	}
 
 	// Dashboard
 	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']['title'] = get_lang('Dashboard');
-            $navigation['dashboard']['key'] = 'dashboard';
+        $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
+        $navigation['dashboard']['title'] = get_lang('Dashboard');
+        $navigation['dashboard']['key'] = 'dashboard';
 	}
 
 	// Reports
@@ -121,6 +121,7 @@ function get_tabs() {
         $navigation['platform_admin']['title'] = get_lang('PlatformAdmin');
         $navigation['platform_admin']['key'] = 'admin';
 	}
+
 	return $navigation;
 }
 
@@ -129,7 +130,8 @@ function get_tabs() {
  *
  * @return array
  */
-function getCustomTabs() {
+function getCustomTabs()
+{
     $tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
     $sql = "SELECT * FROM $tableSettingsCurrent
         WHERE variable = 'show_tabs' AND
@@ -144,7 +146,8 @@ function getCustomTabs() {
     return $customTabs;
 }
 
-function return_logo($theme) {
+function return_logo($theme)
+{
     $_course = api_get_course_info();
     $html = '';
     $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()

+ 13 - 4
main/inc/lib/career.lib.php

@@ -30,7 +30,12 @@ class Career extends Model
      */
     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'];
     }
 
@@ -40,7 +45,11 @@ class Career extends Model
      */
     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
      * @todo the form should be auto generated
-     * @param   string  url
-     * @param   string  action add, edit
+     * @param   string  $url
+     * @param   string  $action add, edit
      * @return  obj     form validator obj
      */
     public function return_form($url, $action)

+ 1 - 0
main/inc/lib/course_description.lib.php

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

+ 1 - 1
main/inc/lib/course_home.lib.php

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