1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054 |
- <?php
- require_once "charts.php";
- require_once "trees.php";
- require_once "obo_loader.php";
- require_once "tripal_cv.api.inc";
- /*************************************************************************
- *
- */
- function tripal_cv_init(){
- // add the tripal_cv JS and CSS
- drupal_add_css(drupal_get_path('theme', 'tripal').
- '/css/tripal_cv.css');
- drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_cv.js');
- // add the jsTree JS and CSS
- drupal_add_css(drupal_get_path('theme', 'tripal').'/js/jsTree/source/tree_component.css');
- drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jsTree/source/_lib.js');
- drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jsTree/source/tree_component.js');
- }
- /*************************************************************************
- *
- */
- function tripal_cv_menu() {
- $items = array();
- $items['admin/tripal/tripal_cv'] = array(
- 'title' => 'Controlled Vocabularies',
- 'description' => 'Basic Description of Tripal CV Module Functionality',
- 'page callback' => 'tripal_cv_module_description_page',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_cv/cvtermpath'] = array(
- 'title' => 'Update Chado cvtermpath tables',
- 'description' => 'The Chado cvtermpath table provides lineage for terms and is useful for quickly finding any ancestor parent of a term. However, this table must be populated. This page allows for populating of this table one vocabulary at a time',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_cv_cvtermpath_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_cv/edit_cv'] = array(
- 'title' => 'Update/Delete Controlled Vocabulary',
- 'description' => 'Manage controlled vocabularies/ontolgoies in Chado ',
- 'page callback' => 'tripal_cv_admin_page',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_cv/add_cv'] = array(
- 'title' => 'Add a Controlled Vocabulary',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_cv_add_form'),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_cv/add_cvterm'] = array(
- 'title' => 'Add Controlled Vocabulary Terms',
- 'description' => 'Manage controlled vocabulary/ontology terms in Chado ',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_cv_add_cvterm_form'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_cv/add_cvterm/js'] = array(
- 'page callback' => 'tripal_cv_add_cvterm_callback',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_CALLBACK,
- );
-
- $items['admin/tripal/tripal_cv/obo_loader'] = array(
- 'title' =>'Add/Update Ontology With OBO File',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_cv_obo_form'),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_cv/edit/js'] = array(
- 'title' => 'Edit Controlled Vocabularies',
- 'page callback' => 'tripal_ajax_cv_edit',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK,
- );
- $items['tripal_cv_chart'] = array(
- 'path' => 'tripal_cv_chart',
- 'title' => t('CV Chart'),
- 'page callback' => 'tripal_cv_chart',
- 'page arguments' => array(1),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK
- );
- $items['tripal_cv_tree'] = array(
- 'path' => 'tripal_cv_tree',
- 'title' => t('CV Term Viewer'),
- 'page callback' => 'tripal_cv_tree',
- 'page arguments' => array(1),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK
- );
- // menu items for working with the CV module tree browser
- $items['cv_browser'] = array(
- 'title' => t('CV Relationship Browser'),
- 'page callback' => 'tripal_cv_show_browser',
- 'access arguments' => array('access chado_cv content'),
- 'type' => MENU_CALLBACK
- );
- $items['tripal_cv_init_browser'] = array(
- 'path' => 'tripal_cv_init_browser',
- 'title' => t('CV Browser'),
- 'page callback' => 'tripal_cv_init_browser',
- 'page arguments' => array(1),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK
- );
- // menu item for interaction with the tree
- $items['tripal_cv_update_tree'] = array(
- 'path' => 'tripal_cv_update_tree',
- 'title' => t('CV Tree'),
- 'page callback' => 'tripal_cv_update_tree',
- 'page arguments' => array(2,3),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK
- );
- // menu items for working with terms
- $items['tripal_cv_cvterm_info'] = array(
- 'path' => 'tripal_cv_cvterm_info',
- 'title' => t('CV Term Viewer'),
- 'page callback' => 'tripal_cv_cvterm_info',
- 'page arguments' => array(1),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK
- );
- $items['tripal_cv_cvterm_edit'] = array(
- 'path' => 'tripal_cv_edit',
- 'title' => t('CV Term Editor'),
- 'page callback' => 'tripal_cv_cvterm_edit',
- 'page arguments' => array(1),
- 'access arguments' => array('edit chado_cv content'),
- 'type' => MENU_CALLBACK
- );
- return $items;
- }
- /*******************************************************************************
- * The following function proves access control for users trying to
- * perform actions on data managed by this module
- */
- function chado_cv_access($op, $node, $account){
- if ($op == 'create') {
- return user_access('create chado_cv content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit chado_cv content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete chado_cv content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'view') {
- if (user_access('access chado_cv content', $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- /*******************************************************************************
- * Set the permission types that the chado module uses. Essentially we
- * want permissionis that protect creation, editing and deleting of chado
- * data objects
- */
- function tripal_cv_perm(){
- return array(
- 'access chado_cv content',
- 'create chado_cv content',
- 'delete chado_cv content',
- 'edit chado_cv content',
- );
- }
- /*************************************************************************
- * Implements hook_views_api()
- * Purpose: Essentially this hook tells drupal that there is views support for
- * for this module which then includes tripal_cv.views.inc where all the
- * views integration code is
- */
- function tripal_cv_views_api() {
- return array('api' => 2.0);
- }
- /*******************************************************************************
- * We need to let drupal know about our theme functions and their arguments.
- * We create theme functions to allow users of the module to customize the
- * look and feel of the output generated in this module
- */
- function tripal_cv_theme () {
- return array(
- 'tripal_cv_cvterm_edit' => array (
- 'arguments' => array('cvterm'),
- ),
- );
- }
- /*************************************************************************
- * Purpose: Provide Guidance to new Tripal Admin
- *
- * @return HTML Formatted text
- */
- function tripal_cv_module_description_page() {
- $text = '';
- $text = '<h3>Tripal Controlled Vocabulary Administrative Tools Quick Links</h3>';
- $text .= '<ul>';
- $text .= '<li>'.l('Add CV', 'admin/tripal/tripal_cv/add_cv').'</li>';
- $text .= '<li>'.l('Update/Delete CV', 'admin/tripal/tripal_cv/edit_cv').'</li>';
- $text .= '<li>'.l('Add/Update Ontology', 'admin/tripal/tripal_cv/obo_loader').'</li>';
- $text .= '<li>'.l('Add CV term', 'admin/tripal/tripal_cv/add_cvterm').'</li>';
- $text .= '<li>'.l('Term Listing', 'admin/tripal/tripal_cv/list_cvterms').'</li>';
- $text .= '<li>'.l('Update cvtermpath', 'admin/tripal/tripal_cv/cvtermpath').'</li>';
- $text .= '</ul>';
-
-
- $text .= '<h3>Module Description:</h3>';
- $text .= '<p>The Tripal CV (Controlled Vocabularies) Module provides
- functionality for managing controlled vocabularies and the terms they are
- comprised of. The flexibility and extendibility of the chado schema depends
- on controlled vocabularies. For example, by using a controlled vocabulary for
- feature types the chado schema can describe features of any type, even those
- we have not concieved of yet.</p>';
- $text .= '<h3>Setup Instructions:</h3>';
- $text .= '<p>After installation of the controlled vocabulary module, the following tasks should be performed:</p>';
- $text .= '<ol>';
- $text .= '<li><p><b>Set Permissions</b>: The cv module supports the Drupal user permissions interface for
- controlling access to cv content and functions. These permissions include viewing,
- creating, editing or administering of
- cv content. The default is that only the original site administrator has these
- permissions. You can <a href="'.url('admin/user/roles').'">add roles</a> for classifying users,
- <a href="'.url('admin/user/user').'">assign users to roles</a> and
- <a href="'.url('admin/user/permissions').'">assign permissions</a> for the cv content to
- those roles. For a simple setup, allow anonymous users access to view organism content and
- allow the site administrator all other permissions.</p></li>';
- $text .= '<li><b>Loading of Ontologies/Controlled Vocabularies</b>: You can access this loader at '.
- l('Admin->Tripal Management->Tripal CV->Add/Update Ontology With OBO File', 'admin/tripal/tripal_cv/obo_loader')
- .'. This loader allows you to choose from a list of common ontologies or
- enter the URL or location to an OBO file. Even the list of common
- ontologies is using a URL ensuring you get the most up to date ontology.</p>';
- $text .= '<p>This loader adds a Tripal Job which then waits in a queue to
- be launched. To launch Tripal Jobs either navidate to the root of your
- drupal installation and execute "php sites/all/modules/tripal/tripal_core/
- tripal_launch_jobs.php <drupal user>" or set up a cron job (See user manual
- for more details).</p>';
- $text .= '<p>NOTE: in some cases, community developed ontologies for your
- data may not yet be developed. In this case, it is suggested that you begin
- developement of an ontology using one of the online tools. You might find
- that many researchers are trying to deal with the same data and are willing
- to help you in this endevor. You can '.l('create a controlled vocabulary','admin/tripal/tripal_cv/add_cv').' and '
- . l('add terms to it', 'admin/tripal/tripal_cv/add_cvterm') .' to provide functionality to your site while you are waiting
- for the ontology to be developed.</p></li>';
- $text .= '</ol>';
-
- $text .= '<h3>Features of this Module:</h3>';
- $text .= '<p>Aside from the data loading described above, the Tripal Controlled Vocabulary (CV) module also provides the following functionality:</p>';
- $text .= '<ul>';
- $text .= '<li><b>Create/Update/Delete A Controlled Vocaulbulary</b>: to create your own controlled vocabulary go to '.
- l('Admin->Tripal Management->Tripal CV->Add a Controlled Vocabulary','admin/tripal/tripal_cv/add_cv')
- .' and fill out the form provided.To Update/Delete a controlled vocabulary
- go to '.l('Admin->Tripal Management->Tripal CV->Update/Delete Controlled Vocabulary', 'admin/tripal/tripal_cv/edit_cv')
- .', select the existing controlled vocabulary you want to modify and then
- edit it as desired. This only modifies the name, description of a
- controlled vocabulary. See the next section for adding, removing, editing
- the term a controlled vocabulary contains.</li>';
-
- $text .= '<li><b>Create a Controlled Vocaulbulary Term</b>: To Add a term to an already existing controlled vocabulary
- go to '.l('Admin->Tripal Management->Tripal CV->Add a Controlled Vocabulary Term','admin/tripal/tripal_cv/add_cvterm')
- .', select the controlled vocabulary you want to add terms to and then fill
- out the form.</li>';
- $text .= '<li><b>Controlled Vocabulary Term Browser</b>: This module provides a '.l('basic listing','admin/tripal/tripal_cv/list_cvterms').' of controlled vocabulry terms for
- for all vocabularies currently in chado. It does not require indexing for Drupal searching but relies on Drupal Views.
- <a href="http://drupal.org/project/views">Drupal Views</a> must be installed.</li>';
- $text .= '<li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
- a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
- It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database
- and create custom lists without PHP programming or customization of Tripal source code. Views can also
- be created to filter content that has not yet been synced with Druapl in order to protect access to non
- published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing
- Views <a href="'.url('admin/build/views/').'">here</a>, as well as create your own. </p></li>';
- $text .= '</ul>';
- return $text;
- }
- /*************************************************************************
- * @section Edit/Delete CVs
- *************************************************************************/
-
- /*************************************************************************
- * Purpose: Provides the form for Updating and Deleteing existing
- * chado controlled vocabularies (See chado cv table)
- */
- function tripal_cv_admin_page(){
- $add_url = url("admin/tripal/tripal_cv/new");
- $obo_url = url("admin/tripal/tripal_cv/obo");
- $cvtermpath_url = url("admin/tripal/tripal_cv/cvtermpath");
- $browser_url = url("cv_browser");
- $output = "<a href=\"$add_url\">Add a new controlled vocabulary</a> | ";
- $output .= "<a href=\"$browser_url\">Browse a vocabulary</a> | ";
- $output .= "<a href=\"$obo_url\">Add/Update Ontology With OBO File</a> | ";
- $output .= "<a href=\"$cvtermpath_url\">Update the cvtermpath table</a> ";
- $output .= drupal_get_form('tripal_cv_select_form');
- $output .= '<div id="db-edit-div">Please select a vocabulary above to view or edit</div>';
- return $output;
- }
- /*************************************************************************
- * Purpose: 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
- */
- function tripal_cv_select_form(){
- $previous_db = tripal_db_set_active('chado'); // use chado database
- // get a list of db from chado for user to choose
- $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
- $results = db_query ($sql);
- tripal_db_set_active($previous_db); // use drupal database
- $cvs = array();
- $cvs[] = '';
- while ($cv = db_fetch_object($results)){
- $cvs[$cv->cv_id] = $cv->name;
- }
- $form['cvid'] = array(
- '#title' => t('Controlled Vocabulary/Ontology Name'),
- '#type' => 'select',
- '#options' => $cvs,
- '#ahah' => array(
- 'path' => 'admin/tripal/tripal_cv/edit/js',
- 'wrapper' => 'db-edit-div',
- 'effect' => 'fade',
- 'event' => 'change',
- 'method' => 'replace',
- ),
- );
- return $form;
- }
- /*************************************************************************
- * Purpose: The edit controlled vocabulary javascript
- */
- function tripal_ajax_cv_edit (){
- // get the database id, build the form and then return the JSON object
- $cvid = $_POST['cvid'];
- $form = drupal_get_form('tripal_cv_edit_form',$cvid);
- drupal_json(array('status' => TRUE, 'data' => $form));
- }
- /*************************************************************************
- * Purpose: Provides a form to allow updating/deleteing of controlled vocabularies
- */
- function tripal_cv_edit_form(&$form_state = NULL,$cvid = NULL){
-
- $sql = "SELECT * FROM {cv} WHERE cv_id = %d ";
- $previous_db = tripal_db_set_active('chado');
- $cv = db_fetch_object(db_query($sql,$cvid));
- tripal_db_set_active($previous_db);
- # set the default values. If there is a value set in the
- # form_state then let's use that, otherwise, we'll pull
- # the values from the database
- $default_db = $form_state['values']['name'];
- $default_desc = $form_state['values']['description'];
- $default_url = $form_state['values']['url'];
- $default_urlprefix = $form_state['values']['urlprefix'];
- if(!$default_db){
- $default_cv = $cv->name;
- }
- if(!$default_desc){
- $default_desc = $cv->definition;
- }
-
- $form['cvid'] = array(
- '#type' => 'hidden',
- '#value' => $cvid
- );
-
- $form['name']= array(
- '#type' => 'textfield',
- '#title' => t("Controlled Vocabulary name"),
- '#description' => t('Please enter the name for this vocabulary.'),
- '#required' => FALSE,
- '#default_value' => $default_cv,
- '#weight' => 1
- );
- $form['definition']= array(
- '#type' => 'textarea',
- '#title' => t('Description'),
- '#description' => t('Please enter a description for this vocabulary'),
- '#default_value' => $default_desc,
- '#weight' => 2
- );
- $form['update'] = array (
- '#type' => 'submit',
- '#value' => t('Update'),
- '#weight' => 5,
- '#executes_submit_callback' => TRUE,
- );
- $form['delete'] = array (
- '#type' => 'submit',
- '#value' => t('Delete'),
- '#weight' => 6,
- '#executes_submit_callback' => TRUE,
- );
- $form['#redirect'] = 'admin/tripal/tripal_cv';
- return $form;
- }
- /************************************************************************
- * Purpose: The submit function of the update/delete controlled vocabulary form
- */
- function tripal_cv_edit_form_submit($form, &$form_state){
- $name = $form_state['values']['name'];
- $desc = $form_state['values']['definition'];
- $cvid = $form_state['values']['cvid'];
- $op = $form_state['values']['op'];
-
- if(strcmp($op,'Update')==0){
- $sql = "
- UPDATE {cv} SET
- name = '%s',
- definition = '%s'
- WHERE cv_id = %d
- ";
- $previous_db = tripal_db_set_active('chado');
- $db = db_query($sql,$name,$desc,$cvid);
- tripal_db_set_active($previous_db);
- if($db){
- drupal_set_message("Controlled vocabulary updated");
- } else {
- drupal_set_message("Failed to update controlled vocabulary.");
- }
- }
- if(strcmp($op,'Delete')==0){
- $sql = "
- DELETE FROM {cv}
- WHERE cv_id = %d
- ";
- $previous_db = tripal_db_set_active('chado');
- $db = db_query($sql,$cvid);
- tripal_db_set_active($previous_db);
- if($db){
- drupal_set_message("Controlled vocabulary deleted");
- } else {
- drupal_set_message("Failed to delete controlled vocabulary.");
- }
- }
- return '';
- }
- /*************************************************************************
- * @section Add CVs
- *************************************************************************/
- /*************************************************************************
- * Purpose: Provides the Add controlled vocabulary form
- */
- function tripal_cv_add_form(&$form_state = NULL){
- $form['cvid'] = array(
- '#type' => 'hidden',
- '#value' => $cvid
- );
- $form['name']= array(
- '#type' => 'textfield',
- '#title' => t("Controlled Vocabulary name"),
- '#description' => t('Please enter the name for this vocabulary. This field will be ignored if an OBO file or URL is provided above'),
- '#required' => FALSE,
- '#default_value' => $default_cv,
- '#weight' => 1
- );
- $form['definition']= array(
- '#type' => 'textarea',
- '#title' => t('Description'),
- '#description' => t('Please enter a description for this vocabulary'),
- '#default_value' => $default_desc,
- '#weight' => 2
- );
- $form['add'] = array (
- '#type' => 'submit',
- '#value' => t('Add'),
- '#weight' => 5,
- '#executes_submit_callback' => TRUE,
- );
- $form['#redirect'] = 'admin/tripal/tripal_cv';
- return $form;
- }
- /************************************************************************
- * Purpose: The submit function for the add controlled vocabulary form
- */
- function tripal_cv_add_form_submit($form, &$form_state){
- $name = $form_state['values']['name'];
- $desc = $form_state['values']['definition'];
- $sql = "
- INSERT INTO {cv}
- (name,definition)
- VALUES
- ('%s','%s')
- ";
- $previous_db = tripal_db_set_active('chado');
- $db = db_query($sql,$name,$desc);
- tripal_db_set_active($previous_db);
- if($db){
- drupal_set_message("Controlled vocabulary added");
- } else {
- drupal_set_message("Failed to add controlled vocabulary.");
- }
- return '';
- }
- /*************************************************************************
- * @section Add Controlled Vocabulary Term
- *************************************************************************/
- /*************************************************************************
- * Purpose: Provides the form that allows adding of terms to an existing
- * controlled vocabulary
- */
- function tripal_cv_add_cvterm_form (&$form_state) {
- $form = array();
-
- $results = tripal_core_chado_select(
- 'cv',
- array('cv_id','name'),
- array()
- );
- $cvs = array();
- $cvs[] = '';
- foreach ($results as $cv) {
- $cvs[$cv->cv_id] = $cv->name;
- }
- $form['cv_id'] = array(
- '#title' => t('Controlled Vocabulary/Ontology Name'),
- '#type' => 'select',
- '#options' => $cvs,
- '#ahah' => array(
- 'path' => 'admin/tripal/tripal_cv/add_cvterm/js',
- 'wrapper' => 'cvterm-add-div',
- 'effect' => 'fade',
- 'event' => 'change',
- 'method' => 'replace',
- ),
- '#required' => TRUE,
- );
- $form['add_cvterm'] = array(
- '#type' => 'item',
- '#value' => t('Please select a vocabulary above to add a term to it'),
- '#prefix' => '<div id="cvterm-add-div">',
- '#suffix' => '</div>'
- );
-
- if ($form_state['values']['cv_id']) {
- $form['add_cvterm'] = array(
- '#type' => 'fieldset',
- '#title' => t('Add Term to the current Controlled Vocabulary'),
- '#prefix' => '<div id="cvterm-add-div">',
- '#suffix' => '</div>'
- );
-
- $form['add_cvterm']['name']= array(
- '#type' => 'textfield',
- '#title' => t("Term Name"),
- '#description' => t('Please enter the name for this vocabulary term.'),
- '#required' => FALSE,
- '#weight' => 1,
- '#required' => TRUE,
- );
- $form['add_cvterm']['definition']= array(
- '#type' => 'textarea',
- '#title' => t('Description'),
- '#description' => t('Please enter a description for this term'),
- '#weight' => 2
- );
-
- $form['add_cvterm']['is_relationshiptype'] = array(
- '#type' => 'checkbox',
- '#title' => t('This term describes a relationship?'),
- '#weight' => 3,
- );
- $form['add_cvterm']['is_obsolete'] = array(
- '#type' => 'checkbox',
- '#title' => t('This term is obsolete?'),
- '#weight' => 3,
- );
-
- $results = tripal_core_chado_select(
- 'db',
- array('db_id', 'name'),
- array()
- );
- $dbs = array();
- $dbs[] = '';
- foreach ($results as $db) {
- $dbs[$db->db_id] = $db->name;
- }
- $form['add_cvterm']['db_id'] = array(
- '#type' => 'select',
- '#title' => t('Database'),
- '#description' => t('All terms must be assocated with an external database.
- Please select the external database to associate with
- this term'),
- '#options' => $dbs,
- '#weight' => 4,
- '#required' => TRUE,
- );
-
- $form['add_cvterm']['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Add Term',
- '#weight' => 5
- );
-
- } //end of if cv selected
-
- return $form;
- }
- /*************************************************************************
- * Purpose: Validates the input for adding a cvterm
- */
- function tripal_cv_add_cvterm_form_validate ($form, &$form_state) {
- if (!empty($form_state['ahah_submission'])) {
- return;
- }
-
- }
- /*************************************************************************
- * Purpose: Adds terms to an existing controlled vocabulary
- */
- function tripal_cv_add_cvterm_form_submit ($form, &$form_state) {
- if (!empty($form_state['ahah_submission'])) {
- return;
- }
-
- // Add dbxref for cvterm
- $dbxref_insert_values = array(
- 'db_id' => $form_state['values']['db_id'],
- 'accession' => $form_state['values']['name'],
- 'description' => 'cvterm reference',
- );
- $dbxref_results = tripal_core_chado_select(
- 'dbxref',
- array('dbxref_id'),
- $dbxref_insert_values
- );
- if (!$dbxref_results[0]->dbxref_id) {
- $dbxref_insert_values['version'] = '1';
- $dbxref_success = tripal_core_chado_insert(
- 'dbxref',
- $dbxref_insert_values
- );
- } else {
- $dbxref_success = true;
- }
-
- // Add cvterm
- if ($dbxref_success) {
- $insert_values = array(
- 'cv_id' => $form_state['values']['cv_id'],
- 'name' => $form_state['values']['name'],
- 'definition' => $form_state['values']['definition'],
- 'dbxref_id' => $dbxref_insert_values,
- 'is_obsolete' => (string) $form_state['values']['is_obsolete'],
- 'is_relationshiptype' => (string) $form_state['values']['is_relationshiptype'],
- );
- $success = tripal_core_chado_insert(
- 'cvterm',
- $insert_values
- );
- if ($success) {
- drupal_set_message('Successfully Added Term to Controlled Vocabulary');
- } else {
- drupal_set_message('Unable to add controlled vocabulary term', 'error');
- watchdog(
- 'tripal_cv',
- 'Cvterm Insert: Unable to insert cvterm where values: %values',
- array('%values' => print_r($insert_values,TRUE)),
- WATCHDOG_ERROR
- );
- }
- } else {
- drupal_set_message('Unable to add database reference for controlled vocabulary term', 'error');
- watchdog(
- 'tripal_cv',
- 'Cvterm Insert: Unable to insert dbxref for cvterm where values: %values',
- array('%values' => print_r($dbxref_insert_values,TRUE)),
- WATCHDOG_ERROR
- );
- }
- return;
- }
- /*************************************************************************
- * Purpose: This function gets called when the selecting of a cv from
- * the select list triggers it. This function simply rebuilds the form
- * with new information. No elements are created here
- */
- function tripal_cv_add_cvterm_callback () {
- // Retrieve the form from the cache
- $form_state = array('storage' => NULL);
- $form_build_id = $_POST['form_build_id'];
- $form = form_get_cache($form_build_id, $form_state);
-
- // Preparing to process the form
- $args = $form['#parameters'];
- $form_id = array_shift($args);
- $form_state['post'] = $form['#post'] = $_POST;
- $form['#programmed'] = $form['#redirect'] = FALSE;
-
- // Sets the form_state so that the validate and submit handlers can tell
- // when the form is submitted via AHAH
- $form_state['ahah_submission'] = TRUE;
- // Process the form with drupal_process_form. This function calls the submit
- // handlers, which put whatever was worthy of keeping into $form_state.
- drupal_process_form($form_id, $form, $form_state);
-
- // You call drupal_rebuild_form which destroys $_POST.
- // The form generator function is called and creates the form again but since
- // it knows to use $form_state, the form will be different.
- // The new form gets cached and processed again, but because $_POST is
- // destroyed, the submit handlers will not be called again.
- $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
- // This is the only piece specific to your form
- // Picks a piece of the form and renders it
- // Specifcally the add cvterm fieldset and all contained fields
- $add_cvterm_form = $form['add_cvterm'];
- unset($add_cvterm_form['#prefix'], $add_cvterm_form['#suffix']);
- $output = theme('status_messages') . drupal_render($add_cvterm_form);
- // Final rendering callback.
- drupal_json(array('status' => TRUE, 'data' => $output));
- }
- /*************************************************************************
- * @section Ontology Loader
- *************************************************************************/
-
- /*************************************************************************
- * Purpose: Provides the form to load an already existing controlled
- * Vocabulary into chado
- */
- function tripal_cv_obo_form(&$form_state = NULL){
- // get a list of db from chado for user to choose
- $sql = "SELECT * FROM {tripal_cv_obo} ORDER BY obo_id";
- $results = db_query ($sql);
- $obos = array();
- $obos[] = '';
- while ($obo = db_fetch_object($results)){
- $obos[$obo->obo_id] = "$obo->name | $obo->path";
- }
- $form['obo_existing'] = array(
- '#type' =>'fieldset',
- '#title' => t('Use a Saved Ontology OBO Reference')
- );
- $form['obo_new'] = array(
- '#type' =>'fieldset',
- '#title' => t('Use a New Ontology OBO Reference')
- );
- $form['obo_existing']['existing_instructions']= array(
- '#value' => t('The Ontology OBO files listed in the drop down below have been automatically added upon
- installation of the Tripal CV module or were added from a previous upload. Select
- an OBO, then click the submit button to load the vocabulary into the database. If the
- vocabularies already exist then the ontology will be updated.'),
- '#weight' => -1
- );
- $form['obo_existing']['obo_id'] = array(
- '#title' => t('Ontology OBO File Reference'),
- '#type' => 'select',
- '#options' => $obos,
- '#weight' => 0
- );
- $form['obo_new']['path_instructions']= array(
- '#value' => t('Provide the name and path for the OBO file. If the vocabulary OBO file
- is stored local to the server provide a file name. If the vocabulry is stored remotely,
- provide a URL. Only provide a URL or a local file, not both.'),
- '#weight' => 0
- );
- $form['obo_new']['obo_name']= array(
- '#type' => 'textfield',
- '#title' => t('New Vocabulary Name'),
- '#description' => t('Please provide a name for this vocabulary. After upload, this name will appear in the drop down
- list above for use again later.'),
- '#weight' => 1
- );
- $form['obo_new']['obo_url']= array(
- '#type' => 'textfield',
- '#title' => t('Remote URL'),
- '#description' => t('Please enter a URL for the online OBO file. The file will be downloaded and parsed.
- (e.g. http://www.obofoundry.org/ro/ro.obo'),
- '#default_value' => $default_desc,
- '#weight' => 2
- );
- $form['obo_new']['obo_file']= array(
- '#type' => 'textfield',
- '#title' => t('Local File'),
- '#description' => t('Please enter the full system path for an OBO definition file, or a path within the Drupal
- installation (e.g. /sites/default/files/xyz.obo). The path must be accessible to the
- server on which this Drupal instance is running.'),
- '#default_value' => $default_desc,
- '#weight' => 3
- );
- $form['submit'] = array (
- '#type' => 'submit',
- '#value' => t('Submit'),
- '#weight' => 5,
- '#executes_submit_callback' => TRUE,
- );
- $form['#redirect'] = 'admin/tripal/tripal_cv/obo';
- return $form;
- }
- /************************************************************************
- * Purpose: The submit function for the load ontology form. It registers a
- * tripal job to run the obo_loader.php script
- */
- function tripal_cv_obo_form_submit($form, &$form_state){
- global $user;
- $obo_id = $form_state['values']['obo_id'];
- $obo_name = $form_state['values']['obo_name'];
- $obo_url = $form_state['values']['obo_url'];
- $obo_file = $form_state['values']['obo_file'];
- $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = %d";
- $obo = db_fetch_object(db_query($sql,$obo_id));
- if($obo_id){
- $args = array($obo_id);
- tripal_add_job("Load OBO $obo->name",'tripal_cv',
- "tripal_cv_load_obo_v1_2_id",$args,$user->uid);
- }
- else {
- if($obo_url){
- $args = array($obo_name,$obo_url);
- tripal_add_job("Load OBO $obo_name",'tripal_cv',
- "tripal_cv_load_obo_v1_2_url",$args,$user->uid);
- }
- elseif($obo_file){
- $args = array($obo_name,$obo_file);
- tripal_add_job("Load OBO $obo_name",'tripal_cv',
- "tripal_cv_load_obo_v1_2_file",$args,$user->uid);
- }
- }
- return '';
- }
- /*************************************************************************
- * @section cvterm path management
- *************************************************************************/
- /*************************************************************************
- *
- */
- function tripal_cv_cvtermpath_form () {
- $previous_db = tripal_db_set_active('chado'); // use chado database
- // get a list of db from chado for user to choose
- $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
- $results = db_query ($sql);
- tripal_db_set_active($previous_db); // use drupal database
- $cvs = array();
- $cvs[] = '';
- while ($cv = db_fetch_object($results)){
- $cvs[$cv->cv_id] = $cv->name;
- }
- $form['cvid'] = array(
- '#title' => t('Controlled Vocabulary/Ontology Name'),
- '#type' => 'select',
- '#options' => $cvs,
- '#description' => t('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;
- }
- /*************************************************************************
- *
- */
- function tripal_cv_cvtermpath_form_validate($form, &$form_state) {
- global $user;
- $cvid = $form_state['values']['cvid'];
- // first get the controlled vocabulary name:
- $previous_db = tripal_db_set_active('chado');
- $cv = db_fetch_object(db_query("SELECT * FROM {cv} WHERE cv_id = %d",$cvid));
- tripal_db_set_active($previous_db);
- // 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_cv_update_cvtermpath',$job_args,$user->uid);
- }
- }
- /***********************************************************
- * Update the cvtermpath table
- */
- function tripal_cv_update_cvtermpath($cvid = NULL, $job_id = NULL) {
- // first get the controlled vocabulary name:
- $previous_db = tripal_db_set_active('chado');
- $cv = db_fetch_object(db_query("SELECT * FROM {cv} WHERE cv_id = %d",$cvid));
- print "\nUpdating cvtermpath for $cv->name...\n";
- // now fill the cvtermpath table
- $sql = "SELECT * FROM fill_cvtermpath('%s')";
- db_query($sql,$cv->name);
- tripal_db_set_active($previous_db);
- return;
- }
- /*************************************************************************
- * @section Miscellaneous
- * @todo check to see if these functions are still needed and/or if they
- * should be moved to the api file
- *************************************************************************/
-
- /*************************************************************************
- */
- function tripal_cv_get_cv_id($cv_name){
- $sql = "
- SELECT cv_id FROM {cv} WHERE name = '%s'
- ";
- $previous_db = tripal_db_set_active('chado');
- $cv = db_fetch_object(db_query($sql,$cv_name));
- tripal_db_set_active($previous_db);
- return $cv->cv_id;
- }
- /*************************************************************************
- *
- */
- function tripal_cv_cvterm_edit($cvterm_id){
- $sql = "
- SELECT CVT.name as cvtermname, CVT.definition, CV.name as cvname
- FROM {CVTerm} CVT
- INNER JOIN CV on CVT.cv_id = CV.cv_id
- WHERE CVT.cvterm_id = %d
- ";
- $previous_db = tripal_db_set_active('chado');
- $cvterm = db_fetch_object(db_query($sql,$cvterm_id));
- tripal_db_set_active($previous_db);
- return theme('tripal_cv_cvterm_edit',$cvterm);
- }
- /*************************************************************************
- *
- */
- function theme_tripal_cv_cvterm_edit(&$cvterm){
- $output = "
- <div id=\"cvterm\">
- <table>
- <tr><th>Term</th><td>$cvterm->cvtermname</td></tr>
- <tr><th>Vocabulary</th><td>$cvterm->cvname</td></tr>
- <tr><th>Definition</th><td>$cvterm->definition</td></tr>
- </table>
- </div>
- ";
- return $output;
- }
|