SHARE
TWEET

Untitled

a guest Jul 29th, 2011 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub editThingDataSave {
  2.  
  3.     my $self = shift;
  4.     my $thingId = shift;
  5.     my $thingDataId = shift;
  6.     my $thingData = shift;
  7.     my $session = $self->session;
  8.     my (%thingData,$fields,@errors,$hadErrors,$newThingDataId);
  9.     my $i18n = WebGUI::International->new($session, 'Asset_Thingy');
  10.  
  11.  
  12.    $self->session->errorHandler->error("Inserting data. Thingdataid: $thingDataId");
  13.  
  14.     if ($thingDataId eq "new"){
  15.         $thingData{dateCreated} = time();
  16.         $thingData{createdById} = $session->user->userId;
  17.         $thingData{ipAddress} = $session->env->getIp;
  18.     }
  19.     else {
  20.         %thingData = $session->db->quickHash("select * from ".$session->db->dbh->quote_identifier("Thingy_".$thingId)
  21.             ." where thingDataId = ?",[$thingDataId]);
  22.     }
  23.  
  24.     %thingData = ( %thingData,
  25.         thingDataId=>$thingDataId,
  26.         updatedById=>$session->user->userId,
  27.         updatedByName=>$session->user->username,
  28.         lastUpDated=>time(),
  29.     );
  30.  
  31.     $fields = $self->getFields($thingId);
  32.     while (my $field = $fields->hashRef) {
  33.         my $fieldName = 'field_'.$field->{fieldId};
  34.         my $fieldValue;
  35.         if ($field->{status} eq "required" || $field->{status} eq "editable"){
  36.             my $fieldType = $field->{fieldType};
  37.             $fieldType = "" if ($fieldType =~ m/^otherThing/x);
  38.             # Modify the defaultValue for certain field types. For most types we want to use
  39.             # the default in the database, for these we want the last known value for this thingData
  40.             if ($self->field_isa($fieldType, 'WebGUI::Form::File')) {
  41.                 $field->{ defaultValue } = $thingData{ "field_" . $field->{ fieldId } };
  42.             }
  43.  
  44.             $fieldValue = $thingData->{$fieldName} || $session->form->process($fieldName,$fieldType,$field->{defaultValue},$field);
  45.         }
  46.         if ($field->{status} eq "required" && ($fieldValue =~ /^\s$/x || $fieldValue eq "" || !(defined $fieldValue))) {
  47.             push (@errors,{
  48.                 "error_message"=>$field->{label}." ".$i18n->get('is required error').".", "field_name"=>$fieldName,
  49.                 });
  50.         }
  51.         if ($field->{status} eq "hidden") {
  52.             $fieldValue = $field->{defaultValue};
  53.             WebGUI::Macro::process($self->session,\$fieldValue);
  54.         }
  55.         if ($field->{status} eq "visible") {
  56.             $fieldValue = $field->{defaultValue};
  57.             #WebGUI::Macro::process($self->session,\$fieldValue);
  58.         }
  59.  
  60.         if ($field->{isUnique}) {
  61.  
  62.              unless ( $self->isUniqueEntry($thingId,$fieldName,$fieldValue,$thingDataId)) {
  63.                push (@errors,{
  64.                 "error_message"=>$field->{label}. $i18n->get('needs to be unique error'),"field_name"=>$fieldName,
  65.                 });
  66.              }
  67.         }
  68.  
  69.  
  70.         $thingData{$fieldName} = $fieldValue;
  71.     }
  72.  
  73.  
  74.    $self->session->errorHandler->error("Checking for errors : " . to_json(@errors));
  75.  
  76.  
  77.     if (@errors) {
  78.         return ('', \@errors);
  79.     }
  80.     $newThingDataId = $self->setCollateral("Thingy_".$thingId,"thingDataId",\%thingData,0,0);
  81.     $self->indexThingData($thingId, \%thingData);
  82.  
  83.     # trigger workflow
  84.     if($thingDataId eq "new"){
  85.         my ($onAddWorkflowId) = $session->db->quickArray("select onAddWorkflowId from Thingy_things where thingId=?"
  86.             ,[$thingId]);
  87.         if ($onAddWorkflowId){
  88.             $self->triggerWorkflow($onAddWorkflowId,$thingId,$newThingDataId);
  89.         }
  90.     }else{
  91.         my ($onEditWorkflowId) = $session->db->quickArray("select onEditWorkflowId from Thingy_things where thingId=?"
  92.             ,[$thingId]);
  93.         if ($onEditWorkflowId){
  94.             $self->triggerWorkflow($onEditWorkflowId,$thingId,$newThingDataId);
  95.         }
  96.     }
  97.  
  98.     return($newThingDataId,\@errors);
  99. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top