tripal_chado.module 51 KB

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