123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251 |
- <?php
- require_once("includes/tripal_stock.admin.inc");
- require_once("includes/tripal_stock.sync_stocks.inc");
- require_once("includes/other_module_api_functions.inc");
- require_once("includes/tripal_stock-secondary_tables.inc");
- require_once("includes/tripal_stock-properties.inc");
- require_once("includes/tripal_stock-relationships.inc");
- require_once("includes/tripal_stock-db_references.inc");
- require_once("api/tripal_stock.api.inc");
- function tripal_stock_menu() {
- $items = array();
-
- $items['admin/tripal/tripal_stock'] = array(
- 'title' => 'Stocks',
- 'description' => 'Basic Description of Tripal Stock Module Functionality',
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_stock_admin'),
- 'access arguments' => array('administer tripal stocks'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items['admin/tripal/tripal_stock/configuration'] = array(
- 'title' => 'Configuration',
- 'description' => 'Settings for Chado Stocks',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_stock_admin'),
- 'access arguments' => array('administer tripal stocks'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_stock/sync'] = array(
- 'title' => ' Sync Stocks',
- 'description' => 'Sync stocks from Chado with Drupal',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_stock_sync_form'),
- 'access arguments' => array('administer tripal stocks'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- $items['node/%cs_node/properties'] = array(
- 'title' => 'Add Properties & Synonyms',
- 'description' => 'Settings for Chado Stocks',
- 'page callback' => 'tripal_stock_add_ALL_property_page',
- 'page arguments' => array(1),
- 'access arguments' => array('create chado_stock content'),
- 'type' => MENU_CALLBACK
- );
- $items['node/%cs_node/db_references'] = array(
- 'title' => 'Add Database References',
- 'description' => 'Settings for Chado Stocks',
- 'page callback' => 'tripal_stock_add_ALL_dbreferences_page',
- 'page arguments' => array(1),
- 'access arguments' => array('create chado_stock content'),
- 'type' => MENU_CALLBACK
- );
- $items['node/%cs_node/relationships'] = array(
- 'title' => 'Add Relationships',
- 'description' => 'Settings for Chado Stocks',
- 'page callback' => 'tripal_stock_add_ALL_relationships_page',
- 'page arguments' => array(1),
- 'access arguments' => array('create chado_stock content'),
- 'type' => MENU_CALLBACK
- );
-
- $items['node/%cs_node/edit_properties'] = array(
- 'title' => 'Edit Properties',
- 'description' => 'Settings for Chado Stocks',
- 'page callback' => 'tripal_stock_edit_ALL_properties_page',
- 'page arguments' => array(1),
- 'access arguments' => array('edit chado_stock content'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 8,
- );
- $items['node/%cs_node/edit_relationships'] = array(
- 'title' => 'Edit Relationships',
- 'description' => 'Settings for Chado Stocks',
- 'page callback' => 'tripal_stock_edit_ALL_relationships_page',
- 'page arguments' => array(1),
- 'access arguments' => array('edit chado_stock content'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 9,
- );
- $items['node/%cs_node/edit_db_references'] = array(
- 'title' => 'Edit DB References',
- 'description' => 'Settings for Chado Stocks',
- 'page callback' => 'tripal_stock_edit_ALL_dbreferences_page',
- 'page arguments' => array(1),
- 'access arguments' => array('edit chado_stock content'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 10,
- );
-
-
- $items['stock/%'] = array(
- 'page callback' => 'tripal_stock_match_stocks_page',
- 'page arguments' => array(1),
- 'access arguments' => array('access chado_stock content'),
- 'type' => MENU_LOCAL_TASK,
- );
- return $items;
- }
- function cs_node_load($nid) {
- if (is_numeric($nid)) {
- $node = node_load($nid);
- if ($node->type == 'chado_stock') {
- return $node;
- }
- }
- return FALSE;
- }
- function tripal_stock_perm() {
- return array(
- 'access chado_stock content',
- 'create chado_stock content',
- 'edit chado_stock content',
- 'delete chado_stock content',
- 'administer tripal stocks',
- );
- }
- function chado_stock_access($op, $node, $account) {
- if ($op == 'create') {
- if (!user_access('create chado_stock content', $account)) {
- return FALSE;
- }
- return TRUE;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_stock content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_stock content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_stock content', $account)) {
- return FALSE;
- }
- }
- return NULL;
- }
- function tripal_stock_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- function tripal_stock_theme() {
- return array(
-
- 'tripal_stock_edit_ALL_properties_form' => array(
- 'arguments' => array('form'),
- 'function' => 'theme_tripal_stock_edit_ALL_properties_form',
- ),
- 'tripal_stock_edit_ALL_db_references_form' => array(
- 'arguments' => array('form'),
- 'function' => 'theme_tripal_stock_edit_ALL_db_references_form',
- ),
- 'tripal_stock_edit_ALL_relationships_form' => array(
- 'arguments' => array('form'),
- 'function' => 'theme_tripal_stock_edit_ALL_relationships_form',
- ),
-
- 'tripal_stock_base' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_base',
- ),
- 'tripal_stock_properties' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_properties',
- ),
- 'tripal_stock_references' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_references',
- ),
- 'tripal_stock_relationships' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_relationships',
- ),
- 'tripal_stock_synonyms' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_synonyms',
- ),
- 'tripal_stock_collections' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_collections',
- ),
- 'tripal_stock_collections' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_collections',
- ),
- 'tripal_stock_phenotypes' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_phenotypes',
- ),
- 'tripal_stock_locations' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_stock_locations',
- ),
- 'tripal_organism_stocks' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_organism_stocks',
- ),
- 'tripal_stock_admin' => array(
- 'template' => 'tripal_stock_admin',
- 'arguments' => array(NULL),
- 'path' => drupal_get_path('module', 'tripal_stock') . '/theme',
- ),
- );
- }
- function tripal_stock_node_info() {
- return array(
- 'chado_stock' => array(
- 'name' => t('Stock'),
- 'module' => 'chado_stock',
- 'description' => t('A Chado Stock is a collection of material that can be sampled and have experiments performed on it.'),
- 'has_title' => TRUE,
- 'has_body' => FALSE,
- ),
- );
- }
- function chado_stock_load($node) {
-
- $stock_id = chado_get_id_for_node('stock', $node);
-
-
- $values = array('stock_id' => $stock_id);
- $stock = tripal_core_generate_chado_var('stock', $values);
-
-
-
-
-
- $title_type = variable_get('chado_stock_title', 'unique_constraint');
- if($title_type == 'unique_constraint') {
- if (strcmp($stock->name, $stock->uniquename)==0) {
- $node->title = $stock->name . " (" . $stock->type_id->name . ") " . $stock->organism_id->genus . " " . $stock->organism_id->species ;
- }
-
-
- else {
- $node->title = $stock->name . ", " . $stock->uniquename . " (" . $stock->type_id->name . ") " . $stock->organism_id->genus . " " . $stock->organism_id->species ;
- }
- }
-
- if($title_type == 'stock_name') {
- $node->title = $stock->name;
- }
- if($title_type == 'stock_unique_name') {
- $node->title = $stock->uniquename;
- }
-
-
- $additions = new stdClass();
- $additions->stock = $stock;
- return $additions;
- }
- function chado_stock_form($node, $form_state) {
-
- $fields_needed = array('stock.uniquename', 'stock.name', 'stock.stock_id', 'stock.type_id', 'stock.organism_id', 'stock.description', 'stock.dbxref_id', 'dbxref.accession', 'dbxref.description', 'dbxref.db_id', 'db.db_id');
- foreach ($fields_needed as $field_name) {
-
- if ($node->expandable_fields) {
- if (in_array($field_name, $node->expandable_fields)) {
- $node = tripal_core_expand_chado_vars($node, 'field', $field_name);
- }
- }
- }
-
-
- $form['next_step_path'] = array(
- '#type' => 'hidden',
- '#value' => 'node/%node/properties'
- );
-
-
- $form['simulate_multipart'] = array(
- '#type' => 'textfield',
- '#attributes' => array('style' => "display:none"),
- '#default_value' => TRUE
- );
- if (!isset($node->stock->uniquename)) {
- $form['progress'] = array(
- '#type' => 'item',
- '#value' => tripal_stock_add_chado_properties_progress('main')
- );
- }
- $form['names'] = array(
- '#type' => 'fieldset',
- '#title' => t('Stock Name')
- );
- $form['names']['sname'] = array(
- '#type' => 'textfield',
- '#title' => t('Name'),
- '#default_value' => $node->stock->name,
- '#required' => TRUE
- );
- $form['names']['uniquename'] = array(
- '#type' => 'textfield',
- '#title' => t('Unique Name'),
- '#default_value' => $node->stock->uniquename,
- '#required' => TRUE
- );
- $form['names']['stock_id'] = array(
- '#type' => 'hidden',
- '#value' => $node->stock->stock_id
- );
- $form['details'] = array(
- '#type' => 'fieldset',
- '#title' => t('Stock Details')
- );
- $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_types_cv', 'NULL') );
- $type_options[0] = 'Select a Type';
- if ($node->nid == '') {
- $type_default = 0;
- }
- else {
- $type_default = $node->stock->type_id->cvterm_id;
- }
- $form['details']['type_id'] = array(
- '#type' => 'select',
- '#title' => t('Type of Stock'),
- '#options' => $type_options,
- '#default_value' => $type_default,
- '#required' => TRUE,
- );
-
-
- $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
- $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['details']['organism_id'] = array(
- '#type' => 'select',
- '#title' => t('Source Organism for stock'),
- '#default_value' => $node->stock->organism_id->organism_id,
- '#options' => $organisms,
- '#required' => TRUE
- );
- $form['details']['stock_description'] = array(
- '#type' => 'textarea',
- '#title' => t('Notes'),
- '#default_value' => $node->stock->description,
- '#description' => t('Briefly enter any notes on the above stock. This should not include phenotypes or genotypes.'),
- );
- $form['database_reference'] = array(
- '#type' => 'fieldset',
- '#title' => t('Stock Database Reference')
- );
- $form['database_reference']['accession'] = array(
- '#type' => 'textfield',
- '#title' => t('Accession'),
- '#default_value' => $node->stock->dbxref_id->accession
- );
- $form['database_reference']['db_description'] = array(
- '#type' => 'textarea',
- '#title' => t('Description of Database Reference'),
- '#default_value' => $node->stock->dbxref_id->description,
- '#description' => t('Optionally enter a description about the database accession.')
- );
- $db_options = tripal_db_get_db_options();
- $db_options[0] = 'Select a Database';
- if ($node->nid == '') {
- $db_default = 0; }
- else { $db_default = $node->stock->dbxref_id->db_id->db_id; }
- $form['database_reference']['database'] = array(
- '#type' => 'select',
- '#title' => t('Database'),
- '#options' => $db_options,
- '#default_value' => $db_default
- );
- return $form;
- }
- function chado_stock_validate($node, &$form) {
- $int_in_chado_sql = "SELECT count(*) as count FROM {%s} WHERE %s=%d";
- $string_in_chado_sql = "SELECT count(*) as count FROM {%s} WHERE %s='%s'";
-
-
-
- if ($node->stock_id) {
- $sql = "SELECT *
- FROM {stock} S
- INNER JOIN {cvterm} CVT ON S.type_id = CVT.cvterm_id
- WHERE uniquename = '%s'
- AND organism_id = %d AND CVT.name = '%s' AND NOT stock_id = %d";
- $result = db_fetch_object(chado_query($sql, $node->uniquename, $node->organism_id, $node->stock_type, $node->stock_id));
- if ($result) {
- form_set_error('uniquename', t("Stock update cannot proceed. The stock name '$node->uniquename' is not unique for this organism. Please provide a unique name for this stock."));
- }
- }
-
-
- else {
- $sql = "SELECT *
- FROM {Stock} S
- INNER JOIN {cvterm} CVT ON S.type_id = CVT.cvterm_id
- WHERE uniquename = '%s'
- AND organism_id = %d AND CVT.name = '%s'";
- $result = db_fetch_object(chado_query($sql, $node->uniquename, $node->organism_id, $node->stock_type));
- if ($result) {
- form_set_error('uniquename', t("Stock insert cannot proceed. The stock name '$node->uniquename' already exists for this organism. Please provide a unique name for this stock."));
- }
- }
-
-
- if ( $node->type_id == 0) {
- form_set_error('type_id', 'Please select a type of stock.');
- }
- else {
- $num_rows = db_fetch_object(chado_query($int_in_chado_sql, 'cvterm', 'cvterm_id', $node->type_id));
- if ( $num_rows->count != 1) {
- form_set_error('type_id', "The type you selected is not valid. Please choose another one. (CODE:$num_rows)"); }
- }
-
- if ( $node->organism_id == 0) {
- form_set_error('organism_id', 'Please select a source organism for this stock');
- }
- else {
- $num_rows = db_fetch_object(chado_query($int_in_chado_sql, 'organism', 'organism_id', $node->organism_id));
- if ( $num_rows->count != 1 ) {
- form_set_error('organism_id', "The organism you selected is not valid. Please choose another one. (CODE:$num_rows)"); }
- }
-
- if ($node->accession != '') {
- if ($node->database == 0) {
-
- form_set_error('database', 'You need to enter both a database and an accession for that database in order to add a database reference.');
- }
- }
- else {
- if ($node->database > 0) {
-
- form_set_error('accession', 'You need to enter both a database and an accession for that database in order to add a database reference.');
- }
- }
-
- if ( $node->database > 0) {
- $num_rows = db_fetch_object(chado_query($int_in_chado_sql, 'db', 'db_id', $node->database));
- if ($num_rows->count != 1) {
- form_set_error('database', 'The database you selected is not valid. Please choose another one.'); }
- }
- }
- function chado_stock_insert($node) {
-
-
-
- if ($node->chado_stock_exists) {
- if (!empty($node->stock_id)) {
- db_query(
- "INSERT INTO {chado_stock} (nid, vid, stock_id) "
- ."VALUES (%d, %d, %d)",
- $node->nid,
- $node->vid,
- $node->stock_id
- );
- }
-
- return $node;
- }
-
-
- $dbxref_status = 0;
- if (!empty($node->accession) ) {
- if (!empty($node->database) ) {
- $values = array(
- 'db_id' => $node->database,
- 'accession' => $node->accession,
- );
- if (!tripal_core_chado_select('dbxref', array(dbxref_id), $values)) {
- $values['description'] = $node->db_description;
- $values['version'] = '1';
- $dbxref_status = tripal_core_chado_insert('dbxref', $values);
- if (!$dbxref_status) {
- drupal_set_message(t('Unable to add database reference to this stock.'), 'warning');
- watchdog('tripal_stock',
- 'Insert Stock: Unable to create dbxref where values:%values',
- array('%values' => print_r($values, TRUE)),
- WATCHDOG_WARNING
- );
- }
- }
- else {
- $dbxref_status = 1;
- }
- }
- }
-
- $stock = '';
- if ($dbxref_status) {
- $values = array(
- 'dbxref_id' => array(
- 'db_id' => $node->database,
- 'accession' => $node->accession
- ),
- 'organism_id' => $node->organism_id,
- 'name' => $node->sname,
- 'uniquename' => $node->uniquename,
- 'description' => $node->stock_description,
- 'type_id' => $node->type_id
- );
- $stock = tripal_core_chado_insert('stock', $values);
- }
-
- else {
- $values = array(
- 'organism_id' => $node->organism_id,
- 'name' => $node->sname,
- 'uniquename' => $node->uniquename,
- 'description' => $node->stock_description,
- 'type_id' => $node->type_id
- );
- $stock = tripal_core_chado_insert('stock', $values);
- }
-
-
-
- if (is_array($stock)) {
-
-
- $stock = (object) $stock;
-
- $sql = "INSERT INTO {chado_stock} (nid, vid, stock_id) VALUES (%d, %d, %d)";
- db_query($sql, $node->nid, $node->vid, $stock->stock_id);
-
- if ($node->simulate_multipart) {
- $next_stage_path = preg_replace('/%node/', $node->nid, $node->next_step_path);
- $_REQUEST['destination'] = $next_stage_path;
- }
- }
- else {
- drupal_set_message(t('Error during stock creation.'), 'error');
- watchdog('tripal_stock',
- 'Insert Stock: Unable to create stock where values:%values',
- array('%values' => print_r($values, TRUE)),
- WATCHDOG_WARNING
- );
- return FALSE;
- }
- }
- function chado_stock_update($node) {
- if ($node->revision) {
-
-
- }
-
- if ($node->database) {
- if ($node->accession) {
- $dbxref_mode = '';
- $stock = tripal_core_chado_select(
- 'stock',
- array('dbxref_id', 'type_id'),
- array('stock_id' => $node->stock_id)
- );
- if ($stock[0]->dbxref_id) {
- $values = array(
- 'db_id' => $node->database,
- 'accession' => $node->accession,
- 'description' => $node->db_description
- );
- $dbxref_status = tripal_core_chado_update(
- 'dbxref',
- array('dbxref_id' => $stock[0]->dbxref_id),
- $values
- );
- $dbxref_mode = 'Update';
- }
- else {
- if ($stock[0]->type_id) {
-
-
- $values = array(
- 'db_id' => $node->database,
- 'accession' => $node->accession,
- 'description' => $node->db_description,
- 'version' => '1',
- );
- $dbxref_status = tripal_core_chado_insert(
- 'dbxref',
- $values
- );
- $dbxref_mode = 'Create';
- }
- else {
- drupal_set_message(t('Unable to find stock to Update'), 'error');
- watchdog(
- 'tripal_stock',
- 'Stock Update: Unable to find stock to update using values: %values',
- array('%values', print_r($values, TRUE)),
- WATCHDOG_ERROR
- );
- return FALSE;
- }
- }
- }
- }
- if (!$dbxref_status) {
- watchdog(
- 'tripal_stock',
- 'Stock Update: Unable to %mode main stock dbxref with values: %values',
- array('%values' => print_r($values, TRUE), '%mode' => $dbxref_mode),
- WATCHDOG_WARNING
- );
- }
-
- $update_values = array(
- 'organism_id' => $node->organism_id,
- 'name' => $node->sname,
- 'uniquename' => $node->uniquename,
- 'description' => $node->stock_description,
- 'type_id' => $node->type_id,
- );
- if ($dbxref_status) {
- $update_values['dbxref_id'] = array(
- 'db_id' => $node->database,
- 'accession' => $node->accession
- );
- }
- $status = tripal_core_chado_update('stock', array('stock_id' => $node->stock_id), $update_values);
-
- if (!$status) {
- drupal_set_message(t('Unable to update stock'), 'error');
- watchdog(
- 'tripal_stock',
- 'Stock Update: Unable to update stock using match values: %mvalues and update values: %uvalues',
- array('%mvalues' => print_r(array('stock_id' => $node->stock_id), TRUE), '%uvalues' => print_r($update_values, TRUE)),
- WATCHDOG_ERROR
- );
- }
- else {
-
- $values = array('stock_id' => $node->stock_id);
- $stock = tripal_core_chado_select('stock', array('*'), $values);
- }
- }
- function chado_stock_delete($node) {
-
- chado_query(
- "DELETE FROM {stock} WHERE stock_id=%d",
- $node->stock->stock_id
- );
-
- db_query(
- "DELETE FROM {chado_stock} WHERE nid=%d",
- $node->nid
- );
- }
- function tripal_stock_block($op = 'list', $delta = 0, $edit=array()) {
- switch ($op) {
- case 'list':
- $blocks['base']['info'] = t('Tripal Stock Details');
- $blocks['base']['cache'] = BLOCK_NO_CACHE;
- $blocks['properties']['info'] = t('Tripal Stock Properties');
- $blocks['properties']['cache'] = BLOCK_NO_CACHE;
- $blocks['references']['info'] = t('Tripal Stock References');
- $blocks['references']['cache'] = BLOCK_NO_CACHE;
- $blocks['relationships_as_object']['info'] = t('Tripal Stock Relationships');
- $blocks['relationships_as_object']['cache'] = BLOCK_NO_CACHE;
- $blocks['synonyms']['info'] = t('Tripal Stock Synonyms');
- $blocks['synonyms']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['collections']['info'] = t('Tripal Stock Collections');
- $blocks['collections']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['phenotypes']['info'] = t('Tripal Stock Phenotypes');
- $blocks['phenotypes']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['genotypes']['info'] = t('Tripal Stock Genotypes');
- $blocks['genotypes']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['locations']['info'] = t('Tripal Stock Locations');
- $blocks['locations']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['orgstocks']['info'] = t('Tripal Organism Stocks');
- $blocks['orgstocks']['cache'] = BLOCK_NO_CACHE;
-
-
- return $blocks;
- case 'view':
- if (user_access('access chado_stock 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('Stock Details');
- $block['content'] = theme('tripal_stock_base', $node);
- break;
- case 'properties':
- $block['subject'] = t('Properties');
- $block['content'] = theme('tripal_stock_properties', $node);
- break;
- case 'references':
- $block['subject'] = t('References');
- $block['content'] = theme('tripal_stock_references', $node);
- break;
- case 'relationships':
- $block['subject'] = t('Relationships');
- $block['content'] = theme('tripal_stock_relationships', $node);
- break;
- case 'synonyms':
- $block['subject'] = t('Synonyms');
- $block['content'] = theme('tripal_stock_synonyms', $node);
- break;
-
- case 'collections':
- $block['subject'] = t('Stock Collections');
- $block['content'] = theme('tripal_stock_collections', $node);
- break;
-
- case 'phenotypes':
- $block['subject'] = t('Stock Phenotypes');
- $block['content'] = theme('tripal_stock_phenotypes', $node);
- break;
-
- case 'genotypes':
- $block['subject'] = t('Stock Genotypes');
- $block['content'] = theme('tripal_stock_genotypes', $node);
- break;
-
- case 'locations':
- $block['subject'] = t('Stock Locations');
- $block['content'] = theme('tripal_stock_locations', $node);
- break;
-
- case 'orgstocks':
- $block['subject'] = t('Organism Stocks');
- $block['content'] = theme('tripal_organism_stocks', $node);
- break;
- }
- return $block;
- }
- }
- }
- function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
-
- $stock = $variables['node']->stock;
-
-
-
-
-
- $sql = "
- SELECT
- S.name, S.uniquename, S.stock_id, CS.nid,
- CVT.name as rel_type, CVTs.name as obj_type,
- SR.value
- FROM {stock_relationship} SR
- INNER JOIN {stock} S on SR.object_id = S.stock_id
- INNER JOIN {cvterm} CVT on SR.type_id = CVT.cvterm_id
- INNER JOIN {cvterm} CVTs on S.type_id = CVTs.cvterm_id
- LEFT JOIN public.chado_stock CS on S.stock_id = CS.stock_id
- WHERE SR.subject_id = %d
- ";
- $as_subject = chado_query($sql, $stock->stock_id);
- $sql = "
- SELECT
- S.name, S.uniquename, S.stock_id, CS.nid,
- CVT.name as rel_type, CVTs.name as sub_type,
- SR.value
- FROM {stock_relationship} SR
- INNER JOIN {stock} S on SR.subject_id = S.stock_id
- INNER JOIN {cvterm} CVT on SR.type_id = CVT.cvterm_id
- INNER JOIN {cvterm} CVTs on S.type_id = CVTs.cvterm_id
- LEFT JOIN public.chado_stock CS on S.stock_id = CS.stock_id
- WHERE SR.object_id = %d
- ";
- $as_object = chado_query($sql, $stock->stock_id);
-
-
- $relationships = array();
- $relationships['object'] = array();
- $relationships['subject'] = array();
-
-
- while ($relationship = db_fetch_object($as_object)) {
-
-
- $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
- $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
-
- if (!array_key_exists($rel_type, $relationships['object'])) {
- $relationships['object'][$rel_type] = array();
- }
- if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
- $relationships['object'][$rel_type][$sub_type] = array();
- }
- $relationships['object'][$rel_type][$sub_type][] = $relationship;
- }
-
-
- while ($relationship = db_fetch_object($as_subject)) {
-
-
- $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
- $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
-
- if (!array_key_exists($rel_type, $relationships['subject'])) {
- $relationships['subject'][$rel_type] = array();
- }
- if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
- $relationships['subject'][$rel_type][$obj_type] = array();
- }
- $relationships['subject'][$rel_type][$obj_type][] = $relationship;
- }
-
-
- $stock->all_relationships = $relationships;
- }
- function tripal_stock_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
-
-
- case 'presave':
- switch ($node->type) {
- case 'chado_stock':
-
- $values = array('organism_id' => $node->organism_id);
- $organism = tripal_core_chado_select('organism', array('genus','species'), $values);
- $values = array('cvterm_id' => $node->type_id);
- $cvterm = tripal_core_chado_select('cvterm', array('name'), $values);
- $node->title = $node->sname . ', ' . $node->uniquename . ' (' . $cvterm[0]->name . ') ' . $organism[0]->genus . ' ' . $organism[0]->species;
- break;
- }
- break;
-
-
-
- case 'insert':
- switch ($node->type) {
- case 'chado_stock':
- if (!$node->stock_id) {
- $sql = "SELECT * FROM {chado_stock} WHERE nid = %d";
- $chado_stock = db_fetch_object(db_query($sql, $node->nid));
- $node->stock_id = $chado_stock->stock_id;
- }
-
-
- db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
-
-
- $url_alias = tripal_stock_get_stock_url($node);
- path_set_alias("node/$node->nid", $url_alias);
- break;
- }
- break;
-
-
-
- case 'update':
- switch ($node->type) {
- case 'chado_stock':
-
-
- db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
-
-
- $url_alias = tripal_stock_get_stock_url($node);
- path_set_alias("node/$node->nid", $url_alias);
- break;
- }
- break;
-
-
- case 'view':
-
- if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
- }
- elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
- }
- else {
- switch ($node->type) {
- case 'chado_organism':
-
- $node->content['tripal_organism_stocks'] = array(
- '#value' => theme('tripal_organism_stocks', $node),
- );
- break;
- }
- }
- break;
- }
- }
- function tripal_stock_match_stocks_page($id) {
-
-
-
-
- $url_alias = variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]');
- if (!$url_alias) {
- $url_alias = '/stock/[genus]/[species]/[type]/[uniquename]';
- }
- $url_alias = preg_replace('/^\//', '', $url_alias);
- if (preg_match('/^stock\//', $url_alias)) {
- drupal_goto($id);
- }
-
- $sql = "
- SELECT
- S.name, S.uniquename, S.stock_id,
- O.genus, O.species, O.organism_id,
- CVT.cvterm_id, CVT.name as type_name,
- CS.nid
- FROM {stock} S
- INNER JOIN {organism} O on S.organism_id = O.organism_id
- INNER JOIN {cvterm} CVT on CVT.cvterm_id = S.type_id
- INNER JOIN public.chado_stock CS on CS.stock_id = S.stock_id
- WHERE
- S.uniquename = '%s' or S.name = '%s'
- ";
- $results = chado_query($sql, $id, $id);
- $num_matches = 0;
-
- $header = array('Uniquename', 'Name', 'Type', 'Species');
- $rows = array();
- $curr_match;
- while ($match = db_fetch_object($results)) {
- $curr_match = $match;
- $rows[] = array(
- $match->uniquename,
- "<a href=\"" . url("node/". $match->nid) ."\">" . $match->name . "</a>",
- $match->type_name,
- '<i>' . $match->genus . ' ' . $match->species . '</i>',
- );
- $num_matches++;
- }
-
-
- if ($num_matches == 1) {
- drupal_goto("node/" . $curr_match->nid);
- }
- if ($num_matches == 0) {
- return "<p>No stocks matched the given name '$id'</p>";
- }
- $table_attrs = array(
- 'class' => 'tripal-table tripal-table-horz'
- );
- $output = "<p>The following stocks match the name '$id'.</p>";
- $output .= theme_table($header, $rows, $table_attrs, $caption);
- return $output;
- }
|