123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785 |
- <?php
- require('api/tripal_library.api.inc');
- require('includes/tripal_library.admin.inc');
- function tripal_library_help($path, $arg) {
- $output = '';
- switch ($path) {
- case "admin/help#tripal_library":
- $output = '<p>'.
- t("Displays links to nodes created on this date") .
- '</p>';
- break;
- }
- return $output;
- }
- function tripal_library_node_info() {
- $nodes = array();
- $nodes['chado_library'] = array(
- 'name' => t('Library'),
- 'module' => 'chado_library',
- 'description' => t('A library from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Library'),
- 'has_body' => FALSE,
- 'body_label' => t('Library Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- function tripal_library_perm() {
- return array(
- 'access chado_library content',
- 'create chado_library content',
- 'delete chado_library content',
- 'edit chado_library content',
- 'administer tripal libraries',
- );
- }
- function chado_library_access($op, $node, $account) {
- if ($op == 'create') {
- if (!user_access('create chado_library content', $account)) {
- return FALSE;
- }
- return TRUE;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_library content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_library content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_library content', $account)) {
- return FALSE;
- }
- }
- return NULL;
- }
- function tripal_library_menu() {
- $items = array();
-
- $items['admin/tripal/tripal_library'] = array(
- 'title' => 'Libraries',
- 'description' => 'Basic Description of Tripal Library Module Functionality',
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_library_admin'),
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_library/configuration'] = array(
- 'title' => 'Configuration',
- 'description' => 'Configure the Tripal Library module',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_library_admin'),
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- $items['chado_sync_libraries'] = array(
- 'title' => 'Sync Library Data',
- 'page callback' => 'tripal_library_sync_libraries',
- 'access arguments' => array('administer tripal libraries'),
- 'type' => MENU_CALLBACK
- );
- return $items;
- }
- function tripal_library_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- function tripal_library_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
-
-
- case 'view':
-
- if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
- $node->content['tripal_library_index_version'] = array(
- '#value' => theme('tripal_library_search_index', $node),
- );
- }
- elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
- $node->content['tripal_library_index_version'] = array(
- '#value' => theme('tripal_library_search_result', $node),
- );
- }
- else {
- switch ($node->type) {
- case 'chado_organism':
-
- $node->content['tripal_organism_libraries'] = array(
- '#value' => theme('tripal_organism_libraries', $node),
- );
- break;
- case 'chado_feature':
-
- $node->content['tripal_feature_libraries'] = array(
- '#value' => theme('tripal_feature_libraries', $node),
- );
- break;
- }
- }
- break;
- }
- }
- function tripal_library_theme() {
- return array(
- 'tripal_library_library_table' => array(
- 'arguments' => array('libraries'),
- ),
- 'tripal_library_search_index' => array(
- 'arguments' => array('node'),
- ),
- 'tripal_library_search_result' => array(
- 'arguments' => array('node'),
- ),
- 'tripal_organism_libraries' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_organism_libraries',
- ),
- 'tripal_feature_libraries' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_feature_libraries',
- ),
- 'tripal_library_base' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_base',
- ),
- 'tripal_library_synonyms' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_synonyms',
- ),
- 'tripal_library_references' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_references',
- ),
- 'tripal_library_properties' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_properties',
- ),
- 'tripal_library_terms' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_terms',
- ),
- 'tripal_library_admin' => array(
- 'template' => 'tripal_library_admin',
- 'arguments' => array(NULL),
- 'path' => drupal_get_path('module', 'tripal_library') . '/theme',
- ),
- );
- }
- function theme_tripal_library_search_index($node) {
- if ($node->type == 'chado_organism') {
- $content = "";
-
- $sql = "SELECT * FROM {library} L ".
- "WHERE L.organism_id = %d";
- $libraries = array();
- $results = chado_query($sql, $node->organism->organism_id);
- while ($library = db_fetch_object($results)) {
-
- $sql = "SELECT * FROM {libraryprop} LP ".
- " INNER JOIN {CVTerm} CVT ON CVT.cvterm_id = LP.type_id ".
- "WHERE LP.library_id = $library->library_id ".
- " AND CVT.name = 'library_description'";
- $desc = db_fetch_object(chado_query($sql));
- $library->description = $desc->value;
- $libraries[] = $library;
- }
- if (count($libraries) > 0) {
- foreach ($libraries as $library) {
- $content .= "$library->name ";
- $content .= "$library->description";
- };
- }
-
- }
- elseif ($node->type == 'chado_feature') {
- $content = "";
- $organism_id = $node->feature->organism_id;
- $sql = "SELECT * FROM {library} L ".
- " INNER JOIN {Library_feature} LF ON L.library_id = LF.library_id ".
- "WHERE LF.feature_id = " . $node->feature->feature_id;
- $libraries = array();
- $results = chado_query($sql);
- while ($library = db_fetch_object($results)) {
- $libraries[] = $library;
- }
- if (count($libraries) > 0) {
- $lib_additions = array();
- foreach ($libraries as $library) {
- $content .= $library->name;
- };
- }
- }
- return $content;
- }
- function theme_tripal_library_node_libraries($node) {
- $content = "";
-
-
-
-
- if ($node->type == 'chado_organism' && $node->organism_id) {
- $box_status = variable_get("tripal_library-box-libraries", "menu_off");
- if (strcmp($box_status, "menu_off")==0) {
- return get_tripal_library_organism_libraries($node->nid);
- }
- }
-
-
-
- elseif ($node->type == 'chado_feature' && $node->feature->feature_id) {
- $organism_id = $node->feature->organism_id;
- $sql = "SELECT * FROM {library} L ".
- " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
- "WHERE LF.feature_id = " . $node->feature->feature_id;
- $libraries = array();
- $results = chado_query($sql);
- while ($library = db_fetch_object($results)) {
- $libraries[] = $library;
- }
- if (count($libraries) > 0) {
- $lib_additions = array();
- foreach ($libraries as $library) {
- $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d";
- $lib_nid = db_result(db_query($sql, $library->library_id));
- if ($lib_nid) {
- $lib_url = url("node/$lib_nid");
- }
- $lib_additions[$lib_url] = $library->name;
- };
- $node->lib_additions = $lib_additions;
- }
- }
- return $content;
- }
- function tripal_library_cron() {
- }
- function tripal_library_library_access($op, $node, $account) {
- if ($op == 'create') {
- if (!user_access('create chado_library content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'update') {
- if (!user_access('edit any chado_library content', $account) &&
- !user_access('edit own chado_library content', $account)) {
- return FALSE;
- }
- if (user_access('edit own chado_library content', $account) &&
- $account->uid != $node->uid) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete any chado_library content', $account) &&
- !user_access('delete own chado_library content', $account)) {
- return FALSE;
- }
- if (user_access('delete own chado_library content', $account) &&
- $account->uid != $node->uid) {
- return FALSE;
- }
- }
- return NULL;
- }
- function chado_library_form($node) {
- $form = array();
- $library = $node->library;
-
- $uniquename = $node->uniquename;
- if (!$uniquename) {
- $uniquename = $library->uniquename;
- }
- $library_type = $node->library_type;
- if (!$library_type) {
- $library_type = $library->type_id->cvterm_id;
- }
- $organism_id = $node->organism_id;
- if (!$organism_id) {
- $organism_id = $library->organism_id->organism_id;
- }
- $library_description = $node->library_description;
- if (!$library_description) {
- $libprop = tripal_library_get_property($library->library_id, 'library_description');
- $library_description = $libprop->value;
- }
-
-
- $form['library_id'] = array(
- '#type' => 'value',
- '#value' => $library->library_id,
- );
- $form['title']= array(
- '#type' => 'textfield',
- '#title' => t('Library Title'),
- '#description' => t('Please enter the title for this library. '.
- 'This appears at the top of the library page.'),
- '#required' => TRUE,
- '#default_value' => $node->title,
- '#weight' => 1
- );
- $form['uniquename']= array(
- '#type' => 'textfield',
- '#title' => t('Unique Library Name'),
- '#description' => t('Please enter a unique name for this library'),
- '#required' => TRUE,
- '#default_value' => $uniquename,
- '#weight' => 2
- );
-
- $values = array(
- 'cv_id' => array(
- 'name' => 'tripal_library_types',
- )
- );
- $columns = array('cvterm_id','name');
- $options = array('order_by' => array('name' => 'ASC'));
- $lib_types = tripal_core_chado_select('cvterm', $columns, $values, $options);
- $types = array();
- $types[''] = '';
- foreach($lib_types as $type) {
- $types[$type->cvterm_id] = $type->name;
- }
- $form['library_type'] = array(
- '#title' => t('Library Type'),
- '#type' => t('select'),
- '#description' => t("Choose the library type."),
- '#required' => TRUE,
- '#default_value' => $library_type,
- '#options' => $types,
- '#weight' => 3
- );
-
- $sql = "SELECT * FROM {Organism}";
- $org_rset = chado_query($sql);
- $organisms = array();
- $organisms[''] = '';
- while ($organism = db_fetch_object($org_rset)) {
- $organisms[$organism->organism_id] =
- "$organism->genus $organism->species ($organism->common_name)";
- }
- $form['organism_id'] = array(
- '#title' => t('Organism'),
- '#type' => t('select'),
- '#description' => t("Choose the organism with which this library is ".
- "associated."),
- '#required' => TRUE,
- '#default_value' => $organism_id,
- '#options' => $organisms,
- '#weight' => 4,
- );
- $form['library_description']= array(
- '#type' => 'textarea',
- '#title' => t('Library Description'),
- '#description' => t('A brief description of the library'),
- '#required' => TRUE,
- '#default_value' => $library_description,
- '#weight' => 5
- );
- return $form;
- }
- function chado_library_validate($node) {
- $lib = 0;
-
-
- if ($node->library_id) {
- $sql = "SELECT * FROM ".
- "{Library} WHERE ".
- "uniquename = '%s' ".
- "AND NOT library_id = %d";
- $lib = db_fetch_object(chado_query($sql, $node->uniquename, $node->library_id));
- }
- else {
- $sql = "SELECT * FROM ".
- "{Library} ".
- "WHERE uniquename = '%s'";
- $lib = db_fetch_object(chado_query($sql, $node->uniquename));
- }
- if ($lib) {
- form_set_error('uniquename', t('The unique library name already exists. '.
- 'Please choose another'));
- }
- }
- function chado_library_insert($node) {
- if ($node->library_id) {
- $library['library_id'] = $node->library_id;
- }
- else {
- $values = array(
- 'name' => $node->title,
- 'uniquename' => $node->uniquename,
- 'organism_id' => $node->organism_id,
- 'type_id' => $node->library_type,
- );
- $library = tripal_core_chado_insert('library', $values);
- }
- if ($library) {
-
- tripal_library_insert_property($library['library_id'], 'library_description',
- $node->library_description);
-
-
- $library_id = chado_get_id_for_node('library', $node->nid) ;
- if (!$library_id) {
-
- $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql, $node->nid, $node->vid, $library['library_id']);
- }
- }
- else {
- drupal_set_message(t('Unable to add library.', 'warning'));
- watchdog('tripal_library',
- 'Insert feature: Unable to create library where values: %values',
- array('%values' => print_r($values, TRUE)),
- WATCHDOG_WARNING
- );
- }
- }
- function chado_library_update($node) {
- if ($node->revision) {
-
-
- }
- $library_id = chado_get_id_for_node('library', $node->nid);
-
- $match = array(
- 'library_id' => $library_id,
- );
- $values = array(
- 'name' => $node->title,
- 'uniquename' => $node->uniquename,
- 'organism_id' => $node->organism_id,
- 'type_id' => $node->library_type,
- );
- $status = tripal_core_chado_update('library', $match, $values);
- tripal_library_update_property($library_id, 'library_description', $node->library_description, 1);
- }
- function chado_library_load($node) {
-
- $library_id = chado_get_id_for_node('library', $node->nid);
- $values = array('library_id' => $library_id);
- $library = tripal_core_generate_chado_var('library', $values);
- $additions = new stdClass();
- $additions->library = $library;
- return $additions;
- }
- function chado_library_view($node, $teaser = FALSE, $page = FALSE) {
-
- if (!$teaser) {
- $node = node_prepare($node, $teaser);
-
-
-
- if (!$node->genus) {
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
- $data = db_fetch_object(chado_query($sql, $node->organism_id));
- $node->genus = $data->genus;
- $node->species = $data->species;
- $node->common_name = $data->common_name;
- }
- }
- return $node;
- }
- function chado_library_delete(&$node) {
- $library_id = chado_get_id_for_node('library', $node->nid);
-
-
- if (!$library_id) {
- return;
- }
-
-
- $sql_del = "DELETE FROM {chado_library} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node_revisions} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
-
- chado_query("DELETE FROM {libraryprop} WHERE library_id = %d", $library_id);
- chado_query("DELETE FROM {library} WHERE library_id = %d", $library_id);
- }
- function tripal_library_block($op = 'list', $delta = '0', $edit = array()) {
- switch ($op) {
- case 'list':
- $blocks['libreferences']['info'] = t('Tripal Library Cross References');
- $blocks['libreferences']['cache'] = BLOCK_NO_CACHE;
- $blocks['libbase']['info'] = t('Tripal Library Details');
- $blocks['libbase']['cache'] = BLOCK_NO_CACHE;
- $blocks['libterms']['info'] = t('Tripal Library Terms');
- $blocks['libterms']['cache'] = BLOCK_NO_CACHE;
- $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
- $blocks['libsynonyms']['cache'] = BLOCK_NO_CACHE;
- $blocks['libproperties']['info'] = t('Tripal Library Properties');
- $blocks['libproperties']['cache'] = BLOCK_NO_CACHE;
- $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
- $blocks['featurelibs']['cache'] = BLOCK_NO_CACHE;
- $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
- $blocks['orglibs']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- case 'view':
- if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
- $block = array();
- switch ($delta) {
- case 'libreferences':
- $block['subject'] = t('Cross References');
- $block['content'] = theme('tripal_library_references', $node);
- break;
- case 'libbase':
- $block['subject'] = t('Library Details');
- $block['content'] = theme('tripal_library_base', $node);
- break;
- case 'libsynonyms':
- $block['subject'] = t('Synonyms');
- $block['content'] = theme('tripal_library_synonyms', $node);
- break;
- case 'libproperties':
- $block['subject'] = t('Properties');
- $block['content'] = theme('tripal_library_properties', $node);
- break;
- case 'libterms':
- $block['subject'] = t('Library Terms');
- $block['content'] = theme('tripal_library_terms', $node);
- break;
- case 'featurelibs':
- $block['subject'] = t('Libraries');
- $block['content'] = theme('tripal_feature_libraries', $node);
- break;
- case 'orglibs':
- $block['subject'] = t('Libraries');
- $block['content'] = theme('tripal_organism_libraries', $node);
- break;
- default :
- }
- return $block;
- }
- }
- }
|