diff --git a/docs/upgrades/upgrade_4.7.0-4.8.0.sql b/docs/upgrades/upgrade_4.7.0-4.8.0.sql
index 714554a06..4fc22cce6 100644
--- a/docs/upgrades/upgrade_4.7.0-4.8.0.sql
+++ b/docs/upgrades/upgrade_4.7.0-4.8.0.sql
@@ -134,7 +134,74 @@ insert into international (internationalId,languageId,namespace,message,lastUpda
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (805,1,'WebGUI','Delete this style.', 1037075787);
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (804,1,'WebGUI','Copy this style.', 1037075775);
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (803,1,'WebGUI','Edit this style.', 1037075751);
-
+insert into incrementer values ("Survey_id",1000);
+alter table Survey_answer change wobjectId Survey_id int;
+alter table Survey_question change wobjectId Survey_id int;
+alter table Survey_response change wobjectId Survey_id int;
+alter table Survey add column Survey_id int not null;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (74,1,'Survey','Are you certain you wish to delete all the responses?', 1037574455);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (73,1,'Survey','Delete all the responses.', 1037573893);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (72,1,'Survey','Are you certain you wish to delete this user\'s responses?', 1037573460);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (71,1,'Survey','Grade Book', 1037573252);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (70,1,'Survey','Individual Responses', 1037573240);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (69,1,'Survey','Delete this user\'s responses.', 1037573082);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (68,1,'Survey','View reports and exports.', 1037560492);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (67,1,'Survey','User', 1037558860);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (66,1,'Survey','Responses', 1037557127);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (65,1,'Survey','Export composite summary.', 1037556821);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (64,1,'Survey','Export responses.', 1037556721);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (63,1,'Survey','Export questions.', 1037556710);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (62,1,'Survey','Export answers.', 1037556697);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (61,1,'Survey','View grade book.', 1037556642);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (60,1,'Survey','Back to survey.', 1037556626);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (59,1,'Survey','View statistical overview.', 1037556614);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (58,1,'Survey','Statistical Overview', 1037556179);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (57,1,'Survey','Comments', 1037556124);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (56,1,'Survey','View comments.', 1037555787);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (55,1,'Survey','View responses.', 1037555778);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (54,1,'Survey','Percentage', 1037555267);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (53,1,'Survey','Responses', 1037555255);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (52,1,'Survey','Score', 1037506007);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (51,1,'Survey','Comments?', 1037499470);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (50,1,'Survey','Next', 1037499410);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (49,1,'Survey','You may not take this quiz at this time.', 1037499363);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (48,1,'Survey','You are not currently eligible to participate in this survey. ', 1037499301);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (47,1,'Survey','You have completed this quiz.', 1037499131);
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (46,1,'Survey','Thank you for taking the time to complete our survey.', 1037499049);
+delete from international where languageId=1 and namespace='Survey' and internationalId=35;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (35,1,'Survey','Somewhat Agree', 1037498927);
+delete from international where languageId=1 and namespace='Survey' and internationalId=34;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (34,1,'Survey','Agree', 1037498914);
+delete from international where languageId=1 and namespace='Survey' and internationalId=38;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (38,1,'Survey','Strongly Disagree', 1037498903);
+delete from international where languageId=1 and namespace='Survey' and internationalId=37;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (37,1,'Survey','Disagree', 1037498886);
+delete from international where languageId=1 and namespace='Survey' and internationalId=36;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (36,1,'Survey','Somewhat Disagree', 1037498872);
+delete from international where languageId=1 and namespace='Survey' and internationalId=33;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (33,1,'Survey','Strongly Agree', 1037498857);
+delete from international where languageId=1 and namespace='Survey' and internationalId=31;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (31,1,'Survey','True', 1037498842);
+delete from international where languageId=1 and namespace='Survey' and internationalId=32;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (32,1,'Survey','False', 1037498832);
+delete from international where languageId=1 and namespace='Survey' and internationalId=42;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (42,1,'Survey','Occasionally', 1037574859);
+delete from international where languageId=1 and namespace='Survey' and internationalId=39;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (39,1,'Survey','Not Applicable', 1037574804);
+delete from international where languageId=1 and namespace='Survey' and internationalId=41;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (41,1,'Survey','Frequently', 1037574786);
+delete from international where languageId=1 and namespace='Survey' and internationalId=43;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (43,1,'Survey','Never', 1037574752);
+delete from international where languageId=1 and namespace='Survey' and internationalId=40;
+insert into international (internationalId,languageId,namespace,message,lastUpdated) values (40,1,'Survey','Always', 1037574725);
+delete from help where helpId=1 and namespace='FileManager';
+insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (1, 'FileManager', 61, 71, '2,FileManager;21,WebGUI;');
+delete from help where helpId=21 and namespace='WebGUI';
+insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (21, 'WebGUI', 671, 626, '1,Article;1,FileManager;1,EventsCalendar;1,ExtraColumn;1,FAQ;1,Item;1,LinkList;19,WebGUI;1,MailForm;1,MessageBoard;1,Poll;1,Product;1,SiteMap;1,SQLReport;18,WebGUI;1,SyndicatedContent;1,USS;1,WobjectProxy;27,WebGUI;14,WebGUI;');
+delete from help where helpId=47 and namespace='WebGUI';
+insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (47, 'WebGUI', 697, 698, '1,Article;17,WebGUI;1,MessageBoard;1,Poll;2,WebGUI;1,USS;');
+delete from help where helpId=2 and namespace='FileManager';
+insert into help (helpId,namespace,titleId,bodyId,seeAlso) values (2, 'FileManager', 72, 73, '1,FileManager;');
diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm
index 959673a3e..27c41e5eb 100644
--- a/lib/WebGUI/Form.pm
+++ b/lib/WebGUI/Form.pm
@@ -160,8 +160,12 @@ sub checkList {
extras=>$_[0]->{extras},
checked=>$checked
});
- $output .= ${$_[0]->{options}}{$key}.' ';
- $output .= ' ' if ($_[0]->{vertical});
+ $output .= ${$_[0]->{options}}{$key};
+ if ($_[0]->{vertical}) {
+ $output .= " \n";
+ } else {
+ $output .= " \n";
+ }
}
return $output;
}
@@ -946,12 +950,6 @@ sub radio {
sub radioList {
my ($output, $key, $checked);
foreach $key (keys %{$_[0]->{options}}) {
- $output .= '{value} eq $key) {
- $checked = 1;
- } else {
- $checked = 0;
- }
$output .= radio({
name=>$_[0]->{name},
value=>$key,
@@ -959,8 +957,11 @@ sub radioList {
extras=>$_[0]->{extras}
});
$output .= ' '.$_[0]->{options}->{$key};
- $output .= ' ';
- $output .= ' ' if ($_[0]->{vertical});
+ if ($_[0]->{vertical}) {
+ $output .= " \n";
+ } else {
+ $output .= " \n";
+ }
}
return $output;
}
diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm
index 9169c5490..876b6d471 100644
--- a/lib/WebGUI/HTMLForm.pm
+++ b/lib/WebGUI/HTMLForm.pm
@@ -1302,7 +1302,7 @@ sub radioList {
my ($name, $options, $label, $value, $vertical, $extras, $subtext, $uiLevel) =
rearrange([qw(name options label value vertical extras subtext uiLevel)], @p);
if (_uiLevelChecksOut($uiLevel)) {
- $output = WebGUI::Form::checkList({
+ $output = WebGUI::Form::radioList({
"name"=>$name,
"options"=>$options,
"value"=>$value,
diff --git a/lib/WebGUI/Operation/Help.pm b/lib/WebGUI/Operation/Help.pm
index 361d69215..4c83c79f1 100644
--- a/lib/WebGUI/Operation/Help.pm
+++ b/lib/WebGUI/Operation/Help.pm
@@ -54,6 +54,10 @@ sub _submenu {
my (%menu);
tie %menu, 'Tie::IxHash';
%menu = %{$_[1]};
+ if ($session{form}{op} ne "viewHelp" && $session{form}{op} ne "viewHelpIndex") {
+ $menu{WebGUI::URL::page('op=editHelp&hid=new')} = "Add new help.";
+ $menu{WebGUI::URL::page('op=exportHelp')} = "Export help.";
+ }
if (($session{form}{op} eq "editHelp" && $session{form}{hid} ne "new") || $session{form}{op} eq "deleteHelp") {
$menu{WebGUI::URL::page('op=editHelpIndex&hid='.$session{form}{hid})} = "Edit this help.";
$menu{WebGUI::URL::page('op=deleteHelpIndex&hid='.$session{form}{hid})} = "Delete this help.";
@@ -68,7 +72,7 @@ sub www_deleteHelp {
my $output = '
Confirm
Are you sure? Deleting help is never a good idea. Yes / No
';
- return _submen($output);
+ return _submenu($output,{});
}
#-------------------------------------------------------------------
@@ -130,7 +134,7 @@ sub www_editHelp {
$f->select("seeAlso",\%data,"See Also",\@seeAlso,8,1);
$f->submit;
$output .= $f->print;
- return _submenu($output);
+ return _submenu($output,{});
}
#-------------------------------------------------------------------
@@ -194,10 +198,7 @@ sub www_manageHelp {
$output .= 'This interface is for WebGUI developers only. If you\'re not a developer, leave this alone. Also,
this interface works ONLY under MySQL and is not supported by Plain Black under any
circumstances.
';
$sth = WebGUI::SQL->read("select help.helpId,help.namespace,international.message from help,international
where help.titleId=international.internationalId and help.namespace=international.namespace
and international.languageId=1 order by international.message");
@@ -212,7 +213,7 @@ sub www_manageHelp {
}
$sth->finish;
$output .= '
';
- return _submenu($output);
+ return _submenu($output,{});
}
#-------------------------------------------------------------------
diff --git a/lib/WebGUI/Operation/Trash.pm b/lib/WebGUI/Operation/Trash.pm
index 70f4a07a3..e352126a0 100644
--- a/lib/WebGUI/Operation/Trash.pm
+++ b/lib/WebGUI/Operation/Trash.pm
@@ -12,6 +12,7 @@ package WebGUI::Operation::Trash;
use Exporter;
use strict qw(vars subs);
+use Tie::CPHash;
use WebGUI::Icon;
use WebGUI::Privilege;
use WebGUI::Session;
@@ -23,11 +24,15 @@ our @EXPORT = qw(&www_purgeTrash &www_purgeTrashConfirm);
#-------------------------------------------------------------------
sub _purgeWobjects {
- my ($b, $wobjectId, $namespace, $w, $cmd);
- $b = WebGUI::SQL->read("select wobjectId, namespace from wobject where pageId=$_[0]");
- while (($wobjectId,$namespace) = $b->array) {
- $cmd = "WebGUI::Wobject::".$namespace;
- $w = $cmd->new({wobjectId=>$wobjectId,namespace=>$namespace});
+ my (%properties, $base, $extended, $b, $wobjectId, $namespace, $w, $cmd);
+ tie %properties, 'Tie::CPHash';
+ $b = WebGUI::SQL->read("select * from wobject where pageId=$_[0]");
+ while ($base = $b->hashRef) {
+ $extended = WebGUI::SQL->quickHashRef("select * from ".$base->{namespace}."
+ where wobjectId=".$base->{wobjectId});
+ %properties = (%{$base}, %{$extended});
+ $cmd = "WebGUI::Wobject::".$properties{namespace};
+ $w = $cmd->new(\%properties);
$w->purge;
}
$b->finish;
diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm
index 9d71f5555..280f5b51a 100644
--- a/lib/WebGUI/SQL.pm
+++ b/lib/WebGUI/SQL.pm
@@ -20,6 +20,7 @@ use strict;
use Tie::IxHash;
use WebGUI::ErrorHandler;
use WebGUI::Session;
+use WebGUI::Utility;
our @ISA = qw(Exporter);
our @EXPORT = qw("e &getNextId);
@@ -45,8 +46,10 @@ our @EXPORT = qw("e &getNextId);
%hash = WebGUI::SQL->buildHash($sql);
$hashRef = WebGUI::SQL->buildHashRef($sql);
@arr = WebGUI::SQL->quickArray($sql);
+ $text = WebGUI::SQL->quickCSV($sql);
%hash = WebGUI::SQL->quickHash($sql);
$hashRef = WebGUI::SQL->quickHashRef($sql);
+ $text = WebGUI::SQL->quickTab($sql);
WebGUI::SQL->write($sql);
@@ -336,6 +339,37 @@ sub quickArray {
}
+#-------------------------------------------------------------------
+
+=head2 quickCSV ( sql [, dbh ] )
+
+ Executes a query and returns a comma delimited text blob with column
+ headers.
+
+=item sql
+
+ An SQL query.
+
+=item dbh
+
+ By default this method uses the WebGUI database handler. However,
+ you may choose to pass in your own if you wish.
+
+=cut
+
+sub quickTab {
+ my ($sth, $output, @data);
+ $sth = WebGUI::SQL->new($_[1],$_[2]);
+ $output = join(",",$sth->getColumnNames)."\n";
+ while (@data = $sth->array) {
+ makeArrayCommaSafe(\@data);
+ $output .= join(",",@data)."\n";
+ }
+ $sth->finish;
+ return $output;
+}
+
+
#-------------------------------------------------------------------
=head2 quickHash ( sql [, dbh ] )
@@ -393,6 +427,36 @@ sub quickHashRef {
#-------------------------------------------------------------------
+=head2 quickTab ( sql [, dbh ] )
+
+ Executes a query and returns a tab delimited text blob with column
+ headers.
+
+=item sql
+
+ An SQL query.
+
+=item dbh
+
+ By default this method uses the WebGUI database handler. However,
+ you may choose to pass in your own if you wish.
+
+=cut
+
+sub quickTab {
+ my ($sth, $output, @data);
+ $sth = WebGUI::SQL->new($_[1],$_[2]);
+ $output = join("\t",$sth->getColumnNames)."\n";
+ while (@data = $sth->array) {
+ makeArrayTabSafe(\@data);
+ $output .= join("\t",@data)."\n";
+ }
+ $sth->finish;
+ return $output;
+}
+
+#-------------------------------------------------------------------
+
=head2 quote ( string )
Returns a string quoted and ready for insert into the database.
diff --git a/lib/WebGUI/Utility.pm b/lib/WebGUI/Utility.pm
index 6f8f81148..7dc8e6137 100644
--- a/lib/WebGUI/Utility.pm
+++ b/lib/WebGUI/Utility.pm
@@ -15,7 +15,8 @@ use strict;
use Tie::IxHash;
our @ISA = qw(Exporter);
-our @EXPORT = qw(&commify &randomizeArray &sortHashDescending &sortHash &isIn &randint &round);
+our @EXPORT = qw(&makeTabSafe &makeArrayTabSafe &randomizeHash &commify &randomizeArray
+ &sortHashDescending &sortHash &isIn &makeCommaSafe &makeArrayCommaSafe &randint &round);
#-------------------------------------------------------------------
sub commify {
@@ -45,6 +46,42 @@ sub isIn {
}
}
+#-------------------------------------------------------------------
+sub makeArrayCommaSafe {
+ my ($array) = $_[0];
+ my ($i);
+ for ($i = @$array; --$i;) {
+ $$array[$i] = makeCommaSafe($$array[$i]);
+ }
+}
+
+#-------------------------------------------------------------------
+sub makeArrayTabSafe {
+ my ($array) = $_[0];
+ my ($i);
+ for ($i = @$array; --$i;) {
+ $$array[$i] = makeTabSafe($$array[$i]);
+ }
+}
+
+#-------------------------------------------------------------------
+sub makeCommaSafe {
+ my ($text) = $_[0];
+ $text =~ s/\n/ /g;
+ $text =~ s/\r/ /g;
+ $text =~ s/,/;/g;
+ return $text;
+}
+
+#-------------------------------------------------------------------
+sub makeTabSafe {
+ my ($text) = $_[0];
+ $text =~ s/\n/ /g;
+ $text =~ s/\r/ /g;
+ $text =~ s/\t/ /g;
+ return $text;
+}
+
#-------------------------------------------------------------------
sub randint {
my ($low, $high) = @_;
@@ -67,6 +104,21 @@ sub randomizeArray {
}
}
+#-------------------------------------------------------------------
+sub randomizeHash {
+ my ($hash, $key, @keys, %temp);
+ $hash = $_[0];
+ foreach $key (keys %{$_[0]}) {
+ push(@keys,$key);
+ }
+ randomizeArray(\@keys);
+ tie %temp, 'Tie::IxHash';
+ foreach $key (@keys) {
+ $temp{$key} = $hash->{$key};
+ }
+ return \%temp;
+}
+
#-------------------------------------------------------------------
sub round {
return sprintf("%.0f", $_[0]);
diff --git a/lib/WebGUI/Wobject.pm b/lib/WebGUI/Wobject.pm
index 5d316437b..44d8116ab 100644
--- a/lib/WebGUI/Wobject.pm
+++ b/lib/WebGUI/Wobject.pm
@@ -376,7 +376,7 @@ sub inDateRange {
#-------------------------------------------------------------------
-=head2 moveCollateralDown ( tableName, idName, id )
+=head2 moveCollateralDown ( tableName, idName, id [ , setName, setValue ] )
Moves a collateral data item down one position. This assumes that the
collateral data table has a column called "wobjectId" that identifies
@@ -396,25 +396,41 @@ sub inDateRange {
An integer that uniquely identifies this collateral data item.
+=item setName
+
+ By default this method assumes that the collateral will have a
+ wobject id in the table. However, since there is not always a wobject
+ id to separate one data set from another, you may specify another
+ field to do that.
+
+=item setValue
+
+ The value of the column defined by "setName" to select a data set
+ from.
+
=cut
### NOTE: There is a redundant use of wobjectId in some of these statements on purpose to support
### two different types of collateral data.
sub moveCollateralDown {
- my ($id, $seq);
- ($seq) = WebGUI::SQL->quickArray("select sequenceNumber from $_[1] where $_[2]=$_[3] and wobjectId=".$_[0]->get("wobjectId"));
- ($id) = WebGUI::SQL->quickArray("select $_[2] from $_[1] where wobjectId=".$_[0]->get("wobjectId")
- ." and sequenceNumber=$seq+1 group by wobjectId");
+ my ($id, $seq, $setName, $setValue);
+ $setName = $_[4] || "wobjectId";
+ $setValue = $_[5] || $_[0]->get($setName);
+ ($seq) = WebGUI::SQL->quickArray("select sequenceNumber from $_[1] where $_[2]=$_[3] and $setName=".quote($setValue));
+ ($id) = WebGUI::SQL->quickArray("select $_[2] from $_[1] where $setName=".quote($setValue)
+ ." and sequenceNumber=$seq+1 group by $setName");
if ($id ne "") {
- WebGUI::SQL->write("update $_[1] set sequenceNumber=sequenceNumber+1 where $_[2]=$_[3] and wobjectId=".$_[0]->get("wobjectId"));
- WebGUI::SQL->write("update $_[1] set sequenceNumber=sequenceNumber-1 where $_[2]=$id and wobjectId=".$_[0]->get("wobjectId"));
+ WebGUI::SQL->write("update $_[1] set sequenceNumber=sequenceNumber+1 where $_[2]=$_[3] and $setName="
+ .quote($setValue));
+ WebGUI::SQL->write("update $_[1] set sequenceNumber=sequenceNumber-1 where $_[2]=$id and $setName="
+ .quote($setValue));
}
}
#-------------------------------------------------------------------
-=head2 moveCollateralUp ( tableName, idName, id )
+=head2 moveCollateralUp ( tableName, idName, id [ , setName, setValue ] )
Moves a collateral data item up one position. This assumes that the
collateral data table has a column called "wobjectId" that identifies
@@ -434,19 +450,35 @@ sub moveCollateralDown {
An integer that uniquely identifies this collateral data item.
+=item setName
+
+ By default this method assumes that the collateral will have a
+ wobject id in the table. However, since there is not always a wobject
+ id to separate one data set from another, you may specify another
+ field to do that.
+
+=item setValue
+
+ The value of the column defined by "setName" to select a data set
+ from.
+
=cut
### NOTE: There is a redundant use of wobjectId in some of these statements on purpose to support
### two different types of collateral data.
sub moveCollateralUp {
- my ($id, $seq);
- ($seq) = WebGUI::SQL->quickArray("select sequenceNumber from $_[1] where $_[2]=$_[3] and wobjectId=".$_[0]->get("wobjectId"));
- ($id) = WebGUI::SQL->quickArray("select $_[2] from $_[1] where wobjectId=".$_[0]->get("wobjectId")
- ." and sequenceNumber=$seq-1 group by wobjectId");
+ my ($id, $seq, $setValue, $setName);
+ $setName = $_[4] || "wobjectId";
+ $setValue = $_[5] || $_[0]->get($setName);
+ ($seq) = WebGUI::SQL->quickArray("select sequenceNumber from $_[1] where $_[2]=$_[3] and $setName=".quote($setValue));
+ ($id) = WebGUI::SQL->quickArray("select $_[2] from $_[1] where $setName=".quote($setValue)
+ ." and sequenceNumber=$seq-1 group by $setValue");
if ($id ne "") {
- WebGUI::SQL->write("update $_[1] set sequenceNumber=sequenceNumber-1 where $_[2]=$_[3] and wobjectId=".$_[0]->get("wobjectId"));
- WebGUI::SQL->write("update $_[1] set sequenceNumber=sequenceNumber+1 where $_[2]=$id and wobjectId=".$_[0]->get("wobjectId"));
+ WebGUI::SQL->write("update $_[1] set sequenceNumber=sequenceNumber-1 where $_[2]=$_[3] and $setName="
+ .quote($setValue));
+ WebGUI::SQL->write("update $_[1] set sequenceNumber=sequenceNumber+1 where $_[2]=$id and $setName="
+ .quote($setValue));
}
}
@@ -547,7 +579,7 @@ sub purge {
#-------------------------------------------------------------------
-=head2 reorderCollateral ( tableName, keyName )
+=head2 reorderCollateral ( tableName, keyName [ , setName, setValue ] )
Resequences collateral data. Typically useful after deleting a
collateral item to remove the gap created by the deletion.
@@ -560,14 +592,27 @@ sub purge {
The key column name used to determine which data needs sorting within the table.
+=item setName
+
+ Defaults to "wobjectId". This is used to define which data set to
+ reorder.
+
+=item setValue
+
+ Used to define which data set to reorder. Defaults to the wobjectId
+ for this instance. Defaults to the value of "setName" in the wobject
+ properties.
+
=cut
sub reorderCollateral {
- my ($sth, $i, $id);
+ my ($sth, $i, $id, $setName, $setValue);
$i = 0;
- $sth = WebGUI::SQL->read("select $_[2] from $_[1] where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
+ $setName = $_[3] || "wobjectId";
+ $setValue = $_[4] || $_[0]->get($setName);
+ $sth = WebGUI::SQL->read("select $_[2] from $_[1] where $setName=".quote($setValue)." order by sequenceNumber");
while (($id) = $sth->array) {
- WebGUI::SQL->write("update $_[1] set sequenceNumber=$i where wobjectId=".$_[0]->get("wobjectId")." and $_[2]=$id");
+ WebGUI::SQL->write("update $_[1] set sequenceNumber=$i where $setName=".quote($setValue)." and $_[2]=$id");
$i++;
}
$sth->finish;
@@ -647,7 +692,7 @@ sub set {
#-----------------------------------------------------------------
-=head2 setCollateral ( tableName, keyName, properties [ , useSequenceNumber, useWobjectId ] )
+=head2 setCollateral ( tableName, keyName, properties [ , useSequenceNumber, useWobjectId, setName, setValue ] )
Performs and insert/update of collateral data for any wobject's
collateral data. Returns the primary key value for that row of
@@ -682,20 +727,37 @@ sub set {
upon creation of a new row. Note that this means the table better
have a wobjectId column. Defaults to "1".
+=item setName
+
+ If this collateral data set is not grouped by wobjectId, but by another
+ column then specify that column here. The useSequenceNumber parameter
+ will then use this column name instead of wobjectId to generate
+ the sequenceNumber.
+
+=item setValue
+
+ If you've specified a setName you may also set a value for that set.
+ Defaults to the value for this id from the wobject properties.
+
+=item
+
=cut
sub setCollateral {
my ($key, $sql, $seq, $dbkeys, $dbvalues, $counter);
- my ($class, $table, $keyName, $properties, $useSequence, $useWobjectId) = @_;
+ my ($class, $table, $keyName, $properties, $useSequence, $useWobjectId, $setName, $setValue) = @_;
$counter = 0;
+ $setName = $setName || "wobjectId";
+ $setValue = $setValue || $_[0]->get($setName);
if ($properties->{$keyName} eq "new" || $properties->{$keyName} eq "") {
$properties->{$keyName} = getNextId($keyName);
$sql = "insert into $table (";
$dbkeys = "";
$dbvalues = "";
unless ($useSequence eq "0") {
+
($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from $table
- where wobjectId=".$_[0]->get("wobjectId"));
+ where $setName=".quote($setValue));
$properties->{sequenceNumber} = $seq+1;
}
unless ($useWobjectId eq "0") {