public function __construct($title)
 {
     $interaction = new SupportedInteractions();
     $this->interactionTitle = $title;
     $this->source = $interaction->interactionToSource($title);
     $this->target = $interaction->interactionToTarget($title);
 }
 private function observationalSearchContainerPopulator($response)
 {
     $columns = $response->{'columns'};
     $dataList = $response->{'data'};
     $container = array();
     $headerPositions = array();
     $interactions = new SupportedInteractions();
     $j = 0;
     foreach ($columns as $headerTitle) {
         switch ($headerTitle) {
             case 'target_taxon_name':
                 $headerPositions['tax'] = $j;
                 break;
             case 'interaction_type':
                 $headerPositions['interactionType'] = $j;
                 break;
             case 'latitude':
                 $headerPositions['lat'] = $j;
                 break;
             case 'longitude':
                 $headerPositions['long'] = $j;
                 break;
             case 'altitude':
                 $headerPositions['alt'] = $j;
                 break;
             case 'study_title':
                 $headerPositions['study'] = $j;
                 break;
             case 'collection_time_in_unix_epoch':
                 $headerPositions['epoch'] = $j;
                 break;
             case 'tmp_and_unique_source_specimen_id':
                 // note that this id is used to aggregate results.
                 // for eats interaction, the source specimen id is the predator specimen id.
                 $headerPositions['id'] = $j;
                 break;
             case 'source_specimen_life_stage':
                 $headerPositions['sourceLS'] = $j;
                 break;
             case 'target_specimen_life_stage':
                 $headerPositions['targetLS'] = $j;
                 break;
             case 'source_specimen_body_part':
                 $headerPositions['sourceBP'] = $j;
                 break;
             case 'target_specimen_body_part':
                 $headerPositions['targetBP'] = $j;
                 break;
             case 'source_specimen_physiological_state':
                 $headerPositions['sourcePS'] = $j;
                 break;
             case 'target_specimen_physiological_state':
                 $headerPositions['targetPS'] = $j;
                 break;
             default:
                 #some new header property
                 break;
         }
         $j += 1;
     }
     if (empty($dataList)) {
         # if nothng is returned from the rest, dont do anything below this
         return null;
     }
     $interactionType = $dataList[0][$headerPositions['interactionType']];
     $target = $interactions->interactionToTarget($interactionType);
     $source = $interactions->interactionToSource($interactionType);
     # here we change the words target and source to the real represenation of the name IE pred, prey, host.. or whatever
     if (in_array($interactionType, $interactions->getSupportedInteractions())) {
         $headerPositions[$target . 'LS'] = $headerPositions['targetLS'];
         $headerPositions[$source . 'LS'] = $headerPositions['sourceLS'];
         $headerPositions[$target . 'BP'] = $headerPositions['targetBP'];
         $headerPositions[$source . 'BP'] = $headerPositions['sourceBP'];
         $headerPositions[$target . 'PS'] = $headerPositions['targetPS'];
         $headerPositions[$source . 'PS'] = $headerPositions['sourcePS'];
     } else {
         throw new UnsupportedInteractionTypeException('Interaction type ' . $dataList[0][$headerPositions['interactionType']] . ' is not yet supported!');
     }
     $i = 0;
     foreach ($dataList as $taxonData) {
         $container[$i] = array();
         $container[$i][0] = $taxonData[$headerPositions['tax']];
         #subjectTaxon
         $container[$i][1] = $taxonData[$headerPositions['lat']];
         #latitude
         $container[$i][2] = $taxonData[$headerPositions['long']];
         #longitude
         $container[$i][3] = $taxonData[$headerPositions['alt']];
         #altitude
         $container[$i][4] = $taxonData[$headerPositions['study']];
         #contributor
         $container[$i][5] = $taxonData[$headerPositions['epoch']];
         #unix epoch
         $container[$i][6] = $taxonData[$headerPositions['id']];
         #tmp_and_unique_specimen_id
         $container[$i][$target . 'LS'] = $taxonData[$headerPositions[$target . 'LS']];
         $container[$i][$source . 'LS'] = $taxonData[$headerPositions[$source . 'LS']];
         $container[$i][$target . 'BP'] = $taxonData[$headerPositions[$target . 'BP']];
         $container[$i][$source . 'BP'] = $taxonData[$headerPositions[$source . 'BP']];
         $container[$i][$target . 'PS'] = $taxonData[$headerPositions[$target . 'PS']];
         $container[$i][$source . 'PS'] = $taxonData[$headerPositions[$source . 'PS']];
         $i += 1;
     }
     return $container;
 }
 public function populateResponseObject($responseObject, $serviceObject, $interaction)
 {
     $instanceDictionary = array();
     #dictionary that holds the tmp_and_unique_specimen_id
     $instanceElement = 0;
     # element where the tmp_and_unique_specimen_id will be stored
     $instanceName = "nullName";
     $interactionHelper = new SupportedInteractions();
     $target = $interactionHelper->interactionToTarget($interaction->getInteractionTitle());
     $source = $interactionHelper->interactionToSource($interaction->getInteractionTitle());
     if (empty($serviceObject)) {
         # if the service object is empty, dont do anything to the response object.
         return;
     }
     foreach ($serviceObject as $instance) {
         $foundElement = array_search($instance[6], $instanceDictionary);
         # $instance[6] is the unique_specimen_id
         #this allows variable names to use noun in place of source/target
         $targetLifeStage = $target . 'LifeStage';
         $sourceLifeStage = $source . 'LifeStage';
         $targetBodyPart = $target . 'BodyPart';
         $sourceBodyPart = $source . 'BodyPart';
         $targetPhysiologicalState = $target . 'PhysiologicalState';
         $sourcePhysiologicalState = $source . 'PhysiologicalState';
         $targetInstances = $target . 'Instances';
         if ($foundElement === false) {
             #if tmp_and_unique_specimen_id does not already exist in the list, add to the list
             $instanceName = $instance[0];
             $latitude = $instance[1];
             $longitude = $instance[2];
             $altitude = $instance[3];
             $contributor = $instance[4];
             $unixEpoch = !empty($instance[5]) ? $instance[5] : null;
             $uniqueID = $instance[6];
             ${$targetLifeStage} = !empty($instance[$target . 'LS']) ? $instance[$target . 'LS'] : null;
             # $$ causes variable to be name whatever the value of the variable is
             ${$sourceLifeStage} = !empty($instance[$source . 'LS']) ? $instance[$source . 'LS'] : null;
             ${$targetBodyPart} = !empty($instance[$target . 'BP']) ? $instance[$target . 'BP'] : null;
             ${$sourceBodyPart} = !empty($instance[$source . 'BP']) ? $instance[$source . 'BP'] : null;
             ${$targetPhysiologicalState} = !empty($instance[$target . 'PS']) ? $instance[$target . 'PS'] : null;
             ${$sourcePhysiologicalState} = !empty($instance[$source . 'PS']) ? $instance[$source . 'PS'] : null;
             $instanceDictionary[$instanceElement] = $uniqueID;
             /*				switch ($interaction->getTargetTitle()) {
                                 case 'prey':
                                 	$instanceList = array($interaction->getTargetTitle() => $instanceName, 'preyLifeStage' => $preyLifeStage, 'preyBodyPart' => $preyBodyPart, 'preyPhysiologicalState' => $preyPhysiologicalState);
                                     $responseObject->preyInstances[$instanceElement] = array('preyData' => array($instanceList), 'date' => $unixEpoch, 'lat' => $latitude, 'long' => $longitude, 'alt' => $altitude, 'ref' => $contributor);
                                     break;
                                 case 'pred':
                                 	$instanceList = array($interaction->getTargetTitle() => $instanceName, 'predLifeStage' => $predLifeStage);
                                     $responseObject->predInstances[$instanceElement] = array('predData' => array($instanceList), 'date' => $unixEpoch, 'lat' => $latitude, 'long' => $longitude, 'alt' => $altitude, 'ref' => $contributor);
                                     break;
                                 default:
                                     throw new UnknownSpeciesClassificationTypeException('type [' . $interaction->getTargetTitle() . '] not recognized as valid parameter type');
                                 	break;
             				}*/
             # new code
             $instanceList = array($interaction->getTargetTitle() => $instanceName, $targetLifeStage => ${$targetLifeStage}, $sourceLifeStage => ${$sourceLifeStage}, $targetBodyPart => ${$targetBodyPart}, $sourceBodyPart => ${$sourceBodyPart}, $targetPhysiologicalState => ${$targetPhysiologicalState}, $sourcePhysiologicalState => ${$sourcePhysiologicalState});
             $responseObject->{$targetInstances}[$instanceElement] = array($interaction->getTargetTitle() . 'Data' => array($instanceList), 'date' => $unixEpoch, 'lat' => $latitude, 'long' => $longitude, 'alt' => $altitude, 'ref' => $contributor);
             $instanceElement++;
         } else {
             # if the ID already exists in the instanceDictionary, then just add the instance properties to the [$foundElement][0]
             /*				$instanceName           = $instance[0];
             	            $predLifeStage          = (!empty($instance[7]))  ? $instance[7]  : null;
             	            $preyLifeStage          = (!empty($instance[8]))  ? $instance[8]  : null;
             	            $preyBodyPart           = (!empty($instance[9])) ? $instance[9] : null;
             	            $preyPhysiologicalState = (!empty($instance[10])) ? $instance[10] : null;
             
             				switch ($interaction->getTargetTitle()) {
             					case 'prey':
                                 	$instanceList = array($interaction->getTargetTitle() => $instanceName, 'preyLifeStage' => $preyLifeStage, 'preyBodyPart' => $preyBodyPart, 'preyPhysiologicalState' => $preyPhysiologicalState);
             						array_push($responseObject->preyInstances[$foundElement]['preyData'], $instanceList);
             						break;
             					case 'pred':
                                 	$instanceList = array($interaction->getTargetTitle() => $instanceName, 'predLifeStage' => $predLifeStage);
             						array_push($responseObject->predInstances[$foundElement]['predData'], $instanceList);
             						break;
             					default:
                                     throw new UnknownSpeciesClassificationTypeException('type [' . $interaction->getTargetTitle() . '] not recognized as valid parameter type');
             						break;
             				}*/
             $instanceName = $instance[0];
             ${$targetLifeStage} = !empty($instance[$target . 'LS']) ? $instance[$target . 'LS'] : null;
             # $$ causes variable to be name whatever the value of the variable is
             ${$sourceLifeStage} = !empty($instance[$source . 'LS']) ? $instance[$source . 'LS'] : null;
             ${$targetBodyPart} = !empty($instance[$target . 'BP']) ? $instance[$target . 'BP'] : null;
             ${$sourceBodyPart} = !empty($instance[$source . 'BP']) ? $instance[$source . 'BP'] : null;
             ${$targetPhysiologicalState} = !empty($instance[$target . 'PS']) ? $instance[$target . 'PS'] : null;
             ${$sourcePhysiologicalState} = !empty($instance[$source . 'PS']) ? $instance[$source . 'PS'] : null;
             $instanceList = array($interaction->getTargetTitle() => $instanceName, $targetLifeStage => ${$targetLifeStage}, $sourceLifeStage => ${$sourceLifeStage}, $targetBodyPart => ${$targetBodyPart}, $sourceBodyPart => ${$sourceBodyPart}, $targetPhysiologicalState => ${$targetPhysiologicalState}, $sourcePhysiologicalState => ${$sourcePhysiologicalState});
             array_push($responseObject->{$targetInstances}[$foundElement][$interaction->getTargetTitle() . 'Data'], $instanceList);
         }
     }
 }