function simpleads_simpleads_order in SimpleAds 7
Implements hook_simpleads_order().
File
- ./
simpleads.module, line 627
Code
function simpleads_simpleads_order($delta, $term_ids, $limit) {
$query = db_select('node', 'n');
$query
->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
$query
->join('field_data_field_ad_status', 'f', 'n.nid = f.entity_id');
$query
->fields('n', array(
'nid',
));
$query
->condition('n.type', 'simpleads');
$query
->condition('f.entity_type', 'node');
$query
->condition('f.field_ad_status_value', 1);
$query
->condition('ti.tid', $term_ids, 'IN');
$query
->condition('n.status', 1);
$query
->range(0, $limit);
$query
->addTag('node_access');
// Random order.
if ($delta == 'random') {
$query
->orderRandom();
return $query
->execute();
}
// Order by created date.
if ($delta == 'order_created_desc') {
$query
->orderBy('n.created', 'DESC');
return $query
->execute();
}
// Order by modified date.
if ($delta == 'order_modified_desc') {
$query
->orderBy('n.changed', 'DESC');
return $query
->execute();
}
// Order by title
if ($delta == 'order_title_asc') {
$query
->orderBy('n.title', 'ASC');
return $query
->execute();
}
// Nodequeue module integration
if (module_exists('nodequeue')) {
$qids = nodequeue_get_qids('simpleads');
foreach ($qids as $row) {
if ($delta == 'nqueue_' . $row->qid) {
$query = db_select('nodequeue_nodes', 'nn');
$query
->fields('nn', array(
'nid',
));
$query
->condition('nn.qid', $row->qid);
$query
->orderBy('nn.position', 'DESC');
$query
->addTag('node_access');
return $query
->execute();
}
}
}
}