tripal_library.module 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <?php
  2. /**
  3. * @defgroup tripal_library Library
  4. * @{
  5. * Provides functions for managing chado libraries including creating details pages for each library
  6. * @}
  7. * @ingroup tripal_modules
  8. */
  9. require('api/tripal_library.api.inc');
  10. require('includes/tripal_library.admin.inc');
  11. /**
  12. * Display help and module information
  13. * @param path which path of the site we're displaying help
  14. * @param arg array that holds the current path as would be returned from arg()
  15. * function
  16. * @return help text for the path
  17. *
  18. * @ingroup tripal_library
  19. */
  20. function tripal_library_help($path, $arg) {
  21. $output = '';
  22. switch ($path) {
  23. case "admin/help#tripal_library":
  24. $output = '<p>'.
  25. t("Displays links to nodes created on this date") .
  26. '</p>';
  27. break;
  28. }
  29. return $output;
  30. }
  31. /**
  32. * Provide information to drupal about the node types that we're creating
  33. * in this module
  34. *
  35. * @ingroup tripal_library
  36. */
  37. function tripal_library_node_info() {
  38. $nodes = array();
  39. $nodes['chado_library'] = array(
  40. 'name' => t('Library'),
  41. 'module' => 'chado_library',
  42. 'description' => t('A library from the chado database'),
  43. 'has_title' => FALSE,
  44. 'title_label' => t('Library'),
  45. 'has_body' => FALSE,
  46. 'body_label' => t('Library Description'),
  47. 'locked' => TRUE
  48. );
  49. return $nodes;
  50. }
  51. /**
  52. * Set the permission types that the chado module uses. Essentially we
  53. * want permissionis that protect creation, editing and deleting of chado
  54. * data objects
  55. *
  56. * @ingroup tripal_library
  57. */
  58. function tripal_library_perm() {
  59. return array(
  60. 'access chado_library content',
  61. 'create chado_library content',
  62. 'delete chado_library content',
  63. 'edit chado_library content',
  64. 'administer tripal libraries',
  65. );
  66. }
  67. /**
  68. * Set the permission types that the module uses.
  69. *
  70. * @ingroup tripal_library
  71. */
  72. function chado_library_access($op, $node, $account) {
  73. if ($op == 'create') {
  74. if (!user_access('create chado_library content', $account)) {
  75. return FALSE;
  76. }
  77. }
  78. if ($op == 'update') {
  79. if (!user_access('edit chado_library content', $account)) {
  80. return FALSE;
  81. }
  82. }
  83. if ($op == 'delete') {
  84. if (!user_access('delete chado_library content', $account)) {
  85. return FALSE;
  86. }
  87. }
  88. if ($op == 'view') {
  89. if (!user_access('access chado_library content', $account)) {
  90. return FALSE;
  91. }
  92. }
  93. return NULL;
  94. }
  95. /**
  96. * Menu items are automatically added for the new node types created
  97. * by this module to the 'Create Content' Navigation menu item. This function
  98. * adds more menu items needed for this module.
  99. *
  100. * @ingroup tripal_library
  101. */
  102. function tripal_library_menu() {
  103. $items = array();
  104. // The administative settings menu
  105. $items['admin/tripal/tripal_library'] = array(
  106. 'title' => 'Libraries',
  107. 'description' => 'Basic Description of Tripal Library Module Functionality',
  108. 'page callback' => 'theme',
  109. 'page arguments' => array('tripal_library_admin'),
  110. 'access arguments' => array('administer tripal libraries'),
  111. 'type' => MENU_NORMAL_ITEM,
  112. );
  113. $items['admin/tripal/tripal_library/configuration'] = array(
  114. 'title' => 'Library Configuration',
  115. 'description' => 'Manage integration of Chado libraries including associated features.',
  116. 'page callback' => 'drupal_get_form',
  117. 'page arguments' => array('tripal_library_admin'),
  118. 'access arguments' => array('administer tripal libraries'),
  119. 'type' => MENU_NORMAL_ITEM,
  120. );
  121. // Synchronizing libraries from Chado to Drupal
  122. $items['chado_sync_libraries'] = array(
  123. 'title' => 'Sync Library Data',
  124. 'page callback' => 'tripal_library_sync_libraries',
  125. 'access arguments' => array('administer tripal libraries'),
  126. 'type' => MENU_CALLBACK
  127. );
  128. return $items;
  129. }
  130. /**
  131. * Implements hook_views_api()
  132. * Purpose: Essentially this hook tells drupal that there is views support for
  133. * for this module which then includes tripal_db.views.inc where all the
  134. * views integration code is
  135. *
  136. * @ingroup tripal_library
  137. */
  138. function tripal_library_views_api() {
  139. return array(
  140. 'api' => 2.0,
  141. );
  142. }
  143. /**
  144. * Implementation of hook_nodeapi().
  145. * Display library information for associated features or organisms
  146. * This function also provides contents for indexing
  147. *
  148. * @ingroup tripal_library
  149. */
  150. function tripal_library_nodeapi(&$node, $op, $teaser, $page) {
  151. switch ($op) {
  152. // Note that this function only adds library view to an organism/feature
  153. // node.
  154. case 'view':
  155. // add the library to the organism/feature search indexing
  156. if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
  157. $node->content['tripal_library_index_version'] = array(
  158. '#value' => theme('tripal_library_search_index', $node),
  159. );
  160. }
  161. elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
  162. $node->content['tripal_library_index_version'] = array(
  163. '#value' => theme('tripal_library_search_result', $node),
  164. );
  165. }
  166. else {
  167. switch ($node->type) {
  168. case 'chado_organism':
  169. // Show library if the organism/feature is not at teaser view
  170. $node->content['tripal_organism_libraries'] = array(
  171. '#value' => theme('tripal_organism_libraries', $node),
  172. );
  173. break;
  174. case 'chado_feature':
  175. // Show library if the organism/feature is not at teaser view
  176. $node->content['tripal_feature_libraries'] = array(
  177. '#value' => theme('tripal_feature_libraries', $node),
  178. );
  179. break;
  180. }
  181. }
  182. break;
  183. }
  184. }
  185. /**
  186. * We need to let drupal know about our theme functions and their arguments.
  187. * We create theme functions to allow users of the module to customize the
  188. * look and feel of the output generated in this module
  189. *
  190. * @ingroup tripal_library
  191. */
  192. function tripal_library_theme() {
  193. return array(
  194. 'tripal_library_library_table' => array(
  195. 'arguments' => array('libraries'),
  196. ),
  197. 'tripal_library_search_index' => array(
  198. 'arguments' => array('node'),
  199. ),
  200. 'tripal_library_search_result' => array(
  201. 'arguments' => array('node'),
  202. ),
  203. 'tripal_organism_libraries' => array(
  204. 'arguments' => array('node' => NULL),
  205. 'template' => 'tripal_organism_libraries',
  206. ),
  207. 'tripal_feature_libraries' => array(
  208. 'arguments' => array('node' => NULL),
  209. 'template' => 'tripal_feature_libraries',
  210. ),
  211. 'tripal_library_base' => array(
  212. 'arguments' => array('node' => NULL),
  213. 'template' => 'tripal_library_base',
  214. ),
  215. 'tripal_library_synonyms' => array(
  216. 'arguments' => array('node' => NULL),
  217. 'template' => 'tripal_library_synonyms',
  218. ),
  219. 'tripal_library_references' => array(
  220. 'arguments' => array('node' => NULL),
  221. 'template' => 'tripal_library_references',
  222. ),
  223. 'tripal_library_properties' => array(
  224. 'arguments' => array('node' => NULL),
  225. 'template' => 'tripal_library_properties',
  226. ),
  227. 'tripal_library_admin' => array(
  228. 'template' => 'tripal_library_admin',
  229. 'arguments' => array(NULL),
  230. 'path' => drupal_get_path('module', 'tripal_library') . '/theme',
  231. ),
  232. );
  233. }
  234. /**
  235. * This function is an extension of the chado_feature_view and
  236. * chado_organism_view by providing the markup for the library object
  237. * THAT WILL BE INDEXED.
  238. *
  239. * @ingroup tripal_library
  240. */
  241. function theme_tripal_library_search_index($node) {
  242. if ($node->type == 'chado_organism') {
  243. $content = "";
  244. // get the libraries for the organism
  245. $sql = "SELECT * FROM {library} L ".
  246. "WHERE L.organism_id = %d";
  247. $libraries = array();
  248. $results = chado_query($sql, $node->organism->organism_id);
  249. while ($library = db_fetch_object($results)) {
  250. // get the description
  251. $sql = "SELECT * FROM {libraryprop} LP ".
  252. " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
  253. "WHERE LP.library_id = $library->library_id ".
  254. " AND CVT.name = 'library_description'";
  255. $desc = db_fetch_object(chado_query($sql));
  256. $library->description = $desc->value;
  257. $libraries[] = $library;
  258. }
  259. if (count($libraries) > 0) {
  260. foreach ($libraries as $library) {
  261. $content .= "$library->name ";
  262. $content .= "$library->description";
  263. };
  264. }
  265. // Provide library names to show in a feature page
  266. }
  267. elseif ($node->type == 'chado_feature') {
  268. $content = "";
  269. $organism_id = $node->feature->organism_id;
  270. $sql = "SELECT * FROM {library} L ".
  271. " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
  272. "WHERE LF.feature_id = " . $node->feature->feature_id;
  273. $libraries = array();
  274. $results = chado_query($sql);
  275. while ($library = db_fetch_object($results)) {
  276. $libraries[] = $library;
  277. }
  278. if (count($libraries) > 0) {
  279. $lib_additions = array();
  280. foreach ($libraries as $library) {
  281. $content .= $library->name;
  282. };
  283. }
  284. }
  285. return $content;
  286. }
  287. /**
  288. * This function shows library information on an organism/feature node
  289. *
  290. * @ingroup tripal_library
  291. */
  292. function theme_tripal_library_node_libraries($node) {
  293. $content = "";
  294. // Show library information in a expandable box for a organism page.
  295. // Make sure we have $node->organism_id. In the case of creating a new
  296. // organism, the organism_id is not created until we save. This will cause
  297. // an error when users preview the creation without a $node->organism_id
  298. if ($node->type == 'chado_organism' && $node->organism_id) {
  299. $box_status = variable_get("tripal_library-box-libraries", "menu_off");
  300. if (strcmp($box_status, "menu_off")==0) {
  301. return get_tripal_library_organism_libraries($node->nid);
  302. }
  303. }
  304. // Provide library names to show in a feature page.
  305. // Make sure we have $node->feature->feature_id or there will be an error
  306. // when a feature is previewed at its creation
  307. elseif ($node->type == 'chado_feature' && $node->feature->feature_id) {
  308. $organism_id = $node->feature->organism_id;
  309. $sql = "SELECT * FROM {library} L ".
  310. " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
  311. "WHERE LF.feature_id = " . $node->feature->feature_id;
  312. $libraries = array();
  313. $results = chado_query($sql);
  314. while ($library = db_fetch_object($results)) {
  315. $libraries[] = $library;
  316. }
  317. if (count($libraries) > 0) {
  318. $lib_additions = array();
  319. foreach ($libraries as $library) {
  320. $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d";
  321. $lib_nid = db_result(db_query($sql, $library->library_id));
  322. if ($lib_nid) {
  323. $lib_url = url("node/$lib_nid");
  324. }
  325. $lib_additions[$lib_url] = $library->name;
  326. };
  327. $node->lib_additions = $lib_additions;
  328. }
  329. }
  330. return $content;
  331. }
  332. /**
  333. *
  334. * @ingroup tripal_library
  335. */
  336. function tripal_library_cron() {
  337. }
  338. /**
  339. * The following function proves access control for users trying to
  340. * perform actions on data managed by this module
  341. *
  342. * @ingroup tripal_library
  343. */
  344. function tripal_library_library_access($op, $node, $account) {
  345. if ($op == 'create') {
  346. if (!user_access('create chado_library content', $account)) {
  347. return FALSE;
  348. }
  349. }
  350. if ($op == 'update') {
  351. if (!user_access('edit any chado_library content', $account) &&
  352. !user_access('edit own chado_library content', $account)) {
  353. return FALSE;
  354. }
  355. if (user_access('edit own chado_library content', $account) &&
  356. $account->uid != $node->uid) {
  357. return FALSE;
  358. }
  359. }
  360. if ($op == 'delete') {
  361. if (!user_access('delete any chado_library content', $account) &&
  362. !user_access('delete own chado_library content', $account)) {
  363. return FALSE;
  364. }
  365. if (user_access('delete own chado_library content', $account) &&
  366. $account->uid != $node->uid) {
  367. return FALSE;
  368. }
  369. }
  370. return NULL;
  371. }
  372. /**
  373. * When editing or creating a new node of type 'chado_library' we need
  374. * a form. This function creates the form that will be used for this.
  375. *
  376. * @ingroup tripal_library
  377. */
  378. function chado_library_form($node) {
  379. $form = array();
  380. $library = $node->library;
  381. // get the default values
  382. $uniquename = $node->uniquename;
  383. if (!$uniquename) {
  384. $uniquename = $library->uniquename;
  385. }
  386. $library_type = $node->library_type;
  387. if (!$library_type) {
  388. $library_type = $library->type_id->cvterm_id;
  389. }
  390. $organism_id = $node->organism_id;
  391. if (!$organism_id) {
  392. $organism_id = $library->organism_id->organism_id;
  393. }
  394. $library_description = $node->library_description;
  395. if (!$library_description) {
  396. $libprop = tripal_library_get_property($library->library_id, 'library_description');
  397. $library_description = $libprop->value;
  398. }
  399. // keep track of the library id if we have. If we do have one then
  400. // this is an update as opposed to an insert.
  401. $form['library_id'] = array(
  402. '#type' => 'value',
  403. '#value' => $library->library_id,
  404. );
  405. $form['title']= array(
  406. '#type' => 'textfield',
  407. '#title' => t('Library Title'),
  408. '#description' => t('Please enter the title for this library. '.
  409. 'This appears at the top of the library page.'),
  410. '#required' => TRUE,
  411. '#default_value' => $node->title,
  412. '#weight' => 1
  413. );
  414. $form['uniquename']= array(
  415. '#type' => 'textfield',
  416. '#title' => t('Unique Library Name'),
  417. '#description' => t('Please enter a unique name for this library'),
  418. '#required' => TRUE,
  419. '#default_value' => $uniquename,
  420. '#weight' => 2
  421. );
  422. // get the list of library types
  423. $values = array(
  424. 'cv_id' => array(
  425. 'name' => 'tripal_library_types',
  426. )
  427. );
  428. $columns = array('cvterm_id','name');
  429. $options = array('order_by' => array('name' => 'ASC'));
  430. $lib_types = tripal_core_chado_select('cvterm', $columns, $values, $options);
  431. $types = array();
  432. $types[''] = '';
  433. foreach($lib_types as $type) {
  434. $types[$type->cvterm_id] = $type->name;
  435. }
  436. $form['library_type'] = array(
  437. '#title' => t('Library Type'),
  438. '#type' => t('select'),
  439. '#description' => t("Choose the library type."),
  440. '#required' => TRUE,
  441. '#default_value' => $library_type,
  442. '#options' => $types,
  443. '#weight' => 3
  444. );
  445. // get the list of organisms
  446. $sql = "SELECT * FROM {Organism}";
  447. $org_rset = chado_query($sql);
  448. $organisms = array();
  449. $organisms[''] = '';
  450. while ($organism = db_fetch_object($org_rset)) {
  451. $organisms[$organism->organism_id] =
  452. "$organism->genus $organism->species ($organism->common_name)";
  453. }
  454. $form['organism_id'] = array(
  455. '#title' => t('Organism'),
  456. '#type' => t('select'),
  457. '#description' => t("Choose the organism with which this library is ".
  458. "associated."),
  459. '#required' => TRUE,
  460. '#default_value' => $organism_id,
  461. '#options' => $organisms,
  462. '#weight' => 4,
  463. );
  464. $form['library_description']= array(
  465. '#type' => 'textarea',
  466. '#title' => t('Library Description'),
  467. '#description' => t('A brief description of the library'),
  468. '#required' => TRUE,
  469. '#default_value' => $library_description,
  470. '#weight' => 5
  471. );
  472. return $form;
  473. }
  474. /**
  475. * validates submission of form when adding or updating a library node
  476. *
  477. * @ingroup tripal_library
  478. */
  479. function chado_library_validate($node) {
  480. $lib = 0;
  481. // check to make sure the unique name on the library is unique
  482. // before we try to insert into chado.
  483. if ($node->library_id) {
  484. $sql = "SELECT * FROM ".
  485. "{Library} WHERE ".
  486. "uniquename = '%s' ".
  487. "AND NOT library_id = %d";
  488. $lib = db_fetch_object(chado_query($sql, $node->uniquename, $node->library_id));
  489. }
  490. else {
  491. $sql = "SELECT * FROM ".
  492. "{Library} ".
  493. "WHERE uniquename = '%s'";
  494. $lib = db_fetch_object(chado_query($sql, $node->uniquename));
  495. }
  496. if ($lib) {
  497. form_set_error('uniquename', t('The unique library name already exists. '.
  498. 'Please choose another'));
  499. }
  500. }
  501. /**
  502. * When a new chado_library node is created we also need to add information
  503. * to our chado_library table. This function is called on insert of a new node
  504. * of type 'chado_library' and inserts the necessary information.
  505. *
  506. * @ingroup tripal_library
  507. */
  508. function chado_library_insert($node) {
  509. if ($node->library_id) {
  510. $library['library_id'] = $node->library_id;
  511. }
  512. else {
  513. $values = array(
  514. 'name' => $node->title,
  515. 'uniquename' => $node->uniquename,
  516. 'organism_id' => $node->organism_id,
  517. 'type_id' => $node->library_type,
  518. );
  519. $library = tripal_core_chado_insert('library', $values);
  520. }
  521. if ($library) {
  522. // add the description property
  523. tripal_library_insert_property($library['library_id'], 'library_description',
  524. $node->library_description);
  525. // make sure the entry for this feature doesn't already exist in the chado_library table
  526. // if it doesn't exist then we want to add it.
  527. $library_id = chado_get_id_for_node('library', $node) ;
  528. if (!$library_id) {
  529. // next add the item to the drupal table
  530. $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
  531. "VALUES (%d, %d, %d)";
  532. db_query($sql, $node->nid, $node->vid, $library['library_id']);
  533. }
  534. }
  535. else {
  536. drupal_set_message(t('Unable to add library.', 'warning'));
  537. watchdog('tripal_library',
  538. 'Insert feature: Unable to create library where values: %values',
  539. array('%values' => print_r($values, TRUE)),
  540. WATCHDOG_WARNING
  541. );
  542. }
  543. }
  544. /**
  545. * Update nodes
  546. *
  547. * @ingroup tripal_library
  548. */
  549. function chado_library_update($node) {
  550. if ($node->revision) {
  551. // there is no way to handle revisions in Chado but leave
  552. // this here just to make not we've addressed it.
  553. }
  554. $library_id = chado_get_id_for_node('library', $node) ;
  555. // update the library record
  556. $match = array(
  557. 'library_id' => $library_id,
  558. );
  559. $values = array(
  560. 'name' => $node->title,
  561. 'uniquename' => $node->uniquename,
  562. 'organism_id' => $node->organism_id,
  563. 'type_id' => $node->library_type,
  564. );
  565. $status = tripal_core_chado_update('library', $match, $values);
  566. tripal_library_update_property($library_id, 'library_description', $node->library_description, 1);
  567. }
  568. /**
  569. * When a node is requested by the user this function is called to allow us
  570. * to add auxiliary data to the node object.
  571. *
  572. * @ingroup tripal_library
  573. */
  574. function chado_library_load($node) {
  575. // get the feature details from chado
  576. $library_id = chado_get_id_for_node('library', $node);
  577. $values = array('library_id' => $library_id);
  578. $library = tripal_core_generate_chado_var('library', $values);
  579. $additions = new stdClass();
  580. $additions->library = $library;
  581. return $additions;
  582. }
  583. /**
  584. * This function customizes the view of the chado_library node. It allows
  585. * us to generate the markup. This function is required for node [Preview]
  586. *
  587. * @ingroup tripal_library
  588. */
  589. function chado_library_view($node, $teaser = FALSE, $page = FALSE) {
  590. // use drupal's default node view:
  591. if (!$teaser) {
  592. $node = node_prepare($node, $teaser);
  593. // If Hook_view() is called by Hook_form(), we'll only have orgnism_id
  594. // but not genus/species/common_name. We need to get those from chado
  595. // database so they will show up in preview
  596. if (!$node->genus) {
  597. $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
  598. $data = db_fetch_object(chado_query($sql, $node->organism_id));
  599. $node->genus = $data->genus;
  600. $node->species = $data->species;
  601. $node->common_name = $data->common_name;
  602. }
  603. }
  604. return $node;
  605. }
  606. /**
  607. * Delete data from drupal and chado databases when a node is deleted
  608. * @ingroup tripal_library
  609. */
  610. function chado_library_delete(&$node) {
  611. $library_id = chado_get_id_for_node('library', $node);
  612. // if we don't have a library id for this node then this isn't a node of
  613. // type chado_library or the entry in the chado_library table was lost.
  614. if (!$library_id) {
  615. return;
  616. }
  617. // Remove data from {chado_library}, {node} and {node_revisions} tables of
  618. // drupal database
  619. $sql_del = "DELETE FROM {chado_library} ".
  620. "WHERE nid = %d ".
  621. "AND vid = %d";
  622. db_query($sql_del, $node->nid, $node->vid);
  623. $sql_del = "DELETE FROM {node} ".
  624. "WHERE nid = %d ".
  625. "AND vid = %d";
  626. db_query($sql_del, $node->nid, $node->vid);
  627. $sql_del = "DELETE FROM {node_revisions} ".
  628. "WHERE nid = %d ".
  629. "AND vid = %d";
  630. db_query($sql_del, $node->nid, $node->vid);
  631. // Remove data from library and libraryprop tables of chado database as well
  632. chado_query("DELETE FROM {library} WHERE library_id = %d", $library_id);
  633. chado_query("DELETE FROM {libraryprop} WHERE library_id = %d", $library_id);
  634. }
  635. /**
  636. * Display block with libraries
  637. * @param op - parameter to define the phase being called for the block
  638. * @param delta - id of the block to return (ignored when op is list)
  639. * @param edit - when op is save, contains the submitted form data
  640. *
  641. * @ingroup tripal_library
  642. */
  643. function tripal_library_block($op = 'list', $delta = '0', $edit = array()) {
  644. switch ($op) {
  645. case 'list':
  646. $blocks['libreferences']['info'] = t('Tripal Library References');
  647. $blocks['libreferences']['cache'] = BLOCK_NO_CACHE;
  648. $blocks['libbase']['info'] = t('Tripal Library Details');
  649. $blocks['libbase']['cache'] = BLOCK_NO_CACHE;
  650. $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
  651. $blocks['libsynonyms']['cache'] = BLOCK_NO_CACHE;
  652. $blocks['libproperties']['info'] = t('Tripal Library Properties');
  653. $blocks['libproperties']['cache'] = BLOCK_NO_CACHE;
  654. $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
  655. $blocks['featurelibs']['cache'] = BLOCK_NO_CACHE;
  656. $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
  657. $blocks['orglibs']['cache'] = BLOCK_NO_CACHE;
  658. return $blocks;
  659. case 'view':
  660. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  661. $nid = arg(1);
  662. $node = node_load($nid);
  663. $block = array();
  664. switch ($delta) {
  665. case 'libreferences':
  666. $block['subject'] = t('References');
  667. $block['content'] = theme('tripal_library_references', $node);
  668. break;
  669. case 'libbase':
  670. $block['subject'] = t('Library Details');
  671. $block['content'] = theme('tripal_library_base', $node);
  672. break;
  673. case 'libsynonyms':
  674. $block['subject'] = t('Synonyms');
  675. $block['content'] = theme('tripal_library_synonyms', $node);
  676. break;
  677. case 'libproperties':
  678. $block['subject'] = t('Properties');
  679. $block['content'] = theme('tripal_library_properties', $node);
  680. break;
  681. case 'featurelibs':
  682. $block['subject'] = t('Libraries');
  683. $block['content'] = theme('tripal_feature_libraries', $node);
  684. break;
  685. case 'orglibs':
  686. $block['subject'] = t('Libraries');
  687. $block['content'] = theme('tripal_organism_libraries', $node);
  688. break;
  689. default :
  690. }
  691. return $block;
  692. }
  693. }
  694. }