tripal_organism.module 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. <?php
  2. require_once "tripal_organism.api.inc";
  3. /**
  4. * @file
  5. * @defgroup tripal_organism Organism
  6. * @ingroup tripal_modules
  7. */
  8. /**
  9. *
  10. * @ingroup tripal_organism
  11. */
  12. function tripal_organism_init() {
  13. // add the jGCharts JS and CSS
  14. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_organism.js');
  15. drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_organism.css');
  16. }
  17. /**
  18. * Provide information to drupal about the node types that we're creating
  19. * in this module
  20. *
  21. * @ingroup tripal_organism
  22. */
  23. function tripal_organism_node_info() {
  24. $nodes = array();
  25. $nodes['chado_organism'] = array(
  26. 'name' => t('Organism'),
  27. 'module' => 'chado_organism',
  28. 'description' => t('An organism from the chado database'),
  29. 'has_title' => FALSE,
  30. 'title_label' => t('Organism'),
  31. 'has_body' => FALSE,
  32. 'body_label' => t('Organism Description'),
  33. 'locked' => TRUE
  34. );
  35. return $nodes;
  36. }
  37. /**
  38. * Display block with organisms
  39. * @param op - parameter to define the phase being called for the block
  40. * @param delta - id of the block to return (ignored when op is list)
  41. * @param edit - when op is save, contains the submitted form data
  42. *
  43. * @ingroup tripal_organism
  44. */
  45. function tripal_organism_block($op = 'list', $delta = '0', $edit = array()) {
  46. switch ($op) {
  47. case 'list':
  48. $blocks['base']['info'] = t('Tripal Organism Details');
  49. $blocks['base']['cache'] = BLOCK_NO_CACHE;
  50. $blocks['description']['info'] = t('Tripal Organism Description');
  51. $blocks['description']['cache'] = BLOCK_NO_CACHE;
  52. $blocks['image']['info'] = t('Tripal Organism Image');
  53. $blocks['image']['cache'] = BLOCK_NO_CACHE;
  54. return $blocks;
  55. case 'view':
  56. if (user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
  57. $nid = arg(1);
  58. $node = node_load($nid);
  59. $block = array();
  60. switch ($delta) {
  61. case 'base':
  62. $block['subject'] = t('Organism Details');
  63. $block['content'] = theme('tripal_organism_base', $node);
  64. break;
  65. case 'description':
  66. $block['subject'] = t('Organism Description');
  67. $block['content'] = theme('tripal_organism_description', $node);
  68. break;
  69. case 'image':
  70. $block['subject'] = t('Organism Image');
  71. $block['content'] = theme('tripal_organism_image', $node);
  72. break;
  73. default:
  74. }
  75. return $block;
  76. }
  77. }
  78. }
  79. /**
  80. * Menu items are automatically added for the new node types created
  81. * by this module to the 'Create Content' Navigation menu item. This function
  82. * adds more menu items needed for this module.
  83. *
  84. * @ingroup tripal_organism
  85. */
  86. function tripal_organism_menu() {
  87. $items = array();
  88. // the administative settings menu
  89. $items['admin/tripal/tripal_organism'] = array(
  90. 'title' => 'Organisms',
  91. 'description' => 'Basic Description of Tripal Organism Module Functionality',
  92. 'page callback' => 'tripal_organism_module_description_page',
  93. 'access arguments' => array('administer site configuration'),
  94. 'type' => MENU_NORMAL_ITEM,
  95. );
  96. $items['admin/tripal/tripal_organism/configuration'] = array(
  97. 'title' => 'Configuration',
  98. 'description' => 'Manage integration of Chado organisms including associated features',
  99. 'page callback' => 'drupal_get_form',
  100. 'page arguments' => array('tripal_organism_admin'),
  101. 'access arguments' => array('administer site configuration'),
  102. 'type' => MENU_NORMAL_ITEM,
  103. );
  104. return $items;
  105. }
  106. /**
  107. * The following function proves access control for users trying to
  108. * perform actions on data managed by this module
  109. *
  110. * @ingroup tripal_organism
  111. */
  112. function chado_organism_access($op, $node, $account) {
  113. if ($op == 'create') {
  114. if (!user_access('create chado_organism content', $account)) {
  115. return FALSE;
  116. }
  117. }
  118. if ($op == 'update') {
  119. if (!user_access('edit chado_organism content', $account)) {
  120. return FALSE;
  121. }
  122. }
  123. if ($op == 'delete') {
  124. if (!user_access('delete chado_organism content', $account)) {
  125. return FALSE;
  126. }
  127. }
  128. if ($op == 'view') {
  129. if (!user_access('access chado_organism content', $account)) {
  130. return FALSE;
  131. }
  132. }
  133. return NULL;
  134. }
  135. /**
  136. * Set the permission types that the chado module uses. Essentially we
  137. * want permissionis that protect creation, editing and deleting of chado
  138. * data objects
  139. *
  140. *
  141. @ingroup tripal_organism
  142. */
  143. function tripal_organism_perm() {
  144. return array(
  145. 'access chado_organism content',
  146. 'create chado_organism content',
  147. 'delete chado_organism content',
  148. 'edit chado_organism content',
  149. );
  150. }
  151. /**
  152. * Purpose: Provide Guidance to new Tripal Admin
  153. *
  154. * @return HTML Formatted text
  155. *
  156. * @ingroup tripal_organism
  157. */
  158. function tripal_organism_module_description_page() {
  159. $text = '';
  160. $text .= '<h3>Tripal Organism Administrative Tools Quick Links:</h3>';
  161. $text .= "<ul>
  162. <li><a href=\"" . url("admin/tripal/tripal_organism/configuration") . "\">Organism Configuration</a></li>
  163. </ul>";
  164. $text .= '<h3>Module Description:</h3>';
  165. $text .= '<p>The Tripal Organism module allows you to add, edit and/or delete chado organisms.
  166. Furthermore, it also provides listing of organisms and details page for each organism.
  167. Basically, the chado organism module is designed to hold information about a given species.
  168. For more information on the chado organism module see the
  169. <a href="http://gmod.org/wiki/Chado_Organism_Module">GMOD wiki page</a></p>';
  170. $text .= '<h3>Setup Instructions:</h3>';
  171. $text .= '<p>After installation of the organism module. The following tasks should be performed.
  172. <ol>
  173. <li><p><b>Set Permissions</b>: The organism module supports the Drupal user permissions interface for
  174. controlling access to organism content and functions. These permissions include viewing,
  175. creating, editing or administering of
  176. organism content. The default is that only the original site administrator has these
  177. permissions. You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
  178. <a href="' . url('admin/user/user') . '">assign users to roles</a> and
  179. <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the organism content to
  180. those roles. For a simple setup, allow anonymous users access to view organism content and
  181. allow the site administrator all other permissions.</p></li>
  182. <li><p><b>Create Organisms</b>: Organism pages can be created in two ways:
  183. <ol>
  184. <li><b>Sync Organisms</b>: If your organism has been pre-loaded into Chado then you need to sync the organism.
  185. This process is what creates the pages for viewing online. Not all organisms need be synced, only those
  186. that you want shown on the site. Use the the
  187. <a href="' . url('admin/tripal/tripal_organism/configuration') . '">Organism Configuration page</a>
  188. to sync organisms. </li>
  189. <li><b>Manually Add An Organism</b>: If your organism is not already present in the Chado database
  190. you can create an organism using the <a href="' . url('node/add/chado-organism') . '">Create Organism page</a>.
  191. Once saved, the organism will be present in Chado and also "synced".
  192. </ol></p></li>
  193. <li><p><b>Indexing</b>: Once organism pages are ready for public access,
  194. you can index the organism pages for searching if you want to ues the Drupal default search mechanism.
  195. Use the <a href="' . url('admin/tripal/tripal_organism/configuration') . '">Organism Configuration page</a>
  196. to either Index (for the first time) or "Reindex" (after updating data)
  197. the organism pages for searching. Once the site is 100% indexed the pages will be searchable using Drupal\'s
  198. full text searching. You can find the percent indexed for the entire site by visiting the
  199. <a href="' . url('admin/settings/search') . '">Search settings page</a>. Indexing
  200. can take quite a while if you have a lot of data</p></li>
  201. <li><p><b>Set Taxonomy</b>: Drupal provides a mechanism for categorizing content to allow
  202. for advanced searching. Drupal calls this "Taxonomy", but is essentially categorizing the pages.
  203. You can categorize feature pages by the
  204. organism to which they belong. This allows for filtering of search results by organism.
  205. Use the <a href="' . url('admin/tripal/tripal_organism/configuration') . '">Organism Configuration page</a> to
  206. set the Taxonomy.</p></li>
  207. </ol>';
  208. $text .= '<h3>Features of this Module:</h3>';
  209. $text .= '<p>Aside from organism page setup (as described in the Setup section above),
  210. The Tripal organism module also provides the following functionality
  211. <ul>
  212. <li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
  213. a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
  214. It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database
  215. and create custom lists without PHP programming or customization of Tripal source code. Views can also
  216. be created to filter content that has not yet been synced with Druapl in order to protect access to non
  217. published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing
  218. Views <a href="' . url('admin/build/views/') . '">here</a>, as well as create your own. </p></li>
  219. <li><p><b>Basic Organism List</b>: This module provides a basic <a href="' . url('organisms') . '">organism list</a>
  220. for showing the list of organisms in Chado. <a href="http://drupal.org/project/views">Drupal Views</a> must be
  221. installed. You can use the Views interface to alter the appearance of this list.</p></li>
  222. </ul>
  223. </p>';
  224. $text .= '<h3>Page Customizations</h3>';
  225. $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
  226. Below is a description of several methods. These methods may be used in conjunction with one another to
  227. provide fine-grained control.
  228. <ul>
  229. <li><p><b>Integration with Drupal Panels</b>: <a href="http://drupal.org/project/views">Drupal Panels</a>
  230. allows for customization of a page layout if you don\'t want to do PHP/Javascript/CSS programming. Tripal comes with pre-set layouts for organism pages. However,
  231. Panels become useful if you prefer a layout that is different from the pre-set layouts. Chado content
  232. is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
  233. Panel\'s GUI.</p></li>
  234. <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the
  235. <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
  236. to any page without need to edit template files or knowing PHP. You must first download and install CCK.
  237. With CCK, the site administartor can create a new field to appear on the page. For example, currently,
  238. the Chado publication module is not yet supported by Tripal. Therefore, the site administrator can add a text
  239. field to the organism pages. This content is not stored in Chado, but will appear on the organism page. A field
  240. added by CCK will also appear in the form when editing a organism to allow users to manually enter the appropriate
  241. text. If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
  242. indicate that it is not to be shown (using the CCK interface), then manually add the new content type
  243. where desired by editing the templates (as described below). If using Panels, the CCK field can be added to the
  244. location desired using the Panels interface.</p></li>
  245. <li><p><b>Drupal Node Templates</b>: The Tripal packages comes with a "theme_tripal" directory that contains the
  246. themeing for Chado content. The organism module has a template file for organism "nodes" (Tripal organism pages). This file
  247. is named "node-chado_organism.tpl.php", and provides javascript, HTML and PHP code for display of the organism
  248. pages. You can edit this file to control which types of information (or which organism "blocks") are displayed for organisms. Be sure to
  249. copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  250. future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
  251. for instructions on how to access variables and other Chado content within the template file.</p></li>
  252. <li><p><b>Organism "Block" Templates</b>: In the "theme_tripal" directory is a subdirectory named "tripal_organism".
  253. Inside this directory is a set of templates that control distinct types of information for organisms. For example,
  254. there is a "base" template for displaying of data directly from the Chado organism table, and a "references"
  255. template for showing external site references for a organism (data from the organism_dbxref table). These templates are used both by Drupal blocks
  256. for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
  257. provides (also desribed above). You can customize this template as you desire. Be sure to copy the
  258. template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  259. future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
  260. for instructions on how to access variables and other Chado content within the template files.</p></li>
  261. </li>
  262. <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
  263. will see a "Resources" sidebar on each page. The links that appear on the sidebar are automatically generated
  264. using Javascript for all of the organism "Blocks" that appear on the page. If you want to add additional links
  265. (e.g. a dynamic link to GBrowse for the organism) and you want that link to appear in the
  266. "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
  267. section at the bottom of the template file where the resources section is found.</p></li>
  268. </ul>
  269. </p>';
  270. return $text;
  271. }
  272. /**
  273. * Administrative settings for chado_orgnism
  274. *
  275. * @ingroup tripal_organism
  276. */
  277. function tripal_organism_admin() {
  278. $form = array();
  279. // before proceeding check to see if we have any
  280. // currently processing jobs. If so, we don't want
  281. // to give the opportunity to sync libraries
  282. $active_jobs = FALSE;
  283. if (tripal_get_module_active_jobs('tripal_organism')) {
  284. $active_jobs = TRUE;
  285. }
  286. // add the field set for syncing libraries
  287. if (!$active_jobs) {
  288. get_tripal_organism_admin_form_sync_set($form);
  289. get_tripal_organism_admin_form_reindex_set($form);
  290. get_tripal_organism_admin_form_taxonomy_set($form);
  291. get_tripal_organism_admin_form_cleanup_set($form);
  292. }
  293. else {
  294. $form['notice'] = array(
  295. '#type' => 'fieldset',
  296. '#title' => t('Organism Management Temporarily Unavailable')
  297. );
  298. $form['notice']['message'] = array(
  299. '#value' => t('Currently, organism management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'),
  300. );
  301. }
  302. return system_settings_form($form);
  303. }
  304. /**
  305. *
  306. *
  307. * @ingroup tripal_organism
  308. */
  309. function get_tripal_organism_admin_form_cleanup_set(&$form) {
  310. $form['cleanup'] = array(
  311. '#type' => 'fieldset',
  312. '#title' => t('Clean Up')
  313. );
  314. $form['cleanup']['description'] = array(
  315. '#type' => 'item',
  316. '#value' => t("With Drupal and chado residing in different databases ".
  317. "it is possible that nodes in Drupal and organisms in Chado become ".
  318. "\"orphaned\". This can occur if an organism node in Drupal is ".
  319. "deleted but the corresponding chado organism is not and/or vice ".
  320. "versa. Click the button below to resolve these discrepancies."),
  321. '#weight' => 1,
  322. );
  323. $form['cleanup']['button'] = array(
  324. '#type' => 'submit',
  325. '#value' => t('Clean up orphaned organisms'),
  326. '#weight' => 2,
  327. );
  328. }
  329. /**
  330. *
  331. *
  332. * @ingroup tripal_organism
  333. */
  334. function get_tripal_organism_admin_form_taxonomy_set(&$form) {
  335. $form['taxonify'] = array(
  336. '#type' => 'fieldset',
  337. '#title' => t('Assign Drupal Taxonomy to Organism Features')
  338. );
  339. // get the list of libraries
  340. $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
  341. $previous_db = tripal_db_set_active('chado'); // use chado database
  342. $org_rset = db_query($sql);
  343. tripal_db_set_active($previous_db); // now use drupal database
  344. // iterate through all of the libraries
  345. $org_boxes = array();
  346. while ($organism = db_fetch_object($org_rset)) {
  347. $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
  348. }
  349. $form['taxonify']['description'] = array(
  350. '#type' => 'item',
  351. '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
  352. "nodes. These terms allow for advanced filtering during searching. This option allows ".
  353. "for setting taxonomy only for features that belong to the selected organisms below. All other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."),
  354. '#weight' => 1,
  355. );
  356. $form['taxonify']['tx-organisms'] = array(
  357. '#title' => t('Organisms'),
  358. '#type' => t('checkboxes'),
  359. '#description' => t("Check the organisms whose features you want to reset taxonomy. Note: this list contains all organisms, even those that may not be synced."),
  360. '#required' => FALSE,
  361. '#prefix' => '<div id="lib_boxes">',
  362. '#suffix' => '</div>',
  363. '#options' => $org_boxes,
  364. '#weight' => 2
  365. );
  366. $form['taxonify']['tx-button'] = array(
  367. '#type' => 'submit',
  368. '#value' => t('Set Feature Taxonomy'),
  369. '#weight' => 3
  370. );
  371. }
  372. /**
  373. *
  374. * @ingroup tripal_organism
  375. */
  376. function get_tripal_organism_admin_form_reindex_set(&$form) {
  377. // define the fieldsets
  378. $form['reindex'] = array(
  379. '#type' => 'fieldset',
  380. '#title' => t('Reindex Organism Features')
  381. );
  382. // get the list of libraries
  383. $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
  384. $previous_db = tripal_db_set_active('chado'); // use chado database
  385. $org_rset = db_query($sql);
  386. tripal_db_set_active($previous_db); // now use drupal database
  387. // iterate through all of the libraries
  388. $org_boxes = array();
  389. while ($organism = db_fetch_object($org_rset)) {
  390. $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
  391. }
  392. $form['reindex']['description'] = array(
  393. '#type' => 'item',
  394. '#value' => t("This option allows for reindexing of only those features that belong to the selected organisms below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
  395. '#weight' => 1,
  396. );
  397. $form['reindex']['re-organisms'] = array(
  398. '#title' => t('Organisms'),
  399. '#type' => t('checkboxes'),
  400. '#description' => t("Check the organisms whoee features you want to reindex. Note: this list contains all organisms, even those that may not be synced."),
  401. '#required' => FALSE,
  402. '#prefix' => '<div id="lib_boxes">',
  403. '#suffix' => '</div>',
  404. '#options' => $org_boxes,
  405. '#weight' => 2,
  406. );
  407. $form['reindex']['re-button'] = array(
  408. '#type' => 'submit',
  409. '#value' => t('Reindex Features'),
  410. '#weight' => 3,
  411. );
  412. }
  413. /**
  414. *
  415. * @ingroup tripal_organism
  416. */
  417. function get_tripal_organism_admin_form_sync_set(&$form) {
  418. // define the fieldsets
  419. $form['sync'] = array(
  420. '#type' => 'fieldset',
  421. '#title' => t('Sync Organisms')
  422. );
  423. // before proceeding check to see if we have any
  424. // currently processing jobs. If so, we don't want
  425. // to give the opportunity to sync libraries
  426. $active_jobs = FALSE;
  427. if (tripal_get_module_active_jobs('tripal_organism')) {
  428. $active_jobs = TRUE;
  429. }
  430. if (!$active_jobs) {
  431. // get the list of organisms
  432. $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
  433. $previous_db = tripal_db_set_active('chado'); // use chado database
  434. $org_rset = db_query($sql);
  435. tripal_db_set_active($previous_db); // now use drupal database
  436. // if we've added any organisms to the list that can be synced
  437. // then we want to build the form components to allow the user
  438. // to select one or all of them. Otherwise, just present
  439. // a message stating that all organisms are currently synced.
  440. $org_boxes = array();
  441. $added = 0;
  442. while ($organism = db_fetch_object($org_rset)) {
  443. // check to see if the organism is already present as a node in drupal.
  444. // if so, then skip it.
  445. $sql = "SELECT * FROM {chado_organism} WHERE organism_id = %d";
  446. if (!db_fetch_object(db_query($sql, $organism->organism_id))) {
  447. $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
  448. $added++;
  449. }
  450. }
  451. // if we have organisms we need to add to the checkbox then
  452. // build that form element
  453. if ($added > 0) {
  454. $org_boxes['all'] = "All Organisms";
  455. $form['sync']['organisms'] = array(
  456. '#title' => t('Available Organisms'),
  457. '#type' => t('checkboxes'),
  458. '#description' => t("Check the organisms you want to sync. Drupal content will be created for each of the organisms listed above. Select 'All Organisms' to sync all of them."),
  459. '#required' => FALSE,
  460. '#prefix' => '<div id="org_boxes">',
  461. '#suffix' => '</div>',
  462. '#options' => $org_boxes,
  463. );
  464. $form['sync']['button'] = array(
  465. '#type' => 'submit',
  466. '#value' => t('Submit Sync Job')
  467. );
  468. }
  469. // we don't have any organisms to select from
  470. else {
  471. $form['sync']['value'] = array(
  472. '#value' => t('All organisms in Chado are currently synced with Drupal.')
  473. );
  474. }
  475. }
  476. // we don't want to present a form since we have an active job running
  477. else {
  478. $form['sync']['value'] = array(
  479. '#value' => t('Currently, jobs exist related to chado organisms. Please check back later for organisms that can by synced once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.')
  480. );
  481. }
  482. }
  483. /**
  484. *
  485. * @ingroup tripal_organism
  486. */
  487. function tripal_organism_admin_validate($form, &$form_state) {
  488. global $user; // we need access to the user info
  489. $job_args = array();
  490. if ($form_state['values']['op'] == t('Submit Sync Job')) {
  491. // check to see if the user wants to sync chado and drupal. If
  492. // so then we need to register a job to do so with tripal
  493. $organisms = $form_state['values']['organisms'];
  494. $do_all = FALSE;
  495. $to_sync = array();
  496. foreach ($organisms as $organism_id) {
  497. if (preg_match("/^all$/i" , $organism_id)) {
  498. $do_all = TRUE;
  499. }
  500. if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
  501. // get the list of organisms
  502. $sql = "SELECT * FROM {Organism} WHERE organism_id = %d";
  503. $previous_db = tripal_db_set_active('chado'); // use chado database
  504. $organism = db_fetch_object(db_query($sql, $organism_id));
  505. tripal_db_set_active($previous_db); // now use drupal database
  506. $to_sync[$organism_id] = "$organism->genus $organism->species";
  507. }
  508. }
  509. // submit the job the tripal job manager
  510. if ($do_all) {
  511. tripal_add_job('Sync all organisms' , 'tripal_organism',
  512. 'tripal_organism_sync_organisms' , $job_args , $user->uid);
  513. }
  514. else{
  515. foreach ($to_sync as $organism_id => $name) {
  516. $job_args[0] = $organism_id;
  517. tripal_add_job("Sync organism: $name" , 'tripal_organism',
  518. 'tripal_organism_sync_organisms' , $job_args , $user->uid);
  519. }
  520. }
  521. }
  522. // -------------------------------------
  523. // Submit the Reindex Job if selected
  524. if ($form_state['values']['op'] == t('Reindex Features')) {
  525. $organisms = $form_state['values']['re-organisms'];
  526. foreach ($organisms as $organism_id) {
  527. if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
  528. // get the organism info
  529. $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
  530. $previous_db = tripal_db_set_active('chado'); // use chado database
  531. $organism = db_fetch_object(db_query($sql , $organism_id));
  532. tripal_db_set_active($previous_db); // now use drupal database
  533. $job_args[0] = $organism_id;
  534. tripal_add_job("Reindex features for organism: $organism->genus ".
  535. "$organism->species", 'tripal_organism' ,
  536. 'tripal_organism_reindex_features', $job_args, $user->uid);
  537. }
  538. }
  539. }
  540. // -------------------------------------
  541. // Submit the taxonomy Job if selected
  542. if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
  543. $organisms = $form_state['values']['tx-organisms'];
  544. foreach ($organisms as $organism_id) {
  545. if ($organism_id and preg_match("/^\d+$/i", $organism_id)) {
  546. // get the organism info
  547. $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
  548. $previous_db = tripal_db_set_active('chado'); // use chado database
  549. $organism = db_fetch_object(db_query($sql , $organism_id));
  550. tripal_db_set_active($previous_db); // now use drupal database
  551. $job_args[0] = $organism_id;
  552. tripal_add_job("Set taxonomy for features in organism: ".
  553. "$organism->genus $organism->species" , 'tripal_organism',
  554. 'tripal_organism_taxonify_features', $job_args, $user->uid);
  555. }
  556. }
  557. }
  558. // -------------------------------------
  559. // Submit the Cleanup Job if selected
  560. if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
  561. tripal_add_job('Cleanup orphaned organisms', 'tripal_organism',
  562. 'tripal_organism_cleanup', $job_args, $user->uid);
  563. }
  564. }
  565. /**
  566. * We need to let drupal know about our theme functions and their arguments.
  567. * We create theme functions to allow users of the module to customize the
  568. * look and feel of the output generated in this module
  569. *
  570. * @ingroup tripal_organism
  571. */
  572. function tripal_organism_theme() {
  573. return array(
  574. 'tripal_organism_base' => array(
  575. 'arguments' => array('node' => NULL),
  576. 'template' => 'tripal_organism_base',
  577. ),
  578. 'tripal_organism_description' => array(
  579. 'arguments' => array('node' => NULL),
  580. 'template' => 'tripal_organism_description',
  581. ),
  582. 'tripal_organism_image' => array(
  583. 'arguments' => array('node' => NULL),
  584. 'template' => 'tripal_organism_image',
  585. ),
  586. );
  587. }
  588. /**
  589. *
  590. * @ingroup tripal_organism
  591. */
  592. function tripal_organism_nodeapi(&$node, $op, $teaser, $page) {
  593. switch ($op) {
  594. case 'view':
  595. switch ($node->type) {
  596. }
  597. }
  598. }
  599. /**
  600. *
  601. * @ingroup tripal_organism
  602. */
  603. function tripal_organism_cron() {
  604. // we want to make sure that any new organisms or features that were
  605. // added to the database external to drupal automatically get new
  606. // nodes created for themselves in drupal.
  607. // tripal_organism_sync_organisms();
  608. }
  609. /**
  610. *
  611. * @ingroup tripal_organism
  612. */
  613. function chado_organism_validate($node, &$form) {
  614. // if this is an update, we want to make sure that a different organism doesn't
  615. // already have this genus and speces
  616. if ($node->organism_id) {
  617. $sql = "SELECT *
  618. FROM {organism} O
  619. WHERE genus = '%s' and species = '%s' AND NOT organism_id = %d";
  620. $previous_db = tripal_db_set_active('chado');
  621. $result = db_fetch_object(db_query($sql, $node->genus, $node->species, $node->organism_id));
  622. tripal_db_set_active($previous_db);
  623. if ($result) {
  624. form_set_error('genus', t("Update cannot proceed. The organism genus
  625. '$node->genus' and species '$node->species' is already present in the database."));
  626. watchdog('tripal_organism',
  627. 'Update organism: genus and species already exists: %values',
  628. array('%values' => "genus = $node->genus, species = $node->species"),
  629. WATCHDOG_WARNING);
  630. }
  631. }
  632. // if this is an insert then check to make sure the genus and species are unique
  633. else {
  634. $values = array(
  635. 'genus' => $node->genus,
  636. 'species' => $node->species,
  637. );
  638. $organism = tripal_core_chado_select('organism', array('organism_id'), $values);
  639. if (sizeof($organism) > 0) {
  640. form_set_error('genus', 'Cannot add the organism with this genus and species.
  641. The organism already exists.');
  642. watchdog('tripal_organism',
  643. 'Insert organism: genus and species already exists: %values',
  644. array('%values' => "genus = $node->genus, species = $node->species"),
  645. WATCHDOG_WARNING);
  646. }
  647. }
  648. }
  649. /**
  650. * When a new chado_organism node is created we also need to add information
  651. * to our chado_organism table. This function is called on insert of a new node
  652. * of type 'chado_organism' and inserts the necessary information.
  653. *
  654. * @ingroup tripal_organism
  655. */
  656. function chado_organism_insert($node) {
  657. $values = array(
  658. 'genus' => $node->genus,
  659. 'species' => $node->species,
  660. 'abbreviation' => $node->abbreviation,
  661. 'common_name' => $node->common_name,
  662. 'comment' => $node->description
  663. );
  664. // if there is an organism_id in the $node object then this must be a sync so
  665. // we can skip adding the organism as it is already there, although
  666. // we do need to proceed with the rest of the insert
  667. if (!$node->organism_id) {
  668. $organism = tripal_core_chado_insert('organism', $values);
  669. if (!$organism) {
  670. drupal_set_message(t('Unable to add organism.', 'warning'));
  671. watchdog('tripal_organism',
  672. 'Insert Organism: Unable to create organism where values:%values',
  673. array('%values' => print_r($values, TRUE)),
  674. WATCHDOG_WARNING
  675. );
  676. return;
  677. }
  678. $organism_id = $organism['organism_id'];
  679. }
  680. else {
  681. $organism_id = $node->organism_id;
  682. }
  683. // Make sure the entry for this organism doesn't already exist in the
  684. // chado_organism table if it doesn't exist then we want to add it.
  685. if (!chado_get_id_for_node('organism', $node) ) {
  686. // next add the item to the drupal table
  687. $sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) ".
  688. "VALUES (%d, %d, %d)";
  689. chado_query($sql, $node->nid, $node->vid, $organism_id);
  690. }
  691. // set the title for the node
  692. $record = new stdClass();
  693. $record->title = "$node->genus $node->species";
  694. $record->nid = $node->nid;
  695. drupal_write_record('node', $record, 'nid');
  696. drupal_write_record('node_revisions', $record, 'nid');
  697. // add the image
  698. chado_organism_add_image($node);
  699. }
  700. /**
  701. * Update organisms
  702. *
  703. * @ingroup tripal_organism
  704. */
  705. function chado_organism_update($node) {
  706. if ($node->revision) {
  707. // TODO -- decide what to do about revisions
  708. }
  709. $match = array(
  710. 'organism_id' => chado_get_id_for_node('organism', $node),
  711. );
  712. $values = array(
  713. 'genus' => $node->genus,
  714. 'species' => $node->species,
  715. 'abbreviation' => $node->abbreviation,
  716. 'common_name' => $node->common_name,
  717. 'comment' => $node->description
  718. );
  719. $org_status = tripal_core_chado_update('organism', $match, $values);
  720. // set the title for the node
  721. $record = new stdClass();
  722. $record->title = "$node->genus $node->species";
  723. $record->nid = $node->nid;
  724. drupal_write_record('node', $record, 'nid');
  725. drupal_write_record('node_revisions', $record, 'nid');
  726. // add the image
  727. chado_organism_add_image($node);
  728. }
  729. /**
  730. * Delete organism from both drupal and chado databases. Check dependency before
  731. * deleting from chado.
  732. *
  733. * @ingroup tripal_organism
  734. */
  735. function chado_organism_delete($node) {
  736. $organism_id = chado_get_id_for_node('organism', $node);
  737. // if we don't have an organism id for this node then this isn't a node of
  738. // type chado_organism or the entry in the chado_organism table was lost.
  739. if (!$organism_id) {
  740. return;
  741. }
  742. // Remove data from the {chado_organism}, {node}, and {node_revisions} tables
  743. $sql_del = "DELETE FROM {chado_organism} ".
  744. "WHERE nid = %d ".
  745. "AND vid = %d";
  746. db_query($sql_del, $node->nid, $node->vid);
  747. $sql_del = "DELETE FROM {node} ".
  748. "WHERE nid = %d ".
  749. "AND vid = %d";
  750. db_query($sql_del, $node->nid, $node->vid);
  751. $sql_del = "DELETE FROM {node_revisions} ".
  752. "WHERE nid = %d ".
  753. "AND vid = %d";
  754. db_query($sql_del, $node->nid, $node->vid);
  755. // Test dependency before deleting from chado database. If a library or
  756. // feature depends on this organism, don't delete it
  757. $sql = "SELECT feature_id FROM {feature} WHERE organism_id = %d";
  758. $previous_db = tripal_db_set_active('chado');
  759. $check_feature = db_result(db_query($sql, $organism_id));
  760. $sql = "SELECT library_id FROM {library} WHERE organism_id = %d";
  761. $check_lib = db_result(db_query($sql, $organism_id));
  762. if ($check_lib == 0 && $check_feature == 0) {
  763. tripal_core_chado_delete('organism', array('organism_id' => $organism_id));
  764. }
  765. else {
  766. drupal_set_message(t("Organism deleted from drupal. Warning: at least one ".
  767. "library or feature depends on this organism. It was ".
  768. "not removed from chado."));
  769. }
  770. tripal_db_set_active($previous_db);
  771. }
  772. /**
  773. *
  774. *
  775. * @ingroup tripal_organism
  776. */
  777. function chado_organism_add_image($node) {
  778. // check to see if a file was uploaded. If so then copy it to the images
  779. // directory for display with the organism
  780. if (isset($_FILES['files']) && $_FILES['files']['name']['organism_image'] &&
  781. is_uploaded_file($_FILES['files']['tmp_name']['organism_image'])) {
  782. $dest = file_directory_path() . "/tripal/tripal_organism/images";
  783. $validators = array(
  784. 'file_validate_is_image' => array(),
  785. );
  786. file_check_directory($dest, FILE_CREATE_DIRECTORY, 'organism_image');
  787. if (!$file = file_save_upload('organism_image', $validators, $dest)) {
  788. drupal_set_message(t("Organism image was not uploaded."));
  789. }
  790. // move this image into the images directory
  791. file_move($file->filepath, $dest . "/" . $node->nid . ".jpg", FILE_EXISTS_REPLACE);
  792. }
  793. }
  794. /**
  795. * When editing or creating a new node of type 'chado_organism' we need
  796. * a form. This function creates the form that will be used for this.
  797. *
  798. * @ingroup tripal_organism
  799. */
  800. function chado_organism_form($node, $param) {
  801. $organism = $node->organism;
  802. // add in the comment since it is a text field and may not be included if too big
  803. $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
  804. // get form defaults
  805. $abbreviation = $node->abbreviation;
  806. if (!$abbreviation) {
  807. $abbreviation = $organism->abbreviation;
  808. }
  809. $genus = $node->genus;
  810. if (!$genus) {
  811. $genus = $organism->genus;
  812. }
  813. $species = $node->species;
  814. if (!$species) {
  815. $species = $organism->species;
  816. }
  817. $common_name = $node->common_name;
  818. if (!$common_name) {
  819. $common_name = $organism->common_name;
  820. }
  821. $description = $node->description;
  822. if (!$description) {
  823. $description = $organism->comment;
  824. }
  825. $organism_image = $node->organism_image;
  826. $form = array();
  827. $form['#attributes']['enctype'] = 'multipart/form-data';
  828. // keep track of the organism id if we have one. If we do have one then
  829. // this would indicate an update as opposed to an insert.
  830. $form['organism_id'] = array(
  831. '#type' => 'value',
  832. '#value' => $organism->organism_id,
  833. );
  834. $form['abbreviation']= array(
  835. '#type' => 'textfield',
  836. '#title' => t('Abbreviation'),
  837. '#required' => TRUE,
  838. '#default_value' => $organism->abbreviation,
  839. '#weight' => 3
  840. );
  841. $form['genus']= array(
  842. '#type' => 'textfield',
  843. '#title' => t('Genus'),
  844. '#required' => TRUE,
  845. '#default_value' => $organism->genus,
  846. '#weight' => 1
  847. );
  848. $form['species']= array(
  849. '#type' => 'textfield',
  850. '#title' => t('Species'),
  851. '#required' => TRUE,
  852. '#default_value' => $organism->species,
  853. '#weight' => 2
  854. );
  855. $form['common_name']= array(
  856. '#type' => 'textfield',
  857. '#title' => t('Common Name'),
  858. '#required' => TRUE,
  859. '#default_value' => $organism->common_name,
  860. '#weight' => 4
  861. );
  862. $form['description']= array(
  863. '#type' => 'textarea',
  864. '#rows' => 15,
  865. '#title' => t('Description'),
  866. '#required' => TRUE,
  867. '#default_value' => $organism->comment,
  868. '#weight' => 5
  869. );
  870. $form['organism_image']= array(
  871. '#type' => 'file',
  872. '#title' => t('Organism Image'),
  873. '#description' => 'Add an image for this organism',
  874. '#weight' => 6
  875. );
  876. return $form;
  877. }
  878. /**
  879. * When a node is requested by the user this function is called to allow us
  880. * to add auxiliary data to the node object.
  881. *
  882. * @ingroup tripal_organism
  883. */
  884. function chado_organism_load($node) {
  885. // find the organism and add in the details
  886. $organism_id = chado_get_id_for_node('organism', $node);
  887. $values = array('organism_id' => $organism_id);
  888. $organism = tripal_core_generate_chado_var('organism', $values);
  889. // add in the description field
  890. $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
  891. $additions = new stdClass();
  892. $additions->organism = $organism;
  893. return $additions;
  894. }
  895. /**
  896. * This function customizes the view of the chado_organism node. It allows
  897. * us to generate the markup.
  898. *
  899. * @ingroup tripal_organism
  900. */
  901. function chado_organism_view($node, $teaser = FALSE, $page = FALSE) {
  902. // use drupal's default node view:
  903. $node = node_prepare($node, $teaser);
  904. return $node;
  905. }
  906. /**
  907. * Synchronize organisms from chado to drupal
  908. *
  909. * @ingroup tripal_organism
  910. */
  911. function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
  912. global $user;
  913. $page_content = '';
  914. if (!$organism_id) {
  915. $sql = "SELECT * FROM {Organism} O";
  916. $previous_db = tripal_db_set_active('chado'); // use chado database
  917. $results = db_query($sql);
  918. tripal_db_set_active($previous_db); // now use drupal database
  919. }
  920. else {
  921. $sql = "SELECT * FROM {Organism} L WHERE organism_id = %d";
  922. $previous_db = tripal_db_set_active('chado'); // use chado database
  923. $results = db_query($sql, $organism_id);
  924. tripal_db_set_active($previous_db); // now use drupal database
  925. }
  926. // We'll use the following SQL statement for checking if the organism
  927. // already exists as a drupal node.
  928. $sql = "SELECT * FROM {chado_organism} ".
  929. "WHERE organism_id = %d";
  930. while ($organism = db_fetch_object($results)) {
  931. // check if this organism already exists in the drupal database. if it
  932. // does then skip this organism and go to the next one.
  933. if (!db_fetch_object(db_query($sql, $organism->organism_id))) {
  934. $new_node = new stdClass();
  935. $new_node->type = 'chado_organism';
  936. $new_node->uid = $user->uid;
  937. $new_node->title = "$organism->genus $organism->species";
  938. $new_node->organism_id = $organism->organism_id;
  939. $new_node->genus = $organism->genus;
  940. $new_node->species = $organism->species;
  941. $new_node->description = '';
  942. node_validate($new_node);
  943. if (!form_get_errors()) {
  944. $node = node_submit($new_node);
  945. node_save($node);
  946. if ($node->nid) {
  947. print "Added $organism->common_name\n";
  948. }
  949. }
  950. else {
  951. print "Failed to insert organism $organism->common_name\n";
  952. }
  953. }
  954. else {
  955. print "Skipped $organism->common_name\n";
  956. }
  957. }
  958. return $page_content;
  959. }
  960. /**
  961. * Display help and module information
  962. * @param path which path of the site we're displaying help
  963. * @param arg array that holds the current path as would be returned from arg()
  964. * function
  965. * @return help text for the path
  966. *
  967. * @ingroup tripal_organism
  968. */
  969. function tripal_organism_help($path, $arg) {
  970. $output = '';
  971. switch ($path) {
  972. case "admin/help#tripal_organism":
  973. $output = '<p>'.
  974. t("Displays links to nodes created on this date") .
  975. '</p>';
  976. break;
  977. }
  978. return $output;
  979. }
  980. /**
  981. * This function uses organism_id's of all drupal organism nodes as input and
  982. * pull the organism information (genus, species, common_name, comment) from
  983. * chado database. The return type is an object array that stores $organism
  984. * objects sorted by common_name
  985. *
  986. * @ingroup tripal_organism
  987. */
  988. function get_chado_organisms() {
  989. $sql_drupal = "SELECT COUNT (organism_id) FROM {chado_organism}";
  990. $no_orgs = db_result(db_query($sql_drupal));
  991. if ($no_orgs != 0) {
  992. $sql = "SELECT organism_id, nid FROM {chado_organism}";
  993. $result = db_query($sql);
  994. $previous_db = tripal_db_set_active('chado');
  995. $sql = "SELECT genus, species, common_name, comment ".
  996. "FROM {Organism} ".
  997. "WHERE organism_id=%d";
  998. $organisms = array();
  999. $count = 0;
  1000. while ($data = db_fetch_object($result)) {
  1001. $organism = db_fetch_object(db_query($sql, $data->organism_id));
  1002. $organism->node_id = $data->nid;
  1003. // Use common_name plus $count as the key so we can sort by common
  1004. // name later. Since common_name is not unique, we need to add $count
  1005. // to the key
  1006. $key = drupal_strtolower($organism->common_name) . $count;
  1007. $organisms [$key] = $organism;
  1008. $count ++;
  1009. }
  1010. tripal_db_set_active($previous_db);
  1011. //Sort organisms by common name
  1012. ksort($organisms, SORT_STRING);
  1013. return $organisms;
  1014. }
  1015. }
  1016. /**
  1017. *
  1018. * @ingroup tripal_organism
  1019. */
  1020. function tripal_organism_reindex_features($organism_id = NULL, $job_id = NULL) {
  1021. $i = 0;
  1022. if (!$organism_id) {
  1023. return;
  1024. }
  1025. $sql = "SELECT * ".
  1026. "FROM {feature} ".
  1027. "WHERE organism_id = $organism_id ".
  1028. "ORDER BY feature_id";
  1029. $previous_db = tripal_db_set_active('chado'); // use chado database
  1030. $results = db_query($sql);
  1031. tripal_db_set_active($previous_db); // now use drupal databa tripal_db_set_active($previous_db); // now use drupal database
  1032. // load into ids array
  1033. $count = 0;
  1034. $ids = array();
  1035. while ($id = db_fetch_object($results)) {
  1036. $ids[$count] = $id->feature_id;
  1037. $count++;
  1038. }
  1039. $interval = intval($count * 0.01);
  1040. foreach ($ids as $feature_id) {
  1041. // update the job status every 1% features
  1042. if ($job_id and $i % $interval == 0) {
  1043. tripal_job_set_progress($job_id , intval(($i/$count)*100));
  1044. }
  1045. tripal_feature_sync_feature($feature_id);
  1046. $i++;
  1047. }
  1048. }
  1049. /**
  1050. *
  1051. * @ingroup tripal_organism
  1052. */
  1053. function tripal_organism_taxonify_features($organism_id = NULL, $job_id = NULL) {
  1054. $i = 0;
  1055. if (!$organism_id) {
  1056. return;
  1057. }
  1058. $sql = "SELECT * ".
  1059. "FROM {feature} ".
  1060. "WHERE organism_id = $organism_id ".
  1061. "ORDER BY feature_id";
  1062. $previous_db = tripal_db_set_active('chado'); // use chado database
  1063. $results = db_query($sql);
  1064. tripal_db_set_active($previous_db); // now use drupal database
  1065. // load into ids array
  1066. $count = 0;
  1067. $ids = array();
  1068. while ($id = db_fetch_object($results)) {
  1069. $ids[$count] = $id->feature_id;
  1070. $count++;
  1071. }
  1072. // make sure our vocabularies are set before proceeding
  1073. tripal_feature_set_vocabulary();
  1074. // use this SQL for getting the nodes
  1075. $nsql = "SELECT * FROM {chado_feature} CF ".
  1076. " INNER JOIN {node} N ON N.nid = CF.nid ".
  1077. "WHERE feature_id = %d";
  1078. // iterate through the features and set the taxonomy
  1079. $interval = intval($count * 0.01);
  1080. foreach ($ids as $feature_id) {
  1081. // update the job status every 1% features
  1082. if ($job_id and $i % $interval == 0) {
  1083. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  1084. }
  1085. $node = db_fetch_object(db_query($nsql, $feature_id));
  1086. tripal_feature_set_taxonomy($node, $feature_id);
  1087. $i++;
  1088. }
  1089. }
  1090. /**
  1091. * Remove orphaned drupal nodes
  1092. *
  1093. * @param $dummy
  1094. * Not Used -kept for backwards compatibility
  1095. * @param $job_id
  1096. * The id of the tripal job executing this function
  1097. *
  1098. * @ingroup tripal_organism
  1099. */
  1100. function tripal_organism_cleanup($dummy = NULL, $job_id = NULL) {
  1101. return tripal_core_clean_orphaned_nodes('organism', $job_id);
  1102. }
  1103. /**
  1104. * Implements hook_views_api()
  1105. * Purpose: Essentially this hook tells drupal that there is views support for
  1106. * for this module which then includes tripal_db.views.inc where all the
  1107. * views integration code is
  1108. *
  1109. * @ingroup tripal_organism
  1110. */
  1111. function tripal_organism_views_api() {
  1112. return array(
  1113. 'api' => 2.0,
  1114. );
  1115. }
  1116. /**
  1117. *
  1118. *
  1119. * @ingroup tripal_organism
  1120. */
  1121. function tripal_organism_job_describe_args($callback, $args) {
  1122. $new_args = array();
  1123. if ($callback == 'tripal_organism_sync_organisms') {
  1124. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  1125. $new_args['Organism'] = $organism[0]->genus ." ". $organism[0]->species;
  1126. }
  1127. return $new_args;
  1128. }