Sfoglia il codice sorgente

Fixed bug with conflicting views handler filter name. Experimenting with Entity Query API... added form to content list page

Stephen Ficklin 10 anni fa
parent
commit
78b10ee6cc

+ 82 - 5
tripal/includes/TripalEntityUIController.inc

@@ -162,18 +162,80 @@ function tripal_view_entity($entity, $view_mode = 'full') {
   *   A form array describing this listing to the Form API.
   */
  function tripal_content_overview_form($form, &$form_state) {
-
+   $filter_status = '';
+   $filter_type = '';
+   if (array_key_exists('values', $form_state)) {
+     if ($form_state['values']['status'] != '[any]') {
+       $filter_status = preg_replace('/status-(\d+)/', '\1', $form_state['values']['status']);
+     }
+     if ($form_state['values']['type'] != '[any]') {
+       $filter_type = $form_state['values']['type'];
+     }
+   }
    // Set the title to be informative (defaults to content for some reason).
    drupal_set_title('Tripal Content');
 
+   $form['filter'] = array(
+     '#type' => 'fieldset',
+     '#title' => 'Filter',
+     '#collapsible' => TRUE,
+     '#collapsed' => TRUE,
+   );
+   $etypes = db_select('tripal_bundle', 'tb')
+     ->fields('tb', array('id', 'label'))
+     ->execute()
+     ->fetchAllKeyed();
+   $etypes = array('[any]' => 'any') +  $etypes;
+   $form['filter']['type'] = array(
+     '#type' => 'select',
+     '#title' => 'Content Type',
+     '#options' => $etypes,
+   );
+   $form['filter']['status'] = array(
+     '#type' => 'select',
+     '#title' => 'Status',
+     '#options' => array(
+       '[any]' => 'any',
+       'status-1' => 'published',
+       'status-0' => 'not published'
+     ),
+   );
+   $form['filter']['filterbtn'] = array(
+     '#type' => 'submit',
+     '#value' => 'Filter',
+   );
+
    // Retrieve a pages list of all tripal entitles (ie: biological data).
    // This will return the 25 most recently created entities.
-   $entities = db_select('tripal_entity', 'td')
-     ->fields('td')
-     ->orderBy('created', 'DESC')
+   $query = db_select('tripal_entity', 'td')
+     ->fields('td');
+   if ($filter_type) {
+     $query = $query->condition('term_id', $filter_type);
+   }
+   if (is_numeric($filter_status)) {
+     $query = $query->condition('status', $filter_status);
+   }
+   $entities = $query->orderBy('created', 'DESC')
      ->range(0,25)
      ->execute();
 
+   global $user;
+   $query = new EntityFieldQuery();
+   $query->entityCondition('entity_type', 'TripalEntity');
+   if ($filter_type) {
+     $query = $query->propertyCondition('term_id', $filter_type);
+   }
+   if (is_numeric($filter_status)) {
+     $query = $query->propertyCondition('status', $filter_status);
+   }
+//   $query = $query->fieldCondition('feature__name', 'value', 'orange1.1g022797m');
+//   $query = $query->fieldCondition('feature__uniquename', 'value', 'PAC:18136225');
+
+   $result = $query->range(0, 25)
+     ->addMetaData('account', $user)
+     ->execute();
+   dpm($result);
+
    $headers = array('Title', 'Vocabulary', 'Term', 'Author', 'Status', 'Updated', 'Operations');
    $rows = array();
 
@@ -214,7 +276,7 @@ function tripal_view_entity($entity, $view_mode = 'full') {
    if (empty($rows)) {
      $rows[] = array(
        array(
-         'data' => t('No Tripal content available.'),
+         'data' => t('No content can be found.'),
          'colspan' => 7
        )
      );
@@ -238,6 +300,21 @@ function tripal_view_entity($entity, $view_mode = 'full') {
    return $form;
  }
 
+ /**
+  *
+  */
+ function tripal_content_overview_form_validate($form, &$form_state) {
+ }
+
+ /**
+  *
+  */
+ function tripal_content_overview_form_submit($form, &$form_state) {
+   // Always just rebuild the form on submit.  that will update the
+   // result table using the filters provided.
+   $form_state['rebuild'] = TRUE;
+ }
+
  /**
   *
   */

+ 1 - 1
tripal/includes/TripalTermViewsController.inc

@@ -17,7 +17,7 @@ class TripalTermViewsController extends EntityDefaultViewsController {
 
     $data['tripal_term']['name']['title'] = 'Content Type';
     $data['tripal_term']['name']['help'] = t('The name of a Tripal content type.');
-    $data['tripal_term']['name']['filter']['handler'] = 'tripal_views_handler_filter_select_string';
+    $data['tripal_term']['name']['filter']['handler'] = 'tripal_views_handler_filter_string_selectbox';
 
     $data['tripal_term']['vocab_id']['title'] = t('Vocabulary ID');
     $data['tripal_term']['vocab_id']['help'] = t('The internal numeric ID for the vocabulary to which the content type term belongs.');

+ 1 - 1
tripal/tripal.info

@@ -9,7 +9,7 @@ configure = admin/tripal
 stylesheets[all][] = theme/css/tripal.css
 scripts[]          = theme/js/tripal.js
 
-files[] = views_handlers/tripal_views_handler_filter_select_string.inc
+files[] = views_handlers/tripal_views_handler_filter_string_selectbox.inc
 files[] = views_handlers/tripal_views_handler_field_entity.inc
 files[] = views_handlers/tripal_views_handler_field_entity_status.inc
 

+ 0 - 55
tripal/tripal.views.inc

@@ -279,59 +279,4 @@ function tripal_views_data_jobs($data) {
   );
 
   return $data;
-}
-
-
-/**
- * Implements hook_views_handlers().
- *
- * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field",
- *   "how a field should be filtered", "how a field should be sorted"
- *
- * @return
- *   An array of handler definitions
- *
- * @ingroup tripal_views
- */
-function tripal_views_views_handlers() {
-
-  return array(
-    'info' => array(
-      'path' => drupal_get_path('module', 'tripal') . '/views_handlers',
-    ),
-    'handlers' => array(
-//       // Custom area handler
-//       'tripal_views_handler_area_action_links' => array(
-//         'parent' => 'views_handler_area',
-//       ),
-
-      // Custom Tripal Filter Handlers
-//       'tripal_views_handler_filter_no_results' => array(
-//         'parent' => 'views_handler_filter'
-//       ),
-//       'tripal_views_handler_filter_select_cvterm' => array(
-//         'parent' => 'tripal_views_handler_filter_select_string',
-//       ),
-//       'tripal_views_handler_filter_select_id' => array(
-//         'parent' => 'tripal_views_handler_filter_select_string',
-//       ),
-      'tripal_views_handler_filter_select_string' => array(
-        'parent' => 'views_handler_filter_string',
-      ),
-      'tripal_views_handler_field_entity' => array(
-        'parent' => 'tripal_views_handler_field_entity',
-      ),
-      'tripal_views_handler_field_entity_status' => array(
-        'parent' => 'tripal_views_handler_field_entity_status',
-      ),
-//       'tripal_views_handler_filter_textarea' => array(
-//         'parent' => 'views_handler_filter',
-//       ),
-//       'tripal_views_handler_filter_file_upload' => array(
-//         'parent' => 'views_handler_filter',
-//       ),
-
-    ),
-  );
 }

+ 2 - 2
tripal/views_handlers/tripal_views_handler_filter_select_string.inc

@@ -1,7 +1,7 @@
 <?php
 /**
  * @file
-* Contains tripal_views_handler_filter_select_string Filter Handler
+* Contains tripal_views_handler_filter_string_selectbox Filter Handler
 */
 
 /**
@@ -10,7 +10,7 @@
 *
 * @ingroup tripal_views
 */
-class tripal_views_handler_filter_select_string extends views_handler_filter_string {
+class tripal_views_handler_filter_string_selectbox extends views_handler_filter_string {
 
   /**
    * {@inheritdoc}

+ 1 - 1
tripal_chado/includes/fields/chado_feature__md5checksum.inc

@@ -127,7 +127,7 @@ class chado_feature__md5checksum  extends TripalField {
 
     $field_name = $field['field_name'];
     if ($record and property_exists($record, 'md5checksum')) {
-      $entity->{$field_name}['und'][] = array('value' => $record->md5checksum);
+      $entity->{$field_name}['und'][0]['value'] = $record->md5checksum;
     }
   }
 }

+ 4 - 4
tripal_chado/includes/fields/chado_linker__featureloc.inc

@@ -56,10 +56,10 @@ class chado_linker__featureloc extends TripalField {
         'chado_column' => $pkey,
         'base_table' => 'feature',
         'semantic_web' => array(
-          'name' => '',
-          'accession' => '',
-          'ns' => '',
-          'nsurl' => '',
+          'name' => 'position_of',
+          'accession' => 'position_of',
+          'ns' => 'SO',
+          'nsurl' => 'http://www.sequenceontology.org/',
         ),
       ),
     );

+ 9 - 1
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -406,4 +406,12 @@ function tripal_chado_field_storage_unnest_fields($fields, $entity_type, $entity
  * NOTE: This function needs to exist or errors are triggered but so far it doesn't
  * appear to actually need to do anything...
  */
-function tripal_chado_field_storage_query($query) { }
+function tripal_chado_field_storage_query($query) {
+  dpm($query);
+  $fieldConditions = $query->fieldConditions;
+  foreach ($fieldConditions as $condition) {
+    $field = $condition['field'];
+    $field_name = $field['field_name'];
+    $column = $condition['column'];
+  }
+}