Skip to content

Instantly share code, notes, and snippets.

@baisong
Created September 17, 2012 13:21
Show Gist options
  • Select an option

  • Save baisong/3737222 to your computer and use it in GitHub Desktop.

Select an option

Save baisong/3737222 to your computer and use it in GitHub Desktop.
A class to extend EntityFieldQuery for common OS conditions.
<?php
// $Id$
/**
* @file
* Common functions for working with node content in OpenScholar.
*/
/**
* Prepares an EntityFieldQuery with any necessary vsite-sensitive conditions.
*/
class OSNodeFieldQuery extends EntityFieldQuery {
public function __construct($type = NULL) {
// Limits only to published nodes.
$this
->entityCondition('entity_type', 'node')
->propertyCondition('status', 1);
if (isset($type) && strlen($type) > 0) {
$this->propertyCondition('type', $type);
}
if (!module_exists('vsite')) {
return;
}
$space = spaces_get_space();
if (is_object($space) && !is_numeric($space->id)) {
return;
}
$this
->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $space->id);
}
}
/**
* Usage
include_once drupal_get_path('module', 'os') . '/includes/node.inc';
$query = new OSNodeFieldQuery('announcement');
$query
->propertyOrderBy('created', 'DESC')
->fieldCondition('field_whatever', 'value', '1')
->range(0,3);
$result = $query->execute();
if (!isset($result['node'])) {
// No results
}
else {
$nodes = node_load_multiple(array_keys($result['node'));
}
*/
@sagotsky

Copy link
Copy Markdown

Why not use ctools_include? All the other in os/includes use it. i.e. https://github.com/openscholar/openscholar/blob/SCHOLAR-3-0/modules/vsite/vsite.module#L94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment