本文整理汇总了PHP中flexible_table::add_data_keyed方法的典型用法代码示例。如果您正苦于以下问题:PHP flexible_table::add_data_keyed方法的具体用法?PHP flexible_table::add_data_keyed怎么用?PHP flexible_table::add_data_keyed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flexible_table
的用法示例。
在下文中一共展示了flexible_table::add_data_keyed方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run_table_test
protected function run_table_test($columns, $headers, $sortable, $collapsible, $suppress, $nosorting, $data, $pagesize)
{
$table = new flexible_table('tablelib_test');
$table->define_columns($columns);
$table->define_headers($headers);
$table->define_baseurl('/invalid.php');
$table->sortable($sortable);
$table->collapsible($collapsible);
foreach ($suppress as $column) {
$table->column_suppress($column);
}
foreach ($nosorting as $column) {
$table->no_sorting($column);
}
$table->setup();
$table->pagesize($pagesize, count($data));
foreach ($data as $row) {
$table->add_data_keyed($row);
}
$table->finish_output();
}
示例2: count
/**
* Prints a table with users and their attempts
*
* @return void
* @todo Add current grade to the table
* Finnish documenting
**/
function view_question($quiz, $question, $totalattempts, $ungraded)
{
global $CFG;
$usercount = count($this->users);
// set up table
$tablecolumns = array('picture', 'fullname', 'timefinish', 'grade');
$tableheaders = array('', get_string('name'), get_string("completedon", "quiz"), '');
$table = new flexible_table('mod-quiz-report-grading');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($this->viewurl->out());
$table->sortable(true);
$table->initialbars($usercount > 20);
// will show initialbars if there are more than 20 users
$table->pageable(true);
$table->collapsible(true);
$table->column_suppress('fullname');
$table->column_suppress('picture');
$table->column_suppress('grade');
$table->column_class('picture', 'picture');
// attributes in the table tag
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
$table->set_attribute('align', 'center');
//$table->set_attribute('width', '50%');
// get it ready!
$table->setup();
list($select, $from, $where) = $this->attempts_sql($quiz->id, true, $question->id);
if ($table->get_sql_where()) {
// forgot what this does
$where .= 'AND ' . $table->get_sql_where();
}
// sorting of the table
if ($sort = $table->get_sql_sort()) {
$sort = 'ORDER BY ' . $sort;
// seems like I would need to have u. or qa. infront of the ORDER BY attribues... but seems to work..
} else {
// my default sort rule
$sort = 'ORDER BY u.firstname, u.lastname, qa.timefinish ASC';
}
// set up the pagesize
$table->pagesize(QUIZ_REPORT_DEFAULT_PAGE_SIZE, $totalattempts);
// get the attempts and process them
if ($attempts = get_records_sql($select . $from . $where . $sort, $table->get_page_start(), $table->get_page_size())) {
// grade all link
$links = "<strong><a href=\"report.php?mode=grading&gradeall=1&q={$quiz->id}&questionid={$question->id}\">" . get_string('gradeall', 'quiz_grading', $totalattempts) . '</a></strong>';
if ($ungraded > 0) {
$links .= "<br /><strong><a href=\"report.php?mode=grading&gradeungraded=1&q={$quiz->id}&questionid={$question->id}\">" . get_string('gradeungraded', 'quiz_grading', $ungraded) . '</a></strong>';
if ($ungraded > QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE) {
$links .= "<br /><strong><a href=\"report.php?mode=grading&gradenextungraded=1&q={$quiz->id}&questionid={$question->id}\">" . get_string('gradenextungraded', 'quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE) . '</a></strong>';
}
}
$table->add_data_keyed(array('grade' => $links));
$table->add_separator();
foreach ($attempts as $attempt) {
$picture = print_user_picture($attempt->userid, $quiz->course, $attempt->picture, false, true);
// link to student profile
$userlink = "<a href=\"{$CFG->wwwroot}/user/view.php?id={$attempt->userid}&course={$quiz->course}\">" . fullname($attempt, true) . '</a>';
$gradedclass = question_state_is_graded($attempt) ? ' class="highlightgraded" ' : '';
$gradedstring = question_state_is_graded($attempt) ? ' ' . get_string('graded', 'quiz_grading') : '';
// link for the attempt
$attemptlink = "<a {$gradedclass}href=\"report.php?mode=grading&q={$quiz->id}&questionid={$question->id}&attemptid={$attempt->attemptid}\">" . userdate($attempt->timefinish, get_string('strftimedatetime')) . $gradedstring . '</a>';
// grade all attempts for this user
$gradelink = "<a href=\"report.php?mode=grading&q={$quiz->id}&questionid={$question->id}&userid={$attempt->userid}\">" . get_string('grade') . '</a>';
$table->add_data(array($picture, $userlink, $attemptlink, $gradelink));
}
$table->add_separator();
$table->add_data_keyed(array('grade' => $links));
// print everything here
echo '<div id="tablecontainer">';
$table->print_html();
echo '</div>';
} else {
notify(get_string('noattemptstoshow', 'quiz'));
}
}
示例3: display
//.........这里部分代码省略.........
}
}
if (!$download) {
$table->add_data($row);
} else {
if ($download == 'Excel' or $download == 'ODS') {
$colnum = 0;
foreach ($row as $item) {
$myxls->write($rownum, $colnum, $item, $format);
$colnum++;
}
$rownum++;
} else {
if ($download == 'CSV') {
$text = implode("\t", $row);
echo $text . " \n";
}
}
}
}
//end of adding data from attempts data to table / download
//now add averages :
if (!$download && $attempts) {
$averagesql = "SELECT AVG(qg.grade) AS grade " . "FROM {$CFG->prefix}quiz_grades qg " . "WHERE quiz=" . $quiz->id;
$table->add_separator();
if ($groupstudentslist) {
$groupaveragesql = $averagesql . " AND qg.userid IN ({$groupstudentslist})";
$groupaverage = get_record_sql($groupaveragesql);
$groupaveragerow = array('fullname' => get_string('groupavg', 'grades'), 'sumgrades' => round($groupaverage->grade, $quiz->decimalpoints), 'feedbacktext' => quiz_report_feedback_for_grade($groupaverage->grade, $quiz->id));
if ($detailedmarks && $qmsubselect) {
$avggradebyq = quiz_get_average_grade_for_questions($quiz, $groupstudentslist);
$groupaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download);
}
$table->add_data_keyed($groupaveragerow);
}
$overallaverage = get_record_sql($averagesql . " AND qg.userid IN ({$studentslist})");
$overallaveragerow = array('fullname' => get_string('overallaverage', 'grades'), 'sumgrades' => round($overallaverage->grade, $quiz->decimalpoints), 'feedbacktext' => quiz_report_feedback_for_grade($overallaverage->grade, $quiz->id));
if ($detailedmarks && $qmsubselect) {
$avggradebyq = quiz_get_average_grade_for_questions($quiz, $studentslist);
$overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download);
}
$table->add_data_keyed($overallaveragerow);
}
if (!$download) {
// Start form
echo '<div id="tablecontainer">';
echo '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) . '" onsubmit="return confirm(\'' . $strreallydel . '\');">';
echo '<div style="display: none;">';
echo $reporturlwithdisplayoptions->hidden_params_out();
echo '</div>';
echo '<div>';
// Print table
$table->print_html();
// Print "Select all" etc.
if (!empty($attempts) && $candelete) {
echo '<table id="commands">';
echo '<tr><td>';
echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectall', 'quiz') . '</a> / ';
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">' . get_string('selectnone', 'quiz') . '</a> ';
echo ' ';
echo '<input type="submit" value="' . get_string('deleteselected', 'quiz_overview') . '"/>';
echo '</td></tr></table>';
}
// Close form
echo '</div>';
echo '</form></div>';
示例4: microtime
$table->setup();
// Start output.
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
echo html_writer::tag('p', stack_string('stackInstall_input_intro'));
$tests = stack_inputvalidation_test_data::get_all();
// Run the tests.
$allpassed = true;
$notests = 0;
$start = microtime(true);
foreach ($tests as $test) {
$notests++;
if ($test->notes) {
reset($columns);
$firstcol = key($columns);
$table->add_data_keyed(array($firstcol => $test->notes), 'notes');
}
set_time_limit(30);
list($passed, $phpvalid, $phpcasstring, $error, $casvalid, $caserrors, $casdisplay, $casvalue, $answernote) = stack_inputvalidation_test_data::run_test($test);
$allpassed = $allpassed && $passed;
if ($passed) {
$class = 'pass';
$passedcol = stack_string('testsuitepass');
} else {
$class = 'fail';
$passedcol = stack_string('testsuitefail');
}
$display = '';
if ('' != $casdisplay) {
$display = '\\(' . $casdisplay . '\\)';
}
示例5: round
$pertest = round($took / $notests, 5);
echo '<p>' . stack_string('testsuitenotests', array('no' => $notests));
echo '<br/>' . stack_string('testsuiteteststook', array('time' => $rtook));
echo '<br/>' . stack_string('testsuiteteststookeach', array('time' => $pertest));
echo '</p>';
$config = get_config('qtype_stack');
echo html_writer::tag('p', stack_string('healthcheckcache_' . $config->casresultscache));
echo html_writer::tag('p', stack_string('settingcasmaximaversion') . ': ' . $config->maximaversion);
}
if ($anstest) {
if ($allpassed) {
echo $OUTPUT->heading(stack_string('stackInstall_testsuite_pass'), 2, 'pass');
} else {
echo $OUTPUT->heading(stack_string('stackInstall_testsuite_fail'), 2, 'fail');
// Print a copy of the failing rows in a separate table.
$tablef = new flexible_table('stack_answertests');
$tablef->define_columns(array_keys($columns));
$tablef->define_headers(array_values($columns));
$tablef->set_attribute('class', 'generaltable generalbox stacktestsuite');
$tablef->define_baseurl($PAGE->url);
$tablef->setup();
$class = 'fail';
foreach ($failedtable as $row) {
$tablef->add_data_keyed($row, $class);
flush();
}
$table->finish_output();
}
}
// Finish output.
echo $OUTPUT->footer();
示例6: test_persistent_table
public function test_persistent_table()
{
global $SESSION;
$data = $this->generate_data(5, 5);
$columns = $this->generate_columns(5);
$headers = $this->generate_headers(5);
// Testing without persistence first to verify that the results are different.
$table1 = new flexible_table('tablelib_test');
$table1->define_columns($columns);
$table1->define_headers($headers);
$table1->define_baseurl('/invalid.php');
$table1->sortable(true);
$table1->collapsible(true);
$table1->is_persistent(false);
$_GET['thide'] = 'column0';
$_GET['tsort'] = 'column1';
$_GET['tifirst'] = 'A';
$_GET['tilast'] = 'Z';
foreach ($data as $row) {
$table1->add_data_keyed($row);
}
$table1->setup();
// Clear session data between each new table.
unset($SESSION->flextable);
$table2 = new flexible_table('tablelib_test');
$table2->define_columns($columns);
$table2->define_headers($headers);
$table2->define_baseurl('/invalid.php');
$table2->sortable(true);
$table2->collapsible(true);
$table2->is_persistent(false);
unset($_GET);
foreach ($data as $row) {
$table2->add_data_keyed($row);
}
$table2->setup();
$this->assertNotEquals($table1, $table2);
unset($SESSION->flextable);
// Now testing with persistence to check that the tables are the same.
$table3 = new flexible_table('tablelib_test');
$table3->define_columns($columns);
$table3->define_headers($headers);
$table3->define_baseurl('/invalid.php');
$table3->sortable(true);
$table3->collapsible(true);
$table3->is_persistent(true);
$_GET['thide'] = 'column0';
$_GET['tsort'] = 'column1';
$_GET['tifirst'] = 'A';
$_GET['tilast'] = 'Z';
foreach ($data as $row) {
$table3->add_data_keyed($row);
}
$table3->setup();
unset($SESSION->flextable);
$table4 = new flexible_table('tablelib_test');
$table4->define_columns($columns);
$table4->define_headers($headers);
$table4->define_baseurl('/invalid.php');
$table4->sortable(true);
$table4->collapsible(true);
$table4->is_persistent(true);
unset($_GET);
foreach ($data as $row) {
$table4->add_data_keyed($row);
}
$table4->setup();
$this->assertEquals($table3, $table4);
unset($SESSION->flextable);
// Finally, another test with no persistence, but without clearing the session data.
$table5 = new flexible_table('tablelib_test');
$table5->define_columns($columns);
$table5->define_headers($headers);
$table5->define_baseurl('/invalid.php');
$table5->sortable(true);
$table5->collapsible(true);
$table5->is_persistent(true);
$_GET['thide'] = 'column0';
$_GET['tsort'] = 'column1';
$_GET['tifirst'] = 'A';
$_GET['tilast'] = 'Z';
foreach ($data as $row) {
$table5->add_data_keyed($row);
}
$table5->setup();
$table6 = new flexible_table('tablelib_test');
$table6->define_columns($columns);
$table6->define_headers($headers);
$table6->define_baseurl('/invalid.php');
$table6->sortable(true);
$table6->collapsible(true);
$table6->is_persistent(true);
unset($_GET);
foreach ($data as $row) {
$table6->add_data_keyed($row);
}
$table6->setup();
$this->assertEquals($table5, $table6);
}