.scripts/symbiota.php
/**
   * Step 3 - Result Parser.
   *
   * Parse the results from CSV to a PHP-acceptable array. Since PapaParse's
   * headers option is not an option here, remap the array to have proper keys.
   */
Step 3 - Result Parser.
Parse the results from CSV to a PHP-acceptable array. Since PapaParse's
headers option is not an option here, remap the array to have proper keys.
Step 3 - Result Parser . Parse the results from CSV to a PHP - acceptable array . Since PapaParse ' s headers option is not an option here remap the array to have proper keys .
public function parseResults() {
    $this->logger("Parsing results.");
    $convert = array_map("str_getcsv", explode("\n", file_get_contents("./tmp/occurrences.csv")));
    $headers = $convert[0];
    unset($convert[0]);
    foreach ($convert as $record=>$plant) {
      $array = array();
      foreach ($plant as $key=>$value) {
        switch ($key) {
          case 0:  
          case 13: 
          case 16: 
          case 37: 
          case 51: 
          case 53: 
          case 55: 
            $array[$headers[$key]] = $value;
            break;
          case 14:
            $array["scientific_name"] = $value;
            break;
          entifiedBy => identified_by
          case 20:
            $array["identified_by"] = $value;
            break;
          case 27:
            $array["recorded_by"] = $value;
            break;
          case 29:
            $array["event_date"] = $value;
            break;
          case 52:
            $array["state_province"] = $value;
            break;
          case 57:
            $array["decimal_latitude"] = $value;
            break;
          case 58:
            $array["decimal_longitude"] = $value;
            break;
        }
      }
      array_push($this->data, $array);
    }
  }
public function parseResults ( ) { $ this -> logger ( " Parsing results. " ) ; $ convert = array_map ( " str_getcsv " , explode ( " \n " , file_get_contents ( " ./tmp/occurrences.csv " ) ) ) ; $ headers = $ convert [ 0 ] ; unset ( $ convert [ 0 ] ) ; foreach ( $ convert as $ record => $ plant ) { $ array = array ( ) ; foreach ( $ plant as $ key => $ value ) { switch ( $ key ) { case 0 : case 13 : case 16 : case 37 : case 51 : case 53 : case 55 : $ array [ $ headers [ $ key ] ] = $ value ; break ; case 14 : $ array [ " scientific_name " ] = $ value ; break ; case 20 : $ array [ " identified_by " ] = $ value ; break ; case 27 : $ array [ " recorded_by " ] = $ value ; break ; case 29 : $ array [ " event_date " ] = $ value ; break ; case 52 : $ array [ " state_province " ] = $ value ; break ; case 57 : $ array [ " decimal_latitude " ] = $ value ; break ; case 58 : $ array [ " decimal_longitude " ] = $ value ; break ; } } array_push ( $ this -> data , $ array ) ; } }
Step 3 - Result Parser.
Step 3 - Result Parser .
// Convert from CSV to an array. // The first array is the headers, all other are data. // Remove the headers. // Run through the initial converted array and remap it. // id // family // genus // habitat // country // county // locality // scientificName => scientific_name // identifiedBy => identified_by // recordedBy => recorded_by // eventDate => event_date // stateProvince => state_province // decimalLatitude => decimal_latitude // decimalLongitude => decimal_longitude