123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- function tripal_contact_get_property($contact_id, $property) {
- return tripal_core_get_property('contact', $contact_id, $property, 'tripal_contact');
- }
- function tripal_contact_insert_property($contact_id, $property, $value, $update_if_present = 0) {
- return tripal_core_insert_property('contact', $contact_id, $property, 'tripal_contact', $value, $update_if_present);
- }
- function tripal_contact_update_property($contact_id, $property, $value, $insert_if_missing = 0) {
- return tripal_core_update_property('contact', $contact_id, $property, 'tripal_contact', $value, $insert_if_missing);
- }
- function tripal_contact_delete_property($contact_id, $property) {
- return tripal_core_delete_property('contact', $contact_id, $property, 'tripal_contact');
- }
- function tripal_contact_add_contact($name, $description, $type, $properties) {
-
- $values = array('name' => $name);
- $options = array('statement_name' => 'sel_contact_na');
- $contact = tripal_core_chado_select('contact', array('contact_id'), $values, $options);
-
- if (count($contact) == 0) {
- $cvterm = tripal_cv_get_cvterm_by_name($type, NULL, 'tripal_contact');
- if (!$cvterm) {
- watchdog('tripal_contact',"Cannot find contact type '%type'",
- array('%type' => $type), WATCHDOG_ERROR);
- return FALSE;
- }
- $values = array(
- 'name' => $name,
- 'description' => '',
- 'type_id' => $cvterm->cvterm_id,
- );
- $options = array('statement_name' => 'ins_contact_nadety');
- $contact = tripal_core_chado_insert('contact', $values, $options);
- if (!$contact) {
- watchdog('tripal_contact','Could not add the contact', array(), WATCHDOG_ERROR);
- 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) {
- watchdog('tripal_contact',"Could not add the contact property '%prop'", array('%prop' => $key), WATCHDOG_ERROR);
- return FALSE;
- }
- }
- return $contact;
- }
|