123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880 |
- <?php
- function tripal_example_node_info() {
- $nodes = array();
-
-
-
-
-
- $nodes['chado_example'] = array(
- 'name' => t('Example'),
- 'base' => 'chado_example',
- 'description' => t('A record from the fake chado example table'),
- 'has_title' => TRUE,
- 'locked' => TRUE,
-
-
-
-
-
-
- 'chado_node_api' => array(
-
- 'base_table' => 'example',
-
- 'hook_prefix' => 'chado_example',
- 'record_type_title' => array(
-
- 'singular' => t('Example'),
-
- 'plural' => t('Examples')
- ),
- 'sync_filters' => array(
- 'type_id' => TRUE,
- 'organism_id' => TRUE
- ),
- )
- );
- return $nodes;
- }
- function chado_example_node_access($node, $op, $account) {
- $node_type = $node;
- if (is_object($node)) {
- $node_type = $node->type;
- }
-
-
-
- if($node_type == 'chado_example') {
- if ($op == 'create') {
- if (!user_access('create chado_example content', $account)) {
- return NODE_ACCESS_DENY;
- }
- return NODE_ACCESS_ALLOW;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_example content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_example content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_example content', $account)) {
- return NODE_ACCESS_DENY;
- }
- }
- }
- return NODE_ACCESS_IGNORE;
- }
- function chado_example_form($node, &$form_state) {
-
-
-
-
-
-
-
-
-
-
-
-
-
- $form = array();
-
-
-
-
-
-
-
-
-
-
-
-
- $example = null;
- $example_id = null;
-
- $uniquename = '';
- $example_type = '';
- $organism_id = '';
- $description = '';
-
-
- if (property_exists($node, 'example')) {
- $example = $node->example;
- $example_id = $example->example_id;
- $uniquename = $example->uniquename;
- $description = $example->description;
- $organism_id = $example->organism_id;
-
- $form['example_id'] = array(
- '#type' => 'value',
- '#value' => $example_id,
- );
- }
-
-
- if (array_key_exists('values', $form_state)) {
- $uniquename = $form_state['values']['uniquename'];
- $example_type = $form_state['values']['example_type'];
- $description = $form_state['values']['description'];
- $organism_id = $form_state['values']['organism_id'];
- }
-
-
- if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
- $uniquename = $form_state['input']['uniquename'];
- $example_type = $form_state['input']['example_type'];
- $organism_id = $form_state['input']['organism_id'];
- }
-
-
- $form['uniquename'] = array(
- '#type' => 'textfield',
- '#title' => t('Unique Name'),
- '#required' => TRUE,
- '#default_value' => $uniquename,
- '#description' => t('Enter a unique name for this example. This name must be unique.'),
- '#maxlength' => 255
- );
-
-
- $type_cv = tripal_get_default_cv('example', 'type_id');
- $cv_id = $type_cv->cv_id;
- $form['example_type'] = array(
- '#title' => t('Example Type'),
- '#type' => 'textfield',
- '#description' => t("Choose the example type (e.g. Test Type)."),
- '#required' => TRUE,
- '#default_value' => $example_type,
- '#autocomplete_path' => "admin/tripal/vocab/cvterm/auto_name/$cv_id",
- );
-
- $organisms = tripal_get_organism_select_options();
- $form['organism_id'] = array(
- '#title' => t('Organism'),
- '#type' => t('select'),
- '#description' => t("Choose the organism with which this example is associated"),
- '#required' => TRUE,
- '#default_value' => $organism_id,
- '#options' => $organisms,
- );
- $form['description'] = array(
- '#type' => 'text_format',
- '#title' => t('Description'),
- '#required' => TRUE,
- '#default_value' => $description,
- '#description' => t('Enter a description for this example.'),
- );
-
-
-
-
-
- $prop_cv = tripal_get_default_cv('exampleprop', 'type_id');
- $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
- $details = array(
-
- 'property_table' => 'exampleprop',
-
- 'chado_id' => $example_id,
-
- 'cv_id' => $cv_id
- );
-
- chado_add_node_form_properties($form, $form_state, $details);
-
-
-
-
-
- $details = array(
-
- 'linking_table' => 'example_dbxref',
-
- 'base_foreign_key' => 'example_id',
-
- 'base_key_value' => $example_id
- );
-
- chado_add_node_form_dbxrefs($form, $form_state, $details);
-
-
-
-
-
- $rels_cv = tripal_get_default_cv('example_relationship', 'type_id');
- $cv_id = $rels_cv ? $rels_cv->cv_id : NULL;
- $details = array(
-
- 'relationship_table' => 'example_relationship',
-
- 'base_table' => 'example',
-
- 'base_foreign_key' => 'example_id',
-
- 'base_key_value' => $example_id,
-
- 'nodetype' => 'example',
-
- 'cv_id' => $cv_id
- );
-
- chado_add_node_form_relationships($form, $form_state, $details);
-
- return $form;
- }
- function chado_example_validate($node, $form, &$form_state) {
-
-
-
-
- if(property_exists($node, "op") and $node->op != 'Save') {
- return;
- }
-
-
- if (!property_exists($node, 'nid') and property_exists($node, 'example_id') and $node->example_id != 0) {
- return;
- }
-
- $node->uniquename = property_exists($node, 'uniquename') ? trim($node->uniquename) : '';
-
-
- if (property_exists($node, 'nid')) {
-
- $type_cv = tripal_get_default_cv('example', 'type_id');
- $type = tripal_get_cvterm(array(
- 'name' => $node->example_type,
- 'cv_id' => $type_cv->cv_id,
- ));
- if (!$type) {
- form_set_error('example_type', t("The example type is not a valid name from the Sequence Ontology."));
- }
-
-
- }
-
- else {
-
- $type_cv = tripal_get_default_cv('example', 'type_id');
- $type = tripal_get_cvterm(array(
- 'name' => $node->example_type,
- 'cv_id' => $type_cv->cv_id,
- ));
- if (!$type) {
- form_set_error('example_type', t("The example type is not a valid name from the Sequence Ontology."));
- }
-
- }
- }
- function chado_example_insert($node) {
- $example_id = '';
-
-
-
- if (!property_exists($node, 'example_id')) {
-
- $node->uniquename = trim($node->uniquename);
- $node->description = trim($node->description['value']);
-
- $type_cv = tripal_get_default_cv('example', 'type_id');
- $type = tripal_get_cvterm(array(
- 'name' => $node->example_type,
- 'cv_id' => $type_cv->cv_id,
- ));
-
- $values = array(
- 'uniquename' => $node->uniquename,
- 'description' => $node->description,
- 'type_id' => $type->cvterm_id,
- 'organism_id' => $node->organism_id,
- );
- $example = chado_insert_record('example', $values);
- if (!$example) {
- drupal_set_message(t('Unable to add example.'), 'warning');
- tripal_report_error('tripal_example', TRIPAL_WARNING, 'Insert example: Unable to create example where values: %values',
- array('%values' => print_r($values, TRUE)));
- return;
- }
-
- $example_id = $example['example_id'];
-
- if ($example_id > 0) {
-
-
- $details = array(
-
- 'property_table' => 'exampleprop',
-
- 'base_table' => 'example',
-
- 'foreignkey_name' => 'example_id',
-
- 'foreignkey_value' => $example_id
- );
- chado_update_node_form_properties($node, $details);
-
-
-
- $details = array(
-
- 'linking_table' => 'example_dbxref',
-
- 'foreignkey_name' => 'example_id',
-
- 'foreignkey_value' => $example_id
- );
- chado_update_node_form_dbxrefs($node, $details);
-
-
-
- $details = array(
-
- 'relationship_table' => 'example_relationship',
-
- 'foreignkey_value' => $example_id
- );
- chado_update_node_form_relationships($node, $details);
- }
- }
- else {
-
-
- $example_id = $node->example_id;
- }
-
-
- $check_org_id = chado_get_id_from_nid('example', $node->nid);
- if (!$check_org_id) {
- $record = new stdClass();
- $record->nid = $node->nid;
- $record->vid = $node->vid;
- $record->example_id = $example_id;
- drupal_write_record('chado_example', $record);
- }
- }
- function chado_example_update($node) {
-
- $node->uniquename = trim($node->uniquename);
- $node->description = trim($node->description['value']);
-
- $match = array(
- 'example_id' => $example_id,
- );
- $values = array(
- 'uniquename' => $node->uniquename,
- );
- $options = array('return_record' => TRUE);
- $status = chado_update_record('example', $match, $values, $options);
- if (!$status) {
- drupal_set_message(t('Unable to update example.'), 'warning');
- tripal_report_error('tripal_example', TRIPAL_WARNING, 'Update example: Unable to update example where values: %values',
- array('%values' => print_r($values, TRUE)));
- }
-
-
- $details = array(
- 'property_table' => 'exampleprop',
- 'base_table' => 'example',
- 'foreignkey_name' => 'example_id',
- 'foreignkey_value' => $example_id
- );
- chado_update_node_form_properties($node, $details);
-
-
- $details = array(
- 'linking_table' => 'example_dbxref',
- 'foreignkey_name' => 'example_id',
- 'foreignkey_value' => $example_id
- );
- chado_update_node_form_dbxrefs($node, $details);
-
-
-
- $details = array(
-
- 'relationship_table' => 'example_relationship',
-
- 'foreignkey_value' => $example_id
- );
- chado_update_node_form_relationships($node, $details);
- }
- function chado_example_delete($node) {
-
- $example_id = chado_get_id_from_nid('example', $node->nid);
-
-
- if (!$example_id) {
- return;
- }
-
-
- $sql_del = "DELETE FROM {chado_example} WHERE nid = :nid AND vid = :vid";
- db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-
-
-
- chado_query("DELETE FROM {example} WHERE example_id = :example_id", array(':example_id' => $example_id));
-
- drupal_set_message(t("The example and all associated data were removed from Chado"));
- }
- function chado_example_load($nodes) {
-
-
-
-
-
- foreach ($nodes as $nid => $node) {
-
- $example_id = chado_get_id_from_nid('example', $nid);
-
-
- if (!$example_id) {
- continue;
- }
-
- $values = array('example_id' => $example_id);
- $example = chado_generate_var('example', $values);
-
-
-
-
-
-
-
-
-
- $example = chado_expand_var($example, 'field', 'example.description');
-
- $nodes[$nid]->example = $example;
-
-
-
- $node->title = chado_get_node_title($node);
- }
- }
- function tripal_example_node_presave($node) {
-
-
-
-
-
-
-
-
-
-
- switch ($node->type) {
-
-
-
-
-
-
- case 'chado_example':
-
-
- if (property_exists($node, 'uniquename')) {
-
- $node->title = $node->uniquename;
- }
- else if (property_exists($node, 'example')) {
- $node->title = $node->example->uniquename;
- }
- break;
- }
- }
- function tripal_example_node_insert($node) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- switch ($node->type) {
- case 'chado_example':
-
- $example_id = chado_get_id_from_nid('example', $nid);
-
- $values = array('example_id' => $example_id);
- $example = chado_generate_var('example', $values);
- $node->example = $example;
-
-
-
-
-
-
-
-
-
-
-
-
-
- $example->title = chado_get_node_title($node);
- chado_set_node_url($node);
- break;
- }
- }
- function tripal_example_node_update($node) {
-
-
-
-
-
-
-
-
-
-
-
-
-
- switch ($node->type) {
- case 'chado_example':
-
-
-
- $example->title = chado_get_node_title($node);
-
-
-
-
-
-
- break;
- }
- }
- function tripal_example_node_view($node, $view_mode, $langcode) {
-
-
-
-
-
- switch ($node->type) {
- case 'chado_example':
-
-
- if ($view_mode == 'full') {
-
-
-
-
-
-
- $node->content['#tripal_generic_node_template'] = TRUE;
-
-
-
-
-
-
-
-
-
-
-
- $node->content['tripal_example_base'] = array(
- '#theme' => 'tripal_example_base',
- '#node' => $node,
- '#tripal_toc_id' => 'base',
- '#tripal_toc_title' => 'Overview',
- '#weight' => -100,
- );
-
-
- $node->content['tripal_example_properties'] = array(
- '#theme' => 'tripal_example_properties',
- '#node' => $node,
- '#tripal_toc_id' => 'properties',
- '#tripal_toc_title' => 'Properties',
- );
- $node->content['tripal_example_references'] = array(
- '#theme' => 'tripal_example_references',
- '#node' => $node,
- '#tripal_toc_id' => 'references',
- '#tripal_toc_title' => 'Cross References',
- );
- $node->content['tripal_example_relationships'] = array(
- '#theme' => 'tripal_example_relationships',
- '#node' => $node,
- '#tripal_toc_id' => 'relationships',
- '#tripal_toc_title' => 'Relationships',
- );
-
-
-
-
-
- }
-
- if ($view_mode == 'teaser') {
-
- $node->content['tripal_example_teaser'] = array(
- '#theme' => 'tripal_example_teaser',
- '#node' => $node,
- );
- }
- break;
-
-
- case 'chado_organism':
- if ($view_mode == 'full') {
- $node->content['tripal_organism_examples'] = array(
- '#theme' => 'tripal_organism_examples',
- '#node' => $node,
- '#tripal_toc_id' => 'examples',
- '#tripal_toc_title' => 'Examples',
- );
- }
- break;
-
- }
- }
- function chado_example_chado_node_default_title_format() {
- return '[example.name], [example.uniquename] ([example.type_id>cvterm.name]) [example.organism_id>organism.genus] [example.organism_id>organism.species]';
- }
- function chado_example_chado_node_default_url_format() {
- return '/example/[example.organism_id>organism.genus]/[example.organism_id>organism.species]/[example.type_id>cvterm.name]/[example.uniquename]';
- }
|