123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- function chado_contact_form(&$node, $form_state) {
- $form = array();
-
-
-
-
-
-
-
-
-
- $contact_id = null;
- $type_id = 0;
- $title = '';
- $description = '';
-
-
- if (property_exists($node, 'contact')) {
- $contact = $node->contact;
- $contact_id = $contact->contact_id;
-
-
- $type_id = $contact->type_id->cvterm_id;
- $title = $contact->name;
-
-
-
-
-
-
-
-
-
-
-
- $description = '';
- if (property_exists($node, 'body')) {
- $description = $node->body;
- }
- else {
- $description = $contact->description;
- }
- if (!$description) {
- $contactprop = tripal_contact_get_property($contact->contact_id, 'contact_description');
- $description = $contactprop->value;
- }
-
-
- $form['contact_id'] = array(
- '#type' => 'value',
- '#value' => $contact->contact_id,
- );
- }
-
-
- if (array_key_exists('values', $form_state)) {
- $type_id = $form_state['values']['type_id'];
- $title = $form_state['values']['title'];
- $description = $form_state['values']['description'];
- }
-
-
- if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
- $type_id = $form_state['input']['type_id'];
- $title = $form_state['input']['title'];
- $description = $form_state['input']['description'];
- }
-
-
-
- $sql = "
- SELECT CVTS.cvterm_id, CVTS.name
- FROM {cvtermpath} CVTP
- INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
- INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
- INNER JOIN {cv} CV ON CVTO.cv_id = CV.cv_id
- WHERE
- CV.name = 'tripal_contact' AND
- CVTO.name = 'Contact Type' AND
- CVTP.pathdistance = 1
- ORDER BY CVTS.name ASC
- ";
- $results = chado_query($sql);
- $contact_types = array();
- while ($contact_type = $results->fetchObject()) {
- $contact_types[$contact_type->cvterm_id] = $contact_type->name;
- if (strcmp($contact_type->name, "Person") == 0 and !$type_id) {
- $type_id = $contact_type->cvterm_id;
- }
- }
- $form['type_id'] = array(
- '#type' => 'select',
- '#title' => t('Contact Type'),
- '#options' => $contact_types,
- '#required' => TRUE,
- '#default_value' => $type_id,
- );
-
- $form['title']= array(
- '#type' => 'textfield',
- '#title' => t('Contact Name'),
- '#description' => t('Enter the name of this contact'),
- '#required' => TRUE,
- '#default_value' => $title,
- '#maxlength' => 255,
- );
- $form['description']= array(
- '#type' => 'textarea',
- '#title' => t('Contact Description'),
- '#description' => t('A brief description of the contact'),
- '#required' => TRUE,
- '#default_value' => $description,
- );
-
- $properties = array();
- $properties[] = 'Select a Property';
- $sql = "
- SELECT CVTS.cvterm_id, CVTS.name
- FROM {cvtermpath} CVTP
- INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
- INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
- INNER JOIN {cv} CV ON CVTO.cv_id = CV.cv_id
- WHERE
- CV.name = 'tripal_contact' AND
- NOT CVTO.name = 'Contact Type'
- ORDER BY CVTS.name ASC
- ";
- $prop_types = chado_query($sql);
- while ($prop = $prop_types->fetchObject()) {
- $properties[$prop->cvterm_id] = $prop->name;
- }
-
- $exclude = array('contact_description');
- $include = array();
- tripal_core_properties_form($form, $form_state, 'contactprop', 'contact_id', 'tripal_contact',
- $properties, $contact_id, $exclude, $include, '', 'Properties');
-
- return $form;
- }
- function chado_contact_validate($node, $form, &$form_state) {
-
- $node->title = trim($node->title);
- $node->description = trim($node->description);
-
-
- if($node->op == 'Delete') {
- return;
- }
-
-
-
- if (is_null($node->nid) and property_exists($node, 'contact_id') and $node->contact_id != 0) {
- return;
- }
-
-
- if (property_exists($node, 'nid')) {
-
- $values = array('contact_id' => $node->contact_id);
- $result = tripal_core_chado_select('contact', array('*'), $values);
- $contact = $result[0];
-
-
- if ($contact->name != $node->title) {
- $values = array('name' => $node->title);
- $result = tripal_core_chado_select('contact', array('contact_id'), $values);
- if ($result and count($result) > 0) {
- form_set_error('title', 'Cannot update the contact with this contact name. A contact with this name already exists.');
- return;
- }
- }
- }
-
- else {
-
- $values = array(
- 'name' => $node->title,
- );
- $contact = tripal_core_chado_select('contact', array('contact_id'), $values);
- if ($contact and count($contact) > 0) {
- form_set_error('title', 'Cannot add the contact with this name. A contact with these values already exists.');
- return;
- }
- }
- }
|