Tagged: coga

Loop 10 times in bash

for i in `seq 1 10`; do drush @cga.prod sapi-i 1 100 10; done

bill search view

$view = new view();
$view->name = 'bill_search';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'search_api_index_cga_main_index';
$view->human_name = 'Bill Search';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Bill Search';
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['search_api_bypass_access'] = 0;
$handler->display->display_options['query']['options']['entity_access'] = 0;
$handler->display->display_options['query']['options']['parse_mode'] = 'direct';
$handler->display->display_options['exposed_form']['type'] = 'better_exposed_filters';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '25';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '7';
$handler->display->display_options['pager']['options']['tags']['first'] = '';
$handler->display->display_options['pager']['options']['tags']['previous'] = 'Prev';
$handler->display->display_options['pager']['options']['tags']['next'] = 'Next';
$handler->display->display_options['pager']['options']['tags']['last'] = '';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'entity';
$handler->display->display_options['row_options']['view_mode'] = 'search';
/* Header: Global: Result summary */
$handler->display->display_options['header']['result']['id'] = 'result';
$handler->display->display_options['header']['result']['table'] = 'views';
$handler->display->display_options['header']['result']['field'] = 'result';
$handler->display->display_options['header']['result']['content'] = 'Displaying @start - @end of @total results';
/* Field: Indexed Content: Node ID */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
/* Filter criterion: Indexed Content: Content type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'bill' => 'bill',
);
/* Filter criterion: Search: Fulltext search */
$handler->display->display_options['filters']['search_api_views_fulltext']['id'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['search_api_views_fulltext']['field'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['exposed'] = TRUE;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator_id'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['label'] = 'Search Bill Name, Bill #, or Keyword';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['identifier'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
);
$handler->display->display_options['filters']['search_api_views_fulltext']['mode'] = 'filter';
/* Filter criterion: Indexed Content: Bill Type */
$handler->display->display_options['filters']['field_bill_type']['id'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_bill_type']['field'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_bill_type']['expose']['operator_id'] = 'field_bill_type_op';
$handler->display->display_options['filters']['field_bill_type']['expose']['label'] = 'Bill Type';
$handler->display->display_options['filters']['field_bill_type']['expose']['operator'] = 'field_bill_type_op';
$handler->display->display_options['filters']['field_bill_type']['expose']['identifier'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['type'] = 'select';
/* Filter criterion: Indexed Content: Chamber of Origination */
$handler->display->display_options['filters']['field_chamber']['id'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_chamber']['field'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_chamber']['expose']['operator_id'] = 'field_chamber_op';
$handler->display->display_options['filters']['field_chamber']['expose']['label'] = 'Chamber of Origination';
$handler->display->display_options['filters']['field_chamber']['expose']['operator'] = 'field_chamber_op';
$handler->display->display_options['filters']['field_chamber']['expose']['identifier'] = 'field_chamber';
/* Filter criterion: Indexed Content: Sessions */
$handler->display->display_options['filters']['field_sessions']['id'] = 'field_sessions';
$handler->display->display_options['filters']['field_sessions']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_sessions']['field'] = 'field_sessions';
/* Filter criterion: Indexed Content: Subjects */
$handler->display->display_options['filters']['field_subjects']['id'] = 'field_subjects';
$handler->display->display_options['filters']['field_subjects']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_subjects']['field'] = 'field_subjects';

/* Display: Full */
$handler = $view->new_display('page', 'Full', 'full');
$handler->display->display_options['defaults']['exposed_form'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'better_exposed_filters';
$handler->display->display_options['exposed_form']['options']['sort_asc_label'] = 'Ascending';
$handler->display->display_options['exposed_form']['options']['sort_desc_label'] = 'Descending';
$handler->display->display_options['exposed_form']['options']['bef'] = array(
  'general' => array(
    'input_required' => 0,
    'text_input_required' => array(
      'text_input_required' => array(
        'value' => 'Select any filter and click on Apply to see results',
        'format' => 'full_html',
      ),
    ),
    'allow_secondary' => 0,
    'secondary_label' => 'Advanced options',
    'secondary_collapse_override' => '0',
  ),
  'sort' => array(
    'bef_format' => 'default',
    'advanced' => array(
      'collapsible' => 0,
      'collapsible_label' => 'Sort options',
      'combine' => 1,
      'combine_param' => 'sort_bef_combine',
      'combine_rewrite' => '',
      'reset' => 0,
      'reset_label' => '',
      'is_secondary' => 0,
    ),
  ),
  'search_api_views_fulltext' => array(
    'bef_format' => 'default',
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
  'field_chamber' => array(
    'bef_format' => 'default',
    'slider_options' => array(
      'bef_slider_min' => '0',
      'bef_slider_max' => '99999',
      'bef_slider_step' => '1',
      'bef_slider_animate' => '',
      'bef_slider_orientation' => 'horizontal',
    ),
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '- All -',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
  'field_bill_type' => array(
    'bef_format' => 'default',
    'slider_options' => array(
      'bef_slider_min' => '0',
      'bef_slider_max' => '99999',
      'bef_slider_step' => '1',
      'bef_slider_animate' => '',
      'bef_slider_orientation' => 'horizontal',
    ),
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '- All -',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
  'field_sessions' => array(
    'bef_format' => 'default',
    'slider_options' => array(
      'bef_slider_min' => '0',
      'bef_slider_max' => '99999',
      'bef_slider_step' => '1',
      'bef_slider_animate' => '',
      'bef_slider_orientation' => 'horizontal',
    ),
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '- All -',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
  'field_subjects' => array(
    'bef_format' => 'default',
    'slider_options' => array(
      'bef_slider_min' => '0',
      'bef_slider_max' => '99999',
      'bef_slider_step' => '1',
      'bef_slider_animate' => '',
      'bef_slider_orientation' => 'horizontal',
    ),
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '- All -',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
);
$handler->display->display_options['exposed_block'] = TRUE;
$handler->display->display_options['defaults']['sorts'] = FALSE;
/* Sort criterion: Search: Relevance */
$handler->display->display_options['sorts']['search_api_relevance']['id'] = 'search_api_relevance';
$handler->display->display_options['sorts']['search_api_relevance']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['sorts']['search_api_relevance']['field'] = 'search_api_relevance';
$handler->display->display_options['sorts']['search_api_relevance']['order'] = 'DESC';
$handler->display->display_options['sorts']['search_api_relevance']['exposed'] = TRUE;
$handler->display->display_options['sorts']['search_api_relevance']['expose']['label'] = 'Most Relevant';
/* Sort criterion: Indexed Content: Bill Number */
$handler->display->display_options['sorts']['field_bill_number']['id'] = 'field_bill_number';
$handler->display->display_options['sorts']['field_bill_number']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['sorts']['field_bill_number']['field'] = 'field_bill_number';
$handler->display->display_options['sorts']['field_bill_number']['exposed'] = TRUE;
$handler->display->display_options['sorts']['field_bill_number']['expose']['label'] = 'Bill #';
/* Sort criterion: Indexed Content: Last Action Date */
$handler->display->display_options['sorts']['field_date']['id'] = 'field_date';
$handler->display->display_options['sorts']['field_date']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['sorts']['field_date']['field'] = 'field_date';
$handler->display->display_options['sorts']['field_date']['exposed'] = TRUE;
$handler->display->display_options['sorts']['field_date']['expose']['label'] = 'Last Action';
/* Sort criterion: Indexed Content: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['sorts']['title']['field'] = 'title';
$handler->display->display_options['sorts']['title']['expose']['label'] = 'Bill Topic';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Indexed Content: Content type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'bill' => 'bill',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Search: Fulltext search */
$handler->display->display_options['filters']['search_api_views_fulltext']['id'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['search_api_views_fulltext']['field'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['group'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['exposed'] = TRUE;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator_id'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['label'] = 'Bill #, Sponsor, or Keyword';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['identifier'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
  11 => 0,
  16 => 0,
  21 => 0,
  26 => 0,
  31 => 0,
  36 => 0,
);
/* Filter criterion: Indexed Content: Chamber of Origination */
$handler->display->display_options['filters']['field_chamber']['id'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_chamber']['field'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['value'] = array(
  2 => '2',
  1 => '1',
);
$handler->display->display_options['filters']['field_chamber']['group'] = 1;
$handler->display->display_options['filters']['field_chamber']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_chamber']['expose']['operator_id'] = 'field_chamber_op';
$handler->display->display_options['filters']['field_chamber']['expose']['label'] = 'House of Origin';
$handler->display->display_options['filters']['field_chamber']['expose']['operator'] = 'field_chamber_op';
$handler->display->display_options['filters']['field_chamber']['expose']['identifier'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
  11 => 0,
  16 => 0,
  21 => 0,
  26 => 0,
  31 => 0,
);
$handler->display->display_options['filters']['field_chamber']['is_grouped'] = TRUE;
$handler->display->display_options['filters']['field_chamber']['group_info']['label'] = 'House of Origin';
$handler->display->display_options['filters']['field_chamber']['group_info']['identifier'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['group_info']['group_items'] = array(
  1 => array(
    'title' => 'House',
    'operator' => '=',
    'value' => array(
      1 => '1',
    ),
  ),
  2 => array(
    'title' => 'Senate',
    'operator' => '=',
    'value' => array(
      2 => '2',
    ),
  ),
);
$handler->display->display_options['filters']['field_chamber']['type'] = 'select';
/* Filter criterion: Indexed Content: Bill Type */
$handler->display->display_options['filters']['field_bill_type']['id'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_bill_type']['field'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['value'] = array();
$handler->display->display_options['filters']['field_bill_type']['group'] = 1;
$handler->display->display_options['filters']['field_bill_type']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_bill_type']['expose']['operator_id'] = 'field_bill_type_op';
$handler->display->display_options['filters']['field_bill_type']['expose']['label'] = 'Type';
$handler->display->display_options['filters']['field_bill_type']['expose']['operator'] = 'field_bill_type_op';
$handler->display->display_options['filters']['field_bill_type']['expose']['identifier'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
);
$handler->display->display_options['filters']['field_bill_type']['type'] = 'select';
/* Filter criterion: Indexed Content: Sessions */
$handler->display->display_options['filters']['field_sessions']['id'] = 'field_sessions';
$handler->display->display_options['filters']['field_sessions']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_sessions']['field'] = 'field_sessions';
$handler->display->display_options['filters']['field_sessions']['group'] = 1;
$handler->display->display_options['filters']['field_sessions']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_sessions']['expose']['operator_id'] = 'field_sessions_op';
$handler->display->display_options['filters']['field_sessions']['expose']['label'] = 'Session';
$handler->display->display_options['filters']['field_sessions']['expose']['operator'] = 'field_sessions_op';
$handler->display->display_options['filters']['field_sessions']['expose']['identifier'] = 'field_sessions';
$handler->display->display_options['filters']['field_sessions']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
);
$handler->display->display_options['filters']['field_sessions']['type'] = 'select';
/* Filter criterion: Indexed Content: Subjects */
$handler->display->display_options['filters']['field_subjects']['id'] = 'field_subjects';
$handler->display->display_options['filters']['field_subjects']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_subjects']['field'] = 'field_subjects';
$handler->display->display_options['filters']['field_subjects']['value'] = array();
$handler->display->display_options['filters']['field_subjects']['group'] = 1;
$handler->display->display_options['filters']['field_subjects']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_subjects']['expose']['operator_id'] = 'field_subjects_op';
$handler->display->display_options['filters']['field_subjects']['expose']['label'] = 'Subject';
$handler->display->display_options['filters']['field_subjects']['expose']['operator'] = 'field_subjects_op';
$handler->display->display_options['filters']['field_subjects']['expose']['identifier'] = 'field_subjects';
$handler->display->display_options['filters']['field_subjects']['expose']['multiple'] = TRUE;
$handler->display->display_options['filters']['field_subjects']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
);
$handler->display->display_options['filters']['field_subjects']['type'] = 'select';
$handler->display->display_options['path'] = 'bill-search';

/* Display: Simple */
$handler = $view->new_display('page', 'Simple', 'simple');
$handler->display->display_options['exposed_block'] = TRUE;
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Indexed Content: Content type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'bill' => 'bill',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Search: Fulltext search */
$handler->display->display_options['filters']['search_api_views_fulltext']['id'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['search_api_views_fulltext']['field'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['group'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['exposed'] = TRUE;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator_id'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['label'] = 'Search by Bill # (ex. HB17-1001), Sponsor, or Keyword';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['identifier'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
  11 => 0,
  16 => 0,
  21 => 0,
  26 => 0,
  31 => 0,
  36 => 0,
  41 => 0,
);
$handler->display->display_options['filters']['search_api_views_fulltext']['mode'] = 'filter';
$handler->display->display_options['path'] = 'bill-search';

Search API Views Query Alter Example

/** 
 * Implements hook_search_api_views_query_alter().
 */
function cga_publications_search_api_views_query_alter(view &$view, SearchApiViewsQuery &$query) {
  if (!empty($view->exposed_raw_input['field_date'])) {
    $or = $query->createFilter('AND');                           
    $start = new DateTime($view->exposed_raw_input['field_date'] . "-01-01");                                                                     
    $start_date = $start->format('Y-m-d H:i:s');                                                                                                  
    $end = new DateTime($view->exposed_raw_input['field_date'] . '-12-31');                                                                       
    $end_date = $end->format('Y-m-d H:i:s');                                                                                                      
    $or->condition('field_date', $start_date, '>=');                                                                                              
    $or->condition('field_date', $end_date, '<=');                                                                                                
    $query->filter($or);                                                                                                                          
  }                                                                                                                                               
} 

Entity Field Query example

$b = new EntityFieldQuery();
$b->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'bill')
  ->propertyCondition('status', NODE_PUBLISHED)
  ->fieldCondition('field_sessions', 'target_id', 10171);
$result = $b->execute();

dpm($result);

Drush command to run queues

# time limit is in seconds
drush @cga.prod queue-run --time-limit=30 node_bills_queue

check if field_date exists in node object before accessing it in entity metadata wrapper

fd.php
// check if field_date exists in node object before accessing it in entity metadata wrapper
if (!empty($vars['content']['field_date'])) {
  $wrapper = entity_metadata_wrapper('node', $vars['node']);
  $timestamp = $wrapper->field_date->value();
  $vars['last_action'][] = date('m/j/Y', $timestamp);
}

// Check if a field_date isset in an object
if(isset($meeting->field_date)) {
  $meeting_date = $meeting_wrapper->field_date->value();
}
else {
  $meeting_date = "";
}