$classification_data = array('genus' => array('columnname' => 'genus')); // store all level names in $classification_level_columns $classification_level_columns = array(); foreach ($classification_data as $classification_level_name => $data) { $classification_level_columns[] = $data['columnname']; } // extract all unique organism classifications $columnstring = implode(',', $classification_level_columns); $sql = "SELECT\n\t\t\t{$columnstring},\n\t\t\tscientific_name\n\t\tFROM\n\t\t\t{$importTable}\n\t\tGROUP BY\n\t\t\tgenus,\n\t\t\tspecies,\n\t\t\tscientific_name\n\t\tORDER BY\n\t\t\t{$columnstring}, scientific_name"; if (false) { print "Query: {$sql}\n"; } $rows = $db->query($sql, array(), array()); if (count($rows) <= 1) { die(print_r($rows)); } $classificator = 'Swisslichens'; $organisms = array(); $organisms[] = array('classificator' => $classificator, 'classifications' => array(array('classificationlevelname' => 'genus'))); foreach ($rows as $row) { $classifications = array(); foreach ($classification_data as $class => $table) { $value = $row[$table['columnname']]; assert($value != NULL); $classifications[] = array('classificationlevelname' => $class, 'classificationname' => $value); } $organism = array('classificator' => $classificator, 'classifications' => $classifications, 'artgroups' => array('Lichens'), 'scientific_names' => $row['scientific_name']); $organisms[] = $organism; } $classifier->addOrganisms($organisms);
assert(count($plant) == 7); assert(!empty($plant[ORGANISM_SCIENTIFIC_NAME])); assert(!empty($plant[ORGANISM_FAMILY])); assert(!empty($plant[ORGANISM_GENUS])); // is this an update or a new plant? if (array_key_exists($plant[ORGANISM_CRSF_ID], $cache["flora"])) { $db_plant = $cache["flora"][$plant[ORGANISM_CRSF_ID]]; organism_check_and_update($db_plant, $plant); } else { // create the array for inserting a new organism $new_organisms[$plant[ORGANISM_CRSF_ID]] = organism_new_organism($plant); echo "NEW: " . $plant[ORGANISM_CRSF_ID] . ", " . $plant[ORGANISM_SCIENTIFIC_NAME] . ", {$plant['ORGANISM_DE']}\n"; } } // add the new organisms $classifier->addOrganisms($new_organisms); echo "import finished!\n"; /* * ################################################################ * * ################################################################ */ /** * compares our database-infos with the new infoflora data. * a plant is only updated, if there was a change. * * the db-attributes are updated using its "$update_func" function. * the global $update_indizes array controls, which attributes * are checked and how they can be updated * (have a look at the update_* functions) *