Tripal Plant PopGen Submit
init_project.inc
Go to the documentation of this file.
1 <?php
2 
20 function tpps_init_project(array &$form_state, $accession = NULL) {
21 
22  if (empty($accession)) {
23  // This code is deprecated since it doesn't work for TGDR numbers over 999
24  // Code originally written by Peter Richter and kept as a backup
25  // Code deprecated by Rish (12/20/2022) as part of a patch to cater for TGDR
26  // numbers over 999
27 
28  // $values = array(
29  // 'accession' => 'TGDR.*',
30  // );
31 
32  // $options = array(
33  // 'order_by' => array(
34  // 'accession' => 'DESC',
35  // ),
36  // 'limit' => '1',
37  // 'regex_columns' => array('accession'),
38  // );
39 
40  // $result = chado_select_record('dbxref', array('accession'), $values, $options);
41 
42  // Rish: New patch that sorts based on integer instead of string values
43  $result_query = chado_query("SELECT *, substr(accession, 5)::INTEGER as accession_number " .
44  "FROM chado.dbxref WHERE accession LIKE 'TGDR%' " .
45  "ORDER BY accession_number DESC LIMIT 1;", []);
46 
47  if (empty($result_query)) {
48  $accession = 'TGDR001';
49  }
50  else {
51  $result = []; // create an empty array
52  $result[] = $result_query->fetchObject(); // add the first record found into result
53  $accession = substr($result[0]->accession, 4) + 1;
54  while (strlen($accession) < 3) {
55  $accession = "0$accession";
56  }
57  $accession = "TGDR$accession";
58  }
59  }
60 
61  $dbxref_id = chado_insert_record('dbxref', array(
62  'db_id' => variable_get('tpps_local_db')->db_id,
63  'accession' => $accession,
64  ));
65 
66  $form_state['dbxref_id'] = $dbxref_id['dbxref_id'];
67  $form_state['created'] = time();
68  $form_state['accession'] = $accession;
69  $form_state['saved_values']['frontpage']['accession'] = $accession;
70  $form_state['status'] = 'Incomplete';
71 
72  return $dbxref_id;
73 }
tpps_init_project(array &$form_state, $accession=NULL)