tripal_core.module 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Core module
  5. */
  6. /**
  7. * @defgroup tripal_core Tripal Core Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * Functionality useful for all other Tripal modules including the Tripal jobs, files,
  11. * materialized views and custom table functions.
  12. * @}
  13. */
  14. // Import the full Tripal API into Scope.
  15. tripal_core_import_api();
  16. // INCLUDES
  17. require_once 'includes/tripal_core.jobs.inc';
  18. require_once 'includes/tripal_core.mviews.inc';
  19. require_once 'includes/tripal_core.custom_tables.inc';
  20. require_once 'includes/tripal_core.chado_install.inc';
  21. require_once 'includes/tripal_core.form_elements.inc';
  22. require_once 'includes/tripal_core.search.inc';
  23. // Set some global variables.
  24. tripal_core_set_globals();
  25. /**
  26. * This function is used to set the global Chado variables
  27. *
  28. * @ingroup tripal_core
  29. */
  30. function tripal_core_set_globals() {
  31. // these global variables are meant to be accessed by all Tripal
  32. // modules to find the chado version installed and if Chado is local.
  33. // these variables are stored as globals rather than using the drupal_set_variable
  34. // functions because the Drupal functions make databaes queries and for long
  35. // running loaders we don't want those queries repeatedly.
  36. $GLOBALS["chado_is_installed"] = chado_is_installed();
  37. if ($GLOBALS["chado_is_installed"]) {
  38. $GLOBALS["chado_is_local"] = chado_is_local();
  39. $GLOBALS["chado_version"] = chado_get_version();
  40. $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
  41. }
  42. }
  43. /**
  44. * Implements hook_init().
  45. * Used to set the search_path, create default content and set default variables.
  46. *
  47. * @ingroup tripal_core
  48. */
  49. function tripal_core_init() {
  50. global $base_url;
  51. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  52. // only if the chado database is present.
  53. if ($GLOBALS["chado_is_installed"]) {
  54. // if the Tripal cv is missing then add
  55. $results = chado_query("SELECT * FROM {cv} WHERE name = 'tripal'");
  56. $tripal_cv = $results->fetchObject();
  57. if (!$tripal_cv) {
  58. $results = chado_query(
  59. "INSERT INTO {cv} (name,definition) " .
  60. "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')"
  61. );
  62. }
  63. // if the Tripal db is missing then add it
  64. $results = chado_query("SELECT * FROM {db} WHERE name = 'tripal'");
  65. $tripal_db = $results->fetchObject();
  66. if (!$tripal_db) {
  67. $results = chado_query(
  68. "INSERT INTO {db} (name,description) " .
  69. "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')"
  70. );
  71. }
  72. }
  73. // add some variables for all javasript to use for building URLs
  74. $theme_dir = drupal_get_path('theme', 'tripal');
  75. $clean_urls = variable_get('clean_url', 0);
  76. drupal_add_js(
  77. " var baseurl = '$base_url';
  78. var themedir = '$theme_dir';
  79. var isClean = $clean_urls;",
  80. 'inline', 'header');
  81. // make sure the date time settings are the way Tripal will insert them
  82. // otherwise PostgreSQL version that may have a different datestyle setting
  83. // will fail when inserting or updating a date column in a table.
  84. db_query("SET DATESTYLE TO :style", array(':style' => 'MDY'));
  85. // If we want AHAH elements on the node forms (e.g. chado_pub form) then we need to include
  86. // the node.pages file. Otherwise this error message is given:
  87. //
  88. // warning: call_user_func_array() expects parameter 1 to be a valid callback,
  89. // function 'node_form' not found or invalid function name
  90. // in /var/www/includes/form.inc on line 382.
  91. module_load_include('inc', 'node', 'node.pages');
  92. }
  93. /**
  94. * Implements hook_menu().
  95. * Defines all menu items needed by Tripal Core
  96. *
  97. * @ingroup tripal_core
  98. */
  99. function tripal_core_menu() {
  100. $items = array();
  101. // Triapl setting groups
  102. $items['admin/tripal'] = array(
  103. 'title' => 'Tripal',
  104. 'description' => t("Manage the behavior or Tripal and its various modules."),
  105. 'weight' => -8,
  106. 'page callback' => 'system_admin_menu_block_page',
  107. 'access arguments' => array('administer tripal'),
  108. 'file' => 'system.admin.inc',
  109. 'file path' => drupal_get_path('module', 'system'),
  110. );
  111. $items['admin/tripal/schema'] = array(
  112. 'title' => 'Chado Schema',
  113. 'description' => t("Tools to extend the chado schema through custom tables & materialized views."),
  114. 'weight' => -2,
  115. 'access arguments' => array('administer tripal'),
  116. );
  117. $items['admin/tripal/chado'] = array(
  118. 'title' => 'Chado Modules',
  119. 'description' => t('Configuration for specific chado data types such as Vocabularies, Features, etc.'),
  120. 'access arguments' => array('administer tripal'),
  121. 'type' => MENU_NORMAL_ITEM,
  122. 'weight' => -6
  123. );
  124. $items['admin/tripal/loaders'] = array(
  125. 'title' => 'Chado Data Loaders',
  126. 'description' => t('Tools facilitating loading data into the chado database. Includes a generic tab-delimited loader (Bulk Loader).'),
  127. 'access arguments' => array('administer tripal'),
  128. 'type' => MENU_NORMAL_ITEM,
  129. 'weight' => -4
  130. );
  131. $items['admin/tripal/extension'] = array(
  132. 'title' => 'Extensions',
  133. 'description' => t('Configuration for Tripal extensions.'),
  134. 'access arguments' => array('administer tripal'),
  135. 'type' => MENU_NORMAL_ITEM,
  136. 'weight' => 0
  137. );
  138. $items['admin/tripal/extension/import'] = array(
  139. 'title' => 'Import Extensions',
  140. 'description' => 'Provides a list of the available extensions that are registered at the tripal.info site. From this page you can easily import or install extensions to your site.',
  141. 'page callback' => 'drupal_get_form',
  142. 'page arguments' => array('tripal_core_extensions_form'),
  143. 'access arguments' => array('administer tripal'),
  144. 'type' => MENU_NORMAL_ITEM,
  145. 'file' => 'includes/tripal_core.extensions.inc',
  146. 'file path' => drupal_get_path('module', 'tripal_core'),
  147. 'weight' => -100,
  148. );
  149. // Tripal Setup
  150. $items['admin/tripal/setup'] = array(
  151. 'title' => 'Setup Tripal',
  152. 'description' => t('Tools for setup of Tripal'),
  153. 'access arguments' => array('administer tripal'),
  154. 'weight' => -8
  155. );
  156. $items['admin/tripal/setup/chado_install'] = array(
  157. 'title' => 'Install Chado Schema',
  158. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  159. 'page callback' => 'drupal_get_form',
  160. 'page arguments' => array('tripal_core_chado_load_form'),
  161. 'access arguments' => array('install chado'),
  162. 'type' => MENU_NORMAL_ITEM,
  163. 'weight' => -10
  164. );
  165. $items['admin/tripal/setup/customize'] = array(
  166. 'title' => 'Customize Tripal',
  167. 'description' => t('Information on how to customize tripal'),
  168. 'page callback' => 'theme',
  169. 'page arguments' => array('tripal_core_customize'),
  170. 'access arguments' => array('administer tripal'),
  171. 'weight' => 10
  172. );
  173. // Jobs Management
  174. $items['admin/tripal/tripal_jobs'] = array(
  175. 'title' => 'Jobs',
  176. 'description' => t('Jobs managed by Tripal'),
  177. 'page callback' => 'tripal_jobs_admin_view',
  178. 'access arguments' => array('administer tripal'),
  179. 'type' => MENU_NORMAL_ITEM,
  180. 'weight' => -10
  181. );
  182. $items['admin/tripal/tripal_jobs/help'] = array(
  183. 'title' => 'Help',
  184. 'description' => t('Help for the tripal job management system'),
  185. 'page callback' => 'theme',
  186. 'page arguments' => array('tripal_core_job_help'),
  187. 'access arguments' => array('administer tripal'),
  188. 'type' => MENU_LOCAL_TASK,
  189. 'weight' => 10
  190. );
  191. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  192. 'title' => 'Jobs',
  193. 'description' => t('Cancel a pending job'),
  194. 'page callback' => 'tripal_cancel_job',
  195. 'page arguments' => array(4),
  196. 'access arguments' => array('administer tripal'),
  197. 'type' => MENU_CALLBACK,
  198. );
  199. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  200. 'title' => 'Jobs',
  201. 'description' => t('Re-run an existing job.'),
  202. 'page callback' => 'tripal_rerun_job',
  203. 'page arguments' => array(4),
  204. 'access arguments' => array('administer tripal'),
  205. 'type' => MENU_CALLBACK,
  206. );
  207. $items['admin/tripal/tripal_jobs/view/%'] = array(
  208. 'title' => 'Jobs Details',
  209. 'description' => t('View job details.'),
  210. 'page callback' => 'tripal_jobs_view',
  211. 'page arguments' => array(4),
  212. 'access arguments' => array('administer tripal'),
  213. 'type' => MENU_CALLBACK,
  214. );
  215. $items['admin/tripal/tripal_jobs/views/jobs/enable'] = array(
  216. 'title' => 'Enable Jobs Administrative View',
  217. 'page callback' => 'tripal_enable_view',
  218. 'page arguments' => array('tripal_core_admin_jobs', 'admin/tripal/tripal_jobs'),
  219. 'access arguments' => array('administer tripal'),
  220. 'type' => MENU_CALLBACK,
  221. );
  222. // Materialized Views
  223. $items['admin/tripal/schema/mviews'] = array(
  224. 'title' => 'Materialized Views',
  225. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  226. 'page callback' => 'tripal_mview_admin_view',
  227. 'access arguments' => array('administer tripal'),
  228. 'type' => MENU_NORMAL_ITEM,
  229. 'weight' => -10
  230. );
  231. $items['admin/tripal/schema/mviews/help'] = array(
  232. 'title' => 'Help',
  233. 'description' => t('Help for the materialized views management system'),
  234. 'page callback' => 'theme',
  235. 'page arguments' => array('tripal_core_mviews_help'),
  236. 'access arguments' => array('administer tripal'),
  237. 'type' => MENU_LOCAL_TASK,
  238. 'weight' => 10
  239. );
  240. $items['admin/tripal/schema/mviews/report/%'] = array(
  241. 'title' => 'Materialized View',
  242. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  243. 'page callback' => 'tripal_mview_report',
  244. 'page arguments' => array(5),
  245. 'access arguments' => array('administer tripal'),
  246. 'type' => MENU_CALLBACK,
  247. );
  248. $items['admin/tripal/schema/mviews/new'] = array(
  249. 'title' => 'Create Materialized View',
  250. 'description' => t('Create a new materialized view.'),
  251. 'page callback' => 'drupal_get_form',
  252. 'page arguments' => array('tripal_mviews_form'),
  253. 'access arguments' => array('administer tripal'),
  254. 'type' => MENU_CALLBACK,
  255. );
  256. $items['admin/tripal/schema/mviews/edit/%'] = array(
  257. 'title' => 'Edit Materialized View',
  258. 'page callback' => 'drupal_get_form',
  259. 'page arguments' => array('tripal_mviews_form', 5),
  260. 'access arguments' => array('administer tripal'),
  261. 'type' => MENU_CALLBACK,
  262. );
  263. $items['admin/tripal/schema/mviews/update/%'] = array(
  264. 'title' => 'Create Materialized View',
  265. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  266. 'page callback' => 'tripal_mviews_add_populate_job',
  267. 'page arguments' => array(5),
  268. 'access arguments' => array('administer tripal'),
  269. 'type' => MENU_CALLBACK,
  270. );
  271. $items['admin/tripal/schema/mviews/delete/%'] = array(
  272. 'title' => 'Create Materialized View',
  273. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  274. 'page callback' => 'drupal_get_form',
  275. 'page arguments' => array('tripal_mviews_delete_form', 5),
  276. 'access arguments' => array('administer tripal'),
  277. 'type' => MENU_CALLBACK,
  278. );
  279. // TODO: complete the code for exporting and importing of MViews.
  280. // Need to address security issues of sharing SQL.
  281. $items['admin/tripal/schema/mviews/import'] = array(
  282. 'title' => 'Import MView',
  283. 'description' => 'Import a materialized view from another Tripal instance.',
  284. 'page callback' => 'drupal_get_form',
  285. 'page arguments' => array('tripal_mviews_import_form'),
  286. 'access arguments' => array('administer tripal'),
  287. 'type' => MENU_CALLBACK,
  288. );
  289. $items['admin/tripal/schema/mviews/%tblid/export'] = array(
  290. 'title' => 'Export MView',
  291. 'description' => 'Export a materialized view for use by another Tripal instance.',
  292. 'page callback' => 'drupal_get_form',
  293. 'page arguments' => array('tripal_mviews_export_form', 5),
  294. 'access arguments' => array('administer tripal'),
  295. 'type' => MENU_CALLBACK,
  296. );
  297. // Custom Tables
  298. $items['admin/tripal/schema/custom_tables'] = array(
  299. 'title' => 'Custom Tables',
  300. 'description' => t('Creation of custom tables that are added to Chado database.'),
  301. 'page callback' => 'tripal_custom_table_admin_view',
  302. 'access arguments' => array('administer tripal'),
  303. 'type' => MENU_NORMAL_ITEM,
  304. 'weight' => -10
  305. );
  306. $items['admin/tripal/schema/custom_tables/help'] = array(
  307. 'title' => 'Help',
  308. 'description' => t('Help for the tripal job management system'),
  309. 'page callback' => 'theme',
  310. 'page arguments' => array('tripal_core_job_help'),
  311. 'access arguments' => array('administer tripal'),
  312. 'type' => MENU_LOCAL_TASK,
  313. 'weight' => 10
  314. );
  315. $items['admin/tripal/schema/custom_tables/view/%'] = array(
  316. 'title' => 'Custom Tables',
  317. 'description' => t('Custom tables are added to Chado.'),
  318. 'page callback' => 'tripal_custom_table_view',
  319. 'page arguments' => array(5),
  320. 'access arguments' => array('administer tripal'),
  321. 'type' => MENU_CALLBACK,
  322. );
  323. $items['admin/tripal/schema/custom_tables/new'] = array(
  324. 'title' => 'Create Custom Table',
  325. 'description' => t('An interface for creating your own custom tables.'),
  326. 'page callback' => 'tripal_custom_table_new_page',
  327. 'access arguments' => array('administer tripal'),
  328. 'type' => MENU_CALLBACK,
  329. );
  330. $items['admin/tripal/schema/custom_tables/edit/%'] = array(
  331. 'title' => 'Edit Custom Table',
  332. 'page callback' => 'drupal_get_form',
  333. 'page arguments' => array('tripal_custom_tables_form', 5),
  334. 'access arguments' => array('administer tripal'),
  335. 'type' => MENU_CALLBACK,
  336. );
  337. $items['admin/tripal/schema/custom_tables/delete/%'] = array(
  338. 'title' => 'Create Custom Table',
  339. 'description' => t('Custom tables are added to Chado.'),
  340. 'page callback' => 'drupal_get_form',
  341. 'page arguments' => array('tripal_custom_tables_delete_form', 5),
  342. 'access arguments' => array('administer tripal'),
  343. 'type' => MENU_CALLBACK,
  344. );
  345. $items['admin/tripal/schema/custom_tables/views/tables/enable'] = array(
  346. 'title' => 'Enable Custom Tables Administrative View',
  347. 'page callback' => 'tripal_enable_view',
  348. 'page arguments' => array('tripal_core_admin_custom_table', 'admin/tripal/schema/custom_tables'),
  349. 'access arguments' => array('administer tripal'),
  350. 'type' => MENU_CALLBACK,
  351. );
  352. // Relationshi API autocomplete callback
  353. $items['tripal_ajax/relationship_nodeform/%/%/name_to_id'] = array(
  354. 'page callback' => 'chado_add_node_form_relationships_name_to_id_callback',
  355. 'page arguments' => array(2,3),
  356. 'access arguments' => array('access content'),
  357. 'type' => MENU_CALLBACK
  358. );
  359. // The node's TOC tab
  360. $items['node/%node/tripal_toc'] = array(
  361. 'title' => 'TOC',
  362. 'page callback' => 'drupal_get_form',
  363. 'page arguments' => array('tripal_core_node_toc_form', 1),
  364. 'access callback' => 'tripal_core_access_node_toc_form',
  365. 'access arguments' => array(1),
  366. 'type' => MENU_LOCAL_TASK,
  367. 'file' => '/includes/tripal_core.toc.inc',
  368. );
  369. // Web Services API callbacks.
  370. // $items['ws/chado/v0.1'] = array(
  371. // 'title' => 'Tripal Web Services API v0.1',
  372. // 'page callback' => 'tripal_core_chado_hal_api',
  373. // 'access arguments' => array('access content'),
  374. // 'type' => MENU_CALLBACK,
  375. // 'file' => '/includes/tripal_core.ws_hal.inc',
  376. // );
  377. return $items;
  378. }
  379. /**
  380. * An access wrapper function for editing the TOC
  381. *
  382. * @param $node
  383. * A node object
  384. * @return
  385. * Returns TRUE if the node is a Tripal-based node and the user hass
  386. * the 'administer tripal' role.
  387. */
  388. function tripal_core_access_node_toc_form($node) {
  389. $types = module_invoke_all('node_info');
  390. if (array_key_exists($node->type, $types) and
  391. array_key_exists('chado_node_api', $types[$node->type])) {
  392. return user_access('administer tripal');
  393. }
  394. return FALSE;
  395. }
  396. /**
  397. * Implements hook_permission().
  398. *
  399. * Set the permission types that the chado module uses. Essentially we
  400. * want permissionis that protect creation, editing and deleting of chado
  401. * data objects
  402. *
  403. * @ingroup tripal_core
  404. */
  405. function tripal_core_permission() {
  406. return array(
  407. 'install chado' => array(
  408. 'title' => t('Install Chado'),
  409. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  410. ),
  411. 'administer tripal' => array(
  412. 'title' => t('Administer Tripal'),
  413. 'description' => t('Allow the user to access administrative pages of Tripal.')
  414. ),
  415. 'view dev helps' => array(
  416. 'title' => t('View Developer Hints'),
  417. 'description' => t('Tripal will provide blue shaded boxes that provide
  418. instructions for how to customize or setup specific pages on a
  419. site. This permission should be enabled for developers. But can
  420. be disabled once developers are accustomed to these hints.'),
  421. 'restrict access' => TRUE,
  422. ),
  423. 'view ids' => array(
  424. 'title' => t('View Internal IDs'),
  425. 'description' => t('On content pages Tripal will typically provide
  426. a table of information pulled from the Chado database but the
  427. primary key IDs for that data is typically not shown. The
  428. default Tripal templates can show the primary key ID inside of a
  429. blue shaded table row if this permission is enabled. This can
  430. be useful for site developers who might want these IDs when working
  431. with the underlying database.'),
  432. 'restrict access' => TRUE,
  433. )
  434. );
  435. }
  436. /**
  437. * Implements hook_theme().
  438. * Registers template files/functions used by this module.
  439. *
  440. * @ingroup tripal_core
  441. */
  442. function tripal_core_theme($existing, $type, $theme, $path) {
  443. return array(
  444. 'tripal_core_customize' => array(
  445. 'arguments' => array('job_id' => NULL),
  446. 'template' => 'tripal_core_customize',
  447. 'path' => "$path/theme/templates"
  448. ),
  449. 'theme_file_upload_combo' => array(
  450. 'render element' => 'element',
  451. ),
  452. 'theme_sequence_combo' => array(
  453. 'render element' => 'element',
  454. ),
  455. 'tripal_core_jobs_help' => array(
  456. 'template' => 'tripal_core_jobs_help',
  457. 'variables' => array(NULL),
  458. 'path' => "$path/theme/templates"
  459. ),
  460. 'tripal_core_customtables_help' => array(
  461. 'template' => 'tripal_core_customtables_help',
  462. 'variables' => array(NULL),
  463. 'path' => "$path/theme/templates"
  464. ),
  465. // Chado Node API Themes
  466. // --------------------------------
  467. // Properties Node Form
  468. 'chado_node_properties_form_table' => array(
  469. 'function' => 'theme_chado_add_node_form_properties',
  470. 'render element' => 'element',
  471. ),
  472. // Additional Dbxrefs Nore Form
  473. 'chado_node_additional_dbxrefs_form_table' => array(
  474. 'function' => 'theme_chado_add_node_form_dbxrefs_table',
  475. 'render element' => 'element',
  476. ),
  477. // Relationships Nore Form
  478. 'chado_node_relationships_form_table' => array(
  479. 'function' => 'theme_chado_add_node_form_relationships_table',
  480. 'render element' => 'element',
  481. ),
  482. // Admin messages theme
  483. // --------------------------------
  484. 'tripal_admin_message' => array(
  485. 'function' => 'theme_tripal_admin_message',
  486. 'variables' => array('message' => NULL),
  487. ),
  488. // Form and form element themes.
  489. // --------------------------------
  490. 'tripal_node_toc_items_table' => array(
  491. 'render element' => 'element',
  492. ),
  493. // Theme function for the extension admin page.
  494. 'tripal_core_extensions_form_tables' => array(
  495. 'render element' => 'element',
  496. )
  497. );
  498. }
  499. /**
  500. * Implements hook_job_describe_args().
  501. * Describes the arguements for the tripal_populate_mview job to allow for greater
  502. * readability in the jobs details pages.
  503. *
  504. * @param $callback
  505. * The callback of the current tripal job (this is the function that will be executed
  506. * when tripal_launch_jobs.php is run.
  507. * @param $args
  508. * An array of arguments passed in when the job was registered.
  509. *
  510. * @return
  511. * A more readable $args array
  512. *
  513. * @ingroup tripal_core
  514. */
  515. function tripal_core_job_describe_args($callback, $args) {
  516. $new_args = array();
  517. if ($callback == 'tripal_populate_mview') {
  518. // get this mview details
  519. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  520. $results = db_query($sql, array(':mview_id' => $args[0]));
  521. $mview = $results->fetchObject();
  522. $new_args['View Name'] = $mview->name;
  523. }
  524. elseif ($callback == 'tripal_core_install_chado') {
  525. $new_args['Action'] = $args[0];
  526. }
  527. return $new_args;
  528. }
  529. /**
  530. * this is just a wrapper for backwards compatibility with a naming mistake.
  531. * it can go away in the future as it only is useful for jobs created by v0.3b
  532. *
  533. * @todo remove this function
  534. */
  535. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  536. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  537. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  538. $update, $refresh, $remove, $job);
  539. }
  540. /**
  541. * Implements hook_coder_ignore().
  542. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  543. */
  544. function tripal_core_coder_ignore() {
  545. return array(
  546. 'path' => drupal_get_path('module', 'tripal_core'),
  547. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  548. );
  549. }
  550. /**
  551. * Implements hook_views_api()
  552. * Purpose: Essentially this hook tells drupal that there is views support for
  553. * for this module which then includes tripal_db.views.inc where all the
  554. * views integration code is
  555. *
  556. * @ingroup tripal_organism
  557. */
  558. function tripal_core_views_api() {
  559. return array(
  560. 'api' => 3.0,
  561. );
  562. }
  563. /**
  564. * Implements hook_node_view_alter()
  565. *
  566. * @param unknown $build
  567. */
  568. function tripal_core_node_view_alter(&$build) {
  569. module_load_include('inc', 'tripal_core', 'includes/tripal_core.toc');
  570. tripal_core_node_view_build_toc($build);
  571. }
  572. /**
  573. * Implements hook_node_view()
  574. *
  575. * @ingroup tripal_core
  576. */
  577. function tripal_core_node_view($node, $view_mode, $langcode) {
  578. // if this node type is a chado-based node (i.e. Tripal node)
  579. // the we want to add a table of contents to it's content list
  580. // this table of contents will be an empty
  581. if (preg_match('/^chado_/', $node->type)) {
  582. // Show feature browser and counts
  583. if ($view_mode == 'full') {
  584. if (!isset($node->content['#tripal_generic_node_template'])) {
  585. $node->content['#tripal_generic_node_template'] = TRUE;
  586. }
  587. }
  588. }
  589. }
  590. /**
  591. * Implements hook_exclude_type_by_default()
  592. *
  593. * This hooks allows fields of a specified type that match a specified criteria to be excluded by
  594. * default from any table when chado_generate_var() is called. Keep in mind that if
  595. * fields are excluded by default they can always be expanded at a later date using
  596. * chado_expand_var().
  597. *
  598. * Criteria are php strings that evaluate to either TRUE or FALSE. These strings are evaluated using
  599. * drupal_eval() which suppresses syntax errors and throws watchdog entries of type php. There are
  600. * also watchdog entries of type tripal_core stating the exact criteria evaluated. Criteria can
  601. * contain the following tokens:
  602. * - <field_name>
  603. * Replaced by the name of the field to be excluded
  604. * - <field_value>
  605. * Replaced by the value of the field in the current record
  606. * Also keep in mind that if your criteria doesn't contain the &gt;field_value&lt; token then it will be
  607. * evaluated before the query is executed and if the field is excluded it won't be included in the
  608. * query.
  609. *
  610. * @return
  611. * An array of type => criteria where the type is excluded if the criteria evaluates to TRUE
  612. *
  613. * @ingroup tripal_core
  614. */
  615. function tripal_core_exclude_type_by_default() {
  616. return array('text' => 'strlen("<field_value> ") > 250');
  617. }
  618. /**
  619. * Adds support for tokens in the field_resource_links field.
  620. *
  621. * The field_resource_links field is a special field that can be manually
  622. * added by the site admin for providing links on the Tripal TOC sidebar.
  623. * Using tokens will allow for creation of custom links. This function
  624. * will add a fieldset contiaining the list of appropriate tokens for the
  625. * content type.
  626. *
  627. * @param unknown $element
  628. * @param unknown $form_state
  629. * @param unknown $context
  630. */
  631. function tripal_core_field_widget_form_alter(&$element, &$form_state, $context) {
  632. // If the name of the field is 'field_resource_links' then we want to
  633. // add a fieldset of tokens.
  634. if (isset($element['#field_name']) AND $element['#field_name'] == 'field_resource_links') {
  635. // Add the tokens fieldset to the last element.
  636. $num_elements = count($context['items']);
  637. if ($num_elements == $element['#delta']) {
  638. $bundle = $element['#bundle'];
  639. $base_table = preg_replace('/^chado_(.*)$/', '\1', $bundle);
  640. $tokens = chado_node_generate_tokens($base_table);
  641. $token_list = chado_node_format_tokens($tokens);
  642. $element['tokens'] = array(
  643. '#type' => 'fieldset',
  644. '#title' => 'Available tokens',
  645. '#collapsible' => TRUE,
  646. '#collapsed' => TRUE,
  647. '#weight' => 100
  648. );
  649. $element['tokens']['tokens_table'] = array(
  650. '#type' => 'item',
  651. '#markup' => $token_list
  652. );
  653. }
  654. }
  655. }
  656. /**
  657. * Imports all of the Tripal API into scope.
  658. *
  659. * Typically this function call is not necessary as all of the API is
  660. * automaticaly included by the tripal_core module. However this function can
  661. * be useful in the .install files during a site upgrade when the tripal_core
  662. * module is not enabld.
  663. *
  664. * Example usage:
  665. * @code
  666. * module_load_include('module', 'tripal_core', 'tripal_core');
  667. * tripal_core_import_api();
  668. * @endcode
  669. *
  670. */
  671. function tripal_core_import_api() {
  672. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_general.api');
  673. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_nodes.api');
  674. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_nodes.dbxrefs.api');
  675. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_nodes.properties.api');
  676. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_nodes.relationships.api');
  677. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_nodes.title_and_path.api');
  678. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_query.api');
  679. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_schema.api');
  680. module_load_include('inc', 'tripal_core', 'api/tripal_core.chado_variables.api');
  681. module_load_include('inc', 'tripal_core', 'api/tripal_core.custom_tables.api');
  682. module_load_include('inc', 'tripal_core', 'api/tripal_core.d3js.api');
  683. module_load_include('inc', 'tripal_core', 'api/tripal_core.DEPRECATED.api');
  684. module_load_include('inc', 'tripal_core', 'api/tripal_core.files.api');
  685. module_load_include('inc', 'tripal_core', 'api/tripal_core.jobs.api');
  686. module_load_include('inc', 'tripal_core', 'api/tripal_core.mviews.api');
  687. module_load_include('inc', 'tripal_core', 'api/tripal_core.schema_v1.11.api');
  688. module_load_include('inc', 'tripal_core', 'api/tripal_core.schema_v1.2.api');
  689. module_load_include('inc', 'tripal_core', 'api/tripal_core.schema_v1.3.api');
  690. module_load_include('inc', 'tripal_core', 'api/tripal_core.tripal_variables.api');
  691. module_load_include('inc', 'tripal_core', 'api/tripal_core.tripal.api');
  692. }
  693. /**
  694. * Implements hook_block_info().
  695. */
  696. function tripal_core_block_info() {
  697. $blocks['tripal_search'] = array(
  698. 'info' => t('Tripal Search Block'),
  699. 'cache' => DRUPAL_NO_CACHE,
  700. );
  701. return $blocks;
  702. }
  703. /**
  704. * Implements hook_block_view().
  705. */
  706. function tripal_core_block_view($delta = '') {
  707. $block = array();
  708. switch ($delta) {
  709. case 'tripal_search':
  710. $block['title'] = 'Search';
  711. $form_render_arr = drupal_get_form('tripal_core_search_block');
  712. $block['content'] = array(
  713. '#markup' => drupal_render($form_render_arr),
  714. );
  715. break;
  716. }
  717. return $block;
  718. }
  719. /**
  720. * A simple search box form.
  721. */
  722. function tripal_core_search_block($form, $form_state) {
  723. $form['wrapper'] = array(
  724. '#prefix' => '<div id="search-block-form" class="container-inline">',
  725. '#suffix' => '</div>',
  726. );
  727. $form['wrapper']['title'] = array(
  728. '#markup' => '<h2 class="element-invisible">Search form</h2>',
  729. );
  730. $form['wrapper']['search_block_form'] = array(
  731. '#title' => 'Search',
  732. '#title_display' => 'invisible',
  733. '#type' => 'textfield',
  734. '#size' => 15,
  735. '#maxlength' => 128,
  736. '#attributes' =>array('placeholder' => t(variable_get('tripal_search_placeholder', 'Keywords')))
  737. );
  738. $form['wrapper']['submit'] = array(
  739. '#type' => 'submit',
  740. '#value' => 'Search',
  741. '#prefix' => '<div class="form-actions form-wrapper" id="edit-actions">',
  742. '#suffix' => '</div>'
  743. );
  744. return $form;
  745. }
  746. /**
  747. * Submit for tripal_core_search_block form.
  748. */
  749. function tripal_core_search_block_submit($form, &$form_state) {
  750. $form_state['redirect'] = array(
  751. variable_get('tripal_search_block_url', 'search/data'),
  752. array(
  753. 'query' => array(
  754. 'keywords' => $form_state['values']['search_block_form']
  755. ),
  756. ),
  757. );
  758. }
  759. /**
  760. * Implements hook_block_configure().
  761. */
  762. function tripal_core_block_configure ($delta = '') {
  763. $form = array();
  764. $form['search_url'] = array(
  765. '#type' => 'textfield',
  766. '#title' => 'Search Page URL',
  767. '#description' => 'The URL for the page you would like to redirect to when the user
  768. clicks "Search". It is expected that this page will be a view with an exposed
  769. filter having a "Filter Identifier" (in "More" fieldset on the edit filter form)
  770. of "keywords".',
  771. '#default_value' => variable_get('tripal_search_block_url', 'search/data'),
  772. );
  773. $form['search_placeholder'] = array(
  774. '#type' => 'textfield',
  775. '#title' => 'Placeholder Text',
  776. '#description' => 'Change the text that shows up within the search box until the user enters any of their own text.',
  777. '#default_value' => variable_get('tripal_search_placeholder', 'Keywords'),
  778. );
  779. return $form;
  780. }
  781. /**
  782. * Implements hook_block_save().
  783. */
  784. function tripal_core_block_save($delta = '', $edit = array()) {
  785. // We simply want to save this information in a Drupal variable for use in the form submit.
  786. if (!empty($edit['search_url'])) {
  787. variable_set('tripal_search_block_url', $edit['search_url']);
  788. }
  789. if (!empty($edit['search_placeholder'])) {
  790. variable_set('tripal_search_placeholder', $edit['search_placeholder']);
  791. }
  792. }