tripal_library.module 23 KB

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