| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825 | 
							- <?php
 
- /**
 
-  * Loads an OBO File using the new TripalImporter. Expected to be run by a Tripal Job.
 
-  */
 
- function tripal_cv_load_obo($obo_id, $job = NULL) {
 
-   module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/OBOImporter');
 
-   $obo_importer = new OBOImporter();
 
-   $obo_importer->create(array('obo_id' => $obo_id));
 
-   if ($job) {
 
-     $obo_importer->setJob($job);
 
-   }
 
-   $obo_importer->run();
 
- }
 
- /**
 
-  * Provide landing page to the new admin pages
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_admin_cv_listing() {
 
-   $output = '';
 
-   // set the breadcrumb
 
-   $breadcrumb = array();
 
-   $breadcrumb[] = l('Home', '<front>');
 
-   $breadcrumb[] = l('Administration', 'admin');
 
-   $breadcrumb[] = l('Tripal', 'admin/tripal');
 
-   $breadcrumb[] = l('Chado Modules', 'admin/tripal/legacy');
 
-   $breadcrumb[] = l('Vocabularies', 'admin/tripal/legacy/vocab');
 
-   drupal_set_breadcrumb($breadcrumb);
 
-   // Add the view
 
-   $cvs_view = views_embed_view('tripal_cv_admin_cvs','default');
 
-   $cvterms_view = views_embed_view('tripal_cv_admin_cvterms','default');
 
-   if (isset($cvs_view) && isset($cvterms_view)) {
 
-     $output .= $cvs_view;
 
-   }
 
-   else {
 
-     $output .= '<p>The Tripal Controlled Vocabulary module uses primarily views to provide an '
 
-         . 'administrative interface. Currently one or more views needed for this '
 
-             . 'administrative interface are disabled. <strong>Click each of the following links to '
 
-                 . 'enable the pertinent views</strong>:</p>';
 
-     $output .= '<ul>';
 
-     if (!isset($cvs_view)) {
 
-       $output .= '<li>'.l('Tripal Vocabularies', 'admin/tripal/vocab/views/cvs/enable').'</li>';
 
-     }
 
-     if (!isset($cvterm_view)) {
 
-       $output .= '<li>'.l('Tripal Vocabulary Terms', 'admin/tripal/vocab/views/cvterms/enable').'</li>';
 
-     }
 
-     $output .= '</ul>';
 
-   }
 
-   return $output;
 
- }
 
- /**
 
-  * Provides the actual "Select CV" form on the Update/Delete Controlled
 
-  *   Vocabulary page. This form also triggers the edit javascript
 
-  * @todo Modify this form to use Drupal AJAX
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cv_edit_form($form, &$form_state) {
 
-   // get the cv_d if form was submitted via AJAX
 
-   $cv_id = 0;
 
-   if (array_key_exists('values', $form_state)) {
 
-     $cv_id = $form_state['values']['cv_id'];
 
-   }
 
-   elseif (isset($form_state['build_info']['args'][0])) {
 
-     $cv_id = $form_state['build_info']['args'][0];
 
-   }
 
-   // get a list of db from chado for user to choose
 
-   $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
 
-   $results = chado_query($sql);
 
-   $cvs = array();
 
-   $cvs[] = 'Select a vocabulary';
 
-   foreach ($results as $cv) {
 
-     $cvs[$cv->cv_id] = $cv->name;
 
-   }
 
-   $form['cv_id'] = array(
 
-     '#title' => t('Controlled Vocabulary Name'),
 
-     '#type' => 'select',
 
-     '#options' => $cvs,
 
-     '#ajax' => array(
 
-       'callback' => 'tripal_cv_edit_form_ajax',
 
-       'wrapper'  => 'cv-edit-div',
 
-       'effect'   => 'fade',
 
-       'event'    => 'change',
 
-       'method'   => 'replace',
 
-     ),
 
-     '#default_value' => $cv_id,
 
-   );
 
-   // if we don't have a db_id then we can  return the form, otherwise
 
-   // add in the other fields
 
-   if ($cv_id) {
 
-     tripal_cv_add_cv_form_fields($form, $form_state, $cv_id);
 
-     $form['update'] = array(
 
-       '#type'         => 'submit',
 
-       '#value'        => t('Update'),
 
-     );
 
-     $form['delete'] = array(
 
-       '#type'         => 'submit',
 
-       '#value'        => t('Delete'),
 
-       '#attributes'   => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
 
-     );
 
-   }
 
-   else {
 
-     // if we don't have a dbid then this is the first time the form has
 
-     // benn loaded and we need to create the div where ajax replacement elements get stored
 
-     $form['div_replace'] = array(
 
-       '#type' => 'item',
 
-       '#prefix' => '<div id="cv-edit-div">',
 
-       '#suffix' => '</div>',
 
-     );
 
-   }
 
-   return $form;
 
- }
 
- /**
 
-  * Form to add contolled vocabularies
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cv_add_form($form, &$form_state) {
 
-   // add in the form fields to this form
 
-   tripal_cv_add_cv_form_fields($form, $form_state);
 
-   $form['add'] = array(
 
-     '#type'         => 'submit',
 
-     '#value'        => t('Add'),
 
-     '#weight'       => 5,
 
-   );
 
-   return $form;
 
- }
 
- /**
 
-  * Form fields in common between the cv add & edit form.
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_add_cv_form_fields(&$form, $form_state, $cv_id = NULL) {
 
-   $default_name = '';
 
-   $default_desc = '';
 
-   if ($cv_id) {
 
-     $values = array('cv_id' => $cv_id);
 
-     $result = chado_select_record('cv', array('*'), $values);
 
-     $cv = $result[0];
 
-     $default_name = $cv->name;
 
-     $default_desc = $cv->definition;
 
-   }
 
-   // add a fieldset for the Drupal Schema API
 
-   $form = array(
 
-     '#type' => 'fieldset',
 
-     '#title' => 'Controlled Vocabulary Details',
 
-     '#collapsible' => 0,
 
-   );
 
-   $form['name']= array(
 
-     '#type'          => 'textfield',
 
-     '#title'         => t("Controlled Vocabulary name"),
 
-     '#description'   => t('Please enter the name for this vocabulary.'),
 
-     '#required'      => TRUE,
 
-     '#default_value' => $default_name,
 
-     '#maxlength'     => 255,
 
-   );
 
-   $form['definition']= array(
 
-     '#type'          => 'textarea',
 
-     '#title'         => t('Description'),
 
-     '#description'   => t('Please enter a definition for this vocabulary'),
 
-     '#default_value' => $default_desc,
 
-   );
 
-   return $form;
 
- }
 
- /**
 
-  * Validation fucntion for tripal_cv_cv_add_form
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cv_add_form_validate($form, &$form_state) {
 
-   tripal_cv_form_fields_validate($form, $form_state);
 
- }
 
- /**
 
-  * Validation fucntion for tripal_cv_cv_edit_form
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cv_edit_form_validate($form, &$form_state) {
 
-   tripal_cv_form_fields_validate($form, $form_state);
 
- }
 
- /**
 
-  * Generic validation form for shared fields of both the edit and add forms
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_form_fields_validate($form, &$form_state) {
 
-   $name =  array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
 
-   $desc =  array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
 
-   $cv_id = array_key_exists('cv_id', $form_state['values'])      ? trim($form_state['values']['cv_id']) : '';
 
-   // make sure the cv name is unique
 
-   $values = array('name' => $name);
 
-   $results = chado_select_record('cv', array('cv_id'), $values);
 
-   if (count($results) > 0 and $results[0]->cv_id != $cv_id) {
 
-     form_set_error('name', 'The vocabulary name must be unique');
 
-   }
 
- }
 
- /**
 
-  * Submit cv add form
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cv_add_form_submit($form, &$form_state) {
 
-   $name =  array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
 
-   $desc =  array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
 
-   $values = array(
 
-     'name' => $name,
 
-     'definition' => $desc,
 
-   );
 
-   $success = chado_insert_record('cv', $values);
 
-   if ($success) {
 
-     drupal_set_message(t("Controlled vocabulary added"));
 
-   }
 
-   else {
 
-     drupal_set_message(t("Failed to add controlled vocabulary."));
 
-   }
 
- }
 
- /**
 
-  * Submit cv edit form
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cv_edit_form_submit($form, &$form_state) {
 
-   $name  = array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
 
-   $desc  = array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
 
-   $cv_id = array_key_exists('cv_id', $form_state['values'])      ? trim($form_state['values']['cv_id']) : '';
 
-   $op    = array_key_exists('op', $form_state['values'])         ? trim($form_state['values']['op']) : '';
 
-   $values = array(
 
-     'name' => $name,
 
-     'definition' => $desc,
 
-   );
 
-   if (strcmp($op, 'Update')==0) {
 
-     $match = array('cv_id' => $cv_id);
 
-     $success = chado_update_record('cv', $match, $values);
 
-     if ($success) {
 
-       drupal_set_message(t("Controlled vocabulary updated"));
 
-     }
 
-     else {
 
-       drupal_set_message(t("Failed to update controlled vocabulary."));
 
-     }
 
-   }
 
-   if (strcmp($op, 'Delete')==0) {
 
-     $match = array('cv_id' => $cv_id);
 
-     $success = chado_delete_record('cv', $match);
 
-     if ($success) {
 
-       drupal_set_message(t("Controlled vocabulary deleted"));
 
-     }
 
-     else {
 
-       drupal_set_message(t("Failed to delete controlled vocabulary."));
 
-     }
 
-   }
 
- }
 
- /**
 
-  * Ajax callback for the tripal_cv_form
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_edit_form_ajax($form, $form_state) {
 
-   $elements = array();
 
-   // add in the form fields and the buttons
 
-   if (array_key_exists('cv_id', $form_state['values'])) {
 
-     $elements['fields'] = $form;
 
-     $elements['update'] = $form['update'];
 
-     $elements['delete'] = $form['delete'];
 
-   }
 
-   // add back in the cv-edit-div that is used for the next round of AJAX
 
-   $elements['fields']['#prefix'] =  '<div id="cv-edit-div">';
 
-   $elements['fields']['#suffix'] =  '</div">';
 
-   // reset the values for the fields to the defaults
 
-   $elements['fields']['name']['#value']        = $elements['fields']['name']['#default_value'];
 
-   $elements['fields']['definition']['#value']  = $elements['fields']['definition']['#default_value'];
 
-   //drupal_set_message('<pre>' . print_r($elements, TRUE) . '</pre>', "status");
 
-   return $elements;
 
- }
 
- /**
 
-  * Form for editing cvterms
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvterm_edit_form($form, &$form_state) {
 
-   $step = 0;
 
-   if (empty($form_state['storage']['step'])) {
 
-     $form_state['storage']['step'] = 0;
 
-   }
 
-   else {
 
-     $step = $form_state['storage']['step'];
 
-   }
 
-   $cv_id = 0;
 
-   if ($step == 1) {
 
-     $cv_id = $form_state['storage']['cv_id'];
 
-     $cvterm_name = $form_state['storage']['name'];
 
-     $cvterm_id = $form_state['storage']['cvterm_id'];
 
-   }
 
-   // get the cv if form was submitted via AJAX
 
-   $cvterm = '';
 
-   if (array_key_exists('values', $form_state)) {
 
-     $cv_id = $form_state['values']['cv_id'];
 
-     if (array_key_exists('cvterm', $form_state['values'])) {
 
-       $cvterm = $form_state['values']['cvterm'];
 
-     }
 
-   }
 
-   elseif (isset($form_state['build_info']['args'][0])) {
 
-     $cv_id = $form_state['build_info']['args'][0];
 
-     $cvterm_id = $form_state['build_info']['args'][1];
 
-     if ($form_state['build_info']['args'][1]) {
 
-       $cvterm_name = chado_query('SELECT name FROM {cvterm} WHERE cvterm_id = :id',
 
-           array(':id' => $cvterm_id))->fetchField();
 
-       $step = 1;
 
-     }
 
-   }
 
-   // get a list of CVs
 
-   $cvs = array();
 
-   $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
 
-   $results = chado_query($sql);
 
-   $cvs[] = 'Select a vocabulary';
 
-   foreach ($results as $cv) {
 
-     $cvs[$cv->cv_id] = $cv->name;
 
-   }
 
-   $form['cv_id'] = array(
 
-     '#title' => t('Controlled Vocabulary Name'),
 
-     '#type' => 'select',
 
-     '#options' => $cvs,
 
-     '#required' => TRUE,
 
-     '#default_value' => $cv_id,
 
-     '#ajax' => array(
 
-       'callback'    => 'tripal_cv_cvterm_edit_form_ajax',
 
-       'wrapper' => 'cvterm-edit-div',
 
-       'event'   => 'change',
 
-       'method'  => 'replace',
 
-       'event'    => 'change',
 
-     ),
 
-   );
 
-   if ($cv_id and $step == 0) {
 
-     $form['name']= array(
 
-       '#type'          => 'textfield',
 
-       '#title'         => t("Term Name"),
 
-       '#default_value' => $cvterm,
 
-       '#required'      => TRUE,
 
-       '#autocomplete_path' => "admin/tripal/tripal_cv/cvterm/auto_name/$cv_id",
 
-       '#description'   => t('Enter the term to edit.')
 
-     );
 
-     $form['continue']= array(
 
-       '#type'          => 'submit',
 
-       '#value'         => 'continue',
 
-     );
 
-   }
 
-   elseif ($step == 1) {
 
-     tripal_cv_add_cvterm_form_fields($form, $form_state, $cv_id, $cvterm_name);
 
-     // when editing there are certain fields the user should not change for a term
 
-     // let's mark those as disabled
 
-     $form['cv_id']['#disabled'] = TRUE;
 
-     $form['db_id']['#disabled'] = TRUE;
 
-     $form['accession']['#disabled'] = TRUE;
 
-     // add in the div for replacing the fields if needed
 
-     $form['#prefix'] = '<div id="cvterm-edit-div">';
 
-     $form['#suffix'] = '</div>';
 
-     // add in the cvterm id
 
-     $form['cvterm_id'] = array(
 
-       '#type' => 'hidden',
 
-       '#value' =>  $cvterm_id,
 
-     );
 
-     $form['update'] = array(
 
-       '#type'         => 'submit',
 
-       '#value'        => t('Update'),
 
-     );
 
-     $form['delete'] = array(
 
-       '#type'         => 'submit',
 
-       '#value'        => t('Delete'),
 
-       '#attributes'   => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
 
-     );
 
-   }
 
-   if ($step == 0) {
 
-     // if we don't have a cv_id then this is the first time the form has
 
-     // benn loaded and we need to create the div where ajax replacement elements get stored
 
-     $form['div_replace'] = array(
 
-       '#type' => 'item',
 
-       '#prefix' => '<div id="cvterm-edit-div">',
 
-       '#suffix' => '</div>',
 
-     );
 
-   }
 
-   return $form;
 
- }
 
- /**
 
-  * Form for adding cvterms
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvterm_add_form($form, &$form_state) {
 
-   $cv_id = 0;
 
-   if (array_key_exists('values', $form_state)) {
 
-     $cv_id = $form_state['values']['cv_id'];
 
-   }
 
-   elseif (isset($form_state['build_info']['args'][0])) {
 
-     $cv_id = $form_state['build_info']['args'][0];
 
-   }
 
-   // get a list of CVs
 
-   $cvs = array();
 
-   $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
 
-   $results = chado_query($sql);
 
-   $cvs[] = 'Select a vocabulary';
 
-   foreach ($results as $cv) {
 
-     $cvs[$cv->cv_id] = $cv->name;
 
-   }
 
-   $form['cv_id'] = array(
 
-     '#title' => t('Controlled Vocabulary (Ontology) Name'),
 
-     '#type' => 'select',
 
-     '#options' => $cvs,
 
-     '#required' => TRUE,
 
-     '#default_value' => $cv_id,
 
-   );
 
-   tripal_cv_add_cvterm_form_fields($form, $form_state);
 
-   $form['add'] = array(
 
-     '#type'         => 'submit',
 
-     '#value'        => t('Add Term'),
 
-   );
 
-   return $form;
 
- }
 
- /**
 
-  * Form fields in common between add/edit forms
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_add_cvterm_form_fields(&$form, $form_state, $cv_id = 0, $cvterm_name = '') {
 
-   $name = '';
 
-   $definition = '';
 
-   $is_relationship = '';
 
-   $is_obsolete = '';
 
-   $db_id = '';
 
-   $accession = '';
 
-   $cvterm = NULL;
 
-   // get default values
 
-   if ($cvterm_name) {
 
-     $values = array('cv_id' => $cv_id, 'name' => $cvterm_name);
 
-     $cvterm = chado_generate_var('cvterm', $values);
 
-     $name = $cvterm->name;
 
-     $definition = $cvterm->definition;
 
-     $is_relationship = $cvterm->is_relationshiptype;
 
-     $is_obsolete = $cvterm->is_obsolete;
 
-     $db_id = $cvterm->dbxref_id->db_id->db_id;
 
-     $accession = $cvterm->dbxref_id->accession;
 
-   }
 
-   $form['name']= array(
 
-     '#type'          => 'textfield',
 
-     '#title'         => t("Term Name"),
 
-     '#default_value' => $name,
 
-     '#description'   => t('The term must be unique within the database selected below.'),
 
-     '#required'      => TRUE,
 
-   );
 
-   $form['internal_id']= array(
 
-     '#type'          => 'item',
 
-     '#title'         => t("Internal ID"),
 
-     '#markup'        => $cvterm ? $cvterm->cvterm_id : '',
 
-   );
 
-   $form['definition']= array(
 
-     '#type'          => 'textarea',
 
-     '#title'         => t('Description'),
 
-     '#description'   => t('Please enter a description for this term'),
 
-     '#default_value' => $definition,
 
-   );
 
-   $form['is_relationship'] = array(
 
-     '#type'          => 'checkbox',
 
-     '#title'         => t('This term describes a relationship?'),
 
-     '#default_value' => $is_relationship,
 
-   );
 
-   $form['is_obsolete'] = array(
 
-     '#type'          => 'checkbox',
 
-     '#title'         => t('This term is obsolete?'),
 
-     '#default_value' => $is_obsolete,
 
-   );
 
-   $values = array();
 
-   $columns = array('db_id', 'name');
 
-   $options = array('order_by' => array('name' => 'ASC'));
 
-   $results = chado_select_record('db', $columns, $values, $options);
 
-   $dbs = array();
 
-   $dbs[] = '';
 
-   foreach ($results as $db) {
 
-     $dbs[$db->db_id] = $db->name;
 
-   }
 
-   $form['db_id'] = array(
 
-     '#type'         => 'select',
 
-     '#title'         => t('Database'),
 
-     '#description'   => t('All terms must be assocated with a database. If there is no database for this term (e.g. it is a custom term specific to this site) then select the database \'null\' or consider creating a database specific for your site and use that anytime you would like to add terms.'),
 
-     '#options'      => $dbs,
 
-     '#default_value' => $db_id,
 
-     '#required' => TRUE,
 
-   );
 
-   $form['accession']= array(
 
-     '#type'          => 'textfield',
 
-     '#title'         => t("Accession"),
 
-     '#description'   => t('If this term has an existing accession (unique identifier) in the database
 
-        please enter that here.  If the accession is numeric with a database prefix (e.g. GO:003023), please
 
-        enter just the numeric value.  The database prefix will be appended whenever the term is displayed.
 
-        If you do not have a numeric value consider entering the term name as the accession.'),
 
-     '#required'      => TRUE,
 
-     '#default_value' => $accession,
 
-   );
 
- }
 
- /**
 
-  * Validate cvterm edit form
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvterm_edit_form_validate($form, &$form_state) {
 
-   $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
 
-   $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
 
-   $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
 
-   $cvterm_id = array_key_exists('cvterm_id', $form_state['values']) ? $form_state['values']['cvterm_id'] : '';
 
-   $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
 
-   $step = $form_state['storage']['step'];
 
-   // make sure the cv term name is unique for this vocabulary
 
-   if ($step == 1) {
 
-     $values = array('name' => $name, 'cv_id' => $cv_id);
 
-     $results = chado_select_record('cvterm', array('cvterm_id'), $values);
 
-     foreach ($results as $r) {
 
-       if ($r->cvterm_id != $cvterm_id) {
 
-         form_set_error('name', 'The term name must be unique for this vocabulary. Another term with this name already exists.');
 
-       }
 
-     }
 
-   }
 
- }
 
- /**
 
-  * Validate cv add form
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvterm_add_form_validate($form, &$form_state) {
 
-   $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
 
-   $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
 
-   $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
 
-   $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
 
-   $values = array('cv_id' => $cv_id);
 
-   $results = chado_select_record('cv', array('name'), $values);
 
-   if (!$results or count($results) == 0) {
 
-     form_set_error('cv_id', 'The controlled vocabulary does not exist');
 
-   }
 
-   // make sure the DB exists
 
-   $values = array('db_id' => $db_id);
 
-   $results = chado_select_record('db', array('name'), $values);
 
-   if (!$results or count($results) == 0) {
 
-     form_set_error('db_id', 'The database name does not exist');
 
-   }
 
-   // make sure the cv term name is unique for this vocabulary
 
-   $values = array('name' => $name, 'cv_id' => $cv_id);
 
-   $results = chado_select_record('cvterm', array('cvterm_id'), $values);
 
-   if (count($results) > 0) {
 
-     form_set_error('name', 'The term name must be unique for this vocabulary. Another term with this name already exists.');
 
-   }
 
-   // make sure this accession is unique for the database
 
-   $values = array('accession' => $accession, 'db_id' => $db_id);
 
-   $results = chado_select_record('dbxref', array('dbxref_id'), $values);
 
-   if (count($results) > 0 ) {
 
-     form_set_error('accession', 'The accession is not uniuqe for this vocabulary\'s database.');
 
-   }
 
- }
 
- /**
 
-  * Edits existing controlled vocabulary terms
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvterm_edit_form_submit($form, &$form_state) {
 
-   $cv_id           = array_key_exists('cv_id', $form_state['values'])           ? trim($form_state['values']['cv_id']) : '';
 
-   $name            = array_key_exists('name', $form_state['values'])            ? trim($form_state['values']['name']) : '';
 
-   $definition      = array_key_exists('definition', $form_state['values'])      ? trim($form_state['values']['definition']) : '';
 
-   $is_relationship = array_key_exists('is_relationship', $form_state['values']) ? trim($form_state['values']['is_relationship']) : '';
 
-   $is_obsolete     = array_key_exists('is_obsolete', $form_state['values'])     ? trim($form_state['values']['is_obsolete']) : '';
 
-   $cvterm_id       = array_key_exists('cvterm_id', $form_state['values'])       ? trim($form_state['values']['cvterm_id']) : '';
 
-   $db_id           = array_key_exists('db_id', $form_state['values'])           ? trim($form_state['values']['db_id']) : '';
 
-   $accession       = array_key_exists('accession', $form_state['values'])       ? trim($form_state['values']['accession']) : '';
 
-   $op              = array_key_exists('op', $form_state['values'])              ? trim($form_state['values']['op']) : '';
 
-   if ($op == 'Update') {
 
-     // get the original cvterm_id
 
-     $values = array('name' => $name, 'cv_id' => $cv_id);
 
-     $results = chado_select_record('cvterm', array('cvterm_id'), $values);
 
-     $cvterm = $results[0];
 
-     // get the cv
 
-     $values = array('cv_id' => $cv_id);
 
-     $results = chado_select_record('cv', array('name'), $values);
 
-     $cv = $results[0];
 
-     // get the db
 
-     $values = array('db_id' => $db_id);
 
-     $results = chado_select_record('db', array('name'), $values);
 
-     $db = $results[0];
 
-     // now add the term
 
-     $term = array(
 
-       'name' => $name,
 
-       'namespace' => $cv->name,
 
-       'id' => $accession,
 
-       'definition' => $definition,
 
-       'is_obsolete' => $is_obsolete,
 
-       'cv_name' => $cv->name,
 
-       'is_relationship' => $is_relationship,
 
-       'db_name' => $db->name
 
-     );
 
-     $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
 
-     if ($cvterm) {
 
-       drupal_set_message('Term updated successfully.');
 
-       drupal_goto('admin/tripal/loaders/chado_vocabs/chado_cvterms');
 
-     }
 
-     else {
 
-       drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
 
-     }
 
-   }
 
-   if ($op == 'Delete') {
 
-     $values = array('cvterm_id' => $cvterm_id);
 
-     $success = chado_delete_record('cvterm', $values);
 
-     if ($success) {
 
-       drupal_set_message('Term deleted successfully.');
 
-     }
 
-     else {
 
-       drupal_set_message('Could not delete term term. Check Drupal recent logs for error messages.', 'error');
 
-     }
 
-   }
 
- }
 
- /**
 
-  * Adds new terms to an existing cv
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvterm_add_form_submit($form, &$form_state) {
 
-   $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
 
-   $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
 
-   $definition = array_key_exists('definition', $form_state['values']) ? $form_state['values']['definition'] : '';
 
-   $is_relationship = array_key_exists('is_relationship', $form_state['values']) ? $form_state['values']['is_relationship'] : '';
 
-   $is_obsolete = array_key_exists('is_obsolete', $form_state['values']) ? $form_state['values']['is_obsolete'] : '';
 
-   $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
 
-   $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
 
-   // get the database
 
-   $values = array('db_id' => $db_id);
 
-   $results = chado_select_record('db', array('name'), $values);
 
-   $db = $results[0];
 
-   // get the cv
 
-   $values = array('cv_id' => $cv_id);
 
-   $results = chado_select_record('cv', array('name'), $values);
 
-   $cv = $results[0];
 
-   // now add the term
 
-   $term = array(
 
-     'name' => $name,
 
-     'namespace' => $cv->name,
 
-     'id' => $accession,
 
-     'definition' => $definition,
 
-     'is_obsolete' => $is_obsolete,
 
-     'cv_name' => $cv->name,
 
-     'is_relationship' => $is_relationship,
 
-     'db_name' => $db->name
 
-   );
 
-   $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
 
-   if ($cvterm) {
 
-     drupal_set_message('Term added successfully.');
 
-   }
 
-   else {
 
-     drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
 
-   }
 
- }
 
- /**
 
-  * Ajax callback for the tripal_cv_form
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvterm_edit_form_ajax($form, $form_state) {
 
-   $elements = array();
 
-   $elements['name'] = $form['name'];
 
-   $elements['continue'] = $form['continue'];
 
-   // add back in the cv-edit-div that is used for the next round of AJAX
 
-   $elements['name']['#prefix'] =  '<div id="cvterm-edit-div">';
 
-   $elements['name']['#suffix'] =  '</div">';
 
-   return $elements;
 
- }
 
- /**
 
-  * Form for re-doing the cvterm path
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvtermpath_form() {
 
-   // get a list of db from chado for user to choose
 
-   $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
 
-   $results = chado_query($sql);
 
-   $cvs = array();
 
-   $cvs[] = '';
 
-   foreach ($results as $cv) {
 
-     $cvs[$cv->cv_id] = $cv->name;
 
-   }
 
-   $form['cvid'] = array(
 
-     '#title' => t('Controlled Vocabulary/Ontology Name'),
 
-     '#type' => 'select',
 
-     '#options' => $cvs,
 
-     '#description' => t('The Chado cvtermpath is a database table that provides lineage for ontology terms
 
-       and is useful for quickly finding any ancestor parent of a term.  This table must be populated for each
 
-       ontology.  Select a controlled vocabulary for which you would like to upate the cvtermpath.'),
 
-   );
 
-   $form['description'] = array(
 
-     '#type' => 'item',
 
-     '#value' => t("Submit a job to update chado cvtermpath table."),
 
-     '#weight' => 1,
 
-   );
 
-   $form['button'] = array(
 
-     '#type' => 'submit',
 
-     '#value' => t('Update cvtermpath'),
 
-     '#weight' => 2,
 
-   );
 
-   return $form;
 
- }
 
- /**
 
-  * Cvterm path form submit
 
-  *
 
-  * @ingroup tripal_cv
 
-  */
 
- function tripal_cv_cvtermpath_form_submit($form, &$form_state) {
 
-   global $user;
 
-   $cvid =  $form_state['values']['cvid'];
 
-   // first get the controlled vocabulary name:
 
-   $sql = "SELECT * FROM {cv} WHERE cv_id = :cv_id";
 
-   $cv = chado_query($sql, array(':cv_id' => $cvid))->fetchObject();
 
-   // Submit a job to update cvtermpath
 
-   $job_args = array($cvid);
 
-   if ($form_state['values']['op'] == t('Update cvtermpath')) {
 
-     tripal_add_job("Update cvtermpath: $cv->name", 'tripal_cv',
 
-         'tripal_update_cvtermpath', $job_args, $user->uid, 10);
 
-   }
 
- }
 
 
  |