tripal_core.module 30 KB

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