/**
  * Get appropriate subcategories visible for the user (and optionally the course and session)
  * @param int $stud_id student id (default: all students)
  * @param string   Course code (optional)
  * @param int      Session ID (optional)
  * @return  array   Array of subcategories
  */
 public function get_subcategories($stud_id = null, $course_code = null, $session_id = null, $order = null)
 {
     // 1 student
     if (isset($stud_id)) {
         // special case: this is the root
         if ($this->id == 0) {
             return Category::get_root_categories_for_student($stud_id, $course_code, $session_id);
         } else {
             return Category::load(null, null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1, $session_id, $order);
         }
     } else {
         // all students
         // course admin
         if (api_is_allowed_to_edit() && !api_is_platform_admin()) {
             // root
             if ($this->id == 0) {
                 return $this->get_root_categories_for_teacher(api_get_user_id(), $course_code, $session_id, false);
                 // inside a course
             } elseif (!empty($this->course_code)) {
                 return Category::load(null, null, $this->course_code, $this->id, null, $session_id, $order);
             } elseif (!empty($course_code)) {
                 return Category::load(null, null, $course_code, $this->id, null, $session_id, $order);
                 // course independent
             } else {
                 return Category::load(null, api_get_user_id(), 0, $this->id, null);
             }
         } elseif (api_is_platform_admin()) {
             // platform admin
             //we explicitly avoid listing subcats from another session
             return Category::load(null, null, $course_code, $this->id, null, $session_id, $order);
         }
     }
     return array();
 }
 /**
  * Get appropriate subcategories visible for the user (and optionally the course and session)
  * @param int    $stud_id student id (default: all students)
  * @param string $course_code Course code (optional)
  * @param int    $session_id Session ID (optional)
  * @param bool   $order
  * @return array Array of subcategories
  */
 public function get_subcategories($stud_id = null, $course_code = null, $session_id = null, $order = null)
 {
     if (!empty($session_id)) {
         /*$tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
           $sql = 'SELECT id FROM '.$tbl_grade_categories. ' WHERE session_id = '.$session_id;
           $result_session = Database::query($sql);
           if (Database::num_rows($result_session) > 0) {
               $data_session = Database::fetch_array($result_session);
               $parent_id = $data_session['id'];
               return Category::load(null, null, null, $parent_id, null, null, $order);
           }*/
     }
     // 1 student
     if (isset($stud_id)) {
         // Special case: this is the root
         if ($this->id == 0) {
             return Category::get_root_categories_for_student($stud_id, $course_code, $session_id);
         } else {
             return Category::load(null, null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1, $session_id, $order);
         }
     } else {
         // All students
         // Course admin
         if (api_is_allowed_to_edit() && !api_is_platform_admin()) {
             // root
             if ($this->id == 0) {
                 return $this->get_root_categories_for_teacher(api_get_user_id(), $course_code, $session_id, false);
                 // inside a course
             } elseif (!empty($this->course_code)) {
                 return Category::load(null, null, $this->course_code, $this->id, null, $session_id, $order);
             } elseif (!empty($course_code)) {
                 return Category::load(null, null, $course_code, $this->id, null, $session_id, $order);
                 // course independent
             } else {
                 return Category::load(null, api_get_user_id(), 0, $this->id, null);
             }
         } elseif (api_is_platform_admin()) {
             // platform admin
             // we explicitly avoid listing subcats from another session
             return Category::load(null, null, $course_code, $this->id, null, $session_id, $order);
         }
     }
     return array();
 }