rewrote the survey and updated the paginator

This commit is contained in:
JT Smith 2004-02-02 03:11:11 +00:00
parent 939dc67dd8
commit 75f6719207
6 changed files with 731 additions and 476 deletions

View file

@ -36,6 +36,15 @@
- Added some processing functions to programatically add meta tags,
javascript, and link tags to the head block of a page from anywhere within
webgui.
- Templatized the Survey.
- Survey now allows for a configurable number of responses from a single user.
- Survey now allows for a configurable number of questions per page.
- Survey now shows progress indicator.
- Survey can now draw from a pool of questions, but does not have to use all
of them.
- Removed depricated functionality from Paginator (see docs/migration.txt).
- Added template variable mechanism to paginator.
- Added a limit option to the page list in the paginator.
- Fixed a bug in AdminBar's clipboard code where a standard hash was
used instead of a CPHash for database access. (Thanks to Steve Simms.)

View file

@ -81,8 +81,19 @@ WebGUI::Form::dateTime() and WebGUI::HTMLForm->dateTime() no longer have
because there is only one field to represent both the date and the time,
unlike before.
5.2 Database Links
The database links API was changed in 6.0. The getHash function was removed and
replaced with a getList function that returns a hash reference.
5.3 Paginator
In 6.0 almost all of the paginator methods were modified in an incompatible
way, including the constructor. We removed depricated parameters from the methods,
which will cause pagination not to function in items that have not been updated.

View file

@ -412,6 +412,7 @@ while (my $data = $a->hashRef) {
}
$a->finish;
WebGUI::SQL->write("alter table SQLReport drop column template");
WebGUI::SQL->write("alter table SQLReport drop column convertCarriageReturns");
@ -466,6 +467,54 @@ WebGUI::SQL->write("update page set wobjectPrivileges=$session{setting}{wobjectP
WebGUI::SQL->write("delete from settings where name='wobjectPrivileges'");
#--------------------------------------------
print "\tMigrating surveys.\n" unless ($quiet);
WebGUI::SQL->write("alter table Survey_response rename Survey_questionResponse");
WebGUI::SQL->write("update Survey_questionResponse set userId='1' where userId='c4ca4238'");
WebGUI::SQL->write("alter table Survey_questionResponse drop primary key");
WebGUI::SQL->write("alter table Survey_questionResponse add primary key (Survey_questionId, Survey_answerId, Survey_responseId)");
WebGUI::SQL->write("create table Survey_response (Survey_id int, Survey_responseId int not null primary key, userId varchar(11),
username varchar(255), ipAddress varchar(15), startDate int, endDate int, isComplete int not null default 0)");
my $a = WebGUI::SQL->read("select Survey_id from Survey");
while (my ($surveyId) = $a->array) {
my $b = WebGUI::SQL->read("select distinct userId from Survey_questionResponse where Survey_id=$surveyId");
while (my ($userId) = $b->array) {
my ($username,$ipAddress) = WebGUI::SQL->quickArray("select username,ipAddress from Survey_questionResponse where Survey_id=$surveyId and
userId=".quote($userId));
WebGUI::SQL->write("insert into (Survey_id, Survey_responseId, userId, username, isComplete, ipAddress) values ($surveyId,
".getNextId("Survey_responseId")." ,".quote($userId).", ".quote($username).", 1, ".quote($ipAddress).")");
}
$b->finish;
$b = WebGUI::SQL->read("select distinct ipAddress from Survey_questionResponse where Survey_id=$surveyId and userId='1'");
while (my ($ipAddress) = $b->array) {
WebGUI::SQL->write("insert into (Survey_id, Survey_responseId, userId, username, isComplete, ipAddress) values (
$surveyId, ".getNextId("Survey_responseId")." ,'1', 'Visitor', 1, ".quote($ipAddress).")");
}
$b->finish;
}
$a->finish;
$a = WebGUI::SQL->read("select Survey_id, Survey_responseId, userId, ipAddress from Survey_response");
while (my $data = $a->hashRef) {
my ($end) = WebGUI::SQL->quickArray("select max(dateOfResponse) from Survey_questionResponse where Survey_id=".$data->{Survey_id}."
and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))");
my ($start) = WebGUI::SQL->quickArray("select min(dateOfResponse) from Survey_questionResponse where Survey_id=".$data->{Survey_id}."
and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))");
WebGUI::SQL->write("update Survey_response set startDate=$start, endDate=$end where Survey_responseId=".$data->{Survey_responseId});
WebGUI::SQL->quickArray("update Survey_questionResponse set Survey_responseId=".$data->{Survey_responseId}." where Survey_id=".$data->{Survey_id}."
and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))");
}
$a->finish;
WebGUI::SQL->write("alter table Survey_questionResponse drop column userId");
WebGUI::SQL->write("alter table Survey_questionResponse drop column username");
WebGUI::SQL->write("alter table Survey_questionResponse drop column ipAddress");
WebGUI::SQL->write("alter table Survey add column questionsPerPage int not null default 1");
WebGUI::SQL->write("alter table Survey add column responseTemplateId int not null default 1");
WebGUI::SQL->write("alter table Survey add column reportcardTemplateId int not null default 1");
WebGUI::SQL->write("alter table Survey add column overviewTemplateId int not null default 1");
WebGUI::SQL->write("alter table Survey add column maxResponsesPerUser int not null default 1");
WebGUI::SQL->write("alter table Survey add column questionsPerResponse int not null default 9999999");
WebGUI::Session::close();

View file

@ -309,7 +309,23 @@ UPDATE userProfileData set fieldData = '2' where fieldName = 'richEditor' and fi
UPDATE userProfileData set fieldData = '3' where fieldName = 'richEditor' and fieldData = 'midas';
UPDATE userProfileData set fieldData = '4' where fieldName = 'richEditor' and fieldData = 'classic';
UPDATE userProfileData set fieldData = '5' where fieldName = 'richEditor' and fieldData = 'lastResort';
-- DataForm
delete from international where namespace='Survey' and internationalId=68;
delete from international where namespace='SQLReport' and internationalId=3;
delete from international where namespace='SQLReport' and internationalId=13;
delete from international where languageId=1 and namespace='Survey' and internationalId=87;
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (87,1,'Survey','Click here to start a new response.', 1075639972,'A label indicating that the user could start a new survey/quiz response by clicking.');
delete from international where languageId=1 and namespace='Survey' and internationalId=86;
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (86,1,'Survey','Progress', 1075639914,'A label indicating how far the user has progressed through the survey\r\n');
delete from international where languageId=1 and namespace='Survey' and internationalId=85;
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (85,1,'Survey','Questions Per Response', 1075639549,'Ask the user how many questions should be displayed to the user per time taking the survey.');
delete from international where languageId=1 and namespace='Survey' and internationalId=84;
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (84,1,'Survey','Max Responses Per User', 1075639389,'Ask the user how many responses the user should be able to submit to the survey.');
delete from international where languageId=1 and namespace='Survey' and internationalId=83;
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (83,1,'Survey','Questions Per Page', 1075639327,'Ask the user how many questions should be displayed per page on the survey.');
INSERT INTO template VALUES (1,'Default Overview Report','<h1><tmpl_var title></h1>\n\n<tmpl_if user.canViewReports>\n <a href=\"<tmpl_var survey.url>\"><tmpl_var survey.label></a> \n &bull;\n <a href=\"<tmpl_var report.gradebook.url>\"><tmpl_var report.gradebook.label></a> \n &bull;\n <a href=\"<tmpl_var delete.all.responses.url>\"><tmpl_var delete.all.responses.label></a> \n <br />\n <a href=\"<tmpl_var export.answers.url>\"><tmpl_var export.answers.label></a> \n &bull;\n <a href=\"<tmpl_var export.questions.url>\"><tmpl_var export.questions.label></a> \n &bull;\n <a href=\"<tmpl_var export.responses.url>\"><tmpl_var export.responses.label></a> \n &bull;\n <a href=\"<tmpl_var export.composite.url>\"><tmpl_var export.composite.label></a> \n</tmpl_if>\n\n<br /> <br />\n\n<script>\nfunction toggleDiv(divId) {\n if (document.getElementById(divId).style.visibility == \"none\") {\n document.getElementById(divId).style.display = \"block\";\n } else {\n document.getElementById(divId).style.display = \"none\"; \n }\n}\n</script>\n\n<tmpl_loop question_loop>\n <b><tmpl_var question></b>\n <tmpl_if question.isRadioList>\n <table class=\"tableData\">\n <tr class=\"tableHeader\"><td width=\"60%\"><tmpl_var answer.label></td>\n <td width=\"20%\"><tmpl_var response.count.label></td>\n <td width=\"20%\"><tmpl_var response.percent.label></td></tr>\n <tmpl_loop answer_loop>\n <tmpl_if answer.isCorrect>\n <tr class=\"highlight\">\n <tmpl_else>\n <tr>\n </tmpl_if>\n <td><tmpl_var answer></td>\n <td><tmpl_var answer.response.count></td>\n <td><tmpl_var answer.response.percent></td>\n <tmpl_if allowComment>\n <td><a href=\"#\" onClick=\"toggle(\'comment<tmpl_var answer.id>\');\"><tmpl_var show.comments.label></a></td>\n </tmpl_if>\n </tr>\n <tmpl_if question.allowComment>\n <tr id=\"comment<tmpl_var answer.id>\">\n <td colspan=\"3\">\n <tmpl_loop comment_loop>\n <p>\n <tmpl_var answer.comment>\n </p>\n </tmpl_loop>\n </td>\n </tr>\n </tmpl_if>\n </tmpl_loop>\n </table>\n <tmpl_else>\n <br />\n <a href=\"#\" onClick=\"toggle(\'response<tmpl_var question.id>\');\"><tmpl_var show.answers.label></a>\n <br />\n <div id=\"response<tmpl_var question.id>\">\n <tmpl_loop answer_loop>\n <p>\n <tmpl_var answer.response>\n </p>\n <tmpl_if question.allowComment>\n <blockquote>\n <tmpl_var answer.comment>\n </blockquote>\n </tmpl_if>\n </tmpl_loop>\n </div>\n </tmpl_if>\n <br /><br /><br />\n\n</tmpl_loop>\n\n\n<tmpl_if pagination.pageCount.isMultiple>\n <div class=\"pagination\">\n <tmpl_var pagination.previousPage> &middot; <tmpl_var pagination.pageList.upTo20> &middot; <tmpl_var pagination.nextPage>\n </div>\n</tmpl_if>\n\n','Survey/Overview');
INSERT INTO template VALUES (1,'Default Gradebook Report','<h1><tmpl_var title></h1>\n\n<tmpl_if user.canViewReports>\n <a href=\"<tmpl_var survey.url>\"><tmpl_var survey.label></a> \n &bull;\n <a href=\"<tmpl_var report.overview.url>\"><tmpl_var report.overview.label></a> \n &bull;\n <a href=\"<tmpl_var delete.all.responses.url>\"><tmpl_var delete.all.responses.label></a> \n <br />\n <a href=\"<tmpl_var export.answers.url>\"><tmpl_var export.answers.label></a> \n &bull;\n <a href=\"<tmpl_var export.questions.url>\"><tmpl_var export.questions.label></a> \n &bull;\n <a href=\"<tmpl_var export.responses.url>\"><tmpl_var export.responses.label></a> \n &bull;\n <a href=\"<tmpl_var export.composite.url>\"><tmpl_var export.composite.label></a> \n</tmpl_if>\n\n<br /> <br />\n\n<table class=\"tableData\">\n<tr class=\"tableHeader\"><td width=\"60%\"><tmpl_var response.user.label></td>\n <td width=\"20%\"><tmpl_var response.count.label></td>\n <td width=\"20%\"><tmpl_var response.percent.label></td></tr>\n<tmpl_loop response_loop>\n<tr>\n <td><a href=\"<tmpl_var response.url>\"><tmpl_var response.user.name></a></td>\n <td><tmpl_var response.count.correct>/<tmpl_var question.count></td>\n <td><tmpl_var response.percent>%</td>\n</tr>\n</tmpl_loop>\n</table>\n\n\n<tmpl_if pagination.pageCount.isMultiple>\n <div class=\"pagination\">\n <tmpl_var pagination.previousPage> &middot; <tmpl_var pagination.pageList.upTo20> &middot; <tmpl_var pagination.nextPage>\n </div>\n</tmpl_if>\n','Survey/Gradebook');
INSERT INTO template VALUES (1,'Default Survey','<tmpl_if displayTitle>\n <h1><tmpl_var title></h1>\n</tmpl_if>\n\n\n<tmpl_if description>\n <tmpl_var description><p />\n</tmpl_if>\n\n\n<tmpl_if user.canTakeSurvey>\n <tmpl_if response.isComplete>\n <tmpl_if mode.isSurvey>\n <tmpl_var thanks.survey.label>\n <tmpl_else>\n <tmpl_var thanks.quiz.label>\n <div align=\"center\">\n <b><tmpl_var questions.correct.count.label>:</b> <tmpl_var questions.correct.count> / <tmpl_var questions.total>\n <br />\n <b><tmpl_var questions.correct.percent.label>:</b><tmpl_var questions.correct.percent>% \n </div>\n </tmpl_if>\n <tmpl_if user.canRespondAgain>\n <br /> <br /> <a href=\"<tmpl_var start.newResponse.url>\"><tmpl_var start.newResponse.label></a>\n </tmpl_if>\n <tmpl_else>\n <tmpl_if response.id>\n <tmpl_var form.header>\n <table width=\"100%\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\" class=\"content\">\n <tr>\n <td valign=\"top\">\n <tmpl_loop question_loop>\n <p><tmpl_var question.question></p>\n <tmpl_var question.answer.label><br />\n <tmpl_var question.answer.field><br />\n <br />\n <tmpl_if question.allowComment>\n <tmpl_var question.comment.label><br />\n <tmpl_var question.comment.field><br />\n </tmpl_if>\n </tmpl_loop>\n </td>\n <td valign=\"top\" nowrap=\"1\">\n <b><tmpl_var questions.sofar.label>:</b> <tmpl_var questions.sofar.count> / <tmpl_var questions.total> <br />\n <tmpl_unless mode.isSurvey>\n <b><tmpl_var questions.correct.count.label>:</b> <tmpl_var questions.correct.count> / <tmpl_var questions.sofar.count><br />\n <b><tmpl_var questions.correct.percent.label>:</b><tmpl_var questions.correct.percent>% / 100%<br />\n </tmpl_unless>\n </td>\n </tr>\n </table>\n <div align=\"center\"><tmpl_var form.submit></div>\n <tmpl_var form.footer>\n <tmpl_else>\n <a href=\"<tmpl_var start.newResponse.url>\"><tmpl_var start.newResponse.label></a>\n </tmpl_if>\n </tmpl_if>\n<tmpl_else>\n <tmpl_if mode.isSurvey>\n <tmpl_var survey.noprivs.label>\n <tmpl_else>\n <tmpl_var quiz.noprivs.label>\n </tmpl_if>\n</tmpl_if>\n<br />\n<br />\n<tmpl_if user.canViewReports>\n <a href=\"<tmpl_var report.gradebook.url>\"><tmpl_var report.gradebook.label></a> \n &bull;\n <a href=\"<tmpl_var report.overview.url>\"><tmpl_var report.overview.label></a> \n &bull;\n <a href=\"<tmpl_var delete.all.responses.url>\"><tmpl_var delete.all.responses.label></a> \n <br />\n <a href=\"<tmpl_var export.answers.url>\"><tmpl_var export.answers.label></a> \n &bull;\n <a href=\"<tmpl_var export.questions.url>\"><tmpl_var export.questions.label></a> \n &bull;\n <a href=\"<tmpl_var export.responses.url>\"><tmpl_var export.responses.label></a> \n &bull;\n <a href=\"<tmpl_var export.composite.url>\"><tmpl_var export.composite.label></a> \n</tmpl_if>\n\n\n<tmpl_if session.var.adminOn>\n <p>\n <a href=\"<tmpl_var question.add.url>\"><tmpl_var question.add.label></a>\n </p>\n <tmpl_loop question.edit_loop>\n <tmpl_var question.edit.controls>\n <tmpl_var question.edit.question>\n <br />\n </tmpl_loop>\n</tmpl_if>\n','Survey');
INSERT INTO template VALUES (1,'Default Response','<h1><tmpl_var title></h1>\n\n<tmpl_if user.canViewReports>\n <a href=\"<tmpl_var survey.url>\"><tmpl_var survey.label></a> \n &bull;\n <a href=\"<tmpl_var report.overview.url>\"><tmpl_var report.overview.label></a> \n &bull;\n <a href=\"<tmpl_var report.gradebook.url>\"><tmpl_var report.gradebook.label></a> \n</tmpl_if>\n<a href=\"<tmpl_var delete.url>\"><tmpl_var delete.label></a><p/>\n<b><tmpl_var start.date.label>:</b> <tmpl_var start.date.human> <tmpl_var start.time.human><br />\n<b><tmpl_var end.date.label>:</b> <tmpl_var end.date.human> <tmpl_var end.time.human><br />\n<b><tmpl_var duration.label>:</b> <tmpl_var duration.minutes> <tmpl_var duration.minutes.label> <tmpl_var duration.seconds> <tmpl_var duration.seconds.label>\n\n<p/>\n<tmpl_loop question_loop>\n\n <b><tmpl_var question></b><br />\n <table class=\"tableData\" width=\"100%\">\n<tmpl_if question.isRadioList>\n \n <tr><td valign=\"top\" class=\"tableHeader\" width=\"25%\">\n <tmpl_var answer.label></td><td width=\"75%\">\n <tmpl_var question.answer> \n</td></tr>\n </tmpl_if>\n <tr><td width=\"25%\" valign=\"top\" class=\"tableHeader\"><tmpl_var response.label></td>\n \n<td width=\"75%\"><tmpl_var question.response></td></tr>\n <tmpl_if question.comment>\n <tr><td valign=\"top\" class=\"tableHeader\">\n <tmpl_var comment.label> </td>\n <td><tmpl_var question.comment></td></tr>\n </tmpl_if>\n\n </table><p/>\n</tmpl_loop>','Survey/Response');
CREATE TABLE DataForm_tab (
wobjectId int(11) NOT NULL default '0',
label varchar(255) NOT NULL default '',
@ -329,4 +345,7 @@ INSERT INTO international VALUES (101,'DataForm',1,'Label',NULL,NULL);
INSERT INTO international VALUES (100,'DataForm',1,'Are you certain that you want to delete this tab ?',NULL,NULL);
INSERT INTO template VALUES (1,'Mail Form','<tmpl_if displayTitle>\r\n <h1><tmpl_var title></h1>\r\n</tmpl_if>\r\n\r\n<tmpl_if error_loop>\r\n<ul>\r\n<tmpl_loop error_loop>\r\n <li><b><tmpl_var error.message></b>\r\n</tmpl_loop>\r\n</ul>\r\n</tmpl_if>\r\n\r\n<tmpl_if description>\r\n <tmpl_var description><p />\r\n</tmpl_if>\r\n\r\n<tmpl_if canEdit>\r\n <a href=\"<tmpl_var entryList.url>\"><tmpl_var entryList.label></a>\r\n &middot; <a href=\"<tmpl_var export.tab.url>\"><tmpl_var export.tab.label></a>\r\n <tmpl_if entryId>\r\n &middot; <a href=\"<tmpl_var delete.url>\"><tmpl_var delete.label></a>\r\n </tmpl_if>\r\n <tmpl_if session.var.adminOn>\r\n &middot; <a href=\"<tmpl_var addField.url>\"><tmpl_var addField.label></a>\r\n &middot; <a href=\"<tmpl_var addTab.url>\"><tmpl_var addTab.label></a>\r\n </tmpl_if>\r\n <p /> \r\n</tmpl_if>\r\n\r\n<tmpl_var form.start>\r\n<table>\r\n<tmpl_loop field_loop>\r\n <tmpl_unless field.isHidden>\r\n <tr><td class=\"formDescription\" valign=\"top\">\r\n <tmpl_if session.var.adminOn><tmpl_if canEdit><tmpl_var field.controls></tmpl_if></tmpl_if>\r\n <tmpl_var field.label>\r\n </td><td class=\"tableData\" valign=\"top\">\r\n <tmpl_if field.isDisplayed>\r\n <tmpl_var field.value>\r\n <tmpl_else>\r\n <tmpl_var field.form>\r\n </tmpl_if>\r\n <tmpl_if field.required>*</tmpl_if>\r\n <span class=\"formSubtext\"><br /><tmpl_var field.subtext></span>\r\n </td></tr>\r\n </tmpl_unless>\r\n</tmpl_loop>\r\n<tr><td></td><td><tmpl_var form.send></td></tr>\r\n</table>\r\n\r\n<tmpl_var form.end>\r\n','DataForm');
INSERT INTO template VALUES (4,'Tab Form','<tmpl_if displayTitle>\r\n <h1><tmpl_var title></h1>\r\n</tmpl_if>\r\n\r\n<tmpl_if error_loop>\r\n <ul>\r\n <tmpl_loop error_loop>\r\n <li><b><tmpl_var error.message></b>\r\n </tmpl_loop>\r\n </ul>\r\n</tmpl_if>\r\n\r\n<tmpl_if description>\r\n <tmpl_var description><p />\r\n</tmpl_if>\r\n\r\n<tmpl_if canEdit>\r\n <a href=\"<tmpl_var entryList.url>\"><tmpl_var entryList.label></a>\r\n &middot; <a href=\"<tmpl_var export.tab.url>\"><tmpl_var export.tab.label></a>\r\n <tmpl_if entryId>\r\n &middot; <a href=\"<tmpl_var delete.url>\"><tmpl_var delete.label></a>\r\n </tmpl_if>\r\n <tmpl_if session.var.adminOn>\r\n &middot; <a href=\"<tmpl_var addField.url>\"><tmpl_var addField.label></a>\r\n &middot; <a href=\"<tmpl_var addTab.url>\"><tmpl_var addTab.label></a>\r\n </tmpl_if>\r\n<p /> \r\n</tmpl_if>\r\n<tmpl_var form.start>\r\n<link href=\"/extras/tabs/tabs.css\" rel=\"stylesheet\" rev=\"stylesheet\" type=\"text/css\">\r\n<div class=\"tabs\">\r\n <tmpl_loop tab_loop>\r\n <span onclick=\"toggleTab(<tmpl_var tab.sequence>)\" id=\"tab<tmpl_var tab.sequence>\" class=\"tab\"><tmpl_var tab.label>\r\n <tmpl_if session.var.adminOn>\r\n <tmpl_if canEdit>\r\n <tmpl_var tab.controls>\r\n </tmpl_if>\r\n </tmpl_if>\r\n </span>\r\n </tmpl_loop>\r\n</div>\r\n<tmpl_loop tab_loop>\r\n <tmpl_var tab.start>\r\n <table>\r\n <tmpl_loop tab.field_loop>\r\n <tmpl_unless tab.field.isHidden>\r\n <tr>\r\n <td class=\"formDescription\" valign=\"top\">\r\n <tmpl_if session.var.adminOn>\r\n <tmpl_if canEdit>\r\n <tmpl_var tab.field.controls>\r\n </tmpl_if>\r\n </tmpl_if>\r\n <tmpl_var tab.field.label>\r\n </td>\r\n <td class=\"tableData\" valign=\"top\">\r\n <tmpl_if tab.field.isDisplayed>\r\n <tmpl_var tab.field.value>\r\n <tmpl_else>\r\n <tmpl_var tab.field.form>\r\n </tmpl_if>\r\n <tmpl_if tab.field.isRequired>*</tmpl_if>\r\n <span class=\"formSubtext\">\r\n <br />\r\n <tmpl_var tab.field.subtext>\r\n </span>\r\n </td>\r\n </tr>\r\n </tmpl_unless>\r\n </tmpl_loop>\r\n <tr>\r\n <td colspan=\"2\">\r\n <span class=\"tabSubtext\"><tmpl_var tab.subtext></span>\r\n </td>\r\n </tr>\r\n </table>\r\n <br>\r\n <div><input type=\"submit\" value=\"save\"></div>\r\n <tmpl_var tab.end>\r\n</tmpl_loop>\r\n<tmpl_var tab.init>\r\n<tmpl_var form.end>\r\n','DataForm');
-- DataForm

View file

@ -18,6 +18,7 @@ use strict;
use WebGUI::International;
use WebGUI::Session;
use WebGUI::URL;
use WebGUI::Utility;
=head1 NAME
@ -30,9 +31,11 @@ Package that paginates rows of arbitrary data for display on the web.
=head1 SYNOPSIS
use WebGUI::Paginator;
$p = WebGUI::Paginator->new("/index.pl/page_name?this=that",\@row);
$p = WebGUI::Paginator->new("/index.pl/page_name?this=that");
$p->setDataByArrayRef(\@array);
$p->setDataByQuery($sql);
$p->appendTemplateVars($hashRef);
$html = $p->getBar;
$html = $p->getBarAdvanced;
$html = $p->getBarSimple;
@ -57,31 +60,55 @@ These methods are available from this class:
#-------------------------------------------------------------------
=head2 getBar ( [ pageNumber ] )
=head2 appendTemplateVars ( hashRef )
Returns the pagination bar including First, Previous, Next, and last links. If there's only one page, nothing is returned.
Adds paginator template vars to a hash reference.
=over
=item pageNumber
=item hashRef
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
The hash reference to append the variables to.
=back
=cut
sub appendTemplateVars {
my $self = shift;
my $var = shift;
$var->{'pagination.firstpage'} = $self->getFirstPageLink;
$var->{'pagination.lastpage'} = $self->getLastPageLink;
$var->{'pagination.nextpage'} = $self->getNextPageLink;
$var->{'pagination.previouspage'} = $self->getPreviousPageLink;
$var->{'pagination.pageNumber'} = $self->getPageNumber;
$var->{'pagination.pageCount'} = $self->getNumberOfPages;
$var->{'pagination.pageCount.isMultiple'} = ($self->getNumberOfPages > 1);
$var->{'pagination.pageList'} = $self->getPageLinks;
$var->{'pagination.pageList.upTo10'} = $self->getPageLinks(10);
$var->{'pagination.pageList.upTo20'} = $self->getPageLinks(20);
}
#-------------------------------------------------------------------
=head2 getBar ( )
Returns the pagination bar including First, Previous, Next, and last links. If there's only one page, nothing is returned.
=cut
sub getBar {
my ($output);
if ($_[0]->getNumberOfPages > 1) {
$output = '<div class="pagination">';
$output .= $_[0]->getFirstPageLink($_[1]);
$output .= $_[0]->getFirstPageLink;
$output .= ' &middot; ';
$output .= $_[0]->getPreviousPageLink($_[1]);
$output .= $_[0]->getPreviousPageLink;
$output .= ' &middot; ';
$output .= $_[0]->getNextPageLink($_[1]);
$output .= $_[0]->getNextPageLink;
$output .= ' &middot; ';
$output .= $_[0]->getLastPageLink($_[1]);
$output .= $_[0]->getLastPageLink;
$output .= '</div>';
return $output;
} else {
@ -92,33 +119,25 @@ sub getBar {
#-------------------------------------------------------------------
=head2 getBarAdvanced ( [ pageNumber ] )
=head2 getBarAdvanced ( )
Returns the pagination bar including First, Previous, Page Numbers, Next, and Last links. If there's only one page, nothing is returned.
=over
=item pageNumber
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
=back
=cut
sub getBarAdvanced {
my ($output);
if ($_[0]->getNumberOfPages > 1) {
$output = '<div class="pagination">';
$output .= $_[0]->getFirstPageLink($_[1]);
$output .= $_[0]->getFirstPageLink;
$output .= ' &middot; ';
$output .= $_[0]->getPreviousPageLink($_[1]);
$output .= $_[0]->getPreviousPageLink;
$output .= ' &middot; ';
$output .= $_[0]->getPageLinks($_[1]);
$output .= $_[0]->getPageLinks;
$output .= ' &middot; ';
$output .= $_[0]->getNextPageLink($_[1]);
$output .= $_[0]->getNextPageLink;
$output .= ' &middot; ';
$output .= $_[0]->getLastPageLink($_[1]);
$output .= $_[0]->getLastPageLink;
$output .= '</div>';
return $output;
} else {
@ -129,27 +148,19 @@ sub getBarAdvanced {
#-------------------------------------------------------------------
=head2 getBarSimple ( [ pageNumber ] )
=head2 getBarSimple ( )
Returns the pagination bar including only Previous and Next links. If there's only one page, nothing is returned.
=over
=item pageNumber
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
=back
=cut
sub getBarSimple {
my ($output);
if ($_[0]->getNumberOfPages > 1) {
$output = '<div class="pagination">';
$output .= $_[0]->getPreviousPageLink($_[1]);
$output .= $_[0]->getPreviousPageLink;
$output .= ' &middot; ';
$output .= $_[0]->getNextPageLink($_[1]);
$output .= $_[0]->getNextPageLink;
$output .= '</div>';
return $output;
} else {
@ -160,29 +171,21 @@ sub getBarSimple {
#-------------------------------------------------------------------
=head2 getBarTraditional ( [ pageNumber ] )
=head2 getBarTraditional ( )
Returns the pagination bar including Previous, Page Numbers, and Next links. If there's only one page, nothing is returned.
=over
=item pageNumber
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
=back
=cut
sub getBarTraditional {
my ($output);
if ($_[0]->getNumberOfPages > 1) {
$output = '<div class="pagination">';
$output .= $_[0]->getPreviousPageLink($_[1]);
$output .= $_[0]->getPreviousPageLink;
$output .= ' &middot; ';
$output .= $_[0]->getPageLinks($_[1]);
$output .= $_[0]->getPageLinks;
$output .= ' &middot; ';
$output .= $_[0]->getNextPageLink($_[1]);
$output .= $_[0]->getNextPageLink;
$output .= '</div>';
return $output;
} else {
@ -193,23 +196,15 @@ sub getBarTraditional {
#-------------------------------------------------------------------
=head2 getFirstPageLink ( [ pageNumber ] )
=head2 getFirstPageLink ( )
Returns a link to the first page's data.
=over
=item pageNumber
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
=back
=cut
sub getFirstPageLink {
my ($text, $pn);
$pn = $_[1] || $_[0]->getPageNumber;
$pn = $_[0]->getPageNumber;
$text = '|&lt;'.WebGUI::International::get(404);
if ($pn > 1) {
return '<a href="'.
@ -223,23 +218,15 @@ sub getFirstPageLink {
#-------------------------------------------------------------------
=head2 getLastPageLink ( [ pageNumber ] )
=head2 getLastPageLink ( )
Returns a link to the last page's data.
=over
=item pageNumber
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
=back
=cut
sub getLastPageLink {
my ($text, $pn);
$pn = $_[1] || $_[0]->getPageNumber;
$pn = $_[0]->getPageNumber;
$text = WebGUI::International::get(405).'&gt;|';
if ($pn != $_[0]->getNumberOfPages) {
return '<a href="'.
@ -253,23 +240,15 @@ sub getLastPageLink {
#-------------------------------------------------------------------
=head2 getNextPageLink ( [ pageNumber ] )
=head2 getNextPageLink ( )
Returns a link to the next page's data.
=over
=item pageNumber
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
=back
=cut
sub getNextPageLink {
my ($text, $pn);
$pn = $_[1] || $_[0]->getPageNumber;
$pn = $_[0]->getPageNumber;
$text = WebGUI::International::get(92).'&raquo;';
if ($pn < $_[0]->getNumberOfPages) {
return '<a href="'.WebGUI::URL::append($_[0]->{_url},($_[0]->{_formVar}.'='.($pn+1))).'">'.$text.'</a>';
@ -362,55 +341,63 @@ sub getPageNumber {
#-------------------------------------------------------------------
=head2 getPageLinks ( [ pageNumber ] )
=head2 getPageLinks ( [ limit ] )
Returns links to all pages in this paginator.
=over
=item pageNumber
=iten limit
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
An integer representing the maximum number of page links to return. Defaultly all page links will be returned.
=back
=cut
sub getPageLinks {
my ($i, $output, $pn);
$pn = $_[1] || $_[0]->getPageNumber;
for ($i=0; $i<$_[0]->getNumberOfPages; $i++) {
my $self = shift;
my $limit = shift;
my $pn = $self->getPageNumber;
my @pages;
for (my $i=0; $i<$self->getNumberOfPages; $i++) {
if ($i+1 == $pn) {
$output .= ' '.($i+1).' ';
push(@pages,($i+1));
} else {
$output .= ' <a href="'.
WebGUI::URL::append($_[0]->{_url},($_[0]->{_formVar}.'='.($i+1)))
.'">'.($i+1).'</a> ';
push(@pages,'<a href="'.WebGUI::URL::append($self->{_url},($self->{_formVar}.'='.($i+1))).'">'.($i+1).'</a>');
}
}
return $output;
if ($limit) {
my $output;
my $i = 1;
my $minPage = $self->getPageNumber - round($limit/2);
my $maxPage = $minPage + $limit;
my $start = ($minPage > 0) ? $minPage : 1;
my $end = ($maxPage < $self->getPageNumber) ? $maxPage : $self->getPageNumber;
foreach my $page (@pages) {
if ($i <= $end && $i >= $start) {
$output .= $page.' ';
}
$i++;
}
return $output;
} else {
return join(" ",@pages);
}
}
#-------------------------------------------------------------------
=head2 getPreviousPageLink ( [ pageNumber ] )
=head2 getPreviousPageLink ( )
Returns a link to the previous page's data.
=over
=item pageNumber
Defaults to the page you're currently viewing. This is mostly here as an override and probably has no real use.
=back
=cut
sub getPreviousPageLink {
my ($text, $pn);
$pn = $_[1] || $_[0]->getPageNumber;
$pn = $_[0]->getPageNumber;
$text = '&laquo;'.WebGUI::International::get(91);
if ($pn > 1) {
return '<a href="'.WebGUI::URL::append($_[0]->{_url},($_[0]->{_formVar}.'='.($pn-1))).'">'.$text.'</a>';
@ -435,7 +422,7 @@ sub getRowCount {
#-------------------------------------------------------------------
=head2 new ( currentURL, rowArrayRef [, paginateAfter, pageNumber, formVar ] )
=head2 new ( currentURL [, paginateAfter, pageNumber, formVar ] )
Constructor.
@ -445,17 +432,13 @@ Constructor.
The URL of the current page including attributes. The page number will be appended to this in all links generated by the paginator.
=item rowArrayRef
An array reference to all the rows of data for this page.
=item paginateAfter
The number of rows to display per page. If left blank it defaults to 50.
=item pageNumber
By default the paginator uses a form variable of "pn" to determine the page number. If you wish it to use some other variable, then specify the page number here.
By default the page number will be determined by looking at $session{form}{pn}. If that is empty the page number will be defaulted to "1". If you'd like to override the page number specify it here.
=item formVar
@ -467,16 +450,38 @@ Specify the form variable the paginator should use in it's links. Defaults to "
sub new {
my ($class, $currentURL, $rowsPerPage, $rowRef, $formVar, $pageRef, $pn);
$class = $_[0];
$currentURL = $_[1];
$rowRef = $_[2];
$rowsPerPage = $_[3] || 25;
$formVar = $_[5] || "pn";
$pn = $_[4] || $session{form}{$formVar} || 1;
my $totalRows = $#{$rowRef};
bless {_url => $currentURL, _rpp => $rowsPerPage, _totalRows=>$totalRows , _rowRef => $rowRef, _formVar => $formVar, _pn => $pn}, $class;
my $class = shift;
my $currentURL = shift;
my $rowsPerPage = shift || 25;
my $formVar = shift || "pn";
my $pn = shift || $session{form}{$formVar} || 1;
bless {_url => $currentURL, _rpp => $rowsPerPage, _formVar => $formVar, _pn => $pn}, $class;
}
#-------------------------------------------------------------------
=head2 setDataByArrayRef ( arrayRef )
Provide the paginator with data by giving it an array reference.
=over
=item arrayRef
The array reference that contains the data to be paginated.
=back
=cut
sub setDataByArrayRef {
my $self = shift;
my $rowRef = shift;
$self->{_rowRef} = $rowRef;
$self->{_totalRows} = $#{$rowRef};
}
#-------------------------------------------------------------------
=head2 setDataByQuery ( query [, dbh, unconditional ] )

File diff suppressed because it is too large Load diff