tripal.views.inc 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. * for the creation of administrative views.
  25. *
  26. * @ingroup tripal
  27. */
  28. function tripal_views_data() {
  29. $data = array();
  30. // Job Management System
  31. $data = tripal_views_data_jobs($data);
  32. $data += tripal_entity_views_data();
  33. return $data;
  34. }
  35. /**
  36. * Integrates the TripalEntity entities with Drupal Views.
  37. */
  38. function tripal_entity_views_data() {
  39. $data = array();
  40. // Get the list of all of the bundles (entity types) and add them
  41. // as "base tables" for views.
  42. $bundles = db_select('tripal_bundle', 'tb')
  43. ->fields('tb')
  44. ->execute();
  45. // Iterate through the bundles.
  46. while ($bundle = $bundles->fetchObject()) {
  47. // Each bundle gets it's own "table".
  48. $data[$bundle->name]['table']['group'] = t('Tripal ' . $bundle->label . ' page');
  49. $data[$bundle->name]['table']['base'] = array(
  50. 'query class' => 'tripal_views_query',
  51. 'title' => t('Tripal ' . $bundle->label . ' page'),
  52. 'help' => t('Searches Tripal ' . $bundle->label . ' pages'),
  53. );
  54. // Now add the fields to the bundle.
  55. $instances = field_info_instances('TripalEntity', $bundle->name);
  56. foreach ($instances as $instance) {
  57. // TODO: how to determine which handler to use for each field? Perhaps
  58. // fields should set their type and here we use that type to determine
  59. // which handler to use. If not handler is specified then we use
  60. // a default string handler.
  61. $field_handler = 'tripal_views_handler_field_entity_default_formatter';
  62. $filter_handler = 'tripal_views_handler_filter_entity_string';
  63. $sort_handler = 'tripal_views_handler_sort_entity_string';
  64. $click_sortable = TRUE;
  65. $field_name = $instance['field_name'];
  66. if ($field_name == 'content_type') {
  67. $field_handler = 'views_handler_field';
  68. }
  69. $data[$bundle->name][$field_name] = array(
  70. 'title' => $instance['label'],
  71. 'help' => $instance['description'],
  72. 'field' => array(
  73. 'handler' => $field_handler,
  74. 'click sortable' => $click_sortable,
  75. ),
  76. 'filter' => array(
  77. 'handler' => $filter_handler,
  78. ),
  79. 'sort' => array(
  80. 'handler' => $sort_handler,
  81. ),
  82. );
  83. }
  84. }
  85. return $data;
  86. }
  87. /**
  88. * Provides the data array for the tripal job management system
  89. *
  90. * @param $data
  91. * Previously generated tripal views data array
  92. * return
  93. * $data array with job management system described
  94. *
  95. * @ingroup tripal
  96. */
  97. function tripal_views_data_jobs($data) {
  98. $data['tripal_jobs']['table']['group'] = t('Tripal Jobs');
  99. $data['tripal_jobs']['table']['base'] = array(
  100. 'field' => 'job_id', // This is the identifier field for the view.
  101. 'title' => t('Tripal Jobs'),
  102. 'help' => t('The Job Management system for Tripal.'),
  103. 'weight' => 10,
  104. );
  105. // Job ID
  106. $data['tripal_jobs']['job_id'] = array(
  107. 'title' => t('Job ID'),
  108. 'help' => t('The job primary key.'),
  109. 'field' => array(
  110. 'handler' => 'views_handler_field_numeric',
  111. 'click sortable' => TRUE,
  112. ),
  113. 'filter' => array(
  114. 'handler' => 'views_handler_filter_numeric',
  115. ),
  116. 'sort' => array(
  117. 'handler' => 'views_handler_sort',
  118. ),
  119. );
  120. // User ID: Submitter
  121. $data['tripal_jobs']['uid'] = array(
  122. 'title' => t('Job Submitter'),
  123. 'help' => t('The user who submitted the job.'),
  124. 'relationship' => array(
  125. 'base' => 'user', // The name of the table to join with.
  126. 'base field' => 'uid', // The name of the field on the joined table.
  127. 'handler' => 'views_handler_relationship',
  128. 'label' => t('Submitting User'),
  129. 'title' => t('Submitting User'),
  130. 'help' => t('The user who submitted the job'),
  131. ),
  132. );
  133. // Job Name
  134. $data['tripal_jobs']['job_name'] = array(
  135. 'title' => t('Job Name'),
  136. 'help' => t('The name of the job.'),
  137. 'field' => array(
  138. 'handler' => 'views_handler_field',
  139. 'click sortable' => TRUE, // This is use by the table display plugin.
  140. ),
  141. 'sort' => array(
  142. 'handler' => 'views_handler_sort',
  143. ),
  144. 'filter' => array(
  145. 'handler' => 'views_handler_filter_string',
  146. ),
  147. 'argument' => array(
  148. 'handler' => 'views_handler_argument_string',
  149. ),
  150. );
  151. // Module Name
  152. $data['tripal_jobs']['modulename'] = array(
  153. 'title' => t('Module Name'),
  154. 'help' => t('The name of the module that submitted the job.'),
  155. 'field' => array(
  156. 'handler' => 'views_handler_field',
  157. 'click sortable' => TRUE, // This is use by the table display plugin.
  158. ),
  159. 'sort' => array(
  160. 'handler' => 'views_handler_sort',
  161. ),
  162. 'filter' => array(
  163. 'handler' => 'views_handler_filter_string',
  164. ),
  165. 'argument' => array(
  166. 'handler' => 'views_handler_argument_string',
  167. ),
  168. );
  169. // Callback
  170. $data['tripal_jobs']['callback'] = array(
  171. 'title' => t('Callback'),
  172. 'help' => t('The callback executed when the job runs.'),
  173. 'field' => array(
  174. 'handler' => 'views_handler_field',
  175. 'click sortable' => TRUE, // This is use by the table display plugin.
  176. ),
  177. 'sort' => array(
  178. 'handler' => 'views_handler_sort',
  179. ),
  180. 'filter' => array(
  181. 'handler' => 'views_handler_filter_string',
  182. ),
  183. 'argument' => array(
  184. 'handler' => 'views_handler_argument_string',
  185. ),
  186. );
  187. // Arguments
  188. $data['tripal_jobs']['arguments'] = array(
  189. 'title' => t('Arguements'),
  190. 'help' => t('Any arguements passed to the callback.'),
  191. 'field' => array(
  192. 'handler' => 'views_handler_field',
  193. 'click sortable' => TRUE, // This is use by the table display plugin.
  194. ),
  195. 'sort' => array(
  196. 'handler' => 'views_handler_sort',
  197. ),
  198. 'filter' => array(
  199. 'handler' => 'views_handler_filter_string',
  200. ),
  201. 'argument' => array(
  202. 'handler' => 'views_handler_argument_string',
  203. ),
  204. );
  205. // Progress
  206. $data['tripal_jobs']['progress'] = array(
  207. 'title' => t('Progress'),
  208. 'help' => t('The current progress of the job.'),
  209. 'field' => array(
  210. 'handler' => 'views_handler_field_numeric',
  211. 'click sortable' => TRUE,
  212. ),
  213. 'filter' => array(
  214. 'handler' => 'views_handler_filter_numeric',
  215. ),
  216. 'sort' => array(
  217. 'handler' => 'views_handler_sort',
  218. ),
  219. );
  220. // Status
  221. $data['tripal_jobs']['status'] = array(
  222. 'title' => t('Status'),
  223. 'help' => t('The current status of the job.'),
  224. 'field' => array(
  225. 'handler' => 'views_handler_field',
  226. 'click sortable' => TRUE, // This is use by the table display plugin.
  227. ),
  228. 'sort' => array(
  229. 'handler' => 'views_handler_sort',
  230. ),
  231. 'filter' => array(
  232. 'handler' => 'views_handler_filter_string',
  233. ),
  234. 'argument' => array(
  235. 'handler' => 'views_handler_argument_string',
  236. ),
  237. );
  238. // Submit Data
  239. $data['tripal_jobs']['submit_date'] = array(
  240. 'title' => t('Submit Date'),
  241. 'help' => t('The date the job was submitted.'),
  242. 'field' => array(
  243. 'handler' => 'views_handler_field_date',
  244. 'click sortable' => TRUE,
  245. ),
  246. 'sort' => array(
  247. 'handler' => 'views_handler_sort_date',
  248. ),
  249. 'filter' => array(
  250. 'handler' => 'views_handler_filter_date',
  251. ),
  252. );
  253. // Start Time
  254. $data['tripal_jobs']['start_time'] = array(
  255. 'title' => t('Start Time'),
  256. 'help' => t('The time the job started.'),
  257. 'field' => array(
  258. 'handler' => 'views_handler_field_date',
  259. 'click sortable' => TRUE,
  260. ),
  261. 'sort' => array(
  262. 'handler' => 'views_handler_sort_date',
  263. ),
  264. 'filter' => array(
  265. 'handler' => 'views_handler_filter_date',
  266. ),
  267. );
  268. // End Time
  269. $data['tripal_jobs']['end_time'] = array(
  270. 'title' => t('End Time'),
  271. 'help' => t('The time the job ended.'),
  272. 'field' => array(
  273. 'handler' => 'views_handler_field_date',
  274. 'click sortable' => TRUE,
  275. ),
  276. 'sort' => array(
  277. 'handler' => 'views_handler_sort_date',
  278. ),
  279. 'filter' => array(
  280. 'handler' => 'views_handler_filter_date',
  281. ),
  282. );
  283. // Error Message
  284. $data['tripal_jobs']['error_msg'] = array(
  285. 'title' => t('Error Message '),
  286. 'help' => t('A short description of any error the job might have had.'),
  287. 'field' => array(
  288. 'handler' => 'views_handler_field',
  289. 'click sortable' => TRUE, // This is use by the table display plugin.
  290. ),
  291. 'sort' => array(
  292. 'handler' => 'views_handler_sort',
  293. ),
  294. 'filter' => array(
  295. 'handler' => 'views_handler_filter_string',
  296. ),
  297. 'argument' => array(
  298. 'handler' => 'views_handler_argument_string',
  299. ),
  300. );
  301. // Unix Pid of the job
  302. $data['tripal_jobs']['pid'] = array(
  303. 'title' => t('Job PID'),
  304. 'help' => t('The Unix PID of the job.'),
  305. 'field' => array(
  306. 'handler' => 'views_handler_field_numeric',
  307. 'click sortable' => TRUE,
  308. ),
  309. 'filter' => array(
  310. 'handler' => 'views_handler_filter_numeric',
  311. ),
  312. 'sort' => array(
  313. 'handler' => 'views_handler_sort',
  314. ),
  315. );
  316. // Priority
  317. $data['tripal_jobs']['priority'] = array(
  318. 'title' => t('Priority'),
  319. 'help' => t('The priority of this job.'),
  320. 'field' => array(
  321. 'handler' => 'views_handler_field_numeric',
  322. 'click sortable' => TRUE,
  323. ),
  324. 'filter' => array(
  325. 'handler' => 'views_handler_filter_numeric',
  326. ),
  327. 'sort' => array(
  328. 'handler' => 'views_handler_sort',
  329. ),
  330. );
  331. return $data;
  332. }