123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- <?php
- require('api/tripal_analysis.api.inc');
- require('includes/tripal_analysis_privacy.inc');
- require('includes/tripal_analysis.admin.inc');
- require('includes/tripal_analysis.form.inc');
- function tripal_analysis_init() {
- drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_analysis.js');
- drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_analysis.css');
- }
- function tripal_analysis_menu() {
-
- $items['chado_sync_analyses'] = array(
- 'title' => 'Sync Data',
- 'page callback' => 'tripal_analysis_sync_analyses',
- 'access arguments' => array('administer tripal analyses'),
- 'type' => MENU_CALLBACK
- );
-
- $items['admin/tripal/tripal_analysis'] = array(
- 'title' => 'Analyses',
- 'description' => 'Basic Description of Tripal Analysis Module Functionality.',
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_analysis_admin'),
- 'access arguments' => array('administer tripal analyses'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'includes/tripal_analysis.admin.inc',
- );
- $items['admin/tripal/tripal_analysis/configuration'] = array(
- 'title' => 'Configuration',
- 'description' => 'Settings for the displays of analysis results.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_analysis_admin'),
- 'access arguments' => array('administer tripal analyses'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'includes/tripal_analysis.admin.inc',
- );
-
-
-
- $items['tripal_analysis/properties/add'] = array(
- 'page callback' => 'tripal_analysis_property_add',
- 'access arguments' => array('edit chado_analysis content'),
- 'type ' => MENU_CALLBACK,
- );
- $items['tripal_analysis/properties/description'] = array(
- 'page callback' => 'tripal_analysis_property_get_description',
- 'access arguments' => array('edit chado_analysis content'),
- 'type ' => MENU_CALLBACK,
- );
- $items['tripal_analysis/properties/minus/%/%'] = array(
- 'page callback' => 'tripal_analysis_property_delete',
- 'page arguments' => array(3, 4),
- 'access arguments' => array('edit chado_analysis content'),
- 'type ' => MENU_CALLBACK,
- );
-
-
- return $items;
- }
- function tripal_analysis_node_info() {
- $nodes = array();
- $nodes['chado_analysis'] = array(
- 'name' => t('Analysis'),
- 'module' => 'chado_analysis',
- 'description' => t('An analysis from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Analysis'),
- 'has_body' => FALSE,
- 'body_label' => t('Analysis Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- function chado_analysis_insert($node) {
- global $user;
-
- $time = $node->timeexecuted;
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $month . '/' . $day . '/' . $year;
-
- $analysis_id = $node->analysis_id;
- if ($analysis_id) {
- $values = array('analysis_id' => $node->analysis_id);
- $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
- if($result and count($result) > 0) {
- $analysis = $result[0];
- }
- }
-
-
- if (!$analysis) {
-
- $values = array(
- 'name' => $node->analysisname,
- 'description' => $node->description,
- 'program' => $node->program,
- 'programversion' => $node->programversion,
- 'algorithm' => $node->algorithm,
- 'sourcename' => $node->sourcename,
- 'sourceversion' => $node->sourceversion,
- 'sourceuri' => $node->sourceuri,
- 'timeexecuted' => $timestamp
- );
- if (tripal_core_chado_insert('analysis', $values)) {
- $analysis = tripal_core_chado_select('analysis', array('*'), $values);
- $analysis_id = $analysis[0]->analysis_id;
- }
- }
-
-
- $node_check_sql = "SELECT * FROM {chado_analysis} ".
- "WHERE analysis_id = %d";
- $node_check = db_fetch_object(db_query($node_check_sql, $analysis_id));
- if (!$node_check) {
-
- $sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql, $node->nid, $node->vid, $analysis_id);
-
-
- $record = new stdClass();
-
-
- if ($node->analysisname) {
- $record->title = $node->analysisname;
- }
- else {
-
- $record->title = "$node->program ($node->programversion)";
- }
- $record->nid = $node->nid;
- drupal_write_record('node', $record, 'nid');
- drupal_write_record('node_revisions', $record, 'nid');
- }
-
-
- $node->analysis = $analysis;
- $node->analysis_id = $analysis_id;
-
-
- $properties = array();
-
- $properties_list = array();
- $sql = "
- SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
- FROM {cvterm} CVT
- INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
- WHERE
- CV.name = 'analysis_property' AND
- NOT CVT.is_obsolete = 1
- ORDER BY CVT.name ASC
- ";
- $prop_types = chado_query($sql);
- while ($prop = db_fetch_object($prop_types)) {
- $properties_list[$prop->cvterm_id] = $prop->name;
- }
-
-
-
-
-
- foreach ($node as $name => $value) {
- if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
- $type_id = $matches[1];
- $index = $matches[2];
- $name = $properties_list[$type_id];
- $properties[$name][$index] = trim($value);
- }
- }
- if ($node->new_id and $node->new_value) {
- $type_id = $node->new_id;
- $name = $properties_list[$type_id];
- $index = count($properties[$name]);
- $properties[$name][$index] = trim($node->new_value);
- }
-
- foreach ($properties as $property => $elements) {
- foreach ($elements as $rank => $value) {
- $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE, 'analysis_property');
- if (!$status) {
- drupal_set_message("Error cannot add property: $property", "error");
- watchdog('t_analysis', "Error cannot add property: %prop",
- array('%property' => $property), WATCHDOG_ERROR);
- }
- }
- }
- }
- function chado_analysis_delete($node) {
- $analysis_id = chado_get_id_for_node('analysis', $node);
-
-
-
- if (!$analysis_id) {
- return;
- }
-
- $sql_del = "DELETE FROM {chado_analysis} ".
- "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);
- $sql_del = "DELETE FROM {node_revisions} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
-
- chado_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
- }
- function chado_analysis_update($node) {
- global $user;
- if ($node->revision) {
-
- }
-
- $time = $node->timeexecuted;
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $month . '/' . $day . '/' . $year;
-
- $sql = "SELECT analysis_id ".
- "FROM {chado_analysis} ".
- "WHERE nid = %d";
- $analysis_id = db_fetch_object(db_query($sql, $node->nid))->analysis_id;
- $sql = "UPDATE {analysis} ".
- "SET name = '%s', ".
- " description = '%s', ".
- " program = '%s', ".
- " programversion = '%s', ".
- " algorithm = '%s', ".
- " sourcename = '%s', ".
- " sourceversion = '%s', ".
- " sourceuri = '%s', ".
- " timeexecuted = '%s' ".
- "WHERE analysis_id = %d ";
- chado_query($sql, $node->analysisname, $node->description, $node->program,
- $node->programversion, $node->algorithm, $node->sourcename,
- $node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
-
-
- $record = new stdClass();
-
-
- if ($node->analysisname) {
- $record->title = $node->analysisname;
- }
- else {
-
- $record->title = "$node->program ($node->programversion)";
- }
- $record->nid = $node->nid;
- drupal_write_record('node', $record, 'nid');
- drupal_write_record('node_revisions', $record, 'nid');
-
- $properties = array();
-
- $properties_list = array();
- $sql = "
- SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
- FROM {cvterm} CVT
- INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
- WHERE
- CV.name = 'analysis_property' AND
- NOT CVT.is_obsolete = 1
- ORDER BY CVT.name ASC
- ";
- $prop_types = chado_query($sql);
- while ($prop = db_fetch_object($prop_types)) {
- $properties_list[$prop->cvterm_id] = $prop->name;
- }
-
-
-
-
-
- foreach ($node as $key => $value) {
- if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
- $type_id = $matches[1];
- $index = $matches[2];
- $name = $properties_list[$type_id];
- $properties[$name][$index] = trim($value);
- }
- if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
- $type_id = $matches[1];
- $index = $matches[2];
- $name = $properties_list[$type_id];
- $properties[$name][$index] = trim($value);
- }
- }
- if ($node->new_id and $node->new_value) {
- $type_id = $node->new_id;
- $name = $properties_list[$type_id];
- $index = count($properties[$name]);
- $properties[$name][$index] = trim($node->new_value);
- }
-
-
- tripal_core_chado_delete('analysisprop', array('analysis_id' => $analysis_id));
- foreach ($properties as $property => $elements) {
- foreach ($elements as $rank => $value) {
- $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE, 'analysis_property');
- if (!$status) {
- drupal_set_message("Error cannot add property: '$property'", "error");
- watchdog('t_analysis', "Error cannot add property: '%prop'",
- array('%prop' => $property), WATCHDOG_ERROR);
- }
- }
- }
- }
-
- function chado_analysis_load($node) {
-
- $analysis_id = chado_get_id_for_node('analysis', $node);
- $values = array('analysis_id' => $analysis_id);
- $analysis = tripal_core_generate_chado_var('analysis', $values);
- $additions = new stdClass();
- $additions->analysis = $analysis;
- return $additions;
- }
- function chado_analysis_view($node, $teaser = FALSE, $page = FALSE) {
-
- if (!$teaser) {
- $node = node_prepare($node, $teaser);
-
-
- $time = $node->timeexecuted;
- if (is_array($time)) {
- $month = $time['month'];
- $day = $time['day'];
- $year = $time['year'];
- $timestamp = $year . '-' . $month . '-' . $day;
- $node->timeexecuted = $timestamp;
- }
- }
- return $node;
- }
- function tripal_analysis_help($path, $arg) {
- $output = '';
- switch ($path) {
- case "admin/help#tripal_analysis":
- $output = '<p>' .
- t("Displays links to nodes created on this date") .
- '</p>';
- break;
- }
- return $output;
- }
- function chado_analysis_access($op, $node, $account) {
- if ($op == 'create') {
- if (!user_access('create chado_analysis content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'update') {
- if (!user_access('edit chado_analysis content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_analysis content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_analysis content', $account)) {
- return FALSE;
- }
- }
- return NULL;
- }
- function tripal_analysis_perm() {
- return array(
- 'access chado_analysis content',
- 'create chado_analysis content',
- 'delete chado_analysis content',
- 'edit chado_analysis content',
- 'administer tripal analyses',
- );
- }
- function tripal_analysis_theme() {
- $items = array(
- 'tripal_analysis_base' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_analysis_base',
- ),
- 'tripal_feature_analyses' => array(
- 'template' => 'tripal_feature_analyses',
- 'arguments' => array('node' => NULL),
- ),
- 'tripal_analysis_admin' => array(
- 'template' => 'tripal_analysis_admin',
- 'arguments' => array(NULL),
- 'path' => drupal_get_path('module', 'tripal_analysis') . '/theme',
- ),
- 'tripal_analysis_properties' => array(
- 'arguments' => array('node' => NULL)
- ),
-
- 'chado_analysis_node_form' => array(
- 'arguments' => array('form'),
- ),
- );
-
- return $items;
- }
- function tripal_analysis_block($op = 'list', $delta = 0, $edit=array()) {
- switch ($op) {
- case 'list':
- $blocks['base']['info'] = t('Tripal Analysis Details');
- $blocks['base']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
- $blocks['featureblast']['cache'] = BLOCK_NO_CACHE;
-
- return $blocks;
- case 'view':
- if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
- $block = array();
- switch ($delta) {
- case 'base':
- $block['subject'] = t('Analysis Details');
- $block['content'] = theme('tripal_analysis_base', $node);
- break;
- case 'tripal_feature_analyses':
- $block['subject'] = t('Feature Analyses');
- $block['content'] = theme('tripal_feature_analyses', $node);
- break;
- default :
- }
- return $block;
- }
- }
- }
- function tripal_analysis_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'view':
- if ($teaser) {
- return '';
- }
-
- if (strcmp($node->type, 'chado_feature') == 0) {
- if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
-
- }
- else {
-
- $node->content['tripal_feature_analyses'] = array(
- '#value' => theme('tripal_feature_analyses', $node),
- '#weight' => 8
- );
- }
- }
- break;
- }
- }
- function tripal_analysis_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- function tripal_analysis_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id == "chado_analysis_node_form") {
- }
- }
|