123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- function chado_insert_contact($values) {
- $name = $values['name'];
- $description = $values['description'];
- $type = $values['type_name'];
- $properties = $values['properties'];
-
- $values = array('name' => $name);
- $options = array('statement_name' => 'sel_contact_na');
- $contact = chado_select_record('contact', array('contact_id'), $values, $options);
- if (count($contact) == 0) {
- $cvterm = tripal_cv_get_cvterm_by_name($type, NULL, 'tripal_contact');
- if (!$cvterm) {
- tripal_report_error('tripal_contact', TRIPAL_ERROR, "Cannot find contact type '%type'",
- array('%type' => $type));
- return FALSE;
- }
- $values = array(
- 'name' => $name,
- 'description' => '',
- 'type_id' => $cvterm->cvterm_id,
- );
- $options = array('statement_name' => 'ins_contact_nadety');
- $contact = chado_insert_record('contact', $values, $options);
- if (!$contact) {
- tripal_report_error('tripal_contact', TRIPAL_ERROR, 'Could not add the contact', array());
- return FALSE;
- }
- }
- else {
- $contact = (array) $contact[0];
- }
-
-
- if ($description) {
- tripal_contact_insert_property($contact['contact_id'], 'contact_description', $description, TRUE);
- }
-
- foreach ($properties as $key => $value) {
- $success = tripal_contact_insert_property($contact['contact_id'], $key,$value, TRUE);
- if (!$success) {
- tripal_report_error('tripal_contact', TRIPAL_ERROR,
- "Could not add the contact property '%prop'", array('%prop' => $key));
- return FALSE;
- }
- }
- return $contact;
- }
|