Thingy now has a copy thing data option.
This commit is contained in:
parent
55da5c6889
commit
1cc87c159b
3 changed files with 97 additions and 1 deletions
|
|
@ -110,6 +110,43 @@ sub definition {
|
|||
return $class->SUPER::definition($session,$definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 copyCollateral ( tableName, keyName, keyValue )
|
||||
|
||||
Copies a row of collateral data where keyName=keyValue. Generates a new key for keyName.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
The name of the table you wish to copy the data from.
|
||||
|
||||
=head3 keyName
|
||||
|
||||
The name of a column in the table. Is not checked for invalid input.
|
||||
|
||||
=head3 keyValue
|
||||
|
||||
Criteria (value) used to find the data to copy.
|
||||
|
||||
=cut
|
||||
|
||||
sub copyCollateral {
|
||||
my $self = shift;
|
||||
my $table = shift;
|
||||
my $keyName = shift;
|
||||
my $keyValue = shift;
|
||||
my $db = $self->session->db;
|
||||
my $newId = $self->session->id->generate;
|
||||
|
||||
my $temp = $self->session->db->buildArrayRefOfHashRefs(
|
||||
"select * from ".$db->dbh->quote_identifier($table)." where ".$db->dbh->quote_identifier($keyName)."=".$db->quote($keyValue));
|
||||
my $hash = $temp->[0];
|
||||
$hash->{$keyName} = $newId;
|
||||
my @keys = keys %$hash;
|
||||
my $sql = "insert into ".$db->dbh->quote_identifier($table)
|
||||
." (".join(',',map("`$_`",@keys)).") values(".join(',',map("?",@keys)).")";
|
||||
$self->session->db->write($sql,[map($hash->{$_},@keys)]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -947,7 +947,7 @@ sub www_viewGradeBook{
|
|||
unless ( $self->session->user->isInGroup( $self->get("groupToViewReports") ) );
|
||||
my @peoples = $self->session->db->quickArray("SELECT UNIQUE(Survey_responseId) from Survey_tempReport where assetId = ?",[$self->getId()]);
|
||||
for my $people(@peoples){
|
||||
|
||||
#my $
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -325,6 +325,35 @@ sub deleteField {
|
|||
return undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 copyThingData ( )
|
||||
|
||||
Copies data in a Thing.
|
||||
|
||||
=head3 thingId
|
||||
|
||||
The id of the Thing that should be copied.
|
||||
|
||||
=head3 thingDataId
|
||||
|
||||
The id of row of data that should be copied.
|
||||
|
||||
=cut
|
||||
|
||||
sub copyThingData {
|
||||
my $self = shift;
|
||||
my $thingId = shift;
|
||||
my $thingDataId = shift;
|
||||
my $db = $self->session->db;
|
||||
return undef unless $self->canEditThingData($thingId, $thingDataId);;
|
||||
|
||||
$self->copyCollateral("Thingy_".$thingId,"thingDataId",$thingDataId);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 deleteThingData ( )
|
||||
|
|
@ -1368,6 +1397,27 @@ sub www_deleteFieldConfirm {
|
|||
}
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_copyThingData( )
|
||||
|
||||
Copies data in a Thing.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_copyThingData{
|
||||
|
||||
my $self = shift;
|
||||
my $thingId = $self->session->form->process("thingId");
|
||||
my $thingDataId = $self->session->form->process('thingDataId');
|
||||
|
||||
return $self->session->privilege->insufficient() unless $self->canEditThingData($thingId, $thingDataId);
|
||||
|
||||
$self->copyThingData($thingId,$thingDataId);
|
||||
|
||||
return $self->www_search;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_deleteThingConfirm ( )
|
||||
|
||||
Deletes a Thing, including field definitions and instances of this Thing and drops the table that holds the
|
||||
|
|
@ -2201,6 +2251,12 @@ sub editThingData {
|
|||
$var->{"manage_url"} = $session->url->append($url, 'func=manage');
|
||||
$var->{"thing_label"} = $thingProperties->{label};
|
||||
|
||||
if($canEditThingData){
|
||||
if ($thingDataId ne "new"){
|
||||
$var->{"copy_url"} = $session->url->append($url, 'func=copyThingData;thingId='.$thingId.';thingDataId='.$thingDataId);
|
||||
}
|
||||
}
|
||||
|
||||
if($canEditThingData){
|
||||
if ($thingDataId ne "new"){
|
||||
$var->{"delete_url"} = $session->url->append($url, 'func=deleteThingDataConfirm;thingId='
|
||||
|
|
@ -2208,6 +2264,7 @@ sub editThingData {
|
|||
}
|
||||
$var->{"delete_confirm"} = "onclick=\"return confirm('".$i18n->get("delete thing data warning")."')\"";
|
||||
}
|
||||
|
||||
if($self->hasPrivileges($thingProperties->{groupIdAdd}) && !$self->hasEnteredMaxPerUser($thingId)){
|
||||
$var->{"add_url"} = $session->url->append($url,'func=editThingData;thingId='.$thingId.';thingDataId=new');
|
||||
}
|
||||
|
|
@ -3083,6 +3140,8 @@ sequenceNumber');
|
|||
.$thingId.';thingDataId='.$thingDataId,$self->get("url"),$i18n->get('delete thing data warning'));
|
||||
$templateVars{searchResult_edit_icon} = $session->icon->edit('func=editThingData;thingId='
|
||||
.$thingId.';thingDataId='.$thingDataId,$self->get("url"));
|
||||
$templateVars{searchResult_copy_icon} = $session->icon->copy('func=copyThingData;thingId='
|
||||
.$thingId.';thingDataId='.$thingDataId,$self->get("url"));
|
||||
}
|
||||
push(@searchResult_loop,\%templateVars);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue