Browse Source

Minor - format code.

Julio Montoya 11 years ago
parent
commit
f412f99510
1 changed files with 72 additions and 72 deletions
  1. 72 72
      main/gradebook/lib/fe/gradebooktable.class.php

+ 72 - 72
main/gradebook/lib/fe/gradebooktable.class.php

@@ -17,8 +17,8 @@ require_once dirname(__FILE__).'/../be.inc.php';
  * @author Bert Steppé (refactored, optimised)
  * @package chamilo.gradebook
  */
-class GradebookTable extends SortableTable {
-
+class GradebookTable extends SortableTable
+{
 	private $currentcat;
 	private $datagen;
 	private $evals_links;
@@ -27,9 +27,9 @@ class GradebookTable extends SortableTable {
 	/**
 	 * Constructor
 	 */
-    function GradebookTable ($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null) {
-  		//$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
-    	parent :: __construct ('gradebooklist', null, null, (api_is_allowed_to_edit()?1:0));
+    function GradebookTable ($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null)
+    {
+    	parent::__construct ('gradebooklist', null, null, (api_is_allowed_to_edit()?1:0));
 		$this->evals_links = array_merge($evals, $links);
 		$this->currentcat = $currentcat;
         $this->cats = $cats;
@@ -59,20 +59,15 @@ class GradebookTable extends SortableTable {
                 $this->set_header($column++, get_lang('Actions'), false);
             }
 		}
-        //Desactivates the odd/even alt rows in order that the +/- buttons work see #4047
 
-        $this->odd_even_rows_enabled = false;
+        // Deactivates the odd/even alt rows in order that the +/- buttons work see #4047
 
-		/*if (api_is_allowed_to_edit(null, true)) {
-			//$this->set_header($column++, get_lang('CreationDate'),true, 'width="100px"');
-		} elseif (($status<>1)  && !api_is_allowed_to_edit() && (!isset($_GET['selectcat']) || $_GET['selectcat']==0)) {
-			//$this->set_header($column++, get_lang('Date'),true, 'width="100px"');
-		}*/
+        $this->odd_even_rows_enabled = false;
 
-		//admins get an edit column
+		// Admins get an edit column.
 		if (api_is_allowed_to_edit(null, true)) {
 			$this->set_header($column++, get_lang('Modify'), false, 'width="195px"');
-			//actions on multiple selected documents
+			// Actions on multiple selected documents.
 			$this->set_form_actions(array (
 				'setvisible' => get_lang('SetVisible'),
 				'setinvisible' => get_lang('SetInvisible'),
@@ -90,25 +85,36 @@ class GradebookTable extends SortableTable {
 		}
     }
 
-    function get_data() {
+    /**
+     * @return GradebookDataGenerator
+     */
+    function get_data()
+    {
         return $this->datagen;
     }
 
 	/**
 	 * Function used by SortableTable to get total number of items in the table
+     * @return int
 	 */
-	function get_total_number_of_items() {
+	function get_total_number_of_items()
+    {
 		return $this->datagen->get_total_items_count();
 	}
 
     /**
      * Function used by SortableTable to generate the data to display
+     * @param int $from
+     * @param int $per_page
+     * @param int $column
+     * @param string $direction
+     * @param int $sort
+     * @return array|mixed
      */
-    function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) {
-
+    function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null)
+    {
         //variables load in index.php
-        global $my_score_in_gradebook, $certificate_min_score;
-        $scoretotal = 0;
+        global $certificate_min_score;
         // determine sorting type
         $col_adjust = (api_is_allowed_to_edit() ? 1 : 0);
         // By id
@@ -141,12 +147,11 @@ class GradebookTable extends SortableTable {
             $sorting |= GradebookDataGenerator :: GDG_SORT_ASC;
         }
 
-        //status of user in course
+        // Status of user in course.
         $user_id        = api_get_user_id();
         $course_code    = api_get_course_id();
         $session_id     = api_get_session_id();
         $status_user    = api_get_status_of_user_in_course($user_id, $course_code);
-
         $data_array     = $this->datagen->get_data($sorting, $from, $this->per_page);
 
         // generate the data to display
@@ -154,34 +159,31 @@ class GradebookTable extends SortableTable {
         $weight_total_links = 0;
 
         $main_categories = array();
-        $main_cat =  Category :: load(null, null, $course_code, null, null, $session_id, false);
+        $main_cat =  Category::load(null, null, $course_code, null, null, $session_id, false);
 
         $total_categories_weight = 0;
         $scoredisplay = ScoreDisplay :: instance();
 
-        //Categories
-
+        // Categories.
         foreach ($data_array as $data) {
 
             // list of items inside the gradebook (exercises, lps, forums, etc)
             $row  = array();
             $item = $item_category = $data[0];
 
-            $id   = $item->get_id();
-
             //if the item is invisible, wrap it in a span with class invisible
             $invisibility_span_open  = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '<span class="invisible">' : '';
             $invisibility_span_close = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '</span>' : '';
 
+            // Id
             if (api_is_allowed_to_edit(null, true)) {
-                //id
                 $row[] = $this->build_id_column($item);
             }
 
-            //Type
+            // Type.
             $row[] = $this->build_type_column($item);
 
-            //Name
+            // Name.
             if (get_class($item) == 'Category') {
                 $row[] = $invisibility_span_open.'<h3>'.$item->get_name().'</h3>'.$invisibility_span_close;
                 $main_categories[$item->get_id()]['name'] = $item->get_name();
@@ -193,13 +195,10 @@ class GradebookTable extends SortableTable {
             $main_categories[$item->get_id()]['weight']= $item->get_weight();
             $total_categories_weight += $item->get_weight();
 
-            //Description
+            // Description.
             $row[] = $invisibility_span_open.$data[2].$invisibility_span_close;
 
-            //Weight
-            //$row[] = $invisibility_span_open .Display::tag('h4', $data['3'] .' / '.$this->currentcat->get_weight()).$invisibility_span_close;
-            //$average = $data['3']/$this->currentcat->get_weight()*100;
-
+            // Weight.
             $average = $scoredisplay->display_score(array($data['3'], $this->currentcat->get_weight()), SCORE_SIMPLE, SCORE_BOTH, true);
 
             if (api_is_allowed_to_edit(null, true)) {
@@ -218,10 +217,7 @@ class GradebookTable extends SortableTable {
                 $item_value = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
             }
 
-            //Date
-            //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close;
-
-            //Edit (for admins)
+            // Edit (for admins).
             if (api_is_allowed_to_edit(null, true)) {
                 $cat = new Category();
                 $show_message = $cat->show_message_resource_delete($item->get_course_code());
@@ -254,19 +250,19 @@ class GradebookTable extends SortableTable {
                 }
             }
 
-            //Category added
+            // Category added.
             $sortable_data[] = $row;
 
-            // Loading childrens
+            // Loading children
 
             if (get_class($item) == 'Category') {
 
                 $stud_id        = api_get_user_id();
                 $course_code    = api_get_course_id();
-                $session_id        = api_get_session_id();
+                $session_id     = api_get_session_id();
                 $parent_id      = $item->get_id();
 
-                $cats = Category :: load ($parent_id, null, null, null, null, null);
+                $cats = Category::load($parent_id, null, null, null, null, null);
 
                 $allcat  = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
                 $alleval = $cats[0]->get_evaluations($stud_id);
@@ -277,12 +273,11 @@ class GradebookTable extends SortableTable {
 
                 $total_weight = 0;
 
-                //Links
+                // Links.
 
                 foreach ($data_array as $data) {
                     $row  = array();
                     $item = $data[0];
-                    $id   = $item->get_id();
 
                     //if the item is invisible, wrap it in a span with class invisible
                     $invisibility_span_open  = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '<span class="invisible">' : '';
@@ -303,15 +298,7 @@ class GradebookTable extends SortableTable {
                     // Description.
                     $row[] = $invisibility_span_open.$data[2].$invisibility_span_close;
 
-                    //Weight
-                    //$weight = $data[3]/$category_weight*$main_cat[0]->get_weight();
-                    /*$weight = $category_weight * $data[3] / $main_cat[0]->get_weight();
-                    $weight = $main_cat[0]->get_weight()*$weight/$category_weight;*/
-
                     $weight = $data[3];
-
-                    //$extra = " - $data[3]  $category_weight -".$main_cat[0]->get_weight();
-
                     $total_weight += $weight;
 
                     $row[] = $invisibility_span_open.$weight.$invisibility_span_close;
@@ -319,15 +306,12 @@ class GradebookTable extends SortableTable {
                     if (api_is_allowed_to_edit(null, true)) {
                         //$weight_total_links += intval($data[3]);
                     } else {
-                        $cattotal   = Category :: load($_GET['selectcat']);
+                        $cattotal   = Category::load($_GET['selectcat']);
                         $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
                         $item_value = $scoretotal[0];
                     }
 
-                    //Date
-                    //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close;
-
-                    //Admins get an edit column
+                    // Admins get an edit column.
                     if (api_is_allowed_to_edit(null, true)) {
                         $cat = new Category();
                         $show_message = $cat->show_message_resource_delete($item->get_course_code());
@@ -355,7 +339,7 @@ class GradebookTable extends SortableTable {
                     $sortable_data[] = $row;
                 }
 
-                //"Warning row"
+                // "Warning row"
                 if (!empty($data_array)) {
                     if (api_is_allowed_to_edit()) {
                         // Compare the category weight to the sum of all weights inside the category
@@ -366,7 +350,14 @@ class GradebookTable extends SortableTable {
                             $label = Display::return_icon('warning.png', sprintf(get_lang('TotalWeightMustBeX'), $category_weight) );
                             $total = Display::badge($total_weight.' / '.$category_weight, 'warning');
                         }
-                        $row = array(null, null, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<h5>".get_lang('SubTotal').'</h5>',null, $total.' '.$label, 'child_of' =>$parent_id);
+                        $row = array(
+                            null,
+                            null,
+                            "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<h5>".get_lang('SubTotal').'</h5>',
+                            null,
+                            $total.' '.$label,
+                            'child_of' => $parent_id
+                        );
                         $sortable_data[] = $row;
                     }
                 }
@@ -376,6 +367,7 @@ class GradebookTable extends SortableTable {
         if (api_is_allowed_to_edit()) {
             if (count($main_cat) > 1) {
                 $main_weight = intval($main_cat[0]->get_weight());
+
                 if (intval($total_categories_weight) == $main_weight) {
                     $total = score_badges(array($total_categories_weight.' / '.$main_weight, '100'));
                 } else {
@@ -393,12 +385,15 @@ class GradebookTable extends SortableTable {
             if (isset($_GET['selectcat']) && $_GET['selectcat'] > 0 && $view <> 'presence') {
                 $id_cat = intval($_GET['selectcat']);
                 $category = Category :: load($id_cat);
-                //$weight_category = intval($this->build_weight($category[0]));
+
                 $weight_category = intval($this->build_weight($category[0]));
                 $course_code = $this->build_course_code($category[0]);
                 $weight_total_links  = round($weight_total_links);
 
-                if ($weight_total_links > $weight_category || $weight_total_links < $weight_category || $weight_total_links > $weight_category) {
+                if ($weight_total_links > $weight_category ||
+                    $weight_total_links < $weight_category ||
+                    $weight_total_links > $weight_category
+                ) {
                     $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category);
                     $modify_icons  = '<a class="right_link" href="gradebook_edit_cat.php?editcat='.$id_cat.'&cidReq='.$course_code.'">'.Display::return_icon('edit.png', $warning_message, array(), ICON_SIZE_SMALL).'</a>';
                     $warning_message .= $modify_icons;
@@ -455,24 +450,28 @@ class GradebookTable extends SortableTable {
                 }
             }
         }
+
         return $sortable_data;
     }
 
     // Other functions
-
-    private function build_certificate_min_score ($item) {
+    private function build_certificate_min_score ($item)
+    {
         return $item->get_certificate_min_score();
     }
 
-    private function build_weight ($item) {
+    private function build_weight ($item)
+    {
         return $item->get_weight();
     }
 
-    private function build_course_code ($item) {
+    private function build_course_code ($item)
+    {
     	return $item->get_course_code();
     }
 
-    private function build_id_column ($item) {
+    private function build_id_column ($item)
+    {
 		switch ($item->get_item_type()) {
 			// category
 			case 'C' :
@@ -486,7 +485,8 @@ class GradebookTable extends SortableTable {
 		}
 	}
 
-	private function build_type_column ($item, $attributes = array()) {
+	private function build_type_column ($item, $attributes = array())
+    {
 		return build_type_icon_tag($item->get_icon_name(), $attributes);
 	}
 
@@ -496,8 +496,8 @@ class GradebookTable extends SortableTable {
 	 * @param unknown_type $item
 	 * @return string
 	 */
-	private function build_name_link ($item) {
-        //$session_id = api_get_session_id();
+	private function build_name_link ($item)
+    {
 		switch ($item->get_item_type()) {
 			// category
 			case 'C' :
@@ -511,7 +511,6 @@ class GradebookTable extends SortableTable {
 
 				$cat = new Category();
 				$show_message=$cat->show_message_resource_delete($item->get_course_code());
-
 				return '&nbsp;<a href="'.Security::remove_XSS($_SESSION['gradebook_dest']).$prms_uri.'">'
 				 		. $item->get_name()
 				 		. '</a>'
@@ -578,7 +577,8 @@ class GradebookTable extends SortableTable {
 		}
 	}
 
-	private function build_edit_column($item) {
+	private function build_edit_column($item)
+    {
 		switch ($item->get_item_type()) {
 			// category
 			case 'C' :