Last active
August 29, 2015 14:20
-
-
Save rudiedirkx/66fe1fadca6e539cac19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Smartqueue providers ('owners') can do this: | |
*/ | |
/** | |
* Implements hook_nodequeue_sqids(). | |
*/ | |
function USER_SMARTQUEUE_nodequeue_sqids($queue) { | |
global $user; | |
if (!empty($user->name)) { | |
$reference = $user->name; | |
$subqueues = nodequeue_load_subqueues_by_reference(array($queue->qid => array($reference))); | |
$sqids = ezmod_always_array_column($subqueues, 'sqid'); | |
return $sqids; | |
} | |
// Anonymous must not see everything. | |
return array(0); | |
} | |
/** | |
* Implements hook_nodequeue_sqids(). | |
*/ | |
function DOMAIN_SMARTQUEUE_nodequeue_sqids($queue) { | |
$domain = domain_get_domain(); | |
$reference = $domain['machine_name']; | |
$subqueues = nodequeue_load_subqueues_by_reference(array($queue->qid => array($reference))); | |
$sqids = ezmod_always_array_column($subqueues, 'sqid'); | |
return $sqids; | |
} | |
/** | |
* Because of this fix: | |
*/ | |
/** | |
* Implements hook_views_data_alter(). | |
*/ | |
function YOURMODULE_views_data_alter(&$data) { | |
// Use our class instead, so we can override query(). | |
$data['node']['nodequeue_rel']['relationship']['handler'] = 'nodequeue_handler_relationship_nodequeue_FIX'; | |
} | |
/** | |
* Sub class for Nodequeue's relationship, to make it work with smartqueues. | |
*/ | |
class nodequeue_handler_relationship_nodequeue_FIX extends nodequeue_handler_relationship_nodequeue { | |
function query() { | |
// Get all queues. | |
$queues = nodequeue_load_queues(nodequeue_get_all_qids(0, 0, TRUE), TRUE); | |
$map = nodequeue_get_qid_map(); | |
// Cycle through all selected queues (hopefully 1). | |
$sqids = array(); | |
foreach (array_filter($this->options['names']) as $queue) { | |
$queue = $queues[ $map[$queue] ]; | |
// Find relevant subqueues for this queue. | |
$more_sqids = module_invoke($queue->owner, 'nodequeue_sqids', $queue); | |
if (!$more_sqids) { | |
// Or load all subqueues if owner doesn't know 'nodequeue_sqids'. | |
$more_sqids = db_query('SELECT sqid FROM {nodequeue_subqueue} WHERE qid = ?', array($queue->qid))->fetchCol(); | |
} | |
// Add to subqueue list. | |
$sqids = array_merge($sqids, array_values($more_sqids)); | |
} | |
// Let Nodequeue do its JOIN thing. It's almost perfect. | |
parent::query(); | |
// Replace 'qid' condition with smart 'sqid'. | |
$join = $this->query->table_queue[$this->alias]['join']; | |
$join->extra[0] = array( | |
'field' => 'sqid', | |
'value' => $sqids, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment