tripal_analysis.module 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. <?php
  2. /**
  3. * @file
  4. * Contains all the main hook implementations for the tripal_analysis module
  5. *
  6. * @defgroup tripal_analysis Analysis Module
  7. * @ingroup tripal_modules
  8. * @{
  9. * Provides functions for managing chado analysis' including creating details pages for each one
  10. *
  11. * @}
  12. *
  13. *
  14. */
  15. require('api/tripal_analysis.api.inc');
  16. require('includes/tripal_analysis_privacy.inc');
  17. require('includes/tripal_analysis.admin.inc');
  18. require('includes/tripal_analysis.form.inc');
  19. require('includes/tripal_analysis.sync.inc');
  20. /**
  21. * Add tripal javascript to page headers
  22. *
  23. * @ingroup tripal_analysis
  24. */
  25. function tripal_analysis_init() {
  26. drupal_add_js(drupal_get_path('module', 'tripal_analysis') . '/theme/js/tripal_analysis.js');
  27. drupal_add_css(drupal_get_path('module', 'tripal_analysis') . '/theme/css/tripal_analysis.css');
  28. }
  29. /**
  30. * Provide information to drupal about the node types that we're creating
  31. * in this module
  32. *
  33. * @ingroup tripal_analysis
  34. */
  35. function tripal_analysis_node_info() {
  36. $nodes = array();
  37. $nodes['chado_analysis'] = array(
  38. 'name' => t('Analysis'),
  39. 'base' => 'chado_analysis',
  40. 'description' => t('An analysis'),
  41. 'has_title' => FALSE,
  42. 'title_label' => t('Analysis'),
  43. 'locked' => TRUE
  44. );
  45. return $nodes;
  46. }
  47. /**
  48. * Implementation of hook_menu().
  49. * Entry points and paths of the module
  50. *
  51. * @ingroup tripal_analysis
  52. */
  53. function tripal_analysis_menu() {
  54. //Sync analysis
  55. $items['chado_sync_analyses'] = array(
  56. 'title' => 'Sync Data',
  57. 'page callback' => 'tripal_analysis_sync_analyses',
  58. 'access arguments' => array('administer tripal analyses'),
  59. 'type' => MENU_CALLBACK
  60. );
  61. // Tripal Analysis administrative settings
  62. $items['admin/tripal/chado/tripal_analysis'] = array(
  63. 'title' => 'Analyses',
  64. 'description' => 'A bioinformatics analysis producing features.',
  65. 'access arguments' => array('administer tripal analyses'),
  66. 'type' => MENU_NORMAL_ITEM,
  67. );
  68. $items['admin/tripal/chado/tripal_analysis/help'] = array(
  69. 'title' => 'Help',
  70. 'description' => "A description of the Tripal Analysis module including a short description of it's usage.",
  71. 'page callback' => 'theme',
  72. 'page arguments' => array('tripal_analysis_help'),
  73. 'access arguments' => array('administer tripal analyses'),
  74. 'type' => MENU_NORMAL_ITEM,
  75. );
  76. $items['admin/tripal/chado/tripal_analysis/configuration'] = array(
  77. 'title' => 'Configuration',
  78. 'description' => 'Settings for the displays of analysis results.',
  79. 'page callback' => 'drupal_get_form',
  80. 'page arguments' => array('tripal_analysis_admin'),
  81. 'access arguments' => array('administer tripal analyses'),
  82. 'type' => MENU_NORMAL_ITEM,
  83. );
  84. $items['admin/tripal/chado/tripal_analysis/sync'] = array(
  85. 'title' => 'Sync Analyses',
  86. 'description' => 'Sync Chado analyses with Drupal.',
  87. 'page callback' => 'drupal_get_form',
  88. 'page arguments' => array('tripal_analysis_sync_form'),
  89. 'access arguments' => array('administer tripal analyses'),
  90. 'type' => MENU_NORMAL_ITEM,
  91. );
  92. $items['tripal_analysis/properties/minus/%/%'] = array(
  93. 'page callback' => 'tripal_analysis_property_delete',
  94. 'page arguments' => array(3, 4),
  95. 'access arguments' => array('edit chado_analysis content'),
  96. 'type ' => MENU_CALLBACK,
  97. );
  98. return $items;
  99. }
  100. /**
  101. * Implements hook_help()
  102. * Purpose: Adds a help page to the module list
  103. */
  104. function tripal_analysis_help ($path, $arg) {
  105. if ($path == 'admin/help#tripal_analysis') {
  106. return theme('tripal_analysis_help', array());
  107. }
  108. }
  109. /**
  110. * Set the permission types that the chado module uses. Essentially we
  111. * want permissionis that protect creation, editing and deleting of chado
  112. * data objects
  113. *
  114. * @ingroup tripal_analysis
  115. */
  116. function tripal_analysis_permission() {
  117. return array(
  118. 'access chado_analysis content' => array(
  119. 'title' => t('View Analyses'),
  120. 'description' => t('Allow users to view analysis pages.'),
  121. ),
  122. 'create chado_analysis content' => array(
  123. 'title' => t('Create Analyses'),
  124. 'description' => t('Allow users to create new analysis pages.'),
  125. ),
  126. 'delete chado_analysis content' => array(
  127. 'title' => t('Delete Analyses'),
  128. 'description' => t('Allow users to delete analysis pages.'),
  129. ),
  130. 'edit chado_analysis content' => array(
  131. 'title' => t('Edit Analyses'),
  132. 'description' => t('Allow users to edit analysis pages.'),
  133. ),
  134. 'adminster tripal analysis' => array(
  135. 'title' => t('Administer Analyses'),
  136. 'description' => t('Allow users to administer all analyses.'),
  137. ),
  138. );
  139. }
  140. /**
  141. * We need to let drupal know about our theme functions and their arguments.
  142. * We create theme functions to allow users of the module to customize the
  143. * look and feel of the output generated in this module
  144. *
  145. * @ingroup tripal_analysis
  146. */
  147. function tripal_analysis_theme($existing, $type, $theme, $path) {
  148. $core_path = drupal_get_path('module', 'tripal_core');
  149. $theme_path = drupal_get_path('module', 'tripal_analysis') . '/theme';
  150. $items = array(
  151. 'node__chado_analysis' => array(
  152. 'template' => 'node--chado-generic',
  153. 'render element' => 'node',
  154. 'base hook' => 'node',
  155. 'path' => "$core_path/theme",
  156. ),
  157. 'tripal_analysis_base' => array(
  158. 'variables' => array('node' => NULL),
  159. 'template' => 'tripal_analysis_base',
  160. 'path' => "$path/theme/tripal_analysis",
  161. ),
  162. 'tripal_feature_analyses' => array(
  163. 'template' => 'tripal_feature_analyses',
  164. 'variables' => array('node' => NULL),
  165. 'path' => "$path/theme/tripal_analysis",
  166. ),
  167. 'tripal_analysis_properties' => array(
  168. 'variables' => array('node' => NULL),
  169. 'path' => "$path/theme/tripal_analysis",
  170. ),
  171. 'tripal_analysis_help' => array(
  172. 'template' => 'tripal_analysis_help',
  173. 'variables' => array(NULL),
  174. 'path' => "$path/theme",
  175. ),
  176. 'chado_analysis_node_form' => array(
  177. 'variables' => array('form'),
  178. 'path' => $theme_path,
  179. ),
  180. );
  181. return $items;
  182. }
  183. /**
  184. *
  185. *
  186. * @ingroup tripal_analysis
  187. */
  188. function tripal_analysis_block_info() {
  189. $blocks['base']['info'] = t('Tripal Analysis Details');
  190. $blocks['base']['cache'] = DRUPAL_NO_CACHE;
  191. $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
  192. $blocks['featureblast']['cache'] = DRUPAL_NO_CACHE;
  193. return $blocks;
  194. }
  195. /**
  196. *
  197. *
  198. * @ingroup tripal_analysis
  199. */
  200. function tripal_analysis_block_view($delta = '') {
  201. if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
  202. $nid = arg(1);
  203. $node = node_load($nid);
  204. $block = array();
  205. switch ($delta) {
  206. case 'base':
  207. $block['subject'] = t('Analysis Details');
  208. $block['content'] = theme('tripal_analysis_base', $node);
  209. break;
  210. case 'tripal_feature_analyses':
  211. $block['subject'] = t('Feature Analyses');
  212. $block['content'] = theme('tripal_feature_analyses', $node);
  213. break;
  214. default :
  215. }
  216. return $block;
  217. }
  218. }
  219. /**
  220. *
  221. * @ingroup tripal_feature
  222. */
  223. function tripal_analysis_node_view($node, $view_mode, $langcode) {
  224. switch ($node->type) {
  225. case 'chado_analysis':
  226. // Show feature browser and counts
  227. if ($view_mode == 'full') {
  228. $node->content['tripal_analysis_base'] = array(
  229. '#value' => theme('tripal_analysis_base', array('node' => $node)),
  230. );
  231. $node->content['tripal_analysis_properties'] = array(
  232. '#value' => theme('tripal_analysis_properties', array('node' => $node)),
  233. );
  234. }
  235. break;
  236. }
  237. }
  238. /**
  239. * Implements hook_views_api()
  240. * Purpose: Essentially this hook tells drupal that there is views support for
  241. * for this module which then includes tripal_analysis.views.inc where all the
  242. * views integration code is
  243. *
  244. * @ingroup tripal_analysis
  245. */
  246. function tripal_analysis_views_api() {
  247. return array(
  248. 'api' => 2.0,
  249. );
  250. }
  251. /*
  252. *
  253. */
  254. function tripal_analysis_form_alter(&$form, &$form_state, $form_id) {
  255. if ($form_id == "chado_analysis_node_form") {
  256. }
  257. }
  258. /**
  259. * When a new chado_analysis node is created we also need to add information
  260. * to our chado_analysis table. This function is called on insert of a new
  261. * node of type 'chado_analysis' and inserts the necessary information.
  262. *
  263. * @ingroup tripal_analysis
  264. */
  265. function chado_analysis_insert($node) {
  266. $node->analysisname = trim($node->analysisname);
  267. $node->description = trim($node->description);
  268. $node->program = trim($node->program);
  269. $node->programversion = trim($node->programversion);
  270. $node->algorithm = trim($node->algorithm);
  271. $node->sourcename = trim($node->sourcename);
  272. $node->sourceversion = trim($node->sourceversion);
  273. $node->sourceuri = trim($node->sourceuri);
  274. // if there is an analysis_id in the $node object then this must be a sync so
  275. // we can skip adding the analysis as it is already there, although
  276. // we do need to proceed with the rest of the insert
  277. if (!property_exists($node,'analysis_id')) {
  278. // Create a timestamp so we can insert it into the chado database
  279. $time = $node->timeexecuted;
  280. $month = $time['month'];
  281. $day = $time['day'];
  282. $year = $time['year'];
  283. $timestamp = $month . '/' . $day . '/' . $year;
  284. // insert and then get the newly inserted analysis record
  285. $values = array(
  286. 'name' => $node->analysisname,
  287. 'description' => $node->description,
  288. 'program' => $node->program,
  289. 'programversion' => $node->programversion,
  290. 'algorithm' => $node->algorithm,
  291. 'sourcename' => $node->sourcename,
  292. 'sourceversion' => $node->sourceversion,
  293. 'sourceuri' => $node->sourceuri,
  294. 'timeexecuted' => $timestamp
  295. );
  296. $analysis = tripal_core_chado_insert('analysis', $values);
  297. if (!$analysis) {
  298. drupal_set_message(t('Unable to add analysis.', 'warning'));
  299. watchdog('tripal_analysis', 'Insert analysis: Unable to create analysis where values:%values',
  300. array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
  301. return;
  302. }
  303. $analysis_id = $analysis['analysis_id'];
  304. }
  305. else {
  306. $analysis_id = $node->analysis_id;
  307. }
  308. // Make sure the entry for this analysis doesn't already exist in the
  309. // chado_analysis table if it doesn't exist then we want to add it.
  310. $check_org_id = chado_get_id_for_node('analysis', $node->nid);
  311. if (!$check_org_id) {
  312. $record = new stdClass();
  313. $record->nid = $node->nid;
  314. $record->vid = $node->vid;
  315. $record->analysis_id = $analysis_id;
  316. drupal_write_record('chado_analysis', $record);
  317. }
  318. // add the analysis to the node object for
  319. // use by other analysis modules that may be using this function
  320. $node->analysis = $analysis;
  321. $node->analysis_id = $analysis_id; // we need to set this for children
  322. // now add the properties
  323. $properties = array(); // stores all of the properties we need to add
  324. // get the list of properties for easy lookup (without doing lots of database queries
  325. $properties_list = array();
  326. $sql = "
  327. SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
  328. FROM {cvterm} CVT
  329. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  330. WHERE
  331. CV.name = 'analysis_property' AND
  332. NOT CVT.is_obsolete = 1
  333. ORDER BY CVT.name ASC
  334. ";
  335. $prop_types = chado_query($sql);
  336. while ($prop = $prop_types->fetchObject()) {
  337. $properties_list[$prop->cvterm_id] = $prop->name;
  338. }
  339. // get the properties that should be added. Properties are in one of two forms:
  340. // 1) prop_value-[type id]-[index]
  341. // 2) new_value-[type id]-[index]
  342. // 3) new_id, new_value
  343. foreach ($node as $name => $value) {
  344. if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
  345. $type_id = $matches[1];
  346. $index = $matches[2];
  347. $name = $properties_list[$type_id];
  348. $properties[$name][$index] = trim($value);
  349. }
  350. }
  351. if ($node->new_id and $node->new_value) {
  352. $type_id = $node->new_id;
  353. $name = $properties_list[$type_id];
  354. $index = count($properties[$name]);
  355. $properties[$name][$index] = trim($node->new_value);
  356. }
  357. // now add in the properties
  358. foreach ($properties as $property => $elements) {
  359. foreach ($elements as $rank => $value) {
  360. $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE, 'analysis_property');
  361. if (!$status) {
  362. drupal_set_message("Error cannot add property: $property", "error");
  363. watchdog('t_analysis', "Error cannot add property: %prop",
  364. array('%property' => $property), WATCHDOG_ERROR);
  365. }
  366. }
  367. }
  368. }
  369. /**
  370. * Removes analysis from the chado database
  371. *
  372. * @param $node
  373. * The node object specifying which chado record to delete
  374. *
  375. * @ingroup tripal_analysis
  376. */
  377. function chado_analysis_delete($node) {
  378. $analysis_id = chado_get_id_for_node('analysis', $node->nid);
  379. // if we don't have an analysis id for this node then this isn't a node of
  380. // type chado_analysis or the entry in the chado_analysis table was lost.
  381. if (!$analysis_id) {
  382. return;
  383. }
  384. // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
  385. $sql_del = "DELETE FROM {chado_analysis} WHERE nid = :nid AND vid = :vid";
  386. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  387. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  388. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  389. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  390. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  391. //Remove from analysis and analysisprop tables of chado database as well
  392. chado_query("DELETE FROM {analysis} WHERE analysis_id = :analysis_id", array(':analysis_id' => $analysis_id));
  393. }
  394. /**
  395. * Update analyses
  396. *
  397. * @param $node
  398. * The updated node object
  399. *
  400. * @ingroup tripal_analysis
  401. */
  402. function chado_analysis_update($node) {
  403. $node->analysisname = trim($node->analysisname);
  404. $node->description = trim($node->description);
  405. $node->program = trim($node->program);
  406. $node->programversion = trim($node->programversion);
  407. $node->algorithm = trim($node->algorithm);
  408. $node->sourcename = trim($node->sourcename);
  409. $node->sourceversion = trim($node->sourceversion);
  410. $node->sourceuri = trim($node->sourceuri);
  411. if ($node->revision) {
  412. // TODO -- decide what to do about revisions
  413. }
  414. // Create a timestamp so we can insert it into the chado database
  415. $time = $node->timeexecuted;
  416. $month = $time['month'];
  417. $day = $time['day'];
  418. $year = $time['year'];
  419. $timestamp = $month . '/' . $day . '/' . $year;
  420. // get the analysis_id for this node:
  421. $sql = "
  422. SELECT analysis_id
  423. FROM {chado_analysis}
  424. WHERE nid = :nid
  425. ";
  426. $analysis = db_query($sql, array(':nid' => $node->nid))->fetchObject();
  427. $analysis_id = $analysis->analysis_id;
  428. $sql = "
  429. UPDATE {analysis}
  430. SET name = :name,
  431. description = :description,
  432. program = :program,
  433. programversion = :programversion,
  434. algorithm = :algorithm,
  435. sourcename = :sourcename,
  436. sourceversion = :sourceversion,
  437. sourceuri = :sourceuri,
  438. timeexecuted = :timeexecuted
  439. WHERE analysis_id = :analysis_id
  440. ";
  441. $args = array(
  442. ':name' => $node->analysisname,
  443. ':description' => $node->description,
  444. ':program' => $node->program,
  445. ':programversion' => $node->programversion,
  446. ':algorithm' => $node->algorithm,
  447. ':sourcename' => $node->sourcename,
  448. ':sourceversion' => $node->sourceversion,
  449. ':sourceuri' => $node->sourceuri,
  450. ':timeexecuted' => $timestamp,
  451. ':analysis_id' => $anslysis_id
  452. );
  453. chado_query($sql, $args);
  454. // Create a title for the analysis node using the unique keys so when the
  455. // node is saved, it will have a title
  456. $record = new stdClass();
  457. // If the analysis has a name, use it as the node title. If not, construct
  458. // the title using program, programversion, and sourcename
  459. if ($node->analysisname) {
  460. $record->title = $node->analysisname;
  461. }
  462. else {
  463. //Construct node title as "program (version)
  464. $record->title = "$node->program ($node->programversion)";
  465. }
  466. $record->nid = $node->nid;
  467. drupal_write_record('node', $record, 'nid');
  468. drupal_write_record('node_revisions', $record, 'nid');
  469. // now update the properties
  470. $properties = array(); // stores all of the properties we need to add
  471. // get the list of properties for easy lookup (without doing lots of database queries
  472. $properties_list = array();
  473. $sql = "
  474. SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
  475. FROM {cvterm} CVT
  476. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  477. WHERE
  478. CV.name = 'analysis_property' AND
  479. NOT CVT.is_obsolete = 1
  480. ORDER BY CVT.name ASC
  481. ";
  482. $prop_types = chado_query($sql);
  483. while ($prop = $prop_types->fetchObject()) {
  484. $properties_list[$prop->cvterm_id] = $prop->name;
  485. }
  486. // get the properties that should be added. Properties are in one of three forms:
  487. // 1) prop_value-[type id]-[index]
  488. // 2) new_value-[type id]-[index]
  489. // 3) new_id, new_value
  490. // dpm($node);
  491. foreach ($node as $key => $value) {
  492. if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
  493. $type_id = $matches[1];
  494. $index = $matches[2];
  495. $name = $properties_list[$type_id];
  496. $properties[$name][$index] = trim($value);
  497. }
  498. if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
  499. $type_id = $matches[1];
  500. $index = $matches[2];
  501. $name = $properties_list[$type_id];
  502. $properties[$name][$index] = trim($value);
  503. }
  504. }
  505. if ($node->new_id and $node->new_value) {
  506. $type_id = $node->new_id;
  507. $name = $properties_list[$type_id];
  508. $index = count($properties[$name]);
  509. $properties[$name][$index] = trim($node->new_value);
  510. }
  511. // now add in the properties by first removing any the analysis
  512. // already has and adding the ones we have
  513. $sql = "
  514. DELETE FROM {analysisprop} WHERE analysis_id = :analysis_id AND type_id IN (
  515. SELECT CVT.cvterm_id
  516. FROM {cvterm} CVT
  517. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  518. WHERE CV.name = 'analysis_property')
  519. ";
  520. $success = chado_query($sql, array(':analysis_id' => $analysis_id));
  521. if (!$success) {
  522. drupal_set_message("Cannot update analysis properties", "error");
  523. watchdog('t_analysis', "Cannot update analysis properties.", array(), WATCHDOG_ERROR);
  524. return;
  525. }
  526. foreach ($properties as $property => $elements) {
  527. foreach ($elements as $rank => $value) {
  528. $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE, 'analysis_property');
  529. if (!$status) {
  530. drupal_set_message("Error cannot add property: '$property'", "error");
  531. watchdog('t_analysis', "Error cannot add property: '%prop'",
  532. array('%prop' => $property), WATCHDOG_ERROR);
  533. }
  534. }
  535. }
  536. }
  537. /**
  538. * When a node is requested by the user this function is called to allow us
  539. * to add auxiliary data to the node object.
  540. *
  541. * @ingroup tripal_analysis
  542. */
  543. function chado_analysis_load($nodes) {
  544. foreach ($nodes as $nid => $node) {
  545. // find the analysis and add in the details
  546. $analysis_id = chado_get_id_for_node('analysis', $nid);
  547. // build the analysis variable
  548. $values = array('analysis_id' => $analysis_id);
  549. $analysis = tripal_core_generate_chado_var('analysis', $values);
  550. // add in the description field
  551. $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
  552. $nodes[$nid]->analysis = $analysis;
  553. }
  554. }
  555. /**
  556. * This function customizes the view of the chado_analysis node. It allows
  557. * us to generate the markup.
  558. *
  559. * @ingroup tripal_analysis
  560. */
  561. function chado_analysis_view($node, $teaser = FALSE, $page = FALSE) {
  562. // use drupal's default node view:
  563. if (!$teaser) {
  564. $node = node_prepare($node, $teaser);
  565. // When previewing a node submitting form, it shows 'Array' instead of
  566. // correct date format. We need to format the date here
  567. $time = $node->timeexecuted;
  568. if (is_array($time)) {
  569. $month = $time['month'];
  570. $day = $time['day'];
  571. $year = $time['year'];
  572. $timestamp = $year . '-' . $month . '-' . $day;
  573. $node->timeexecuted = $timestamp;
  574. }
  575. }
  576. return $node;
  577. }
  578. /**
  579. * Implement hook_access().
  580. *
  581. * This hook allows node modules to limit access to the node types they define.
  582. *
  583. * @param $node
  584. * The node on which the operation is to be performed, or, if it does not yet exist, the
  585. * type of node to be created
  586. *
  587. * @param $op
  588. * The operation to be performed
  589. *
  590. * @param $account
  591. * A user object representing the user for whom the operation is to be performed
  592. *
  593. * @return
  594. * If the permission for the specified operation is not set then return FALSE. If the
  595. * permission is set then return NULL as this allows other modules to disable
  596. * access. The only exception is when the $op == 'create'. We will always
  597. * return TRUE if the permission is set.
  598. *
  599. * @ingroup tripal_analysis
  600. */
  601. function chado_analysis_node_access($node, $op, $account) {
  602. if ($op == 'create') {
  603. if (!user_access('create chado_analysis content', $account)) {
  604. return FALSE;
  605. }
  606. return TRUE;
  607. }
  608. if ($op == 'update') {
  609. if (!user_access('edit chado_analysis content', $account)) {
  610. return FALSE;
  611. }
  612. }
  613. if ($op == 'delete') {
  614. if (!user_access('delete chado_analysis content', $account)) {
  615. return FALSE;
  616. }
  617. }
  618. if ($op == 'view') {
  619. if (!user_access('access chado_analysis content', $account)) {
  620. return FALSE;
  621. }
  622. }
  623. return NULL;
  624. }