tripal_chado.module 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. <?php
  2. // APPLICATION PROGRAMMER INTERFACE -------------
  3. // Chado API
  4. require_once "api/tripal_chado.api.inc";
  5. require_once 'api/tripal_chado.general.api.inc';
  6. require_once 'api/tripal_chado.query.api.inc';
  7. require_once 'api/tripal_chado.variables.api.inc';
  8. require_once 'api/tripal_chado.schema.api.inc';
  9. require_once 'api/tripal_chado.custom_tables.api.inc';
  10. require_once 'api/tripal_chado.mviews.api.inc';
  11. require_once 'api/tripal_chado.schema_v1.2.api.inc';
  12. require_once 'api/tripal_chado.schema_v1.11.api.inc';
  13. require_once 'api/modules/tripal_chado.analysis.api.inc';
  14. require_once 'api/modules/tripal_chado.contact.api.inc';
  15. require_once 'api/modules/tripal_chado.cv.api.inc';
  16. require_once 'api/modules/tripal_chado.db.api.inc';
  17. require_once 'api/modules/tripal_chado.feature.api.inc';
  18. require_once 'api/modules/tripal_chado.organism.api.inc';
  19. require_once 'api/modules/tripal_chado.pub.api.inc';
  20. require_once 'api/modules/tripal_chado.stock.api.inc';
  21. require_once "includes/tripal_chado.entity.inc";
  22. require_once "includes/tripal_chado.schema.inc";
  23. require_once "includes/tripal_chado.term_storage.inc";
  24. require_once "includes/tripal_chado.field_storage.inc";
  25. tripal_chado_set_globals();
  26. /**
  27. * This function is used to set the global Chado variables
  28. *
  29. * @ingroup tripal_chado
  30. */
  31. function tripal_chado_set_globals() {
  32. // these global variables are meant to be accessed by all Tripal
  33. // modules to find the chado version installed and if Chado is local.
  34. // these variables are stored as globals rather than using the drupal_set_variable
  35. // functions because the Drupal functions make databaes queries and for long
  36. // running loaders we don't want those queries repeatedly.
  37. $GLOBALS["chado_is_installed"] = chado_is_installed();
  38. if ($GLOBALS["chado_is_installed"]) {
  39. $GLOBALS["chado_is_local"] = chado_is_local();
  40. $GLOBALS["chado_version"] = chado_get_version();
  41. $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
  42. }
  43. }
  44. /**
  45. * Implements hook_init().
  46. * Used to set the search_path, create default content and set default variables.
  47. *
  48. * @ingroup tripal_chado
  49. */
  50. function tripal_chado_init() {
  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. $cv = $results->fetchObject();
  57. if (!$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. $db = $results->fetchObject();
  66. if (!$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. }
  74. /**
  75. * Implements hook_menu().
  76. */
  77. function tripal_chado_menu() {
  78. $items = array();
  79. $items['admin/tripal/loaders'] = array(
  80. 'title' => 'Data Loaders',
  81. 'description' => t('Tools facilitating data import.'),
  82. 'access arguments' => array('administer tripal'),
  83. 'type' => MENU_NORMAL_ITEM,
  84. 'weight' => 6
  85. );
  86. // Chado Storage Backend
  87. $items['admin/tripal/storage/chado'] = array(
  88. 'title' => 'Chado Schema',
  89. 'description' => t("Tools to extend the chado schema through custom tables & materialized views."),
  90. 'weight' => -100,
  91. 'access arguments' => array('administer tripal'),
  92. );
  93. $items['admin/tripal/storage/chado/chado_install'] = array(
  94. 'title' => 'Install Chado Schema',
  95. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  96. 'page callback' => 'drupal_get_form',
  97. 'page arguments' => array('tripal_chado_load_form'),
  98. 'access arguments' => array('install chado'),
  99. 'type' => MENU_NORMAL_ITEM,
  100. 'weight' => -100
  101. );
  102. // Materialized Views
  103. $items['admin/tripal/storage/chado/mviews'] = array(
  104. 'title' => 'Materialized Views',
  105. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  106. 'page callback' => 'tripal_mview_admin_view',
  107. 'access arguments' => array('administer tripal'),
  108. 'type' => MENU_NORMAL_ITEM,
  109. 'weight' => -10
  110. );
  111. $items['admin/tripal/storage/chado/mviews/help'] = array(
  112. 'title' => 'Help',
  113. 'description' => t('Help for the materialized views management system'),
  114. 'page callback' => 'theme',
  115. 'page arguments' => array('tripal_mviews_help'),
  116. 'access arguments' => array('administer tripal'),
  117. 'type' => MENU_LOCAL_TASK,
  118. 'weight' => 10
  119. );
  120. $items['admin/tripal/storage/chado/mviews/report/%'] = array(
  121. 'title' => 'Materialized View',
  122. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  123. 'page callback' => 'tripal_mview_report',
  124. 'page arguments' => array(5),
  125. 'access arguments' => array('administer tripal'),
  126. 'type' => MENU_CALLBACK,
  127. );
  128. $items['admin/tripal/storage/chado/mviews/new'] = array(
  129. 'title' => 'Create Materialized View',
  130. 'description' => t('Create a new materialized view.'),
  131. 'page callback' => 'drupal_get_form',
  132. 'page arguments' => array('tripal_mviews_form'),
  133. 'access arguments' => array('administer tripal'),
  134. 'type' => MENU_CALLBACK,
  135. );
  136. $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
  137. 'title' => 'Edit Materialized View',
  138. 'page callback' => 'drupal_get_form',
  139. 'page arguments' => array('tripal_mviews_form', 5),
  140. 'access arguments' => array('administer tripal'),
  141. 'type' => MENU_CALLBACK,
  142. );
  143. $items['admin/tripal/storage/chado/mviews/update/%'] = array(
  144. 'title' => 'Create Materialized View',
  145. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  146. 'page callback' => 'tripal_mviews_add_populate_job',
  147. 'page arguments' => array(5),
  148. 'access arguments' => array('administer tripal'),
  149. 'type' => MENU_CALLBACK,
  150. );
  151. $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
  152. 'title' => 'Create Materialized View',
  153. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  154. 'page callback' => 'drupal_get_form',
  155. 'page arguments' => array('tripal_mviews_delete_form', 5),
  156. 'access arguments' => array('administer tripal'),
  157. 'type' => MENU_CALLBACK,
  158. );
  159. // TODO: complete the code for exporting and importing of MViews.
  160. // Need to address security issues of sharing SQL.
  161. $items['admin/tripal/storage/chado/mviews/import'] = array(
  162. 'title' => 'Import MView',
  163. 'description' => 'Import a materialized view from another Tripal instance.',
  164. 'page callback' => 'drupal_get_form',
  165. 'page arguments' => array('tripal_mviews_import_form'),
  166. 'access arguments' => array('administer tripal'),
  167. 'type' => MENU_CALLBACK,
  168. );
  169. $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
  170. 'title' => 'Export MView',
  171. 'description' => 'Export a materialized view for use by another Tripal instance.',
  172. 'page callback' => 'drupal_get_form',
  173. 'page arguments' => array('tripal_mviews_export_form', 5),
  174. 'access arguments' => array('administer tripal'),
  175. 'type' => MENU_CALLBACK,
  176. );
  177. // Custom Tables
  178. $items['admin/tripal/storage/chado/custom_tables'] = array(
  179. 'title' => 'Custom Tables',
  180. 'description' => t('Creation of custom tables that are added to Chado database.'),
  181. 'page callback' => 'tripal_custom_table_admin_view',
  182. 'access arguments' => array('administer tripal'),
  183. 'type' => MENU_NORMAL_ITEM,
  184. 'weight' => -10
  185. );
  186. $items['admin/tripal/storage/chado/custom_tables/help'] = array(
  187. 'title' => 'Help',
  188. 'description' => t('Help for the tripal job management system'),
  189. 'page callback' => 'theme',
  190. 'page arguments' => array('tripal_job_help'),
  191. 'access arguments' => array('administer tripal'),
  192. 'type' => MENU_LOCAL_TASK,
  193. 'weight' => 10
  194. );
  195. $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
  196. 'title' => 'Custom Tables',
  197. 'description' => t('Custom tables are added to Chado.'),
  198. 'page callback' => 'tripal_custom_table_view',
  199. 'page arguments' => array(5),
  200. 'access arguments' => array('administer tripal'),
  201. 'type' => MENU_CALLBACK,
  202. );
  203. $items['admin/tripal/storage/chado/custom_tables/new'] = array(
  204. 'title' => 'Create Custom Table',
  205. 'description' => t('An interface for creating your own custom tables.'),
  206. 'page callback' => 'tripal_custom_table_new_page',
  207. 'access arguments' => array('administer tripal'),
  208. 'type' => MENU_CALLBACK,
  209. );
  210. $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array(
  211. 'title' => 'Edit Custom Table',
  212. 'page callback' => 'drupal_get_form',
  213. 'page arguments' => array('tripal_custom_tables_form', 5),
  214. 'access arguments' => array('administer tripal'),
  215. 'type' => MENU_CALLBACK,
  216. );
  217. $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array(
  218. 'title' => 'Create Custom Table',
  219. 'description' => t('Custom tables are added to Chado.'),
  220. 'page callback' => 'drupal_get_form',
  221. 'page arguments' => array('tripal_custom_tables_delete_form', 5),
  222. 'access arguments' => array('administer tripal'),
  223. 'type' => MENU_CALLBACK,
  224. );
  225. $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
  226. 'title' => 'Enable Custom Tables Administrative View',
  227. 'page callback' => 'tripal_enable_view',
  228. 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
  229. 'access arguments' => array('administer tripal'),
  230. 'type' => MENU_CALLBACK,
  231. );
  232. return $items;
  233. }
  234. /**
  235. * Implements hook_permission().
  236. *
  237. * Set the permission types that the chado module uses. Essentially we
  238. * want permissionis that protect creation, editing and deleting of chado
  239. * data objects
  240. *
  241. * @ingroup tripal
  242. */
  243. function tripal_chado_permission() {
  244. return array(
  245. 'install chado' => array(
  246. 'title' => t('Install Chado'),
  247. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  248. ),
  249. 'view chado_ids' => array(
  250. 'title' => t('View Internal IDs'),
  251. 'description' => t('On content pages Tripal will typically provide
  252. a table of information pulled from the Chado database but the
  253. primary key IDs for that data is typically not shown. The
  254. default Tripal templates can show the primary key ID inside of a
  255. blue shaded table row if this permission is enabled. This can
  256. be useful for site developers who might want these IDs when working
  257. with the underlying database.'),
  258. 'restrict access' => TRUE,
  259. )
  260. );
  261. }
  262. /**
  263. * Implements hook_field_info().
  264. */
  265. function tripal_chado_field_info() {
  266. $fields = array(
  267. 'organism_id' => array(
  268. 'label' => t('Organism'),
  269. 'description' => t('A field for specifying an organism.'),
  270. 'default_widget' => 'tripal_chado_organism_select_widget',
  271. 'default_formatter' => 'tripal_chado_organism_formatter',
  272. 'settings' => array(),
  273. 'storage' => array(
  274. 'type' => 'field_chado_storage',
  275. 'module' => 'tripal_chado',
  276. 'active' => TRUE
  277. ),
  278. ),
  279. 'dbxref_id' => array(
  280. 'label' => t('Cross-reference'),
  281. 'description' => t('This record can be cross-referenced with a record in
  282. another online database. This field is intended for the most prominent
  283. reference. At a minimum, the database and accession must be provided.'),
  284. 'default_widget' => 'tripal_chado_dbxref_id_widget',
  285. 'default_formatter' => 'tripal_chado_dbxref_id_formatter',
  286. 'settings' => array(),
  287. 'storage' => array(
  288. 'type' => 'field_chado_storage',
  289. 'module' => 'tripal_chado',
  290. 'active' => TRUE
  291. ),
  292. ),
  293. 'residues' => array(
  294. 'label' => t('Residues'),
  295. 'description' => t('A field for managing nucleotide and protein residues.'),
  296. 'default_widget' => 'tripal_chado_residue_textarea_widget',
  297. 'default_formatter' => 'tripal_chado_residues_formatter',
  298. 'settings' => array(),
  299. 'storage' => array(
  300. 'type' => 'field_chado_storage',
  301. 'module' => 'tripal_chado',
  302. 'active' => TRUE
  303. ),
  304. ),
  305. 'md5checksum' => array(
  306. 'label' => t('MD5 checksum'),
  307. 'description' => t('A field for generating MD5 checksum for a sequence.'),
  308. 'default_widget' => 'tripal_chado_md5checksum_checkbox_widget',
  309. 'default_formatter' => 'tripal_chado_md5checksum_formatter',
  310. 'settings' => array(),
  311. 'storage' => array(
  312. 'type' => 'field_chado_storage',
  313. 'module' => 'tripal_chado',
  314. 'active' => TRUE
  315. ),
  316. ),
  317. 'seqlen' => array(
  318. 'label' => t('Sequence length'),
  319. 'description' => t('A field for calculating the length of a sequence.'),
  320. 'default_widget' => 'tripal_chado_seqlen_hidden_widget',
  321. 'default_formatter' => 'tripal_chado_seqlen_formatter',
  322. 'settings' => array(),
  323. 'storage' => array(
  324. 'type' => 'field_chado_storage',
  325. 'module' => 'tripal_chado',
  326. 'active' => TRUE
  327. ),
  328. ),
  329. // The field provides a widget for adding new properties
  330. // to an entity that is connected to a base table that has a prop table
  331. // in Chado.
  332. 'kvproperty_adder' => array(
  333. 'label' => t('Add a Property Type'),
  334. 'description' => t('This record may have any number of properties. Use
  335. this field to first add the type.'),
  336. 'default_widget' => 'tripal_chado_kvproperty_adder_widget',
  337. //'default_formatter' => 'tripal_chado_kvproperty_adder_formatter',
  338. 'default_formatter' => 'hidden',
  339. 'settings' => array(),
  340. 'storage' => array(
  341. 'type' => 'field_chado_storage',
  342. 'module' => 'tripal_chado',
  343. 'active' => TRUE
  344. ),
  345. ),
  346. // The field provides form elements for adding a property to an entity
  347. // that in turn gets stored in a prop table of Chado (e.g. featureprop,
  348. // stockprop, etc).
  349. 'kvproperty' => array(
  350. 'label' => t('Add a Property'),
  351. 'description' => t('Add details about this property.'),
  352. 'default_widget' => 'tripal_chado_kvproperty_widget',
  353. 'default_formatter' => 'tripal_chado_kvproperty_formatter',
  354. 'settings' => array(),
  355. 'storage' => array(
  356. 'type' => 'field_chado_storage',
  357. 'module' => 'tripal_chado',
  358. 'active' => TRUE
  359. ),
  360. ),
  361. );
  362. return $fields;
  363. }
  364. /**
  365. * Implements hook_field_widget_info().
  366. */
  367. function tripal_chado_field_widget_info() {
  368. return array(
  369. 'tripal_chado_organism_select_widget' => array(
  370. 'label' => t('Organism Select'),
  371. 'field types' => array('organism_id')
  372. ),
  373. 'tripal_chado_dbxref_id_widget' => array(
  374. 'label' => t('Cross-reference'),
  375. 'field types' => array('dbxref_id'),
  376. 'description' => t('This record can be cross-referenced with a record in another online database. This field is intended for the most prominent reference. At a minimum, the database and accession must be provided.'),
  377. ),
  378. 'tripal_chado_md5checksum_checkbox_widget' => array(
  379. 'label' => t('MD5 Checksum Checkbox'),
  380. 'field types' => array('md5checksum'),
  381. ),
  382. 'tripal_chado_residues_textarea_widget' => array(
  383. 'label' => t('Residues'),
  384. 'field types' => array('residues'),
  385. ),
  386. 'tripal_chado_seqlen_hidden_widget' => array(
  387. 'label' => t('Sequence Length'),
  388. 'field types' => array('seqlen'),
  389. ),
  390. 'tripal_chado_kvproperty_adder_widget' => array(
  391. 'label' => t('Add a Property'),
  392. 'field types' => array('kvproperty_adder'),
  393. ),
  394. 'tripal_chado_kvproperty_widget' => array(
  395. 'label' => t('Property'),
  396. 'field types' => array('kvproperty'),
  397. ),
  398. );
  399. }
  400. /**
  401. * Implements hook_field_formatter_info().
  402. */
  403. function tripal_chado_field_formatter_info() {
  404. return array(
  405. 'tripal_chado_organism_formatter' => array(
  406. 'label' => t('Organism'),
  407. 'field types' => array('organism_id')
  408. ),
  409. 'tripal_chado_dbxref_id_formatter' => array(
  410. 'label' => t('Cross-reference'),
  411. 'field types' => array('dbxref_id')
  412. ),
  413. 'tripal_chado_md5checksum_formatter' => array(
  414. 'label' => t('MD5 checksum'),
  415. 'field types' => array('md5checksum')
  416. ),
  417. 'tripal_chado_residues_formatter' => array(
  418. 'label' => t('Residues'),
  419. 'field types' => array('residues')
  420. ),
  421. 'tripal_chado_seqlen_formatter' => array(
  422. 'label' => t('Sequence length'),
  423. 'field types' => array('seqlen')
  424. ),
  425. 'tripal_chado_kvproperty_adder_formatter' => array(
  426. 'label' => t('Add a Property'),
  427. 'field types' => array('kvproperty_adder')
  428. ),
  429. 'tripal_chado_kvproperty_formatter' => array(
  430. 'label' => t('Property'),
  431. 'field types' => array('kvproperty')
  432. ),
  433. );
  434. }
  435. /**
  436. * Implements hook_chado_field_alter().
  437. *
  438. * This function is used to change the default field formatter and widget
  439. * that are assigned to fields of an Entity. This hook is only used for
  440. * those fields that correspond to a column in a Chado table. An implementation
  441. * of this hook can be used to change the default formatters and widgets to
  442. * custom formatters and widgets that are created by the module creating
  443. * this hook.
  444. *
  445. * By default, Tripal will provide custom formatters and widgets for many
  446. * columns in Chado tables, therefore, this hook will most likely be of use
  447. * to extension modules that create custom table inside of Chado.
  448. *
  449. * @param $field
  450. */
  451. function hook_chado_field_alter(&$field) {
  452. if (!array_key_exists('field_settings', $field)) {
  453. return;
  454. }
  455. // If the field doesn't list the Chado table or column then just return.
  456. if (!array_key_exists('chado_table', $field['field_settings']) or
  457. !array_key_exists('chado_column', $field['field_settings'])) {
  458. return;
  459. }
  460. // Here we provide new field types and widgets for FK fields
  461. // and fields that need special attention.
  462. }
  463. /**
  464. * Implements hook_field_widget_form_alter().
  465. */
  466. function tripal_chado_field_widget_form_alter(&$element, &$form_state, $context) {
  467. if (array_key_exists('#field_name', $element)) {
  468. $field_name = $element['#field_name'];
  469. $matches = array();
  470. if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
  471. $tablename = $matches[1];
  472. $colname = $matches[2];
  473. $schema = chado_get_schema($tablename);
  474. // The timelastmodified field exists in many Chado tables. We want
  475. // the form element to update to the most recent time rather than the time
  476. // in the database.
  477. if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
  478. // We want the default value for the field to be the current time.
  479. $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
  480. $element['#date_items']['value'] = $element['#default_value']['value'];
  481. }
  482. // We want the date combo fieldset to be collaspible so we will
  483. // add our own theme_wrapper to replace the one added by the date
  484. // module.
  485. if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
  486. $element['#theme_wrappers'] = array('tripal_chado_date_combo');
  487. }
  488. }
  489. }
  490. }
  491. /**
  492. * Implements hook_field_formatter_view().
  493. */
  494. function tripal_chado_field_formatter_view($entity_type, $entity, $field,
  495. $instance, $langcode, $items, $display) {
  496. $element = array();
  497. switch ($display['type']) {
  498. case 'tripal_chado_organism_formatter':
  499. module_load_include('inc', 'tripal_chado', 'includes/fields/organism_id');
  500. tripal_chado_organism_select_formatter($element, $entity_type, $entity, $field,
  501. $instance, $langcode, $items, $display);
  502. break;
  503. case 'tripal_chado_dbxref_id_formatter':
  504. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
  505. tripal_chado_dbxref_id_formatter($element, $entity_type, $entity, $field,
  506. $instance, $langcode, $items, $display);
  507. break;
  508. case 'tripal_chado_md5checksum_formatter':
  509. module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
  510. tripal_chado_md5checksum_checkbox_formatter($element, $entity_type, $entity, $field,
  511. $instance, $langcode, $items, $display);
  512. break;
  513. case 'tripal_chado_residues_formatter':
  514. module_load_include('inc', 'tripal_chado', 'includes/fields/residues');
  515. tripal_chado_residues_textarea_formatter($element, $entity_type, $entity, $field,
  516. $instance, $langcode, $items, $display);
  517. break;
  518. case 'tripal_chado_seqlen_formatter':
  519. module_load_include('inc', 'tripal_chado', 'includes/fields/seqlen');
  520. tripal_chado_seqlen_hidden_formatter($element, $entity_type, $entity, $field,
  521. $instance, $langcode, $items, $display);
  522. break;
  523. case 'tripal_chado_kvproperty_adder_formatter':
  524. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  525. tripal_chado_kvproperty_adder_formatter($element, $entity_type, $entity, $field,
  526. $instance, $langcode, $items, $display);
  527. break;
  528. case 'tripal_chado_kvproperty_formatter':
  529. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty');
  530. tripal_chado_kvproperty_formatter($element, $entity_type, $entity, $field,
  531. $instance, $langcode, $items, $display);
  532. break;
  533. }
  534. return $element;
  535. }
  536. /**
  537. * Implements hook_field_widget_form().
  538. */
  539. function tripal_chado_field_widget_form(&$form, &$form_state, $field,
  540. $instance, $langcode, $items, $delta, $element) {
  541. $widget = $element;
  542. switch ($instance['widget']['type']) {
  543. case 'tripal_chado_organism_select_widget':
  544. // Make sure the include files get parsed now and for the form submits.
  545. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/organism_id');
  546. module_load_include('inc', 'tripal_chado', 'includes/fields/organism_id');
  547. // Update the widget with the new field.
  548. tripal_chado_organism_select_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  549. break;
  550. case 'tripal_chado_dbxref_id_widget':
  551. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/dbxref_id');
  552. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
  553. tripal_chado_dbxref_id_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  554. break;
  555. case 'tripal_chado_md5checksum_checkbox_widget':
  556. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/md5checksum');
  557. module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
  558. tripal_chado_md5checksum_checkbox_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  559. break;
  560. case 'tripal_chado_residues_textarea_widget':
  561. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/residues');
  562. module_load_include('inc', 'tripal_chado', 'includes/fields/residues');
  563. tripal_chado_residues_textarea_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  564. break;
  565. case 'tripal_chado_seqlen_hidden_widget':
  566. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/seqlen');
  567. module_load_include('inc', 'tripal_chado', 'includes/fields/seqlen');
  568. tripal_chado_seqlen_hidden_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  569. break;
  570. case 'tripal_chado_kvproperty_adder_widget':
  571. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  572. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  573. tripal_chado_kvproperty_adder_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  574. break;
  575. case 'tripal_chado_kvproperty_widget':
  576. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/kvproperty');
  577. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty');
  578. tripal_chado_kvproperty_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  579. break;
  580. }
  581. return $widget;
  582. }
  583. /**
  584. * Implements hook_form_FORM_ID_alter().
  585. *
  586. * The field_ui_display_overview_form is used for formatting the display
  587. * or layout of fields attached to an entity and shown on the entity view page.
  588. */
  589. function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
  590. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  591. // on the add/edit form of an entity for adding new property fields.
  592. $fields_names = element_children($form['fields']);
  593. foreach ($fields_names as $field_name) {
  594. $field_info = field_info_field($field_name);
  595. if ($field_info['type'] == 'kvproperty_adder') {
  596. unset($form['fields'][$field_name]);
  597. }
  598. }
  599. }
  600. /**
  601. * Implements hook_form_FORM_ID_alter().
  602. *
  603. * The field_ui_field_overview_form is used for ordering and configuring the
  604. * fields attached to an entity.
  605. */
  606. function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  607. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  608. // on the add/edit form of an entity for adding new property fields.
  609. $fields_names = element_children($form['fields']);
  610. foreach ($fields_names as $field_name) {
  611. $field_info = field_info_field($field_name);
  612. if ($field_info['type'] == 'kvproperty_adder') {
  613. unset($form['fields'][$field_name]);
  614. }
  615. }
  616. }
  617. /**
  618. * Implements hook_field_is_empty().
  619. */
  620. function tripal_chado_field_is_empty($item, $field) {
  621. // If there is no value field then the field is empty.
  622. if (!array_key_exists('value', $item)) {
  623. return TRUE;
  624. }
  625. // Iterate through all of the fields and if at least one has a value
  626. // the field is not empty.
  627. foreach ($item as $form_field_name => $value) {
  628. if (isset($value) and $value != NULL and $value != '') {
  629. return FALSE;
  630. }
  631. }
  632. // Otherwise, the field is empty.
  633. return TRUE;
  634. }
  635. /**
  636. * Returns the values of the field from the $form_state.
  637. */
  638. function tripal_chado_get_field_form_values($field_name, $form_state, $delta = 0, $child = NULL) {
  639. $value = NULL;
  640. // The form_state must have the 'values' key. If not then just return.
  641. if (!array_key_exists('values', $form_state)) {
  642. return $value;
  643. }
  644. // If the field name is not in the form_state['values'] then return.
  645. if (!array_key_exists($field_name, $form_state['values'])) {
  646. return $value;
  647. }
  648. // Iterate through the values looking for the field_name provided.
  649. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  650. $item = $items[$delta];
  651. if ($child){
  652. if(array_key_exists($child, $item) and $item[$child] != '') {
  653. $value = $item[$child];
  654. }
  655. }
  656. else {
  657. $value = $item['value'];
  658. }
  659. }
  660. return $value;
  661. }
  662. /**
  663. * Sets the values of the field from the $form_state.
  664. */
  665. function tripal_chado_set_field_form_values($field_name, &$form_state, $newvalue, $delta = 0, $child = NULL) {
  666. // The form_state must have the 'values' key. If not then just return.
  667. if (!array_key_exists('values', $form_state)) {
  668. return FALSE;
  669. }
  670. // If the field name is not in the form_state['values'] then reutrn.
  671. if (!array_key_exists($field_name, $form_state['values'])) {
  672. return FALSE;
  673. }
  674. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  675. if ($child) {
  676. $form_state['values'][$field_name][$langcode][$delta][$child] = $newvalue;
  677. }
  678. else {
  679. $form_state['values'][$field_name][$langcode][$delta]['value'] = $newvalue;
  680. }
  681. }
  682. return TRUE;
  683. }
  684. /**
  685. * Implements hook_theme().
  686. */
  687. function tripal_chado_theme($existing, $type, $theme, $path) {
  688. return array(
  689. 'tripal_chado_dbxref_id_widget' => array(
  690. 'render element' => 'element',
  691. 'file' => 'includes/fields/dbxref_id.inc',
  692. ),
  693. 'tripal_chado_kvproperty_addr_widget' => array(
  694. 'render element' => 'element',
  695. 'file' => 'includes/fields/dbxref_id.inc',
  696. ),
  697. 'tripal_chado_date_combo' => array(
  698. 'render element' => 'element',
  699. 'file' => 'theme/tripal_chado.theme.inc',
  700. ),
  701. );
  702. }
  703. /**
  704. * Implements hook_add_bundle_fields().
  705. */
  706. function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
  707. $bundle_name = $bundle->name;
  708. // This array will hold details that map the bundle to tables in Chado.
  709. $bundle_data = array();
  710. // Get the cvterm that corresponds to this TripalTerm object.
  711. $vocab = entity_load('TripalVocab', array($term->vocab_id));
  712. $vocab = reset($vocab);
  713. $match = array(
  714. 'dbxref_id' => array(
  715. 'db_id' => array(
  716. 'name' => $vocab->namespace,
  717. ),
  718. 'accession' => $term->accession
  719. ),
  720. );
  721. $cvterm = chado_generate_var('cvterm', $match);
  722. // The organism table does not have a type_id so we won't ever find
  723. // a record for it in the tripal_cv_defaults table.
  724. if ($cvterm->name == 'organism') {
  725. $bundle_data = array(
  726. 'cv_id' => $cvterm->cv_id->cv_id,
  727. 'cvterm_id' => $cvterm->cvterm_id,
  728. 'data_table' => 'organism',
  729. 'type_table' => 'organism',
  730. 'field' => '',
  731. );
  732. }
  733. // The analysis table does not have a type_id so we won't ever find
  734. // a record for it in the tripalcv_defaults table.
  735. else if ($cvterm->name == 'analysis') {
  736. $bundle_data = array(
  737. 'cv_id' => $cvterm->cv_id->cv_id,
  738. 'cvterm_id' => $cvterm->cvterm_id,
  739. 'data_table' => 'analysis',
  740. 'type_table' => 'analysis',
  741. 'field' => '',
  742. );
  743. }
  744. else if ($cvterm->name == 'project') {
  745. $bundle_data = array(
  746. 'cv_id' => $cvterm->cv_id->cv_id,
  747. 'cvterm_id' => $cvterm->cvterm_id,
  748. 'data_table' => 'project',
  749. 'type_table' => 'project',
  750. 'field' => '',
  751. );
  752. }
  753. else {
  754. // TODO: WHAT TO DO IF A VOCABULARY IS USED AS A DEFAULT FOR MULTIPLE
  755. // TABLES.
  756. // Look to see if this vocabulary is used as a default for any table.
  757. $default = db_select('tripal_cv_defaults', 't')
  758. ->fields('t')
  759. ->condition('cv_id', $cvterm->cv_id->cv_id)
  760. ->execute()
  761. ->fetchObject();
  762. if ($default) {
  763. $bundle_data = array(
  764. 'cv_id' => $cvterm->cv_id->cv_id,
  765. 'cvterm_id' => $cvterm->cvterm_id,
  766. 'data_table' => $default->table_name,
  767. 'type_table' => $default->table_name,
  768. 'field' => $default->field_name,
  769. );
  770. }
  771. }
  772. // Adds the fields for the base table to the entity.
  773. tripal_chado_add_bundle_base_fields($entity_type, $bundle_name, $bundle_data);
  774. // Save the mapping information so that we can reuse it when we need to
  775. // look things up for later for an entity
  776. tripal_set_bundle_variable('chado_cvterm_id', $bundle->id, $bundle_data['cvterm_id']);
  777. tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
  778. tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
  779. // Check to see if there are any kv-property tables associated to this
  780. // base table. If so, add the fields for that type of table.
  781. // TODO: the 'featurprop' table should not be hardcoded.
  782. tripal_chado_add_bundle_kvproperty_adder_field($entity_type, $bundle_name, 'featureprop');
  783. }
  784. /**
  785. * Adds the fields for a kv-property table fields
  786. *
  787. * @param $entity_type_name
  788. * @param $bundle_name
  789. * @param $kv_table
  790. */
  791. function tripal_chado_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table) {
  792. // First add a generic property field so that users can add new proeprty types.
  793. $field_name = $kv_table;
  794. // Initialize the field array.
  795. $field_info = array(
  796. 'field_type' => 'kvproperty_adder',
  797. 'widget_type' => 'tripal_fields_kvproperty_adder_widget',
  798. 'field_settings' => array(),
  799. 'widget_settings' => array('display_label' => 1),
  800. 'description' => '',
  801. 'label' => 'Additional Properties',
  802. 'is_required' => 0,
  803. );
  804. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  805. }
  806. /**
  807. * Adds the fields for the base table to the entity.
  808. */
  809. function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_name, $bundle_data) {
  810. $table_name = $bundle_data['data_table'];
  811. $type_table = $bundle_data['type_table'];
  812. $type_field = $bundle_data['field'];
  813. // Iterate through the columns of the table and see if fields have been
  814. // created for each one. If not, then create them.
  815. $schema = chado_get_schema($table_name);
  816. $columns = $schema['fields'];
  817. foreach ($columns as $column_name => $details) {
  818. $field_name = $table_name . '__' . $column_name;
  819. // Skip the primary key field.
  820. if ($column_name == $schema['primary key'][0]) {
  821. continue;
  822. }
  823. // Skip the type field.
  824. if ($table_name == $type_table and $column_name == $type_field) {
  825. continue;
  826. }
  827. // Get the field defaults for this column.
  828. $field_info = tripal_chado_get_table_column_field_default($table_name, $schema, $column_name);
  829. // Determine if the field is required.
  830. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  831. $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
  832. }
  833. // If we don't have a field type then we don't need to create a field.
  834. if (!$field_info['field_type']) {
  835. // If we don't have a field type but it is required and doesn't have
  836. // a default value then we are in trouble.
  837. if ($field_info['is_required'] and !array_key_exists('default', $details)) {
  838. throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
  839. array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
  840. }
  841. continue;
  842. }
  843. // If this field is a foreign key field then we will have a special custom
  844. // field provided by Tripal.
  845. $is_fk = FALSE;
  846. if (array_key_exists('foreign keys', $schema)) {
  847. foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
  848. if (array_key_exists($column_name, $fk_details['columns'])) {
  849. $is_fk = TRUE;
  850. }
  851. }
  852. }
  853. // Add the field to the bundle.
  854. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  855. }
  856. }
  857. /**
  858. * Returns a $field_info array for a field based on a database column.
  859. *
  860. */
  861. function tripal_chado_get_table_column_field_default($table_name, $schema, $column_name) {
  862. $details = $schema['fields'][$column_name];
  863. // Create an array with information about this field.
  864. $field = array(
  865. 'field_type' => '',
  866. 'widget_type' => '',
  867. 'field_settings' => array(
  868. 'chado_table' => $table_name,
  869. 'chado_column' => $column_name,
  870. 'semantic_web' => array(
  871. // The type is the term from a vocabulary that desribes this field..
  872. 'type' => '',
  873. // The namepsace for the vocabulary (e.g. 'foaf').
  874. 'ns' => '',
  875. // The URL for the namespace. It must be that the type can be
  876. // appended to the URL.
  877. 'nsurl' => '',
  878. ),
  879. ),
  880. 'widget_settings' => array(
  881. 'display_label' => 1
  882. ),
  883. 'description' => '',
  884. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  885. 'is_required' => 0,
  886. );
  887. // Alter the field info array depending on the column details.
  888. switch($details['type']) {
  889. case 'char':
  890. $field['field_type'] = 'text';
  891. $field['widget_type'] = 'text_textfield';
  892. $field['field_settings']['max_length'] = $details['length'];
  893. break;
  894. case 'varchar':
  895. $field['field_type'] = 'text';
  896. $field['widget_type'] = 'text_textfield';
  897. $field['field_settings']['max_length'] = $details['length'];
  898. break;
  899. case 'text':
  900. $field['field_type'] = 'text';
  901. $field['widget_type'] = 'text_textarea';
  902. $field['field_settings']['max_length'] = 17179869184;
  903. $field['field_settings']['text_processing'] = 1;
  904. break;
  905. case 'blob':
  906. // not sure how to support a blob field.
  907. continue;
  908. break;
  909. case 'int':
  910. $field['field_type'] = 'number_integer';
  911. $field['widget_type'] = 'number';
  912. break;
  913. case 'float':
  914. $field['field_type'] = 'number_float';
  915. $field['widget_type'] = 'number';
  916. $field['field_settings']['precision'] = 10;
  917. $field['field_settings']['scale'] = 2;
  918. $field['field_settings']['decimal_separator'] = '.';
  919. break;
  920. case 'numeric':
  921. $field['field_type'] = 'number_decimal';
  922. $field['widget_type'] = 'number';
  923. break;
  924. case 'serial':
  925. // Serial fields are most likely not needed as a field.
  926. break;
  927. case 'boolean':
  928. $field['field_type'] = 'list_boolean';
  929. $field['widget_type'] = 'options_onoff';
  930. $field['field_settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  931. break;
  932. case 'datetime':
  933. // Use the Drupal Date and Date API to create the field/widget
  934. $field['field_type'] = 'datetime';
  935. $field['widget_type'] = 'date_select';
  936. $field['widget_settings']['increment'] = 1;
  937. $field['widget_settings']['tz_handling'] = 'none';
  938. $field['widget_settings']['collapsible'] = TRUE;
  939. // TODO: Add settings so that the minutes increment by 1.
  940. // And turn off the timezone, as the Chado field doesn't support it.
  941. break;
  942. }
  943. // Set some default semantic web information
  944. if ($column_name == 'name') {
  945. $field['field_settings']['semantic_web']['type'] = 'name';
  946. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  947. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  948. }
  949. if ($column_name == 'description' or $column_name == 'definition' or
  950. $column_name == 'comment') {
  951. $field['field_settings']['semantic_web']['type'] = 'description';
  952. $field['field_settings']['semantic_web']['ns'] = 'hydra';
  953. $field['field_settings']['semantic_web']['nsurl'] = 'http://www.w3.org/ns/hydra/core#';
  954. }
  955. //
  956. // GENERIC COLUMNS
  957. //
  958. if ($field['field_settings']['chado_column'] =='organism_id') {
  959. $field['field_type'] = 'organism_id';
  960. $field['widget_type'] = 'tripal_chado_organism_select_widget';
  961. $field['label'] = 'Organism';
  962. $field['description'] = 'Select an organism.';
  963. }
  964. elseif ($field['field_settings']['chado_column'] =='dbxref_id') {
  965. $field['field_type'] = 'dbxref_id';
  966. $field['widget_type'] = 'tripal_chado_primary_dbxref_widget';
  967. $field['label'] = 'Primary Cross Reference';;
  968. $field['description'] = 'This record can be cross-referenced with a ' .
  969. 'record in another online database. The primary reference is for the ' .
  970. 'most prominent reference. At a minimum, the database and accession ' .
  971. 'must be provided. To remove a set reference, change the database ' .
  972. 'field to "Select a Database".';
  973. }
  974. elseif ($field['label'] == 'Timeaccessioned') {
  975. $field['label'] = 'Time Accessioned';
  976. $field['description'] = 'Please enter the time that this record was first added to the database.';
  977. }
  978. elseif ($field['label'] == 'Timelastmodified') {
  979. $field['label'] = 'Time Last Modified';
  980. $field['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  981. }
  982. //
  983. // ORGANISM TABLE
  984. //
  985. elseif ($field['field_settings']['chado_table'] == 'organism' and $field['field_settings']['chado_column'] == 'comment') {
  986. $field['label'] = 'Description';
  987. }
  988. //
  989. // FEATURE TABLE
  990. //
  991. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'uniquename') {
  992. $field['field_type'] = 'text';
  993. $field['widget_type'] = 'text_textfield';
  994. $field['field_settings']['text_processing'] = 0;
  995. $field['field_settings']['semantic_web']['type'] = 'name';
  996. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  997. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  998. }
  999. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'md5checksum') {
  1000. $field['field_type'] = 'md5checksum';
  1001. $field['widget_type'] = 'tripal_chado_md5checksum_checkbox_widget';
  1002. $field['label'] = 'MD5 Checksum';
  1003. $field['description'] = 'Generating MD5 checksum for the sequence.';
  1004. }
  1005. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'seqlen') {
  1006. $field['field_type'] = 'seqlen';
  1007. $field['widget_type'] = 'tripal_chado_seqlen_hidden_widget';
  1008. $field['label'] = 'Seqlen';
  1009. $field['description'] = 'The length of the residues.';
  1010. }
  1011. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'residues') {
  1012. $field['field_type'] = 'residues';
  1013. $field['widget_type'] = 'tripal_chado_residues_textarea_widget';
  1014. $field['label'] = 'Residues';
  1015. $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
  1016. }
  1017. return $field;
  1018. }
  1019. /**
  1020. * Implements hook_exclude_type_by_default()
  1021. *
  1022. * This hooks allows fields of a specified type that match a specified criteria
  1023. * to be excluded by default from any table when chado_generate_var() is called.
  1024. * Keep in mind that if fields are excluded by default they can always be
  1025. * expanded at a later date using chado_expand_var().
  1026. *
  1027. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  1028. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  1029. * throws watchdog entries of type php. There are also watchdog entries of type
  1030. * tripal stating the exact criteria evaluated. Criteria can
  1031. * contain the following tokens:
  1032. * - <field_name>
  1033. * Replaced by the name of the field to be excluded
  1034. * - <field_value>
  1035. * Replaced by the value of the field in the current record
  1036. * Also keep in mind that if your criteria doesn't contain the
  1037. * &gt;field_value&lt; token then it will be evaluated before the query is
  1038. * executed and if the field is excluded it won't be included in the
  1039. * query.
  1040. *
  1041. * @return
  1042. * An array of type => criteria where the type is excluded if the criteria
  1043. * evaluates to TRUE
  1044. *
  1045. * @ingroup tripal
  1046. */
  1047. function tripal_chado_exclude_type_by_default() {
  1048. return array('text' => 'strlen("<field_value> ") > 250');
  1049. }
  1050. /**
  1051. * Implements hook_job_describe_args().
  1052. *
  1053. * Describes the arguements for the tripal_populate_mview job to allow for
  1054. * greater readability in the jobs details pages.
  1055. *
  1056. * @param $callback
  1057. * The callback of the current tripal job (this is the function that will be
  1058. * executed when tripal_launch_jobs.php is run.
  1059. * @param $args
  1060. * An array of arguments passed in when the job was registered.
  1061. *
  1062. * @return
  1063. * A more readable $args array
  1064. *
  1065. * @ingroup tripal
  1066. */
  1067. function tripal_chado_describe_args($callback, $args) {
  1068. $new_args = array();
  1069. if ($callback == 'tripal_populate_mview') {
  1070. // get this mview details
  1071. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  1072. $results = db_query($sql, array(':mview_id' => $args[0]));
  1073. $mview = $results->fetchObject();
  1074. $new_args['View Name'] = $mview->name;
  1075. }
  1076. elseif ($callback == 'tripal_install_chado') {
  1077. $new_args['Action'] = $args[0];
  1078. }
  1079. return $new_args;
  1080. }