Moved all collateral reorder operations into the Wobject superclass.

This commit is contained in:
JT Smith 2002-09-30 04:52:28 +00:00
parent 82490a390f
commit d309be32f5
6 changed files with 40 additions and 117 deletions

View file

@ -503,6 +503,36 @@ sub purge {
WebGUI::Discussion::purge($_[0]->get("wobjectId"));
}
#-------------------------------------------------------------------
=head2 reorderCollateral ( tableName, keyName )
Resequences collateral data. Typically useful after deleting a
collateral item to remove the gap created by the deletion.
=item tableName
The name of the table to resequence.
=item keyName
The key column name used to determine which data needs sorting within the table.
=cut
sub reorderCollateral {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select $_[2] from $_[1] where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update $_[1] set sequenceNumber='$i' where wobjectId=$_[0] and $_[2]=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
=head2 set ( [ hashRef, arrayRef ] )

View file

@ -51,18 +51,6 @@ sub sortByColumn {
}
#-------------------------------------------------------------------
sub _reorderDownloads {
my ($sth, $i, $did);
$sth = WebGUI::SQL->read("select downloadId from DownloadManager_file where wobjectId=$_[0] order by sequenceNumber");
while (($did) = $sth->array) {
WebGUI::SQL->write("update DownloadManager_file set sequenceNumber='$i' where downloadId=$did");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub duplicate {
my ($file, $w, %row, $sth, $newDownloadId);
@ -136,7 +124,7 @@ sub www_deleteDownloadConfirm {
$file = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
$file->deleteNode;
$_[0]->deleteCollateral("DownloadManager_file","downloadId",$session{form}{did});
_reorderDownloads($session{form}{wid});
$_[0]->reorderCollateral("DownloadManager_file","downloadId");
return "";
} else {
return WebGUI::Privilege::insufficient();
@ -268,7 +256,7 @@ sub www_editDownloadSave {
dateUploaded => time(),
groupToView => $session{form}{groupToView}
});
_reorderDownloads($_[0]->get("wobjectId"));
$_[0]->reorderCollateral("DownloadManager_file","downloadId");
$file = WebGUI::Attachment->new("",$session{form}{wid},$session{form}{did});
$file->save("downloadFile");
$files{downloadFile} = $file->getFilename;

View file

@ -26,17 +26,6 @@ our $namespace = "FAQ";
our $name = WebGUI::International::get(2,$namespace);
#-------------------------------------------------------------------
sub _reorderQuestions {
my ($sth, $i, $qid);
$sth = WebGUI::SQL->read("select questionId from FAQ_question where wobjectId=$_[0] order by sequenceNumber");
while (($qid) = $sth->array) {
WebGUI::SQL->write("update FAQ_question set sequenceNumber='$i' where questionId=$qid");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub duplicate {
my ($w, %data, $newQuestionId, $sth);
@ -83,7 +72,7 @@ sub www_deleteQuestionConfirm {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$_[0]->deleteCollateral("FAQ_question","questionId",$session{form}{qid});
_reorderQuestions($_[0]->get("wobjectId"));
$_[0]->reorderCollateral("FAQ_question","questionId");
return "";
} else {
return WebGUI::Privilege::insufficient();

View file

@ -27,17 +27,6 @@ our $namespace = "LinkList";
our $name = WebGUI::International::get(6,$namespace);
#-------------------------------------------------------------------
sub _reorderLinks {
my ($sth, $i, $lid);
$sth = WebGUI::SQL->read("select linkId from LinkList_link where wobjectId=$_[0] order by sequenceNumber");
while (($lid) = $sth->array) {
WebGUI::SQL->write("update LinkList_link set sequenceNumber='$i' where linkId=$lid");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub duplicate {
my ($w, $sth, @row, $newLinkId);
@ -83,7 +72,7 @@ sub www_deleteLinkConfirm {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$_[0]->deleteCollateral("LinkList_link","linkId",$session{form}{lid});
_reorderLinks($session{form}{wid});
$_[0]->reorderCollateral("LinkList_link","linkId");
return "";
} else {
return WebGUI::Privilege::insufficient();

View file

@ -29,17 +29,6 @@ our $name = WebGUI::International::get(1,$namespace);
our @fields = qw(width fromField fromStatus toField toStatus
ccField ccStatus bccField bccStatus subjectField subjectStatus acknowledgement storeEntries);
#-------------------------------------------------------------------
sub _reorderFields {
my ($sth, $i, $fid);
$sth = WebGUI::SQL->read("select mailFieldId from MailForm_field where wobjectId=$_[0] order by sequenceNumber");
while (($fid) = $sth->array) {
WebGUI::SQL->write("update MailForm_field set sequenceNumber='$i' where mailFieldId=$fid");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub duplicate {
my ($w, %data, $newFieldId, $sth);
@ -104,7 +93,7 @@ sub www_deleteFieldConfirm {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$_[0]->deleteCollateral("MailForm_field","mailFieldId",$session{form}{fid});
_reorderFields($_[0]->get("wobjectId"));
$_[0]->reorderCollateral("MailForm_field","mailFieldId");
return "";
} else {
return WebGUI::Privilege::insufficient();

View file

@ -27,68 +27,6 @@ our $namespace = "Product";
our $name = WebGUI::International::get(1,$namespace);
#-------------------------------------------------------------------
sub _reorderAccessories {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select accessoryWobjectId from
Product_accessory where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_accessory set sequenceNumber='$i'
where wobjectId=$_[0] and accessoryWobjectId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub _reorderBenefits {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select productBenefitId from
Product_benefit where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_benefit set sequenceNumber='$i' where productBenefitId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub _reorderFeatures {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select productFeatureId from
Product_feature where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_feature set sequenceNumber='$i' where productFeatureId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub _reorderRelated {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select relatedWobjectId from
Product_related where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_related set sequenceNumber='$i'
where wobjectId=$_[0] and relatedWobjectId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub _reorderSpecifications {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select productSpecificationId from
Product_specification where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_specification set sequenceNumber='$i' where productSpecificationId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub duplicate {
my ($w, $file, %data, $newId, $sth);
@ -283,7 +221,7 @@ sub www_deleteAccessoryConfirm {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("delete from Product_accessory where wobjectId=$session{form}{wid}
and accessoryWobjectId=$session{form}{aid}");
_reorderAccessories($_[0]->get("wobjectId"));
$_[0]->reorderCollateral("Product_accessory","accessoryWobjectId");
return "";
} else {
return WebGUI::Privilege::insufficient();
@ -302,7 +240,7 @@ sub www_deleteBenefit {
sub www_deleteBenefitConfirm {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->deleteCollateral("Product_benefit","productBenefitId",$session{form}{bid});
_reorderBenefits($_[0]->get("wobjectId"));
$_[0]->reorderCollateral("Product_benefit","productBenefitId");
return "";
} else {
return WebGUI::Privilege::insufficient();
@ -321,7 +259,7 @@ sub www_deleteFeature {
sub www_deleteFeatureConfirm {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->deleteCollateral("Product_feature","productFeatureId",$session{form}{fid});
_reorderFeatures($_[0]->get("wobjectId"));
$_[0]->reorderCollateral("Product_feature","productFeatureId");
return "";
} else {
return WebGUI::Privilege::insufficient();
@ -341,7 +279,7 @@ sub www_deleteRelatedConfirm {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("delete from Product_related where wobjectId=$session{form}{wid}
and relatedWobjectId=$session{form}{rid}");
_reorderRelated($_[0]->get("wobjectId"));
$_[0]->reorderCollateral("Product_related","relatedWobjectId");
return "";
} else {
return WebGUI::Privilege::insufficient();
@ -360,7 +298,7 @@ sub www_deleteSpecification {
sub www_deleteSpecificationConfirm {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->deleteCollateral("Product_specification","productSpecificationId",$session{form}{sid});
_reorderSpecifications($_[0]->get("wobjectId"));
$_[0]->reorderCollateral("Product_specification","productSpecificationId");
return "";
} else {
return WebGUI::Privilege::insufficient();