tripal_pub_base.tpl.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. /*
  3. * Note, the table generated by this template that lists the publication
  4. * details is generic. It can be customized to look different for different
  5. * publication types. To create a custom template for a given type, create a
  6. * new file in the pub_types directory. Name the file using the name of the
  7. * type. The name must be all lower-case and spaces should be replaced with
  8. * and underscore symbol. For example, to create a custom table for the
  9. * "Conference Proceedings", create the file conference_proceedings.inc inside
  10. * of the pub_types folder. Cut and paste the code below that generates the table
  11. * structure into the new file. Then edit to your liking.
  12. *
  13. */
  14. $pub = $variables['node']->pub;
  15. // expand the title
  16. $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
  17. $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.volumetitle');
  18. // get the citation
  19. $values = array(
  20. 'pub_id' => $pub->pub_id,
  21. 'type_id' => array(
  22. 'name' => 'Citation',
  23. ),
  24. );
  25. $citation = tripal_core_generate_chado_var('pubprop', $values);
  26. $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value');
  27. // get the abstract
  28. $values = array(
  29. 'pub_id' => $pub->pub_id,
  30. 'type_id' => array(
  31. 'name' => 'Abstract',
  32. ),
  33. );
  34. $abstract = tripal_core_generate_chado_var('pubprop', $values);
  35. $abstract = tripal_core_expand_chado_vars($abstract, 'field', 'pubprop.value');
  36. $abstract_text = '';
  37. if ($abstract) {
  38. $abstract_text = htmlspecialchars($abstract->value);
  39. }
  40. // get the author list
  41. $values = array(
  42. 'pub_id' => $pub->pub_id,
  43. 'type_id' => array(
  44. 'name' => 'Authors',
  45. ),
  46. );
  47. $authors = tripal_core_generate_chado_var('pubprop', $values);
  48. $authors = tripal_core_expand_chado_vars($authors, 'field', 'pubprop.value');
  49. $authors_list = 'N/A';
  50. if ($authors) {
  51. $authors_list = $authors->value;
  52. }
  53. // get the first database cross-reference with a url
  54. $options = array('return_array' => 1);
  55. $pub = tripal_core_expand_chado_vars($pub, 'table', 'pub_dbxref', $options);
  56. $dbxref = NULL;
  57. if ($pub->pub_dbxref) {
  58. foreach ($pub->pub_dbxref as $index => $pub_dbxref) {
  59. if ($pub_dbxref->dbxref_id->db_id->urlprefix) {
  60. $dbxref = $pub_dbxref->dbxref_id;
  61. }
  62. }
  63. }
  64. // get the URL
  65. // get the author list
  66. $values = array(
  67. 'pub_id' => $pub->pub_id,
  68. 'type_id' => array(
  69. 'name' => 'URL',
  70. ),
  71. );
  72. $options = array('return_array' => 1);
  73. $urls = tripal_core_generate_chado_var('pubprop', $values, $options);
  74. $urls = tripal_core_expand_chado_vars($urls, 'field', 'pubprop.value');
  75. $url = '';
  76. if (count($urls) > 0) {
  77. $url = $urls[0]->value;
  78. }?>
  79. <div id="tripal_pub-base-box" class="tripal_pub-info-box tripal-info-box">
  80. <div class="tripal_pub-info-box-title tripal-info-box-title">Publication Details</div>
  81. <!-- <div class="tripal_pub-info-box-desc tripal-info-box-desc"></div> --> <?php
  82. // to simplify the template, we have a subdirectory named 'pub_types'. This directory
  83. // should have include files each specific to a publication type. If the type is
  84. // not present then the base template will be used, otherwise the template in the
  85. // include file is used.
  86. $inc_name = strtolower(preg_replace('/ /', '_', $pub->type_id->name)) . '.inc';
  87. $inc_path = drupal_realpath(drupal_get_path('module', 'tripal_pub') . "/theme/tripal_pub/pub_types/$inc_name");
  88. if (file_exists($inc_path)) {
  89. require_once "pub_types/$inc_name";
  90. }
  91. else {
  92. // ========================================================================
  93. // TO CUSTOMIZE A SPECIFIC PUBLICATION TYPE, CUT-AND-PASTE THE CODE
  94. // BELOW INTO A NEW FILE WITH THE SAME NAME AS THE TYPE (SEE INSTRUCTIONS
  95. // ABOVE), AND EDIT.
  96. // ========================================================================
  97. // the $headers array is an array of fields to use as the colum headers.
  98. // additional documentation can be found here
  99. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  100. // This table for the analysis has a vertical header (down the first column)
  101. // so we do not provide headers here, but specify them in the $rows array below.
  102. $headers = array();
  103. // the $rows array contains an array of rows where each row is an array
  104. // of values for each column of the table in that row. Additional documentation
  105. // can be found here:
  106. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  107. $rows = array();
  108. // Title row
  109. $title = '';
  110. if ($url) {
  111. $title = l(htmlspecialchars($pub->title), $url, array('attributes' => array('target' => '_blank')));
  112. }
  113. elseif ($dbxref and $dbxref->db_id->urlprefix) {
  114. $title = l(htmlspecialchars($pub->title), $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
  115. }
  116. else {
  117. $title = htmlspecialchars($pub->title);
  118. }
  119. $rows[] = array(
  120. array(
  121. 'data' => 'Title',
  122. 'header' => TRUE
  123. ),
  124. $title,
  125. );
  126. // Authors row
  127. $rows[] = array(
  128. array(
  129. 'data' => 'Authors',
  130. 'header' => TRUE
  131. ),
  132. $authors_list,
  133. );
  134. // Type row
  135. $rows[] = array(
  136. array(
  137. 'data' => 'Type',
  138. 'header' => TRUE
  139. ),
  140. $pub->type_id->name,
  141. );
  142. // Media Title
  143. $rows[] = array(
  144. array(
  145. 'data' => 'Media Title',
  146. 'header' => TRUE,
  147. 'nowrap' => 'nowrap'
  148. ),
  149. $pub->series_name,
  150. );
  151. // Volume
  152. $rows[] = array(
  153. array(
  154. 'data' => 'Volume',
  155. 'header' => TRUE
  156. ),
  157. $pub->volume ? $pub->volume : 'N/A',
  158. );
  159. // Issue
  160. $rows[] = array(
  161. array(
  162. 'data' => 'Issue',
  163. 'header' => TRUE
  164. ),
  165. $pub->issue ? $pub->issue : 'N/A'
  166. );
  167. // Year
  168. $rows[] = array(
  169. array(
  170. 'data' => 'Year',
  171. 'header' => TRUE
  172. ),
  173. $pub->pyear
  174. );
  175. // Pages
  176. $rows[] = array(
  177. array(
  178. 'data' => 'Page(s)',
  179. 'header' => TRUE
  180. ),
  181. $pub->pages ? $pub->pages : 'N/A'
  182. );
  183. // Citation row
  184. $rows[] = array(
  185. array(
  186. 'data' => 'Citation',
  187. 'header' => TRUE
  188. ),
  189. htmlspecialchars($citation->value)
  190. );
  191. // allow site admins to see the pub ID
  192. if (user_access('access administration pages')) {
  193. // Pub ID
  194. $rows[] = array(
  195. array(
  196. 'data' => 'Pub ID',
  197. 'header' => TRUE
  198. ),
  199. $pub->pub_id
  200. );
  201. }
  202. // Is Obsolete Row
  203. if($pub->is_obsolete == TRUE){
  204. $rows[] = array(
  205. array(
  206. 'data' => '<div class="tripal_pub-obsolete">This publication is obsolete</div>',
  207. 'colspan' => 2
  208. ),
  209. );
  210. }
  211. // the $table array contains the headers and rows array as well as other
  212. // options for controlling the display of the table. Additional
  213. // documentation can be found here:
  214. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  215. $table = array(
  216. 'header' => $headers,
  217. 'rows' => $rows,
  218. 'attributes' => array(
  219. 'id' => 'tripal_pub-table-base',
  220. ),
  221. 'sticky' => FALSE,
  222. 'caption' => '',
  223. 'colgroups' => array(),
  224. 'empty' => '',
  225. );
  226. // once we have our table array structure defined, we call Drupal's theme_table()
  227. // function to generate the table.
  228. print theme_table($table);
  229. if ($abstract_text) { ?>
  230. <p><b>Abstract</b></p>
  231. <div style="text-align: justify"><?php print $abstract_text; ?></div> <?php
  232. }
  233. // ========================================================================
  234. // END OF CUT-AND-PASTE REGION
  235. // ========================================================================
  236. } ?>
  237. </div>