本文整理汇总了PHP中order_in_string函数的典型用法代码示例。如果您正苦于以下问题:PHP order_in_string函数的具体用法?PHP order_in_string怎么用?PHP order_in_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了order_in_string函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stdClass
}
// 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);
示例2: test_order_in_string
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));
}
示例3: print_headers
/**
* 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');
}
示例4: useredit_get_enabled_name_fields
/**
* 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;
}
示例5: get_all_user_name_fields
$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']);
示例6: userlist_fill_workbook
/**
* 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++;
//.........这里部分代码省略.........