tripal_library.chado_node.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <?php
  2. /**
  3. * @file
  4. * Implements the library node content type
  5. */
  6. /**
  7. * Implements hook_node_info().
  8. *
  9. * Provide information to drupal about the node types that we're creating
  10. * in this module
  11. *
  12. * @ingroup tripal_library
  13. */
  14. function tripal_library_node_info() {
  15. $nodes = array();
  16. $nodes['chado_library'] = array(
  17. 'name' => t('Library'),
  18. 'base' => 'chado_library',
  19. 'description' => t('A library from the chado database'),
  20. 'has_title' => TRUE,
  21. 'locked' => TRUE,
  22. 'chado_node_api' => array(
  23. 'base_table' => 'library',
  24. 'hook_prefix' => 'chado_library',
  25. 'record_type_title' => array(
  26. 'singular' => t('Library'),
  27. 'plural' => t('Libraries')
  28. ),
  29. 'sync_filters' => array(
  30. 'type_id' => TRUE,
  31. 'organism_id' => TRUE
  32. ),
  33. )
  34. );
  35. return $nodes;
  36. }
  37. /**
  38. * Implements hook_form().
  39. *
  40. * When editing or creating a new node of type 'chado_library' we need
  41. * a form. This function creates the form that will be used for this.
  42. *
  43. * @ingroup tripal_library
  44. */
  45. function chado_library_form($node, &$form_state) {
  46. $form = array();
  47. // Default values can come in the following ways:
  48. //
  49. // 1) As elements of the $node object: this occurs when editing an existing
  50. // library.
  51. // 2) In the $form_state['values'] array which occurs on a failed validation
  52. // or ajax callbacks from non submit form elements.
  53. // 3) In the $form_state['input'] array which occurs on ajax callbacks from
  54. // submit form elements and the form is being rebuilt.
  55. // Set form field defaults.
  56. $library_id = NULL;
  57. $libraryname = '';
  58. $uniquename = '';
  59. $library_type = '';
  60. $organism_id = '';
  61. $description = '';
  62. // If we are editing an existing node then the library is already part of
  63. // the node
  64. if (property_exists($node, 'library')) {
  65. $library = $node->library;
  66. $library_id = $library->library_id;
  67. $libraryname = $library->name;
  68. $uniquename = $library->uniquename;
  69. $library_type = $library->type_id->cvterm_id;
  70. $organism_id = $library->organism_id->organism_id;
  71. $libprop = chado_get_property(
  72. array('table' => 'library', 'id' => $library->library_id),
  73. array('type_name' => 'Library Description', 'cv_name' => 'library_property')
  74. );
  75. $description = $libprop->value;
  76. // Keep track of the library id if we have. If we do have one then
  77. // this is an update as opposed to an insert.
  78. $form['library_id'] = array(
  79. '#type' => 'value',
  80. '#value' => $library_id,
  81. );
  82. }
  83. // If we are re constructing the form from a failed validation or ajax callback
  84. // then use the $form_state['values'] values.
  85. if (array_key_exists('values', $form_state)) {
  86. $libraryname = $form_state['values']['libraryname'];
  87. $uniquename = $form_state['values']['uniquename'];
  88. $library_type = $form_state['values']['library_type'];
  89. $organism_id = $form_state['values']['organism_id'];
  90. $description = $form_state['values']['description'];
  91. }
  92. // If we are re building the form from after submission (from ajax call) then
  93. // the values are in the $form_state['input'] array.
  94. if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
  95. $libraryname = $form_state['input']['libraryname'];
  96. $uniquename = $form_state['input']['uniquename'];
  97. $library_type = $form_state['input']['library_type'];
  98. $organism_id = $form_state['input']['organism_id'];
  99. $description = $form_state['input']['description'];
  100. }
  101. $form['libraryname']= array(
  102. '#type' => 'textfield',
  103. '#title' => t('Library Name'),
  104. '#description' => t('Please enter the name for this library. Library names should be recognizable but do not need to be unique.'),
  105. '#required' => TRUE,
  106. '#default_value' => $libraryname,
  107. );
  108. $form['uniquename']= array(
  109. '#type' => 'textfield',
  110. '#title' => t('Unique Name'),
  111. '#description' => t('Please enter a unique name for this library. This can be any value used to uniquely identify a library.'),
  112. '#required' => TRUE,
  113. '#default_value' => $uniquename,
  114. );
  115. // Get the list of library types.
  116. $lt_cv = tripal_get_default_cv("library", "type_id");
  117. $types = tripal_get_cvterm_default_select_options('library', 'type_id', 'library types');
  118. $types[0] = 'Select a Type';
  119. $lt_message = tripal_set_message("To add additional items to the library type drop down list,
  120. add a term to the " .
  121. l($lt_cv->name . " controlled vocabulary",
  122. "admin/tripal/chado/tripal_cv/cv/" . $lt_cv->cv_id . "/cvterm/add",
  123. array('attributes' => array('target' => '_blank'))
  124. ),
  125. TRIPAL_INFO, array('return_html' => TRUE)
  126. );
  127. $form['library_type'] = array(
  128. '#title' => t('Library Type'),
  129. '#type' => t('select'),
  130. '#description' => t("Choose the library type."),
  131. '#required' => TRUE,
  132. '#default_value' => $library_type,
  133. '#options' => $types,
  134. '#suffix' => $lt_message,
  135. );
  136. // Get the list of organisms.
  137. $sql = "SELECT * FROM {organism}";
  138. $org_rset = chado_query($sql);
  139. $organisms = array();
  140. $organisms[''] = '';
  141. while ($organism = $org_rset->fetchObject()) {
  142. $organisms[$organism->organism_id] =
  143. "$organism->genus $organism->species ($organism->common_name)";
  144. }
  145. $form['organism_id'] = array(
  146. '#title' => t('Organism'),
  147. '#type' => t('select'),
  148. '#description' => t("Choose the organism with which this library is associated."),
  149. '#required' => TRUE,
  150. '#default_value' => $organism_id,
  151. '#options' => $organisms,
  152. );
  153. $form['description']= array(
  154. '#type' => 'text_format',
  155. '#title' => t('Library Description'),
  156. '#description' => t('A brief description of the library'),
  157. '#required' => TRUE,
  158. '#default_value' => $description,
  159. );
  160. // PROPERTIES FORM.
  161. //---------------------------------------------
  162. $prop_cv = tripal_get_default_cv('libraryprop', 'type_id');
  163. $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
  164. $details = array(
  165. // The name of the prop table.
  166. 'property_table' => 'libraryprop',
  167. // The value of library_id for this record.
  168. 'chado_id' => $library_id,
  169. // The cv.cv_id of the cv governing libraryprop.type_id.
  170. 'cv_id' => $cv_id,
  171. );
  172. // If the default is the 'library_property' vocabulary then we want
  173. // to exclude the 'Library Description' term since it has it's own form
  174. // element above
  175. if ($prop_cv->name == 'library_property') {
  176. // Generate our own select list so we can exclude the description element
  177. $select_options = array();
  178. $cv_result = chado_select_record('cv', array('cv_id'), array('name' => 'library_property'));
  179. $cv_id = $cv_result[0]->cv_id;
  180. $select_options = tripal_get_cvterm_select_options($cv_id);
  181. $descrip_id = array_search('Library Description', $select_options);
  182. unset($select_options[$descrip_id]);
  183. $details['select_options'] = $select_options;
  184. }
  185. // Adds the form elements to your current form
  186. chado_add_node_form_properties($form, $form_state, $details);
  187. // ADDITIONAL DBXREFS FORM
  188. //---------------------------------------------
  189. $details = array(
  190. // The name of the _dbxref table.
  191. 'linking_table' => 'library_dbxref',
  192. // The name of the key in your base chado table.
  193. 'base_foreign_key' => 'library_id',
  194. // The value of library_id for this record.
  195. 'base_key_value' => $library_id
  196. );
  197. // Adds the form elements to your current form
  198. chado_add_node_form_dbxrefs($form, $form_state, $details);
  199. return $form;
  200. }
  201. /**
  202. * Implements hook_validate().
  203. *
  204. * Validates submission of form when adding or updating a library node
  205. *
  206. * @ingroup tripal_library
  207. */
  208. function chado_library_validate($node, $form, &$form_state) {
  209. // We only want to validate when the node is saved.
  210. // Since this validate can be called on AJAX and Deletion of the node
  211. // we need to make this check to ensure queries are not executed
  212. // without the proper values.
  213. if(property_exists($node, "op") and $node->op != 'Save') {
  214. return;
  215. }
  216. // we are syncing if we do not have a node ID but we do have a featuremap_id. We don't
  217. // need to validate during syncing so just skip it.
  218. if (!property_exists($node, 'nid') and property_exists($node, 'library_id') and $node->library_id != 0) {
  219. return;
  220. }
  221. // trim white space from text fields
  222. $node->libraryname = property_exists($node, 'libraryname') ? trim($node->libraryname) : '';
  223. $node->uniquename = property_exists($node, 'uniquename') ? trim($node->uniquename) : '';
  224. $lib = 0;
  225. // check to make sure the unique name on the library is unique
  226. // before we try to insert into chado.
  227. if (property_exists($node, 'library_id')) {
  228. $sql = "
  229. SELECT *
  230. FROM {library}
  231. WHERE uniquename = :uname AND NOT library_id = :library_id
  232. ";
  233. $lib = chado_query($sql, array(':uname' => $node->uniquename, ':library_id' => $node->library_id))->fetchObject();
  234. }
  235. else {
  236. $sql = "SELECT * FROM {library} WHERE uniquename = :uname";
  237. $lib = chado_query($sql, array(':uname' => $node->uniquename))->fetchObject();
  238. }
  239. if ($lib) {
  240. form_set_error('uniquename', t('The unique library name already exists. Please choose another'));
  241. }
  242. }
  243. /**
  244. * Implements hook_insert().
  245. *
  246. * When a new chado_library node is created we also need to add information
  247. * to our chado_library table. This function is called on insert of a new node
  248. * of type 'chado_library' and inserts the necessary information.
  249. *
  250. * @ingroup tripal_library
  251. */
  252. function chado_library_insert($node) {
  253. $library_id = '';
  254. // if there is an library_id in the $node object then this must be a sync so
  255. // we can skip adding the library as it is already there, although
  256. // we do need to proceed with insertion into the chado/drupal linking table.
  257. if (!property_exists($node, 'library_id')) {
  258. $node->libraryname = trim($node->libraryname);
  259. $node->uniquename = trim($node->uniquename);
  260. $node->description = trim($node->description['value']);
  261. $values = array(
  262. 'name' => $node->libraryname,
  263. 'uniquename' => $node->uniquename,
  264. 'organism_id' => $node->organism_id,
  265. 'type_id' => $node->library_type,
  266. );
  267. $library = chado_insert_record('library', $values);
  268. if (!$library) {
  269. drupal_set_message(t('Unable to add library.', 'warning'));
  270. watchdog('tripal_library', 'Insert library: Unable to create library where values: %values',
  271. array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
  272. return;
  273. }
  274. $library_id = $library['library_id'];
  275. // * Properties Form *
  276. // add the description property
  277. $properties = chado_retrieve_node_form_properties($node);
  278. $descrip_id = tripal_get_cvterm(array(
  279. 'name' => 'Library Description',
  280. 'cv_id' => array('name' => 'library_property')
  281. ));
  282. $properties[$descrip_id->cvterm_id][0] = $node->description;
  283. $details = array(
  284. 'property_table' => 'libraryprop', // the name of the prop table
  285. 'base_table' => 'library', // the name of your chado base table
  286. 'foreignkey_name' => 'library_id', // the name of the key in your base table
  287. 'foreignkey_value' => $library_id // the value of the library_id key
  288. );
  289. chado_update_node_form_properties($node, $details, $properties);
  290. // * Additional DBxrefs Form *
  291. $details = array(
  292. 'linking_table' => 'library_dbxref', // the name of your _dbxref table
  293. 'foreignkey_name' => 'library_id', // the name of the key in your base table
  294. 'foreignkey_value' => $library_id // the value of the library_id key
  295. );
  296. chado_update_node_form_dbxrefs($node, $details);
  297. }
  298. else {
  299. $library_id = $node->library_id;
  300. }
  301. // Make sure the entry for this library doesn't already exist in the
  302. // chado_library table if it doesn't exist then we want to add it.
  303. $check_org_id = chado_get_id_from_nid('library', $node->nid);
  304. if (!$check_org_id) {
  305. $record = new stdClass();
  306. $record->nid = $node->nid;
  307. $record->vid = $node->vid;
  308. $record->library_id = $library_id;
  309. drupal_write_record('chado_library', $record);
  310. }
  311. }
  312. /**
  313. * Implements hook_update().
  314. *
  315. * @ingroup tripal_library
  316. */
  317. function chado_library_update($node) {
  318. $node->libraryname = trim($node->libraryname);
  319. $node->uniquename = trim($node->uniquename);
  320. $node->description = trim($node->description['value']);
  321. // update the library record
  322. $library_id = chado_get_id_from_nid('library', $node->nid);
  323. $match = array(
  324. 'library_id' => $library_id,
  325. );
  326. $values = array(
  327. 'name' => $node->libraryname,
  328. 'uniquename' => $node->uniquename,
  329. 'organism_id' => $node->organism_id,
  330. 'type_id' => $node->library_type,
  331. );
  332. $status = chado_update_record('library', $match, $values);
  333. if (!$status) {
  334. drupal_set_message(t('Unable to update library.', 'warning'));
  335. watchdog('tripal_library', 'Update library: Unable to update library where values: %values',
  336. array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
  337. }
  338. // * Properties Form *
  339. // add the description property
  340. $properties = chado_retrieve_node_form_properties($node);
  341. $descrip_id = tripal_get_cvterm(array(
  342. 'name' => 'Library Description',
  343. 'cv_id' => array('name' => 'library_property')
  344. ));
  345. $properties[$descrip_id->cvterm_id][0] = $node->description;
  346. $details = array(
  347. 'property_table' => 'libraryprop', // the name of the prop table
  348. 'base_table' => 'library', // the name of your chado base table
  349. 'foreignkey_name' => 'library_id', // the name of the key in your base table
  350. 'foreignkey_value' => $library_id // the value of the library_id key
  351. );
  352. chado_update_node_form_properties($node, $details, $properties);
  353. // * Additional DBxrefs Form *
  354. $details = array(
  355. 'linking_table' => 'library_dbxref', // the name of your _dbxref table
  356. 'foreignkey_name' => 'library_id', // the name of the key in your base table
  357. 'foreignkey_value' => $library_id // the value of the library_id key
  358. );
  359. chado_update_node_form_dbxrefs($node, $details);
  360. }
  361. /**
  362. * Implements hook_load().
  363. *
  364. * When a node is requested by the user this function is called to allow us
  365. * to add auxiliary data to the node object.
  366. *
  367. * @ingroup tripal_library
  368. */
  369. function chado_library_load($nodes) {
  370. foreach ($nodes as $nid => $node) {
  371. // get the feature details from chado
  372. $library_id = chado_get_id_from_nid('library', $node->nid);
  373. // if the nid does not have a matching record then skip this node.
  374. // this can happen with orphaned nodes.
  375. if (!$library_id) {
  376. continue;
  377. }
  378. $values = array('library_id' => $library_id);
  379. $library = chado_generate_var('library', $values);
  380. // the uniquename field is a text field so we need to expand it
  381. $library = chado_expand_var($library, 'field', 'library.uniquename');
  382. $nodes[$nid]->library = $library;
  383. // Now get the title
  384. $node->title = chado_get_node_title($node);
  385. }
  386. }
  387. /**
  388. * Implements hook_delete().
  389. *
  390. * Delete data from drupal and chado databases when a node is deleted
  391. *
  392. * @ingroup tripal_library
  393. */
  394. function chado_library_delete(&$node) {
  395. $library_id = chado_get_id_from_nid('library', $node->nid);
  396. // if we don't have a library id for this node then this isn't a node of
  397. // type chado_library or the entry in the chado_library table was lost.
  398. if (!$library_id) {
  399. return;
  400. }
  401. // Remove data from {chado_library}, {node} and {node_revisions} tables of
  402. // drupal database
  403. $sql_del = "DELETE FROM {chado_library} WHERE nid = :nid AND vid = :vid";
  404. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  405. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  406. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  407. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  408. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  409. // Remove data from library and libraryprop tables of chado database as well
  410. chado_query("DELETE FROM {libraryprop} WHERE library_id = :library_id", array(':library_id' => $library_id));
  411. chado_query("DELETE FROM {library} WHERE library_id = :library_id", array(':library_id' => $library_id));
  412. }
  413. /**
  414. * Implement hook_node_access().
  415. *
  416. * This hook allows node modules to limit access to the node types they define.
  417. *
  418. * @param $node
  419. * The node on which the operation is to be performed, or, if it does not yet exist, the
  420. * type of node to be created
  421. *
  422. * @param $op
  423. * The operation to be performed
  424. *
  425. * @param $account
  426. * A user object representing the user for whom the operation is to be performed
  427. *
  428. * @return
  429. * If the permission for the specified operation is not set then return FALSE. If the
  430. * permission is set then return NULL as this allows other modules to disable
  431. * access. The only exception is when the $op == 'create'. We will always
  432. * return TRUE if the permission is set.
  433. *
  434. * @ingroup tripal_library
  435. */
  436. function chado_library_node_access($node, $op, $account) {
  437. $node_type = $node;
  438. if (is_object($node)) {
  439. $node_type = $node->type;
  440. }
  441. if($node_type == 'chado_library') {
  442. if ($op == 'create') {
  443. if (!user_access('create chado_library content', $account)) {
  444. return NODE_ACCESS_DENY;
  445. }
  446. return NODE_ACCESS_ALLOW;
  447. }
  448. if ($op == 'update') {
  449. if (!user_access('edit chado_library content', $account)) {
  450. return NODE_ACCESS_DENY;
  451. }
  452. }
  453. if ($op == 'delete') {
  454. if (!user_access('delete chado_library content', $account)) {
  455. return NODE_ACCESS_DENY;
  456. }
  457. }
  458. if ($op == 'view') {
  459. if (!user_access('access chado_library content', $account)) {
  460. return NODE_ACCESS_DENY;
  461. }
  462. }
  463. return NODE_ACCESS_IGNORE;
  464. }
  465. }
  466. /**
  467. * Implements hook_node_view(). Acts on all content types
  468. *
  469. * @ingroup tripal_library
  470. */
  471. function tripal_library_node_view($node, $view_mode, $langcode) {
  472. switch ($node->type) {
  473. case 'chado_library':
  474. if ($view_mode == 'full') {
  475. $node->content['tripal_library_base'] = array(
  476. '#theme' => 'tripal_library_base',
  477. '#node' => $node,
  478. '#tripal_toc_id' => 'base',
  479. '#tripal_toc_title' => 'Overview',
  480. '#weight' => -100,
  481. );
  482. $node->content['tripal_library_features'] = array(
  483. '#theme' => 'tripal_library_features',
  484. '#node' => $node,
  485. '#tripal_toc_id' => 'features',
  486. '#tripal_toc_title' => 'Features',
  487. );
  488. $node->content['tripal_library_properties'] = array(
  489. '#theme' => 'tripal_library_properties',
  490. '#node' => $node,
  491. '#tripal_toc_id' => 'properties',
  492. '#tripal_toc_title' => 'Properties',
  493. );
  494. $node->content['tripal_library_publications'] = array(
  495. '#theme' => 'tripal_library_publications',
  496. '#node' => $node,
  497. '#tripal_toc_id' => 'publications',
  498. '#tripal_toc_title' => 'Publications',
  499. );
  500. $node->content['tripal_library_references'] = array(
  501. '#theme' => 'tripal_library_references',
  502. '#node' => $node,
  503. '#tripal_toc_id' => 'references',
  504. '#tripal_toc_title' => 'Cross References',
  505. );
  506. $node->content['tripal_library_synonyms'] = array(
  507. '#theme' => 'tripal_library_synonyms',
  508. '#node' => $node,
  509. '#tripal_toc_id' => 'synonyms',
  510. '#tripal_toc_title' => 'Synonyms',
  511. );
  512. $node->content['tripal_library_terms'] = array(
  513. '#theme' => 'tripal_library_terms',
  514. '#node' => $node,
  515. '#tripal_toc_id' => 'terms',
  516. '#tripal_toc_title' => 'Annotated Terms',
  517. );
  518. }
  519. if ($view_mode == 'teaser') {
  520. $node->content['tripal_library_teaser'] = array(
  521. '#theme' => 'tripal_library_teaser',
  522. '#node' => $node,
  523. );
  524. }
  525. break;
  526. case 'chado_organism':
  527. if ($view_mode == 'full') {
  528. $node->content['tripal_organism_libraries'] = array(
  529. '#theme' => 'tripal_organism_libraries',
  530. '#node' => $node,
  531. '#tripal_toc_id' => 'libraries',
  532. '#tripal_toc_title' => 'Libraries',
  533. );
  534. }
  535. break;
  536. case 'chado_feature':
  537. if ($view_mode == 'full') {
  538. $node->content['tripal_feature_libraries'] = array(
  539. '#theme' => 'tripal_feature_libraries',
  540. '#node' => $node,
  541. '#tripal_toc_id' => 'libraries',
  542. '#tripal_toc_title' => 'Libraries',
  543. );
  544. }
  545. break;
  546. }
  547. }
  548. /**
  549. * Implements hook_node_presave(). Acts on all node content types.
  550. *
  551. * @ingroup tripal_library
  552. */
  553. function tripal_library_node_presave($node) {
  554. switch ($node->type) {
  555. // This step is for setting the title for the Drupal node. This title
  556. // is permanent and thus is created to be unique. Title changes provided
  557. // by tokens are generated on the fly dynamically, but the node title
  558. // seen in the content listing needs to be set here. Do not call
  559. // the chado_get_node_title() function here to set the title as the node
  560. // object isn't properly filled out and the function will fail.
  561. case 'chado_library':
  562. // for a form submission the 'libraryname' field will be set,
  563. // for a sync, we must pull from the library object
  564. if (property_exists($node, 'libraryname')) {
  565. // set the title
  566. $node->title = $node->libraryname;
  567. }
  568. else if (property_exists($node, 'library')) {
  569. $node->title = $node->library->name;
  570. }
  571. break;
  572. }
  573. }
  574. /**
  575. * Implements hook_node_insert().
  576. * Acts on all content types.
  577. *
  578. * @ingroup tripal_library
  579. */
  580. function tripal_library_node_insert($node) {
  581. switch ($node->type) {
  582. case 'chado_library':
  583. $library_id = chado_get_id_from_nid('library', $node->nid);
  584. $values = array('library_id' => $library_id);
  585. $library = chado_generate_var('library', $values);
  586. $library = chado_expand_var($library, 'field', 'library.uniquename');
  587. $node->library = $library;
  588. // Now get the title
  589. $node->title = chado_get_node_title($node);
  590. // Now use the API to set the path.
  591. chado_set_node_url($node);
  592. break;
  593. }
  594. }
  595. /**
  596. * Implements hook_node_update().
  597. * Acts on all content types.
  598. *
  599. * @ingroup tripal_library
  600. */
  601. function tripal_library_node_update($node) {
  602. switch ($node->type) {
  603. case 'chado_library':
  604. // Now get the title
  605. $node->title = chado_get_node_title($node);
  606. // Now use the API to set the path.
  607. chado_set_node_url($node);
  608. break;
  609. }
  610. }
  611. /**
  612. * Implements [content_type]_chado_node_default_title_format().
  613. *
  614. * Defines a default title format for the Chado Node API to set the titles on
  615. * Chado library nodes based on chado fields.
  616. */
  617. function chado_library_chado_node_default_title_format() {
  618. return '[library.name], [library.uniquename] ([library.type_id>cvterm.name])';
  619. }
  620. /**
  621. * Implements hook_chado_node_default_url_format().
  622. *
  623. * Designates a default URL format for library nodes.
  624. */
  625. function chado_library_chado_node_default_url_format() {
  626. return '/library/[library.organism_id>organism.genus]/[library.organism_id>organism.species]/[library.type_id>cvterm.name]/[library.uniquename]';
  627. }