123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- <?php
- function tripal_views_plugins() {
- return array(
- 'module' => 'tripal',
- 'query' => array(
- 'tripal_views_query' => array(
- 'title' => t('Tripal Entity Query'),
- 'help' => t('Query that allows you to search with Tripal entities.'),
- 'handler' => 'tripal_views_query',
- 'parent' => 'views_query',
- ),
- ),
- );
- }
- function tripal_views_data() {
- $data = array();
-
- tripal_views_data_jobs($data);
-
- tripal_views_data_tripal_bundles($data);
-
- tripal_views_data_fields($data);
- $data['views']['tripal_area_collections'] = array(
- 'title' => t('Tripal Content Data Collections'),
- 'help' => t('Save Tripal content search results into a data collection for downloading or use with other tools.'),
- 'area' => array(
- 'handler' => 'tripal_views_handler_area_collections',
- ),
- );
- return $data;
- }
- function tripal_views_data_alter(&$data) {
-
-
-
-
- foreach ($data as $data_table => $definition) {
- foreach ($definition as $data_column => $element) {
- if (is_array($element) and array_key_exists('field', $element) and
- is_array($element['field']) and array_key_exists('field_name', $element['field'])) {
- $field_name = $element['field']['field_name'];
- $field = field_info_field($field_name);
-
- if (!array_key_exists('TripalEntity', $field['bundles'])) {
- continue;
- }
-
- if (array_key_exists('tripal_storage_api', $field['storage']['settings'])) {
- continue;
- }
-
-
-
-
-
-
- $bundles = $field['bundles']['TripalEntity'];
- $result = array();
- foreach ($bundles as $bundle_name) {
-
-
-
- $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
- $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
- $bundle_term_id = $term->vocab->vocabulary . '__' . $term->accession;
- if (!array_key_exists($bundle_term_id, $data)) {
- continue;
- }
-
-
- if ($field['type'] == 'taxonomy_term_reference') {
- $data[$bundle_term_id][$field_name] = [
- 'title' => t('Tagged Categories'),
- 'help' => t('Relates this Tripal content type to categories that have been assigned to it using Drupal\'s Taxonomy system.'),
- 'relationship' => array(
- 'base' => $data_table,
- 'base field' => 'entity_id',
- 'relationship field' => 'entity_id',
- 'handler' => 'views_handler_relationship',
- 'label' => t('Tags'),
- ),
- ];
- }
- }
- }
- }
- }
- }
- function tripal_views_data_fields(&$data) {
-
-
- $all_bundles = [];
- $sql = "
- SELECT TB.name, TV.vocabulary, TT.accession
- FROM {tripal_bundle} TB
- INNER JOIN {tripal_term} TT on TT.id = TB.term_id
- INNER JOIN {tripal_vocab} TV on TV.id = TT.vocab_id
- ";
- $results = db_query($sql);
- while ($bundle = $results->fetchObject()) {
- $all_bundles[$bundle->name] = $bundle;
- }
-
-
- $tripal_field_types = tripal_get_field_types();
-
-
- $fields = field_info_fields();
- foreach ($fields as $field) {
- $field_type = $field['type'];
-
- if (!array_key_exists('TripalEntity', $field['bundles'])) {
- continue;
- }
-
-
- if (!array_key_exists('tripal_storage_api', $field['storage']['settings'])) {
- continue;
- }
-
- $fdata = [];
-
-
-
- $bundles = $field['bundles']['TripalEntity'];
- if (!is_array($bundles)) {
- $bundles = [$bundles];
- }
- foreach ($bundles as $bundle_name) {
-
-
-
- if (!in_array($bundle_name, array_keys($all_bundles))) {
- continue;
- }
-
-
- $vocabulary = $all_bundles[$bundle_name]->vocabulary;
- $accession = $all_bundles[$bundle_name]->accession;
- $view_base_id = $vocabulary . '__' . $accession;
-
-
-
- $instance = field_info_instance('TripalEntity', $field['field_name'], $bundle_name);
- if (!in_array($field_type, $tripal_field_types)) {
- $tfield = new TripalField($field, $instance);
- $fdata += $tfield->viewsData($view_base_id);
- }
-
-
- else {
- $tfield = new $field_type($field, $instance);
- $fdata += $tfield->viewsData($view_base_id);
- }
- }
-
- drupal_alter('field_views_data', $fdata, $field);
- if (is_array($fdata)) {
- $data = drupal_array_merge_deep($fdata, $data);
- }
- }
- }
- function tripal_views_data_tripal_bundles(&$data) {
-
-
- $bundles = db_select('tripal_bundle', 'tb')
- ->fields('tb')
- ->execute();
-
- while ($bundle = $bundles->fetchObject()) {
-
-
-
- $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
- $table = $term->vocab->vocabulary . '__' . $term->accession;
-
- $data[$table]['table']['group'] = t($bundle->label);
- $data[$table]['table']['base'] = array(
- 'query class' => 'tripal_views_query',
- 'title' => t($bundle->label),
- 'help' => t('Tripal ' . $bundle->label . ' pages'),
- );
- $data[$table]['entity_id'] = array(
- 'title' => t('Entity ID'),
- 'help' => t('The unique entity ID for this content type.'),
- 'field' => array(
- 'handler' => 'tripal_views_handler_field_entity',
- ),
- 'filter' => array(
- 'handler' => 'tripal_views_handler_filter',
- ),
- 'sort' => array(
- 'handler' => 'tripal_views_handler_sort',
- ),
- );
- $data[$table]['link'] = array(
- 'title' => t('Link'),
- 'help' => t('Provide a simple link to the content.'),
- 'field' => array(
- 'handler' => 'tripal_views_handler_field_entity_link',
- ),
- );
- $data[$table]['edit_link'] = array(
- 'title' => t('Edit Link'),
- 'help' => t('Provide a simple link to edit the content.'),
- 'field' => array(
- 'handler' => 'tripal_views_handler_field_entity_link_edit',
- ),
- );
- $data[$table]['delete_link'] = array(
- 'title' => t('Delete Link'),
- 'help' => t('Provide a simple link to delete the content.'),
- 'field' => array(
- 'handler' => 'tripal_views_handler_field_entity_link_delete',
- ),
- );
- $data[$table]['status'] = array(
- 'title' => t('Published'),
- 'help' => t('Whether or not the content is published.'),
- 'field' => array(
- 'handler' => 'tripal_views_handler_field_boolean',
- 'click sortable' => TRUE,
- 'output formats' => array(
- 'published-notpublished' => array(t('Published'), t('Not published')),
- ),
- ),
- 'filter' => array(
- 'handler' => 'tripal_views_handler_filter_boolean_operator',
- 'label' => t('Published'),
- 'type' => 'yes-no',
- 'use equal' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'tripal_views_handler_sort',
- ),
- );
- }
- }
- function tripal_views_data_jobs(&$data) {
- $data['tripal_jobs']['table']['group'] = t('Tripal Jobs');
- $data['tripal_jobs']['table']['base'] = array(
- 'field' => 'job_id',
- 'title' => t('Tripal Jobs'),
- 'help' => t('The Job Management system for Tripal.'),
- 'weight' => 10,
- );
-
- $data['tripal_jobs']['job_id'] = array(
- 'title' => t('Job ID'),
- 'help' => t('The job primary key.'),
- 'field' => array(
- 'handler' => 'views_handler_field_numeric',
- 'click sortable' => TRUE,
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_numeric',
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- );
-
- $data['tripal_jobs']['uid'] = array(
- 'title' => t('Job Submitter'),
- 'help' => t('The user who submitted the job.'),
- 'relationship' => array(
- 'base' => 'user',
- 'base field' => 'uid',
- 'handler' => 'views_handler_relationship',
- 'label' => t('Submitting User'),
- 'title' => t('Submitting User'),
- 'help' => t('The user who submitted the job'),
- ),
- );
-
- $data['tripal_jobs']['job_name'] = array(
- 'title' => t('Job Name'),
- 'help' => t('The name of the job.'),
- 'field' => array(
- 'handler' => 'views_handler_field',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_string',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_string',
- ),
- );
-
- $data['tripal_jobs']['modulename'] = array(
- 'title' => t('Module Name'),
- 'help' => t('The name of the module that submitted the job.'),
- 'field' => array(
- 'handler' => 'views_handler_field',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_string',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_string',
- ),
- );
-
- $data['tripal_jobs']['callback'] = array(
- 'title' => t('Callback'),
- 'help' => t('The callback executed when the job runs.'),
- 'field' => array(
- 'handler' => 'views_handler_field',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_string',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_string',
- ),
- );
-
- $data['tripal_jobs']['arguments'] = array(
- 'title' => t('Arguements'),
- 'help' => t('Any arguments passed to the callback.'),
- 'field' => array(
- 'handler' => 'views_handler_field',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_string',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_string',
- ),
- );
-
- $data['tripal_jobs']['progress'] = array(
- 'title' => t('Progress'),
- 'help' => t('The current progress of the job.'),
- 'field' => array(
- 'handler' => 'views_handler_field_numeric',
- 'click sortable' => TRUE,
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_numeric',
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- );
-
- $data['tripal_jobs']['status'] = array(
- 'title' => t('Status'),
- 'help' => t('The current status of the job.'),
- 'field' => array(
- 'handler' => 'views_handler_field',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_string',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_string',
- ),
- );
-
- $data['tripal_jobs']['submit_date'] = array(
- 'title' => t('Submit Date'),
- 'help' => t('The date the job was submitted.'),
- 'field' => array(
- 'handler' => 'views_handler_field_date',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort_date',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_date',
- ),
- );
-
- $data['tripal_jobs']['start_time'] = array(
- 'title' => t('Start Time'),
- 'help' => t('The time the job started.'),
- 'field' => array(
- 'handler' => 'views_handler_field_date',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort_date',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_date',
- ),
- );
-
- $data['tripal_jobs']['end_time'] = array(
- 'title' => t('End Time'),
- 'help' => t('The time the job ended.'),
- 'field' => array(
- 'handler' => 'views_handler_field_date',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort_date',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_date',
- ),
- );
-
- $data['tripal_jobs']['error_msg'] = array(
- 'title' => t('Error Message '),
- 'help' => t('A short description of any error the job might have had.'),
- 'field' => array(
- 'handler' => 'views_handler_field',
- 'click sortable' => TRUE,
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_string',
- ),
- 'argument' => array(
- 'handler' => 'views_handler_argument_string',
- ),
- );
-
- $data['tripal_jobs']['pid'] = array(
- 'title' => t('Job PID'),
- 'help' => t('The Unix PID of the job.'),
- 'field' => array(
- 'handler' => 'views_handler_field_numeric',
- 'click sortable' => TRUE,
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_numeric',
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- );
-
- $data['tripal_jobs']['priority'] = array(
- 'title' => t('Priority'),
- 'help' => t('The priority of this job.'),
- 'field' => array(
- 'handler' => 'views_handler_field_numeric',
- 'click sortable' => TRUE,
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_numeric',
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- );
- }
|