123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645 |
- <?php
- function tripal_featuremap_node_info() {
- $nodes = [];
- $nodes['chado_featuremap'] = [
- 'name' => t('Feature Map (Tripal v2 legacy)'),
- 'base' => 'chado_featuremap',
- 'description' => t('A map of features from the chado database (e.g. genetic map)'),
- 'has_title' => TRUE,
- 'locked' => TRUE,
- 'chado_node_api' => [
- 'base_table' => 'featuremap',
- 'hook_prefix' => 'chado_featuremap',
- 'record_type_title' => [
- 'singular' => t('Feature Map'),
- 'plural' => t('Feature Maps'),
- ],
- 'sync_filters' => [
- 'type_id' => FALSE,
- 'organism_id' => FALSE,
- ],
- ],
- ];
- return $nodes;
- }
- function chado_featuremap_form($node, &$form_state) {
- $form = [];
-
-
-
-
-
-
-
-
-
- $featuremap_id = NULL;
- $fmapname = '';
- $description = '';
- $unittype_id = '';
-
- if (property_exists($node, 'featuremap')) {
- $featuremap = $node->featuremap;
- $featuremap = chado_expand_var($featuremap, 'field', 'featuremap.description');
- $featuremap_id = $featuremap->featuremap_id;
-
- $fmapname = $featuremap->name;
- $description = $featuremap->description;
- $unittype_id = $featuremap->unittype_id->cvterm_id;
-
- $form['featuremap_id'] = [
- '#type' => 'hidden',
- '#value' => $featuremap_id,
- ];
- }
-
-
- if (array_key_exists('values', $form_state)) {
- $fmapname = $form_state['values']['fmapname'];
- $description = $form_state['values']['description'];
- $unittype_id = $form_state['values']['unittype_id'];
- }
-
-
- if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
- $fmapname = $form_state['input']['fmapname'];
- $description = $form_state['input']['description'];
- $unittype_id = $form_state['input']['unittype_id'];
- }
- $form['fmapname'] = [
- '#type' => 'textfield',
- '#title' => t('Map Name'),
- '#description' => t('Please enter a name for this map'),
- '#required' => TRUE,
- '#default_value' => $fmapname,
- '#maxlength' => 255,
- ];
- $form['description'] = [
- '#type' => 'text_format',
- '#title' => t('Map Description'),
- '#description' => t('A description of the map.'),
- '#required' => TRUE,
- '#default_value' => $description,
- ];
-
- $units = tripal_get_cvterm_default_select_options('featuremap', 'unittype_id', 'map unit types');
- $form['unittype_id'] = [
- '#title' => t('Map Units'),
- '#type' => t('select'),
- '#description' => t("Chose the units for this map"),
- '#required' => TRUE,
- '#default_value' => $unittype_id,
- '#options' => $units,
- ];
-
-
- $prop_cv = tripal_get_default_cv('featuremap_property', 'type_id');
- $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
- $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the featuremap_property vocabulary", "admin/tripal/vocab/cvterm/add") . ".");
- $details = [
- 'property_table' => 'featuremapprop',
- 'chado_id' => $featuremap_id,
- 'cv_id' => $cv_id,
- 'fieldset_name' => 'Additional Details',
- 'additional_instructions' => $instructions,
- ];
-
-
- chado_add_node_form_properties($form, $form_state, $details);
-
-
- $details = [
- 'linking_table' => 'featuremap_dbxref',
-
- 'base_foreign_key' => 'featuremap_id',
-
- 'base_key_value' => $featuremap_id
-
- ];
-
- chado_add_node_form_dbxrefs($form, $form_state, $details);
- return $form;
- }
- function chado_featuremap_validate($node, $form, &$form_state) {
-
-
-
-
- if (property_exists($node, "op") and $node->op != 'Save') {
- return;
- }
-
-
- if (!property_exists($node, 'nid') and property_exists($node, 'featuremap_id') and $node->featuremap_id != 0) {
- return;
- }
- if ($node->unittype_id == 0) {
- form_set_error('unittype_id', 'Please provide a unit type for this map.');
- }
-
- $node->fmapname = property_exists($node, 'fmapname') ? trim($node->fmapname) : '';
- $featuremap = 0;
-
-
-
-
-
- if (property_exists($node, 'featuremap_id')) {
- $sql = "
- SELECT * FROM {featuremap}
- WHERE name = :name AND NOT featuremap_id = :featuremap_id
- ";
- $featuremap = chado_query($sql, [
- ':name' => $node->fmapname,
- ':featuremap_id' => $node->featuremap_id,
- ])->fetchObject();
- }
- else {
- $sql = "SELECT * FROM {featuremap} WHERE name = :name";
- $featuremap = chado_query($sql, [':name' => $node->fmapname])->fetchObject();
- }
- if ($featuremap) {
- form_set_error('fmapname', t('The unique map name already exists. Please choose another'));
- }
- }
- function tripal_featuremap_node_access($node, $op, $account) {
- $node_type = $node;
- if (is_object($node)) {
- $node_type = $node->type;
- }
- if ($node_type == 'chado_featuremap') {
- if ($op == 'create') {
- if (!user_access('create chado_featuremap content', $account)) {
- return NODE_ACCESS_DENY;
- }
- return NODE_ACCESS_ALLOW;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_featuremap content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_featuremap content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_featuremap content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- return NODE_ACCESS_IGNORE;
- }
- }
- function chado_featuremap_insert($node) {
- $featuremap_id = '';
-
-
-
- if (!property_exists($node, 'featuremap_id')) {
- $node->fmapname = trim($node->fmapname);
- $node->description = trim($node->description['value']);
- $values = [
- 'name' => $node->fmapname,
- 'description' => $node->description,
- 'unittype_id' => $node->unittype_id,
- ];
- $featuremap = chado_insert_record('featuremap', $values);
- if (!$featuremap) {
- drupal_set_message(t('Unable to add featuremap.', 'warning'));
- tripal_report_error('tripal_featuremap', TRIPAL_WARNING, 'Unable to create feature map where values: %values',
- ['%values' => print_r($values, TRUE)]);
- return;
- }
- $featuremap_id = $featuremap['featuremap_id'];
-
- $properties = chado_retrieve_node_form_properties($node);
-
- $cvterm = chado_select_record(
- 'cvterm',
- ['cvterm_id'],
- ['name' => 'Map Dbxref', 'cv_id' => ['name' => 'featuremap_property']]
- );
- $map_dbxref_cvterm_id = $cvterm[0]->cvterm_id;
- if (isset($properties[$map_dbxref_cvterm_id])) {
- foreach ($properties[$map_dbxref_cvterm_id] as $rank => $value) {
- $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
- if (!$featuremap_dbxref) {
- drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
- tripal_report_error('t_featuremap', TRIPAL_ERROR, "Error cannot add featuremap cross reference: %ref",
- ['%ref' => $value]);
- }
- }
- unset($properties[$map_dbxref_cvterm_id]);
- }
- $details = [
- 'property_table' => 'featuremapprop',
- 'base_table' => 'featuremap',
- 'foreignkey_name' => 'featuremap_id',
- 'foreignkey_value' => $featuremap_id,
- ];
- chado_update_node_form_properties($node, $details, $properties);
-
- $details = [
- 'linking_table' => 'featuremap_dbxref',
-
- 'foreignkey_name' => 'featuremap_id',
-
- 'foreignkey_value' => $featuremap_id
-
- ];
- chado_update_node_form_dbxrefs($node, $details);
- }
- else {
- $featuremap_id = $node->featuremap_id;
- }
-
-
- $check_org_id = chado_get_id_from_nid('featuremap', $node->nid);
- if (!$check_org_id) {
- $record = new stdClass();
- $record->nid = $node->nid;
- $record->vid = $node->vid;
- $record->featuremap_id = $featuremap_id;
- drupal_write_record('chado_featuremap', $record);
- }
- }
- function chado_featuremap_update($node) {
- $node->fmapname = trim($node->fmapname);
- $node->description = trim($node->description['value']);
- $featuremap_id = chado_get_id_from_nid('featuremap', $node->nid);
-
- $match = [
- 'featuremap_id' => $featuremap_id,
- ];
- $values = [
- 'name' => $node->fmapname,
- 'description' => $node->description,
- 'unittype_id' => $node->unittype_id,
- ];
- $status = chado_update_record('featuremap', $match, $values);
- if (!$status) {
- drupal_set_message("Error updating map", "error");
- tripal_report_error('t_featuremap', TRIPAL_ERROR, "Error updating map", []);
- return;
- }
-
- $properties = chado_retrieve_node_form_properties($node);
-
- $cvterm = chado_select_record(
- 'cvterm',
- ['cvterm_id'],
- ['name' => 'Map Dbxref', 'cv_id' => ['name' => 'featuremap_property']]
- );
- $map_dbxref_cvterm_id = $cvterm[0]->cvterm_id;
- if (isset($properties[$map_dbxref_cvterm_id])) {
- foreach ($properties[$map_dbxref_cvterm_id] as $rank => $value) {
- $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
- if (!$featuremap_dbxref) {
- drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
- tripal_report_error('t_featuremap', TRIPAL_ERROR, "Error cannot add featuremap cross reference: %ref",
- ['%ref' => $value]);
- }
- }
- unset($properties[$map_dbxref_cvterm_id]);
- }
- $details = [
- 'property_table' => 'featuremapprop',
- 'base_table' => 'featuremap',
- 'foreignkey_name' => 'featuremap_id',
- 'foreignkey_value' => $featuremap_id,
- ];
- chado_update_node_form_properties($node, $details, $properties);
-
- $details = [
- 'linking_table' => 'featuremap_dbxref',
-
- 'foreignkey_name' => 'featuremap_id',
-
- 'foreignkey_value' => $featuremap_id
-
- ];
- chado_update_node_form_dbxrefs($node, $details);
- }
- function chado_featuremap_load($nodes) {
- foreach ($nodes as $nid => $node) {
-
- $featuremap_id = chado_get_id_from_nid('featuremap', $node->nid);
-
-
- if (!$featuremap_id) {
- continue;
- }
- $values = ['featuremap_id' => $featuremap_id];
- $featuremap = chado_generate_var('featuremap', $values);
-
- $featuremap = chado_expand_var($featuremap, 'field', 'featuremap.description');
- $nodes[$nid]->featuremap = $featuremap;
-
- $node->title = chado_get_node_title($node);
- }
- }
- function chado_featuremap_delete(&$node) {
- $featuremap_id = chado_get_id_from_nid('featuremap', $node->nid);
-
-
- if (!$featuremap_id) {
- return;
- }
-
-
- $sql_del = "DELETE FROM {chado_featuremap} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, [':nid' => $node->nid, ':vid' => $node->vid]);
- $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, [':nid' => $node->nid, ':vid' => $node->vid]);
- $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, [':nid' => $node->nid, ':vid' => $node->vid]);
-
- chado_query("DELETE FROM {featuremapprop} WHERE featuremap_id = :featuremap_id", [':featuremap_id' => $featuremap_id]);
- chado_query("DELETE FROM {featuremap_dbxref} WHERE featuremap_id = :featuremap_id", [':featuremap_id' => $featuremap_id]);
- chado_query("DELETE FROM {featuremap} WHERE featuremap_id = :featuremap_id", [':featuremap_id' => $featuremap_id]);
- }
- function tripal_featuremap_node_presave($node) {
- switch ($node->type) {
-
-
-
-
-
-
- case 'chado_featuremap':
-
-
- if (property_exists($node, 'fmapname')) {
-
- $node->title = $node->fmapname;
- }
- else {
- if (property_exists($node, 'featuremap')) {
- $node->title = $node->featuremap->name;
- }
- }
- break;
- }
- }
- function tripal_featuremap_node_view($node, $view_mode, $langcode) {
- switch ($node->type) {
- case 'chado_featuremap':
-
- if ($view_mode == 'full') {
- $node->content['tripal_featuremap_base'] = [
- '#theme' => 'tripal_featuremap_base',
- '#node' => $node,
- '#tripal_toc_id' => 'base',
- '#tripal_toc_title' => 'Overview',
- '#weight' => -100,
- ];
- $node->content['tripal_featuremap_featurepos'] = [
- '#theme' => 'tripal_featuremap_featurepos',
- '#node' => $node,
- '#tripal_toc_id' => 'featurepos',
- '#tripal_toc_title' => 'Map Features',
- ];
- $node->content['tripal_featuremap_properties'] = [
- '#theme' => 'tripal_featuremap_properties',
- '#node' => $node,
- '#tripal_toc_id' => 'properties',
- '#tripal_toc_title' => 'Properties',
- ];
- $node->content['tripal_featuremap_publication'] = [
- '#theme' => 'tripal_featuremap_publication',
- '#node' => $node,
- '#tripal_toc_id' => 'publications',
- '#tripal_toc_title' => 'Publications',
- ];
- $node->content['tripal_featuremap_references'] = [
- '#theme' => 'tripal_featuremap_references',
- '#node' => $node,
- '#tripal_toc_id' => 'references',
- '#tripal_toc_title' => 'Cross References',
- ];
- }
- if ($view_mode == 'teaser') {
- $node->content['tripal_featuremap_teaser'] = [
- '#theme' => 'tripal_featuremap_teaser',
- '#node' => $node,
- ];
- }
- break;
- case 'chado_feature':
- if ($view_mode == 'full') {
- $node->content['tripal_feature_featurepos'] = [
- '#theme' => 'tripal_feature_featurepos',
- '#node' => $node,
- '#tripal_toc_id' => 'featurepos',
- '#tripal_toc_title' => 'Maps',
- ];
- }
- break;
- }
- }
- function tripal_featuremap_node_insert($node) {
- switch ($node->type) {
- case 'chado_featuremap':
-
- $featuremap_id = chado_get_id_from_nid('featuremap', $node->nid);
- $values = ['featuremap_id' => $featuremap_id];
- $featuremap = chado_generate_var('featuremap', $values);
- $node->featuremap = $featuremap;
-
- $node->title = chado_get_node_title($node);
-
- chado_set_node_url($node);
- break;
- }
- }
- function tripal_featuremap_node_update($node) {
- switch ($node->type) {
- case 'chado_featuremap':
-
- $node->title = chado_get_node_title($node);
-
- chado_set_node_url($node);
- break;
- }
- }
- function chado_featuremap_chado_node_default_title_format() {
- return '[featuremap.name]';
- }
- function chado_featuremap_chado_node_default_url_format() {
- return '/featuremap/[featuremap.featuremap_id]';
- }
|