123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- <?php
- require_once 'api/tripal_stock.DEPRECATED.inc';
- require_once 'theme/tripal_stock.theme.inc';
- require_once 'includes/tripal_stock.admin.inc';
- require_once 'includes/tripal_stock.chado_node.inc';
- function tripal_stock_menu() {
- $items = array();
-
- $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,
- );
-
- $items['admin/tripal/legacy/tripal_stock'] = array(
- 'title' => 'Stocks',
- 'description' => 'A stock is the physical entities of an organism, either living or preserved.',
- 'page callback' => 'tripal_stock_admin_stock_view',
- 'access arguments' => array('administer tripal stock'),
- 'type' => MENU_NORMAL_ITEM
- );
- $items['admin/tripal/legacy/tripal_stock/configuration'] = array(
- 'title' => 'Settings',
- 'description' => 'Settings for Chado Stocks',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_stock_admin'),
- 'access arguments' => array('administer tripal stock'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 5
- );
- $items['admin/tripal/legacy/tripal_stock/sync'] = array(
- 'title' => ' Sync',
- 'description' => 'Sync stocks from Chado with Drupal',
- 'page callback' => 'drupal_get_form',
-
- 'page arguments' => array('chado_node_sync_form', 'tripal_stock', 'chado_stock'),
- 'access arguments' => array('administer tripal stock'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 0
- );
- $items['admin/tripal/legacy/tripal_stock/chado_stock_toc'] = array(
- 'title' => ' TOC',
- 'description' => 'Manage the table of contents for stock nodes.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_core_content_type_toc_form', 'chado_stock'),
- 'access arguments' => array('administer tripal stock'),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'includes/tripal_core.toc.inc',
- 'file path' => drupal_get_path('module', 'tripal_core'),
- 'weight' => 3
- );
- $items['admin/tripal/legacy/tripal_stock/help'] = array(
- 'title' => 'Help',
- 'description' => 'Basic Description of Tripal Stock Module Functionality',
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_stock_help'),
- 'access arguments' => array('administer tripal stock'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 10
- );
- return $items;
- }
- function tripal_stock_search_biological_data_views() {
- return array(
- 'tripal_stock_user_stocks' => array(
- 'machine_name' => 'tripal_stock_user_stocks',
- 'human_name' => 'Stocks',
- 'description' => 'A stock is the physical entities of an organism, either living or preserved.',
- 'link' => 'chado/stock'
- ),
- );
- }
- 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_permission() {
- return array(
-
- );
- }
- function tripal_stock_node_access($node, $op, $account) {
- $node_type = $node;
- if (is_object($node)) {
- $node_type = $node->type;
- }
- if($node_type == 'chado_stock') {
- if ($op == 'create') {
- if (!user_access('create chado_stock content', $account)) {
- return NODE_ACCESS_DENY;
- }
- return NODE_ACCESS_ALLOW;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_stock content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_stock content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_stock content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- return NODE_ACCESS_IGNORE;
- }
- }
- function tripal_stock_views_api() {
- return array(
- 'api' => 3.0,
- );
- }
- function tripal_stock_theme($existing, $type, $theme, $path) {
- $core_path = drupal_get_path('module', 'tripal_core');
- $items = array(
-
- 'node__chado_stock' => array(
- 'template' => 'node--chado-generic',
- 'render element' => 'node',
- 'base hook' => 'node',
- 'path' => "$core_path/theme/templates",
- ),
- 'tripal_stock_base' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_base',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_properties' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_properties',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_publications' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_publications',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_references' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_references',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_relationships' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_relationships',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_synonyms' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_synonyms',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_collections' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_collections',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_collections' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_collections',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_phenotypes' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_phenotypes',
- 'path' => "$path/theme/templates",
- ),
- 'tripal_stock_locations' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_locations',
- 'path' => "$path/theme/templates",
- ),
-
- 'tripal_organism_stocks' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_organism_stocks',
- 'path' => "$path/theme/templates",
- ),
-
- 'tripal_stock_help' => array(
- 'template' => 'tripal_stock_help',
- 'variables' => array(NULL),
- 'path' => "$path/theme/templates",
- ),
-
- 'tripal_stock_teaser' => array(
- 'variables' => array('node' => NULL),
- 'template' => 'tripal_stock_teaser',
- 'path' => "$path/theme/templates",
- ),
- );
- return $items;
- }
- function tripal_stock_help ($path, $arg) {
- if ($path == 'admin/help#tripal_stock') {
- return theme('tripal_stock_help', array());
- }
- }
- 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 = :uname or S.name = :name
- ";
- $results = chado_query($sql, array(':uname' => $id, ':name' => $id));
- $num_matches = 0;
-
- $header = array('Uniquename', 'Name', 'Type', 'Species');
- $rows = array();
- $curr_match;
- while ($match = $results->fetchObject()) {
- $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;
- }
- function tripal_stock_form_alter(&$form, &$form_state, $form_id) {
-
- if ($form_id == "chado_stock_node_form") {
- $form['actions']['preview']['#access'] = FALSE;
-
- unset($form['body']);
- }
- }
- function tripal_stock_load_organism_stock_counts($organism) {
- $args = array();
- $order = array();
- $names = array();
-
-
-
- $is_custom = 0;
- $temp = rtrim(variable_get('tripal_stock_summary_report_mapping', ''));
- $where = '';
- if ($temp) {
- $is_custom = 1;
- $temp = explode("\n", $temp);
- $i = 0;
- foreach ($temp as $value) {
-
- $temp2 = explode("=", $value);
- $stock_type = rtrim($temp2[0]);
- $order[] = $stock_type;
- $where .= " OFC.stock_type = :name$i OR ";
- $args[":name$i"] = rtrim($temp2[0]);
-
-
- if(count($temp2) == 2) {
- $names[] = rtrim($temp2[1]);
- }
- else {
- $names[] = $stock_type;
- }
- $i++;
- }
- if ($where) {
- $where = drupal_substr($where, 0, -4);
- $where = "($where) AND";
- }
- }
-
-
- $sql = "
- SELECT OFC.num_stocks,OFC.stock_type,CVT.definition
- FROM {organism_stock_count} OFC
- INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
- WHERE $where organism_id = :organism_id
- ORDER BY num_stocks desc
- ";
- $args[':organism_id'] = $organism->organism_id;
- $org_stocks = chado_query($sql, $args);
-
- $types = array();
- while ($type = $org_stocks->fetchObject()) {
- $types[$type->stock_type] = $type;
-
-
- if (!$is_custom) {
- $names[] = $type->stock_type;
- $order[] = $type->stock_type;
- }
- }
-
- $ordered_types = array();
- foreach ($order as $type) {
- $ordered_types[] = $types[$type];
- }
- return array(
- 'types' => $ordered_types,
- 'names' => $names
- );
- }
|