MDL-60681 lib/tablelib.php: Make flexible_table class better extendable
authorTim Schroeder <tim.schroeder.90@gmail.com>
Thu, 7 Dec 2017 13:23:16 +0000 (14:23 +0100)
committerTim Schroeder <t.schroeder@itc.rwth-aachen.de>
Fri, 13 Apr 2018 14:52:52 +0000 (16:52 +0200)
Previously the member functions get_initial_first and get_initial_last of flexible_table were public but deprecated due to being no
longer used. Now they are used by print_initials_bar and made protected. That allows classes deriving from flexible_table to access
the first and last name initials without having to use deprecated methods.

lib/tablelib.php

index 835c751..8235cbf 100644 (file)
@@ -913,12 +913,8 @@ class flexible_table {
     /**
      * This function is not part of the public api.
      * @return string initial of first name we are currently filtering by
-     *
-     * @deprecated since Moodle 3.3
      */
     function get_initial_first() {
-        debugging('Method get_initial_first() is no longer used and has been deprecated, ' .
-            'to print initials bar call print_initials_bar()', DEBUG_DEVELOPER);
         if (!$this->use_initials) {
             return NULL;
         }
@@ -929,12 +925,8 @@ class flexible_table {
     /**
      * This function is not part of the public api.
      * @return string initial of last name we are currently filtering by
-     *
-     * @deprecated since Moodle 3.3
      */
     function get_initial_last() {
-        debugging('Method get_initial_last() is no longer used and has been deprecated, ' .
-            'to print initials bar call print_initials_bar()', DEBUG_DEVELOPER);
         if (!$this->use_initials) {
             return NULL;
         }
@@ -982,21 +974,17 @@ class flexible_table {
     function print_initials_bar() {
         global $OUTPUT;
 
-        if ((!empty($this->prefs['i_last']) || !empty($this->prefs['i_first']) ||$this->use_initials)
-            && isset($this->columns['fullname'])) {
-
-            if (!empty($this->prefs['i_first'])) {
-                $ifirst = $this->prefs['i_first'];
-            } else {
-                $ifirst = '';
-            }
-
-            if (!empty($this->prefs['i_last'])) {
-                $ilast = $this->prefs['i_last'];
-            } else {
-                $ilast = '';
-            }
+        $ifirst = $this->get_initial_first();
+        $ilast = $this->get_initial_last();
+        if (is_null($ifirst)) {
+            $ifirst = '';
+        }
+        if (is_null($ilast)) {
+            $ilast = '';
+        }
 
+        if ((!empty($ifirst) || !empty($ilast) ||$this->use_initials)
+                && isset($this->columns['fullname'])) {
             $prefixfirst = $this->request[TABLE_VAR_IFIRST];
             $prefixlast = $this->request[TABLE_VAR_ILAST];
             echo $OUTPUT->initials_bar($ifirst, 'firstinitial', get_string('firstname'), $prefixfirst, $this->baseurl);