Exemple #1
0
}
// We need to check that alternativefullnameformat is not set to '' or language.
// We don't need to check the fullnamedisplay setting here as the fullname function call further down has
// the override parameter set to true.
$fullnamesetting = $CFG->alternativefullnameformat;
// If we are using language or it is empty, then retrieve the default user names of just 'firstname' and 'lastname'.
if ($fullnamesetting == 'language' || empty($fullnamesetting)) {
    // Set $a variables to return 'firstname' and 'lastname'.
    $a = new stdClass();
    $a->firstname = 'firstname';
    $a->lastname = 'lastname';
    // Getting the fullname display will ensure that the order in the language file is maintained.
    $fullnamesetting = get_string('fullnamedisplay', null, $a);
}
// Order in string will ensure that the name columns are in the correct order.
$usernames = order_in_string($allusernamefields, $fullnamesetting);
$fullnamedisplay = array();
foreach ($usernames as $name) {
    // Use the link from $$column for sorting on the user's name.
    $fullnamedisplay[] = ${$name};
}
// All of the names are in one column. Put them into a string and separate them with a /.
$fullnamedisplay = implode(' / ', $fullnamedisplay);
// If $sort = name then it is the default for the setting and we should use the first name to sort by.
if ($sort == "name") {
    // Use the first item in the array.
    $sort = reset($usernames);
}
//$course_sql = "JO";
list($extrasql, $params) = $ufiltering->get_sql_filter();
$users = $ufiltering->get_users_listing($sort, $dir, $page * $perpage, $perpage, $extrasql, $params, $systemcontext);
 public function test_order_in_string()
 {
     $this->resetAfterTest();
     // Return an array in an order as they are encountered in a string.
     $valuearray = array('second', 'firsthalf', 'first');
     $formatstring = 'first firsthalf some other text (second)';
     $expectedarray = array('0' => 'first', '6' => 'firsthalf', '33' => 'second');
     $this->assertEquals($expectedarray, order_in_string($valuearray, $formatstring));
     // Try again with a different order for the format.
     $valuearray = array('second', 'firsthalf', 'first');
     $formatstring = 'firsthalf first second';
     $expectedarray = array('0' => 'firsthalf', '10' => 'first', '16' => 'second');
     $this->assertEquals($expectedarray, order_in_string($valuearray, $formatstring));
     // Try again with yet another different order for the format.
     $valuearray = array('second', 'firsthalf', 'first');
     $formatstring = 'start seconds away second firstquater first firsthalf';
     $expectedarray = array('19' => 'second', '38' => 'first', '44' => 'firsthalf');
     $this->assertEquals($expectedarray, order_in_string($valuearray, $formatstring));
 }
 /**
  * This function is not part of the public api.
  */
 function print_headers()
 {
     global $CFG, $OUTPUT;
     echo html_writer::start_tag('thead');
     echo html_writer::start_tag('tr');
     foreach ($this->columns as $column => $index) {
         $icon_hide = '';
         if ($this->is_collapsible) {
             $icon_hide = $this->show_hide_link($column, $index);
         }
         $primary_sort_column = '';
         $primary_sort_order = '';
         if (reset($this->sess->sortby)) {
             $primary_sort_column = key($this->sess->sortby);
             $primary_sort_order = current($this->sess->sortby);
         }
         switch ($column) {
             case 'fullname':
                 // Check the full name display for sortable fields.
                 $nameformat = $CFG->fullnamedisplay;
                 if ($nameformat == 'language') {
                     $nameformat = get_string('fullnamedisplay');
                 }
                 $requirednames = order_in_string(array('firstname', 'lastname'), $nameformat);
                 if (!empty($requirednames)) {
                     if ($this->is_sortable($column)) {
                         // Done this way for the possibility of more than two sortable full name display fields.
                         $this->headers[$index] = '';
                         foreach ($requirednames as $name) {
                             $sortname = $this->sort_link(get_string($name), $name, $primary_sort_column === $name, $primary_sort_order);
                             $this->headers[$index] .= $sortname . ' / ';
                         }
                         $this->headers[$index] = substr($this->headers[$index], 0, -3);
                     }
                 }
                 break;
             case 'userpic':
                 // do nothing, do not display sortable links
                 break;
             default:
                 if ($this->is_sortable($column)) {
                     $this->headers[$index] = $this->sort_link($this->headers[$index], $column, $primary_sort_column == $column, $primary_sort_order);
                 }
         }
         $attributes = array('class' => 'header c' . $index . $this->column_class[$column], 'scope' => 'col');
         if ($this->headers[$index] === NULL) {
             $content = ' ';
         } else {
             if (!empty($this->sess->collapse[$column])) {
                 $content = $icon_hide;
             } else {
                 if (is_array($this->column_style[$column])) {
                     $attributes['style'] = $this->make_styles_string($this->column_style[$column]);
                 }
                 $content = $this->headers[$index] . html_writer::tag('div', $icon_hide, array('class' => 'commands'));
             }
         }
         echo html_writer::tag('th', $content, $attributes);
     }
     echo html_writer::end_tag('tr');
     echo html_writer::end_tag('thead');
 }
Exemple #4
0
/**
 * Gets enabled (from fullnameformate setting) user name fields in appropriate order.
 *
 * @return array Enabled user name fields.
 */
function useredit_get_enabled_name_fields()
{
    global $CFG;
    // Get all of the other name fields which are not ranked as necessary.
    $additionalusernamefields = array_diff(get_all_user_name_fields(), array('firstname', 'lastname'));
    // Find out which additional name fields are actually being used from the fullnamedisplay setting.
    $enabledadditionalusernames = array();
    foreach ($additionalusernamefields as $enabledname) {
        if (strpos($CFG->fullnamedisplay, $enabledname) !== false) {
            $enabledadditionalusernames[] = $enabledname;
        }
    }
    // Order all of the name fields in the postion they are written in the fullnamedisplay setting.
    $enabledadditionalusernames = order_in_string($enabledadditionalusernames, $CFG->fullnamedisplay);
    return $enabledadditionalusernames;
}
Exemple #5
0
$allusernames = get_all_user_name_fields(false, null, null, null, true);
// Initialise the variable for the user's names in the table header.
$usernameheader = null;
// Get the alternative full name format for users with the viewfullnames capability.
$fullusernames = $CFG->alternativefullnameformat;
// If fullusernames is empty or accidentally set to language then fall back to default of just first and last name.
if ($fullusernames == 'language' || empty($fullusernames)) {
    // Set $a variables to return 'firstname' and 'lastname'.
    $a = new stdClass();
    $a->firstname = 'firstname';
    $a->lastname = 'lastname';
    // Getting the fullname display will ensure that the order in the language file is maintained.
    $usernameheader = explode(' ', get_string('fullnamedisplay', null, $a));
} else {
    // If everything is as expected then put them in the order specified by the alternative full name format setting.
    $usernameheader = order_in_string($allusernames, $fullusernames);
}
// Loop through each name and return the language string.
foreach ($usernameheader as $key => $username) {
    $userdetails[$username] = get_string($username);
}
$extrafields = get_extra_user_fields($context);
foreach ($extrafields as $field) {
    $userdetails[$field] = get_user_field_name($field);
}
$fields = array('userdetails' => $userdetails, 'lastcourseaccess' => get_string('lastcourseaccess'), 'role' => get_string('roles', 'role'), 'group' => get_string('groups', 'group'), 'enrol' => get_string('enrolmentinstances', 'enrol'));
// Remove hidden fields if the user has no access
if (!has_capability('moodle/course:viewhiddenuserfields', $context)) {
    $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
    if (isset($hiddenfields['lastaccess'])) {
        unset($fields['lastcourseaccess']);
 /**
  * fills workbook (either XLSX or ODS) with data
  *
  * @param MoodleExcelWorkbook $workbook workbook to put data into
  * @param stdClass[] $data userdata with headline at index 0
  * @param stdClass[] $orderby current sort-array
  * @param string[] $collapsed current collapsed columns
  */
 private function userlist_fill_workbook(&$workbook, $data = array(), $orderby = array(), $collapsed = array())
 {
     global $SESSION, $CFG;
     $orientation = optional_param('orientation', 0, PARAM_BOOL);
     if (count($data) > 0) {
         if (count($data) > 1) {
             // General information? unused at the moment!
             $worksheet = $workbook->add_worksheet(get_string('all'));
             if (is_a($worksheet, 'Moodle_Excel_Worksheet')) {
                 if ($orientation) {
                     $worksheet->pear_excel_worksheet->setLandscape();
                 } else {
                     $worksheet->pear_excel_worksheet->setPortrait();
                 }
             }
         }
         // Prepare formats!
         $headlineprop = array('size' => 12, 'bold' => 1, 'HAlign' => 'center', 'bottom' => 2, 'VAlign' => 'vcenter');
         $headlineformat = $workbook->add_format($headlineprop);
         $headlineformat->set_right(1);
         $headlineformat->set_align('center');
         $headlineformat->set_align('vcenter');
         $headlinelast = $workbook->add_format($headlineprop);
         $headlinelast->set_align('center');
         $headlinelast->set_align('vcenter');
         $headlinelast->set_left(1);
         $headlinenb = $workbook->add_format($headlineprop);
         $headlinenb->set_align('center');
         $headlinenb->set_align('vcenter');
         unset($headlineprop['bottom']);
         $headlinenbb = $workbook->add_format($headlineprop);
         $headlinenbb->set_align('center');
         $headlinenbb->set_align('vcenter');
         $regentryprop = array('size' => 10, 'align' => 'left');
         $queueentryprop = $regentryprop;
         $queueentryprop['italic'] = true;
         $queueentryprop['color'] = 'grey';
         $regentryformat = $workbook->add_format($regentryprop);
         $regentryformat->set_right(1);
         $regentryformat->set_align('vcenter');
         $regentrylast = $workbook->add_format($regentryprop);
         $regentrylast->set_align('vcenter');
         $noregentriesformat = $workbook->add_format($regentryprop);
         $noregentriesformat->set_align('center');
         $noregentriesformat->set_align('vcenter');
         $noregentriesformat->set_right(1);
         $queueentryformat = $workbook->add_format($queueentryprop);
         $queueentryformat->set_right(1);
         $queueentryformat->set_align('vcenter');
         $queueentrylast = $workbook->add_format($queueentryprop);
         $queueentrylast->set_align('vcenter');
         $noqueueentriesformat = $workbook->add_format($queueentryprop);
         $noqueueentriesformat->set_align('center');
         $noqueueentriesformat->set_align('vcenter');
         // Start row for groups general sheet!
         $j = 0;
         // We create a dummy user-object to get the fullname-format!
         $dummy = new stdClass();
         $namefields = get_all_user_name_fields();
         foreach ($namefields as $namefield) {
             $dummy->{$namefield} = $namefield;
         }
         $fullnameformat = fullname($dummy);
         // Now get the ones used in fullname in the correct order!
         $namefields = order_in_string($namefields, $fullnameformat);
         $columnwidth = array(0 => 26, 'fullname' => 26, 'firstname' => 20, 'surname' => 20, 'email' => 35, 'registrations' => 47, 'queues_rank' => 7.5, 'queues_grp' => 47);
         // Unit: mm!
         foreach ($data as $key => $user) {
             if ($key == 0) {
                 // Headline!
                 $k = 0;
                 // First we output every namefield from used by fullname in exact the defined order!
                 foreach ($namefields as $namefield) {
                     $worksheet->write_string($j, $k, get_user_field_name($namefield), $headlineformat);
                     $worksheet->write_blank($j + 1, $k, $headlineformat);
                     $worksheet->merge_cells($j, $k, $j + 1, $k);
                     $hidden = in_array($namefield, $collapsed) ? true : false;
                     $columnwidth[$namefield] = empty($columnwidth[$namefield]) ? $columnwidth[0] : $columnwidth[$namefield];
                     $worksheet->set_column($k, $k, $columnwidth[$namefield], null, $hidden);
                     $k++;
                 }
                 // ...k = n!
                 if (!empty($CFG->showuseridentity)) {
                     $fields = explode(',', $CFG->showuseridentity);
                     foreach ($fields as $field) {
                         $worksheet->write_string($j, $k, get_user_field_name($field), $headlineformat);
                         $worksheet->write_blank($j + 1, $k, $headlineformat);
                         $hidden = in_array($field, $collapsed) ? true : false;
                         $columnwidth[$field] = empty($columnwidth[$field]) ? $columnwidth[0] : $columnwidth[$field];
                         $worksheet->set_column($k, $k, $columnwidth[$field], null, $hidden);
                         $worksheet->merge_cells($j, $k, $j + 1, $k);
                         $k++;
                         // ...k = n+x!
                     }
                 } else {
                     $worksheet->write_string($j, $k, get_user_field_name('idnumber'), $headlineformat);
                     $worksheet->write_blank($j + 1, $k, $headlineformat);
                     $hidden = in_array('idnumber', $collapsed) ? true : false;
                     $columnwidth['idnumber'] = empty($columnwidth['idnumber']) ? $columnwidth[0] : $columnwidth['idnumber'];
                     $worksheet->set_column($k, $k, $columnwidth['idnumber'], null, $hidden);
                     $worksheet->merge_cells($j, $k, $j + 1, $k);
                     $k++;
                     // ...k = n+1!
                     $worksheet->write_string($j, $k, get_user_field_name('email'), $headlineformat);
                     $worksheet->write_blank($j + 1, $k, $headlineformat);
                     $hidden = in_array('email', $collapsed) ? true : false;
                     $columnwidth['email'] = empty($columnwidth['email']) ? $columnwidth[0] : $columnwidth['email'];
                     $worksheet->set_column($k, $k, $columnwidth['email'], null, $hidden);
                     $worksheet->merge_cells($j, $k, $j + 1, $k);
                     $k++;
                     // ...k = n+2!
                 }
                 $worksheet->write_string($j, $k, $user['registrations'], $headlineformat);
                 $worksheet->write_blank($j + 1, $k, $headlineformat);
                 $hidden = in_array('registrations', $collapsed) ? true : false;
                 $columnwidth['registrations'] = empty($columnwidth['registrations']) ? $columnwidth[0] : $columnwidth['registrations'];
                 $worksheet->set_column($k, $k, $columnwidth['registrations'], null, $hidden);
                 $worksheet->merge_cells($j, $k, $j + 1, $k);
                 $k++;
                 // ...k = n+3!
                 $worksheet->write_string($j, $k, $user['queues'], $headlinenbb);
                 $worksheet->write_blank($j, $k + 1, $headlinenbb);
                 $hidden = in_array('queues', $collapsed) ? true : false;
                 $columnwidth['queues_rank'] = empty($columnwidth['queues_rank']) ? $columnwidth[0] : $columnwidth['queues_rank'];
                 $worksheet->set_column($k, $k, $columnwidth['queues_rank'], null, $hidden);
                 $columnwidth['queues_grp'] = empty($columnwidth['queues_grp']) ? $columnwidth[0] : $columnwidth['queues_grp'];
                 $worksheet->set_column($k + 1, $k + 1, $columnwidth['queues_grp'], null, $hidden);
                 $worksheet->merge_cells($j, $k, $j, $k + 1);
                 $worksheet->write_string($j + 1, $k, get_string('rank', 'grouptool'), $headlinelast);
                 $worksheet->write_string($j + 1, $k + 1, get_string('group', 'group'), $headlinenb);
                 $k += 2;
                 // ...k = n+5!
                 $rows = 2;
             } else {
                 $k = 0;
                 $rows = max(array(1, count($user['registrations']), count($user['queues'])));
                 // First we output every namefield from used by fullname in exact the defined order!
                 foreach ($namefields as $namefield) {
                     if (empty($user[$namefield])) {
                         $user[$namefield] = '';
                     }
                     $worksheet->write_string($j, $k, $user[$namefield], $regentryformat);
                     if ($rows > 1) {
                         $worksheet->merge_cells($j, $k, $j + $rows - 1, $k);
                     }
                     $k++;
                 }
                 // ...k = n!
                 if (!empty($CFG->showuseridentity)) {
                     $fields = explode(',', $CFG->showuseridentity);
                     foreach ($fields as $field) {
                         if (empty($user[$field])) {
                             $worksheet->write_blank($j, $k, $regentryformat);
                         } else {
                             $worksheet->write_string($j, $k, $user[$field], $regentryformat);
                         }
                         if ($rows > 1) {
                             $worksheet->merge_cells($j, $k, $j + $rows - 1, $k);
                         }
                         $k++;
                         // ...k = n+x!
                     }
                 } else {
                     $worksheet->write_string($j, $k, $user['idnumber'], $regentryformat);
                     if ($rows > 1) {
                         $worksheet->merge_cells($j, $k, $j + $rows - 1, $k);
                     }
                     $k++;
                     // ...k = n+1!
                     $worksheet->write_string($j, $k, $user['email'], $regentryformat);
                     if ($rows > 1) {
                         $worksheet->merge_cells($j, $k, $j + $rows - 1, $k);
                     }
                     $k++;
                     // ...k = n+2!
                 }
                 for ($i = 0; $i < $rows; $i++) {
                     if ($i != 0) {
                         for ($m = 0; $m < $k; $m++) {
                             // Write all the empty cells!
                             $worksheet->write_blank($j + $i, $m, $regentryformat);
                         }
                     }
                     if (count($user['registrations']) == 0 && $i == 0) {
                         $worksheet->write_string($j, $k, get_string('no_registrations', 'grouptool'), $noregentriesformat);
                         if ($rows > 1) {
                             $worksheet->merge_cells($j, $k, $j + $rows - 1, $k);
                         }
                     } else {
                         if (key_exists($i, $user['registrations'])) {
                             $worksheet->write_string($j + $i, $k, $user['registrations'][$i], $regentryformat);
                         } else {
                             $worksheet->write_blank($j + $i, $k, $regentryformat);
                         }
                     }
                     if (count($user['queues']) == 0 && $i == 0) {
                         $worksheet->write_string($j, $k + 1, get_string('nowhere_queued', 'grouptool'), $noqueueentriesformat);
                         $worksheet->merge_cells($j, $k + 1, $j + $rows - 1, $k + 2);
                     } else {
                         if (key_exists($i, $user['queues'])) {
                             $worksheet->write_number($j + $i, $k + 1, $user['queues'][$i]['rank'], $queueentrylast);
                             $worksheet->write_string($j + $i, $k + 2, $user['queues'][$i]['name'], $queueentrylast);
                         } else {
                             $worksheet->write_blank($j + $i, $k + 1, $queueentrylast);
                             $worksheet->write_blank($j + $i, $k + 2, $queueentrylast);
                         }
                     }
                 }
                 $k += 3;
             }
             $j += $rows;
             // We use 1 row space between groups!
         }
     }
 }