tripal.views.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?php
  2. /**
  3. * @file
  4. * Integrates many of the core database tables with drupal views
  5. */
  6. /**
  7. * Implements of hook_views_plugins().
  8. */
  9. function tripal_views_plugins() {
  10. return array(
  11. 'module' => 'tripal',
  12. 'query' => array(
  13. 'tripal_views_query' => array(
  14. 'title' => t('Tripal Entity Query'),
  15. 'help' => t('Query that allows you to search with Tripal entities.'),
  16. 'handler' => 'tripal_views_query',
  17. 'parent' => 'views_query',
  18. ),
  19. ),
  20. );
  21. }
  22. /**
  23. * Describe various Tripal Core systems to Views
  24. *
  25. * @ingroup tripal
  26. */
  27. function tripal_views_data() {
  28. $data = array();
  29. // Job Management System
  30. tripal_views_data_jobs($data);
  31. tripal_views_data_tripal_entity($data);
  32. tripal_views_data_fields($data);
  33. return $data;
  34. }
  35. /**
  36. * Integreates the Tripal fields with Views.
  37. */
  38. function tripal_views_data_fields(&$data) {
  39. // Iterate through the fields.
  40. $fields = field_info_fields();
  41. foreach ($fields as $field) {
  42. // Skip fields that aren't attached to TripalEntity fields.
  43. if (!array_key_exists('TripalEntity', $field['bundles'])) {
  44. continue;
  45. }
  46. // Call the hook_field_views_data() but only for the tripal module.
  47. // Otherwise the other modules will expect that this is an SQL-based
  48. // view.
  49. $result = (array) module_invoke('tripal', 'field_views_data', $field);
  50. // Set defaults for the field if no data array was returned.
  51. if (empty($result)) {
  52. // Iterate through the bundles to which this field is attached and
  53. // if it is a TripalField field then we'll call the viewsDataAlater function.
  54. $bundles = $field['bundles']['TripalEntity'];
  55. $result = array();
  56. foreach ($bundles as $bundle_name) {
  57. $instance = field_info_instance('TripalEntity', $field['field_name'], $bundle_name);
  58. $tfield = new TripalField($field, $instance);
  59. $result += $tfield->viewsData();
  60. }
  61. }
  62. drupal_alter('field_views_data', $result, $field, $module);
  63. if (is_array($result)) {
  64. $data = drupal_array_merge_deep($result, $data);
  65. }
  66. }
  67. }
  68. /**
  69. * Integrates the TripalEntity entities with Drupal Views.
  70. */
  71. function tripal_views_data_tripal_entity(&$data) {
  72. // Get the list of all of the bundles (entity types) and add them
  73. // as "base tables" for views.
  74. $bundles = db_select('tripal_bundle', 'tb')
  75. ->fields('tb')
  76. ->execute();
  77. // Iterate through the bundles.
  78. while ($bundle = $bundles->fetchObject()) {
  79. // Each bundle gets it's own "table".
  80. $data[$bundle->name]['table']['group'] = t($bundle->label);
  81. $data[$bundle->name]['table']['base'] = array(
  82. 'query class' => 'tripal_views_query',
  83. 'title' => t($bundle->label),
  84. 'help' => t('Tripal ' . $bundle->label . ' pages'),
  85. );
  86. $data[$bundle->name]['entity_id'] = array(
  87. 'title' => t('Entity ID'),
  88. 'help' => t('The unique entity ID for this content type.'),
  89. 'field' => array(
  90. 'handler' => 'tripal_views_handler_field_entity',
  91. ),
  92. 'filter' => array(
  93. 'handler' => 'tripal_views_handler_filter',
  94. ),
  95. 'sort' => array(
  96. 'handler' => 'views_handler_sort',
  97. ),
  98. );
  99. }
  100. }
  101. /**
  102. * Provides the data array for the tripal job management system
  103. *
  104. * @param $data
  105. * Previously generated tripal views data array
  106. * return
  107. * $data array with job management system described
  108. *
  109. * @ingroup tripal
  110. */
  111. function tripal_views_data_jobs(&$data) {
  112. $data['tripal_jobs']['table']['group'] = t('Tripal Jobs');
  113. $data['tripal_jobs']['table']['base'] = array(
  114. 'field' => 'job_id', // This is the identifier field for the view.
  115. 'title' => t('Tripal Jobs'),
  116. 'help' => t('The Job Management system for Tripal.'),
  117. 'weight' => 10,
  118. );
  119. // Job ID
  120. $data['tripal_jobs']['job_id'] = array(
  121. 'title' => t('Job ID'),
  122. 'help' => t('The job primary key.'),
  123. 'field' => array(
  124. 'handler' => 'views_handler_field_numeric',
  125. 'click sortable' => TRUE,
  126. ),
  127. 'filter' => array(
  128. 'handler' => 'views_handler_filter_numeric',
  129. ),
  130. 'sort' => array(
  131. 'handler' => 'views_handler_sort',
  132. ),
  133. );
  134. // User ID: Submitter
  135. $data['tripal_jobs']['uid'] = array(
  136. 'title' => t('Job Submitter'),
  137. 'help' => t('The user who submitted the job.'),
  138. 'relationship' => array(
  139. 'base' => 'user', // The name of the table to join with.
  140. 'base field' => 'uid', // The name of the field on the joined table.
  141. 'handler' => 'views_handler_relationship',
  142. 'label' => t('Submitting User'),
  143. 'title' => t('Submitting User'),
  144. 'help' => t('The user who submitted the job'),
  145. ),
  146. );
  147. // Job Name
  148. $data['tripal_jobs']['job_name'] = array(
  149. 'title' => t('Job Name'),
  150. 'help' => t('The name of the job.'),
  151. 'field' => array(
  152. 'handler' => 'views_handler_field',
  153. 'click sortable' => TRUE, // This is use by the table display plugin.
  154. ),
  155. 'sort' => array(
  156. 'handler' => 'views_handler_sort',
  157. ),
  158. 'filter' => array(
  159. 'handler' => 'views_handler_filter_string',
  160. ),
  161. 'argument' => array(
  162. 'handler' => 'views_handler_argument_string',
  163. ),
  164. );
  165. // Module Name
  166. $data['tripal_jobs']['modulename'] = array(
  167. 'title' => t('Module Name'),
  168. 'help' => t('The name of the module that submitted the job.'),
  169. 'field' => array(
  170. 'handler' => 'views_handler_field',
  171. 'click sortable' => TRUE, // This is use by the table display plugin.
  172. ),
  173. 'sort' => array(
  174. 'handler' => 'views_handler_sort',
  175. ),
  176. 'filter' => array(
  177. 'handler' => 'views_handler_filter_string',
  178. ),
  179. 'argument' => array(
  180. 'handler' => 'views_handler_argument_string',
  181. ),
  182. );
  183. // Callback
  184. $data['tripal_jobs']['callback'] = array(
  185. 'title' => t('Callback'),
  186. 'help' => t('The callback executed when the job runs.'),
  187. 'field' => array(
  188. 'handler' => 'views_handler_field',
  189. 'click sortable' => TRUE, // This is use by the table display plugin.
  190. ),
  191. 'sort' => array(
  192. 'handler' => 'views_handler_sort',
  193. ),
  194. 'filter' => array(
  195. 'handler' => 'views_handler_filter_string',
  196. ),
  197. 'argument' => array(
  198. 'handler' => 'views_handler_argument_string',
  199. ),
  200. );
  201. // Arguments
  202. $data['tripal_jobs']['arguments'] = array(
  203. 'title' => t('Arguements'),
  204. 'help' => t('Any arguements passed to the callback.'),
  205. 'field' => array(
  206. 'handler' => 'views_handler_field',
  207. 'click sortable' => TRUE, // This is use by the table display plugin.
  208. ),
  209. 'sort' => array(
  210. 'handler' => 'views_handler_sort',
  211. ),
  212. 'filter' => array(
  213. 'handler' => 'views_handler_filter_string',
  214. ),
  215. 'argument' => array(
  216. 'handler' => 'views_handler_argument_string',
  217. ),
  218. );
  219. // Progress
  220. $data['tripal_jobs']['progress'] = array(
  221. 'title' => t('Progress'),
  222. 'help' => t('The current progress of the job.'),
  223. 'field' => array(
  224. 'handler' => 'views_handler_field_numeric',
  225. 'click sortable' => TRUE,
  226. ),
  227. 'filter' => array(
  228. 'handler' => 'views_handler_filter_numeric',
  229. ),
  230. 'sort' => array(
  231. 'handler' => 'views_handler_sort',
  232. ),
  233. );
  234. // Status
  235. $data['tripal_jobs']['status'] = array(
  236. 'title' => t('Status'),
  237. 'help' => t('The current status of the job.'),
  238. 'field' => array(
  239. 'handler' => 'views_handler_field',
  240. 'click sortable' => TRUE, // This is use by the table display plugin.
  241. ),
  242. 'sort' => array(
  243. 'handler' => 'views_handler_sort',
  244. ),
  245. 'filter' => array(
  246. 'handler' => 'views_handler_filter_string',
  247. ),
  248. 'argument' => array(
  249. 'handler' => 'views_handler_argument_string',
  250. ),
  251. );
  252. // Submit Data
  253. $data['tripal_jobs']['submit_date'] = array(
  254. 'title' => t('Submit Date'),
  255. 'help' => t('The date the job was submitted.'),
  256. 'field' => array(
  257. 'handler' => 'views_handler_field_date',
  258. 'click sortable' => TRUE,
  259. ),
  260. 'sort' => array(
  261. 'handler' => 'views_handler_sort_date',
  262. ),
  263. 'filter' => array(
  264. 'handler' => 'views_handler_filter_date',
  265. ),
  266. );
  267. // Start Time
  268. $data['tripal_jobs']['start_time'] = array(
  269. 'title' => t('Start Time'),
  270. 'help' => t('The time the job started.'),
  271. 'field' => array(
  272. 'handler' => 'views_handler_field_date',
  273. 'click sortable' => TRUE,
  274. ),
  275. 'sort' => array(
  276. 'handler' => 'views_handler_sort_date',
  277. ),
  278. 'filter' => array(
  279. 'handler' => 'views_handler_filter_date',
  280. ),
  281. );
  282. // End Time
  283. $data['tripal_jobs']['end_time'] = array(
  284. 'title' => t('End Time'),
  285. 'help' => t('The time the job ended.'),
  286. 'field' => array(
  287. 'handler' => 'views_handler_field_date',
  288. 'click sortable' => TRUE,
  289. ),
  290. 'sort' => array(
  291. 'handler' => 'views_handler_sort_date',
  292. ),
  293. 'filter' => array(
  294. 'handler' => 'views_handler_filter_date',
  295. ),
  296. );
  297. // Error Message
  298. $data['tripal_jobs']['error_msg'] = array(
  299. 'title' => t('Error Message '),
  300. 'help' => t('A short description of any error the job might have had.'),
  301. 'field' => array(
  302. 'handler' => 'views_handler_field',
  303. 'click sortable' => TRUE, // This is use by the table display plugin.
  304. ),
  305. 'sort' => array(
  306. 'handler' => 'views_handler_sort',
  307. ),
  308. 'filter' => array(
  309. 'handler' => 'views_handler_filter_string',
  310. ),
  311. 'argument' => array(
  312. 'handler' => 'views_handler_argument_string',
  313. ),
  314. );
  315. // Unix Pid of the job
  316. $data['tripal_jobs']['pid'] = array(
  317. 'title' => t('Job PID'),
  318. 'help' => t('The Unix PID of the job.'),
  319. 'field' => array(
  320. 'handler' => 'views_handler_field_numeric',
  321. 'click sortable' => TRUE,
  322. ),
  323. 'filter' => array(
  324. 'handler' => 'views_handler_filter_numeric',
  325. ),
  326. 'sort' => array(
  327. 'handler' => 'views_handler_sort',
  328. ),
  329. );
  330. // Priority
  331. $data['tripal_jobs']['priority'] = array(
  332. 'title' => t('Priority'),
  333. 'help' => t('The priority of this job.'),
  334. 'field' => array(
  335. 'handler' => 'views_handler_field_numeric',
  336. 'click sortable' => TRUE,
  337. ),
  338. 'filter' => array(
  339. 'handler' => 'views_handler_filter_numeric',
  340. ),
  341. 'sort' => array(
  342. 'handler' => 'views_handler_sort',
  343. ),
  344. );
  345. }