Tagged: coga

Entity Field Query

efq.php
$query = new EntityFieldQuery;
$results = $query
     ->entityCondition('entity_type', 'node')
     ->propertyCondition('type', 'bill')
     ->fieldCondition("field_field_bill_budget_rel", 1)
     ->addMetaData('account', user_load(1))->execute();

node_load(key($results['node']), NULL, TRUE);

add task to cron api (Elysia Cron)

cron.php
/**
 * Use Elysia Cron to run jobs
 */
function cga_import_cronapi($op, $job = NULL) {

  $items['download_house_status_sheet'] = array(
    'description' => 'Download House Status Sheet',
    'rule' => '0 0,2,18,20,22 * * *', // 12am, 2am, 6pm, 8pm, 10pm
    'callback' => 'cga_import_download_house_status_sheet',
  );
  $items['download_senate_status_sheet'] = array(
    'description' => 'Download Senate Status Sheet',
    'rule' => '5 0,2,18,20,22 * * *', // 12am, 2am, 6pm, 8pm, 10pm
    'callback' => 'cga_import_download_senate_status_sheet',
  );
  $items['download_senate_journal'] = array(
    'description' => 'Download Senate Journal',
    'rule' => '10 0,2,18,20,22 * * *', // 12am, 2am, 6pm, 8pm, 10pm
    'callback' => 'cga_import_download_senate_journal',
  );
  $items['download_house_journal'] = array(
    'description' => 'Download House Journal',
    'rule' => '15 0,2,18,20,22 * * *', // 12am, 2am, 6pm, 8pm, 10pm
    'callback' => 'cga_import_download_house_journal',
  );
  return $items;
}
function cga_import_download_house_status_sheet() {
  $url = 'http://192.70.175.128/Public/cgaAPI.nsf/api.xsp/schedules/house/ss';
  cga_import_cron_get_session_doc($url, "house_status_sheet");
}
function cga_import_cron_get_senate_status_sheet() {
  $url = 'http://192.70.175.128/Public/cgaAPI.nsf/api.xsp/schedules/senate/ss';
  cga_import_cron_get_session_doc($url, "senate_status_sheet");
}
function cga_import_cron_get_senate_journal() {
  $url = 'http://192.70.175.128/Public/cgaAPI.nsf/api.xsp/schedules/senate/journal';
  cga_import_cron_get_session_doc($url, "senate_journal");
}
function cga_import_cron_get_house_journal() {
  $url = 'http://192.70.175.128/Public/cgaAPI.nsf/api.xsp/schedules/house/journal';
  cga_import_cron_get_session_doc($url, "house_journal");
}

Session Docs template

bean--chamber-publications--default.tpl.php
<div id="status_sheets" class="document-container">
   <h4 class="document-section-title" >Status of Bills:</h4>
      <a href="<?php print $content['field_house_status_sheet'][0]['#markup'] . "?t=$last_changed"; ?>" class="chamber-document cta-button <?php print cga_entity_queries_in_session() ? '' : 'disabled'; ?>" >House Status Sheet</a>
      <a href="<?php print $content['field_senate_status_sheet'][0]['#markup'] . "?t=$last_changed"; ?>" class="chamber-document cta-button <?php print cga_entity_queries_in_session() ? '' : 'disabled'; ?>" >Senate Status Sheet</a>
</div>
<div id="journals" class="document-container">
    <h4 class="document-section-title">Cumulative Journals:</h4>
      <a href="<?php print $content['field_house_status_sheet'][0]['#markup'] . "?t=$last_changed"; ?>" class="chamber-document cta-button <?php print cga_entity_queries_in_session() ? '' : 'disabled'; ?>" >House Status Sheet</a>
      <a href="<?php print $content['field_senate_status_sheet'][0]['#markup'] . "?t=$last_changed"; ?>" class="chamber-document cta-button <?php print cga_entity_queries_in_session() ? '' : 'disabled'; ?>" >Senate Status Sheet</a>
</div>

htaccess prevent pdf caching

.htaccess
<FilesMatch ".(pdf)$">
  FileETag None
  <ifModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</FilesMatch>

Clear Node's Cache in hook_node_update

clear_cache_node_update.php
function cga_import_node_update($node) {
  $nodeurl = url('node/'. $node->nid);
  cache_clear_all($nodeurl, 'cache_page');
}

// The above doesnay work, below does but it is overkill.
$core = array('cache', 'cache_path', 'cache_filter', 'cache_bootstrap', 'cache_page');
$cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
foreach ($cache_tables as $table) {
  cache_clear_all('*', $table, TRUE);
}

// This works and is more narrow
$cache_tables = array('cache_field', 'cache_block');
foreach ($cache_tables as $table) {
  cache_clear_all('*', $table, TRUE);
}

// field:node:[nid]
// 
cache_clear_all('*', 'cache_field', TRUE);

Get Block ID from Block Type

cga_utilities.php
<?php
/**
 * Utility function to get Block ID for a certain block type
 */
function cga_import_get_id_of_block_type($block_type) {
  $bids = array();

  $query = new EntityFieldQuery();
  $result = $query
   ->entityCondition('entity_type', 'bean')
   ->entityCondition('bundle', $block_type)
   ->execute();
  //get bean ids
  if (isset($result['bean'])) {
   $bids = array_keys($result['bean']);
  }
  return array_shift($bids);
}