tripal_library.module 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <?php
  2. /**
  3. * @defgroup tripal_library Library Module
  4. * @ingroup tripal_modules
  5. * @{
  6. * Provides functions for managing chado libraries including creating details pages for each library
  7. * @}
  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_terms' => array(
  228. 'arguments' => array('node' => NULL),
  229. 'template' => 'tripal_library_terms',
  230. ),
  231. 'tripal_library_admin' => array(
  232. 'template' => 'tripal_library_admin',
  233. 'arguments' => array(NULL),
  234. 'path' => drupal_get_path('module', 'tripal_library') . '/theme',
  235. ),
  236. );
  237. }
  238. /**
  239. * This function is an extension of the chado_feature_view and
  240. * chado_organism_view by providing the markup for the library object
  241. * THAT WILL BE INDEXED.
  242. *
  243. * @ingroup tripal_library
  244. */
  245. function theme_tripal_library_search_index($node) {
  246. if ($node->type == 'chado_organism') {
  247. $content = "";
  248. // get the libraries for the organism
  249. $sql = "SELECT * FROM {library} L ".
  250. "WHERE L.organism_id = %d";
  251. $libraries = array();
  252. $results = chado_query($sql, $node->organism->organism_id);
  253. while ($library = db_fetch_object($results)) {
  254. // get the description
  255. $sql = "SELECT * FROM {libraryprop} LP ".
  256. " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
  257. "WHERE LP.library_id = $library->library_id ".
  258. " AND CVT.name = 'library_description'";
  259. $desc = db_fetch_object(chado_query($sql));
  260. $library->description = $desc->value;
  261. $libraries[] = $library;
  262. }
  263. if (count($libraries) > 0) {
  264. foreach ($libraries as $library) {
  265. $content .= "$library->name ";
  266. $content .= "$library->description";
  267. };
  268. }
  269. // Provide library names to show in a feature page
  270. }
  271. elseif ($node->type == 'chado_feature') {
  272. $content = "";
  273. $organism_id = $node->feature->organism_id;
  274. $sql = "SELECT * FROM {library} L ".
  275. " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
  276. "WHERE LF.feature_id = " . $node->feature->feature_id;
  277. $libraries = array();
  278. $results = chado_query($sql);
  279. while ($library = db_fetch_object($results)) {
  280. $libraries[] = $library;
  281. }
  282. if (count($libraries) > 0) {
  283. $lib_additions = array();
  284. foreach ($libraries as $library) {
  285. $content .= $library->name;
  286. };
  287. }
  288. }
  289. return $content;
  290. }
  291. /**
  292. * This function shows library information on an organism/feature node
  293. *
  294. * @ingroup tripal_library
  295. */
  296. function theme_tripal_library_node_libraries($node) {
  297. $content = "";
  298. // Show library information in a expandable box for a organism page.
  299. // Make sure we have $node->organism_id. In the case of creating a new
  300. // organism, the organism_id is not created until we save. This will cause
  301. // an error when users preview the creation without a $node->organism_id
  302. if ($node->type == 'chado_organism' && $node->organism_id) {
  303. $box_status = variable_get("tripal_library-box-libraries", "menu_off");
  304. if (strcmp($box_status, "menu_off")==0) {
  305. return get_tripal_library_organism_libraries($node->nid);
  306. }
  307. }
  308. // Provide library names to show in a feature page.
  309. // Make sure we have $node->feature->feature_id or there will be an error
  310. // when a feature is previewed at its creation
  311. elseif ($node->type == 'chado_feature' && $node->feature->feature_id) {
  312. $organism_id = $node->feature->organism_id;
  313. $sql = "SELECT * FROM {library} L ".
  314. " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
  315. "WHERE LF.feature_id = " . $node->feature->feature_id;
  316. $libraries = array();
  317. $results = chado_query($sql);
  318. while ($library = db_fetch_object($results)) {
  319. $libraries[] = $library;
  320. }
  321. if (count($libraries) > 0) {
  322. $lib_additions = array();
  323. foreach ($libraries as $library) {
  324. $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d";
  325. $lib_nid = db_result(db_query($sql, $library->library_id));
  326. if ($lib_nid) {
  327. $lib_url = url("node/$lib_nid");
  328. }
  329. $lib_additions[$lib_url] = $library->name;
  330. };
  331. $node->lib_additions = $lib_additions;
  332. }
  333. }
  334. return $content;
  335. }
  336. /**
  337. *
  338. * @ingroup tripal_library
  339. */
  340. function tripal_library_cron() {
  341. }
  342. /**
  343. * The following function proves access control for users trying to
  344. * perform actions on data managed by this module
  345. *
  346. * @ingroup tripal_library
  347. */
  348. function tripal_library_library_access($op, $node, $account) {
  349. if ($op == 'create') {
  350. if (!user_access('create chado_library content', $account)) {
  351. return FALSE;
  352. }
  353. }
  354. if ($op == 'update') {
  355. if (!user_access('edit any chado_library content', $account) &&
  356. !user_access('edit own chado_library content', $account)) {
  357. return FALSE;
  358. }
  359. if (user_access('edit own chado_library content', $account) &&
  360. $account->uid != $node->uid) {
  361. return FALSE;
  362. }
  363. }
  364. if ($op == 'delete') {
  365. if (!user_access('delete any chado_library content', $account) &&
  366. !user_access('delete own chado_library content', $account)) {
  367. return FALSE;
  368. }
  369. if (user_access('delete own chado_library content', $account) &&
  370. $account->uid != $node->uid) {
  371. return FALSE;
  372. }
  373. }
  374. return NULL;
  375. }
  376. /**
  377. * When editing or creating a new node of type 'chado_library' we need
  378. * a form. This function creates the form that will be used for this.
  379. *
  380. * @ingroup tripal_library
  381. */
  382. function chado_library_form($node) {
  383. $form = array();
  384. $library = $node->library;
  385. // get the default values
  386. $uniquename = $node->uniquename;
  387. if (!$uniquename) {
  388. $uniquename = $library->uniquename;
  389. }
  390. $library_type = $node->library_type;
  391. if (!$library_type) {
  392. $library_type = $library->type_id->cvterm_id;
  393. }
  394. $organism_id = $node->organism_id;
  395. if (!$organism_id) {
  396. $organism_id = $library->organism_id->organism_id;
  397. }
  398. $library_description = $node->library_description;
  399. if (!$library_description) {
  400. $libprop = tripal_library_get_property($library->library_id, 'library_description');
  401. $library_description = $libprop->value;
  402. }
  403. // keep track of the library id if we have. If we do have one then
  404. // this is an update as opposed to an insert.
  405. $form['library_id'] = array(
  406. '#type' => 'value',
  407. '#value' => $library->library_id,
  408. );
  409. $form['title']= array(
  410. '#type' => 'textfield',
  411. '#title' => t('Library Title'),
  412. '#description' => t('Please enter the title for this library. '.
  413. 'This appears at the top of the library page.'),
  414. '#required' => TRUE,
  415. '#default_value' => $node->title,
  416. '#weight' => 1
  417. );
  418. $form['uniquename']= array(
  419. '#type' => 'textfield',
  420. '#title' => t('Unique Library Name'),
  421. '#description' => t('Please enter a unique name for this library'),
  422. '#required' => TRUE,
  423. '#default_value' => $uniquename,
  424. '#weight' => 2
  425. );
  426. // get the list of library types
  427. $values = array(
  428. 'cv_id' => array(
  429. 'name' => 'tripal_library_types',
  430. )
  431. );
  432. $columns = array('cvterm_id','name');
  433. $options = array('order_by' => array('name' => 'ASC'));
  434. $lib_types = tripal_core_chado_select('cvterm', $columns, $values, $options);
  435. $types = array();
  436. $types[''] = '';
  437. foreach($lib_types as $type) {
  438. $types[$type->cvterm_id] = $type->name;
  439. }
  440. $form['library_type'] = array(
  441. '#title' => t('Library Type'),
  442. '#type' => t('select'),
  443. '#description' => t("Choose the library type."),
  444. '#required' => TRUE,
  445. '#default_value' => $library_type,
  446. '#options' => $types,
  447. '#weight' => 3
  448. );
  449. // get the list of organisms
  450. $sql = "SELECT * FROM {Organism}";
  451. $org_rset = chado_query($sql);
  452. $organisms = array();
  453. $organisms[''] = '';
  454. while ($organism = db_fetch_object($org_rset)) {
  455. $organisms[$organism->organism_id] =
  456. "$organism->genus $organism->species ($organism->common_name)";
  457. }
  458. $form['organism_id'] = array(
  459. '#title' => t('Organism'),
  460. '#type' => t('select'),
  461. '#description' => t("Choose the organism with which this library is ".
  462. "associated."),
  463. '#required' => TRUE,
  464. '#default_value' => $organism_id,
  465. '#options' => $organisms,
  466. '#weight' => 4,
  467. );
  468. $form['library_description']= array(
  469. '#type' => 'textarea',
  470. '#title' => t('Library Description'),
  471. '#description' => t('A brief description of the library'),
  472. '#required' => TRUE,
  473. '#default_value' => $library_description,
  474. '#weight' => 5
  475. );
  476. return $form;
  477. }
  478. /**
  479. * validates submission of form when adding or updating a library node
  480. *
  481. * @ingroup tripal_library
  482. */
  483. function chado_library_validate($node) {
  484. $lib = 0;
  485. // check to make sure the unique name on the library is unique
  486. // before we try to insert into chado.
  487. if ($node->library_id) {
  488. $sql = "SELECT * FROM ".
  489. "{Library} WHERE ".
  490. "uniquename = '%s' ".
  491. "AND NOT library_id = %d";
  492. $lib = db_fetch_object(chado_query($sql, $node->uniquename, $node->library_id));
  493. }
  494. else {
  495. $sql = "SELECT * FROM ".
  496. "{Library} ".
  497. "WHERE uniquename = '%s'";
  498. $lib = db_fetch_object(chado_query($sql, $node->uniquename));
  499. }
  500. if ($lib) {
  501. form_set_error('uniquename', t('The unique library name already exists. '.
  502. 'Please choose another'));
  503. }
  504. }
  505. /**
  506. * When a new chado_library node is created we also need to add information
  507. * to our chado_library table. This function is called on insert of a new node
  508. * of type 'chado_library' and inserts the necessary information.
  509. *
  510. * @ingroup tripal_library
  511. */
  512. function chado_library_insert($node) {
  513. if ($node->library_id) {
  514. $library['library_id'] = $node->library_id;
  515. }
  516. else {
  517. $values = array(
  518. 'name' => $node->title,
  519. 'uniquename' => $node->uniquename,
  520. 'organism_id' => $node->organism_id,
  521. 'type_id' => $node->library_type,
  522. );
  523. $library = tripal_core_chado_insert('library', $values);
  524. }
  525. if ($library) {
  526. // add the description property
  527. tripal_library_insert_property($library['library_id'], 'library_description',
  528. $node->library_description);
  529. // make sure the entry for this feature doesn't already exist in the chado_library table
  530. // if it doesn't exist then we want to add it.
  531. $library_id = chado_get_id_for_node('library', $node) ;
  532. if (!$library_id) {
  533. // next add the item to the drupal table
  534. $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
  535. "VALUES (%d, %d, %d)";
  536. db_query($sql, $node->nid, $node->vid, $library['library_id']);
  537. }
  538. }
  539. else {
  540. drupal_set_message(t('Unable to add library.', 'warning'));
  541. watchdog('tripal_library',
  542. 'Insert feature: Unable to create library where values: %values',
  543. array('%values' => print_r($values, TRUE)),
  544. WATCHDOG_WARNING
  545. );
  546. }
  547. }
  548. /**
  549. * Update nodes
  550. *
  551. * @ingroup tripal_library
  552. */
  553. function chado_library_update($node) {
  554. if ($node->revision) {
  555. // there is no way to handle revisions in Chado but leave
  556. // this here just to make not we've addressed it.
  557. }
  558. $library_id = chado_get_id_for_node('library', $node) ;
  559. // update the library record
  560. $match = array(
  561. 'library_id' => $library_id,
  562. );
  563. $values = array(
  564. 'name' => $node->title,
  565. 'uniquename' => $node->uniquename,
  566. 'organism_id' => $node->organism_id,
  567. 'type_id' => $node->library_type,
  568. );
  569. $status = tripal_core_chado_update('library', $match, $values);
  570. tripal_library_update_property($library_id, 'library_description', $node->library_description, 1);
  571. }
  572. /**
  573. * When a node is requested by the user this function is called to allow us
  574. * to add auxiliary data to the node object.
  575. *
  576. * @ingroup tripal_library
  577. */
  578. function chado_library_load($node) {
  579. // get the feature details from chado
  580. $library_id = chado_get_id_for_node('library', $node);
  581. $values = array('library_id' => $library_id);
  582. $library = tripal_core_generate_chado_var('library', $values);
  583. $additions = new stdClass();
  584. $additions->library = $library;
  585. return $additions;
  586. }
  587. /**
  588. * This function customizes the view of the chado_library node. It allows
  589. * us to generate the markup. This function is required for node [Preview]
  590. *
  591. * @ingroup tripal_library
  592. */
  593. function chado_library_view($node, $teaser = FALSE, $page = FALSE) {
  594. // use drupal's default node view:
  595. if (!$teaser) {
  596. $node = node_prepare($node, $teaser);
  597. // If Hook_view() is called by Hook_form(), we'll only have orgnism_id
  598. // but not genus/species/common_name. We need to get those from chado
  599. // database so they will show up in preview
  600. if (!$node->genus) {
  601. $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
  602. $data = db_fetch_object(chado_query($sql, $node->organism_id));
  603. $node->genus = $data->genus;
  604. $node->species = $data->species;
  605. $node->common_name = $data->common_name;
  606. }
  607. }
  608. return $node;
  609. }
  610. /**
  611. * Delete data from drupal and chado databases when a node is deleted
  612. * @ingroup tripal_library
  613. */
  614. function chado_library_delete(&$node) {
  615. $library_id = chado_get_id_for_node('library', $node);
  616. // if we don't have a library id for this node then this isn't a node of
  617. // type chado_library or the entry in the chado_library table was lost.
  618. if (!$library_id) {
  619. return;
  620. }
  621. // Remove data from {chado_library}, {node} and {node_revisions} tables of
  622. // drupal database
  623. $sql_del = "DELETE FROM {chado_library} ".
  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. $sql_del = "DELETE FROM {node} ".
  632. "WHERE nid = %d ".
  633. "AND vid = %d";
  634. db_query($sql_del, $node->nid, $node->vid);
  635. // Remove data from library and libraryprop tables of chado database as well
  636. chado_query("DELETE FROM {libraryprop} WHERE library_id = %d", $library_id);
  637. chado_query("DELETE FROM {library} WHERE library_id = %d", $library_id);
  638. }
  639. /**
  640. * Display block with libraries
  641. * @param op - parameter to define the phase being called for the block
  642. * @param delta - id of the block to return (ignored when op is list)
  643. * @param edit - when op is save, contains the submitted form data
  644. *
  645. * @ingroup tripal_library
  646. */
  647. function tripal_library_block($op = 'list', $delta = '0', $edit = array()) {
  648. switch ($op) {
  649. case 'list':
  650. $blocks['libreferences']['info'] = t('Tripal Library Cross References');
  651. $blocks['libreferences']['cache'] = BLOCK_NO_CACHE;
  652. $blocks['libbase']['info'] = t('Tripal Library Details');
  653. $blocks['libbase']['cache'] = BLOCK_NO_CACHE;
  654. $blocks['libterms']['info'] = t('Tripal Library Terms');
  655. $blocks['libterms']['cache'] = BLOCK_NO_CACHE;
  656. $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
  657. $blocks['libsynonyms']['cache'] = BLOCK_NO_CACHE;
  658. $blocks['libproperties']['info'] = t('Tripal Library Properties');
  659. $blocks['libproperties']['cache'] = BLOCK_NO_CACHE;
  660. $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
  661. $blocks['featurelibs']['cache'] = BLOCK_NO_CACHE;
  662. $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
  663. $blocks['orglibs']['cache'] = BLOCK_NO_CACHE;
  664. return $blocks;
  665. case 'view':
  666. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  667. $nid = arg(1);
  668. $node = node_load($nid);
  669. $block = array();
  670. switch ($delta) {
  671. case 'libreferences':
  672. $block['subject'] = t('Cross References');
  673. $block['content'] = theme('tripal_library_references', $node);
  674. break;
  675. case 'libbase':
  676. $block['subject'] = t('Library Details');
  677. $block['content'] = theme('tripal_library_base', $node);
  678. break;
  679. case 'libsynonyms':
  680. $block['subject'] = t('Synonyms');
  681. $block['content'] = theme('tripal_library_synonyms', $node);
  682. break;
  683. case 'libproperties':
  684. $block['subject'] = t('Properties');
  685. $block['content'] = theme('tripal_library_properties', $node);
  686. break;
  687. case 'libterms':
  688. $block['subject'] = t('Library Terms');
  689. $block['content'] = theme('tripal_library_terms', $node);
  690. break;
  691. case 'featurelibs':
  692. $block['subject'] = t('Libraries');
  693. $block['content'] = theme('tripal_feature_libraries', $node);
  694. break;
  695. case 'orglibs':
  696. $block['subject'] = t('Libraries');
  697. $block['content'] = theme('tripal_organism_libraries', $node);
  698. break;
  699. default :
  700. }
  701. return $block;
  702. }
  703. }
  704. }