Created
September 29, 2014 18:24
-
-
Save victorkane/8c1bce07a4f626f6da05 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 | |
/** | |
* @file news_features.module | |
* Expose an API for getting smartqueue content from Section and Edition vocabulary term based queues | |
* Given a taxonomy term (tid) of a section or category | |
* return the qid and sqid, and return lists of content populating the sub-queues. | |
*/ | |
/* | |
* Given a $tid, bring 9 featured members of the tid based smartqueue, | |
* If the number of featured articles for the tid is less than 9 | |
* fill up with the most recent un-featured articles | |
*/ | |
function news_features_get_nodes($tid) { | |
$sq_nodes = news_features_get_sq_nodes($tid); | |
$lacking = 9 - count($sq_nodes); | |
$nodes = $sq_nodes; | |
$nodenids = array(); | |
foreach ($nodes as $n) $nodenids[] = $n->nid; | |
if ($lacking > 0) { | |
$tid_nodes = news_features_get_tid_nodes($tid, $nodenids); | |
if (isset($tid_nodes)) { | |
for ($i = 0; $i < $lacking; $i++) { | |
if(isset($tid_nodes[$i])) { | |
$nid = $tid_nodes[$i]->nid; | |
$node = node_load($nid); | |
$nodes[] = $node; | |
} | |
} | |
} | |
} | |
return $nodes; | |
} | |
/* | |
* Given a tid, return an object containing qid and sqid from the nodequeue_subqueue table | |
* | |
* Returns, for exaple: | |
* stdClass Object | |
* ( | |
* [qid] => 3 | |
* [sqid] => 9 | |
* ) | |
*/ | |
function news_features_get_sq($tid) { | |
$query = db_select('nodequeue_subqueue', 'n') | |
->fields('n', array('qid', 'sqid')) | |
->condition('n.reference', $tid, '=') | |
; | |
$result = $query->execute(); | |
$record = $result->fetch(); | |
return $record; | |
} | |
/* | |
* Given an $sqid return the content in the position number one of the subqueue if it exists | |
*/ | |
function news_features_get_sq_node($tid) { | |
$sq_info = news_features_get_sq($tid); | |
if (isset($sq_info->sqid)) { | |
$query = db_select('nodequeue_nodes', 'n') | |
->fields('n', array('nid')) | |
->condition('n.sqid', $sq_info->sqid, '=') | |
->orderBy('n.position', 'ASC') | |
; | |
$result = $query->execute(); | |
$record = $result->fetch(); | |
if ($record) return node_load($record->nid); | |
} | |
} | |
/* | |
* Given an $sqid return the list of already published content, | |
* ordered by position in the queue | |
*/ | |
function news_features_get_sq_nodes($tid) { | |
$nodes = array(); | |
$sq_info = news_features_get_sq($tid); | |
if (isset($sq_info->sqid)) { | |
$query = db_select('nodequeue_nodes', 'n') | |
->fields('n', array('nid')) | |
->condition('n.sqid', $sq_info->sqid, '=') | |
->orderBy('n.position', 'ASC') | |
; | |
$result = $query->execute(); | |
foreach($result as $record) { | |
$nodes[] = node_load($record->nid); | |
} | |
} | |
return $nodes; | |
} | |
/* | |
* Given a tid get the last nine nodes | |
*/ | |
function news_features_get_tid_nodes($tid, $nodenids = array()) { | |
$view = views_get_view('secciones_y_ediciones'); | |
$view->set_display('block_1'); | |
$view->set_arguments(array($tid)); | |
$view->execute(); | |
$nodes = array(); | |
foreach($view->result as $n) { | |
if (!in_array($n->nid, $nodenids)) { | |
$nodes[] = $n; | |
} | |
} | |
return (count($nodes) > 0)?$nodes:NULL; | |
} | |
/* | |
* Given a tid, get the latest node | |
*/ | |
function news_features_get_tid_node($tid) { | |
$resultado = NULL; | |
$view = views_get_view('secciones_y_ediciones'); | |
$view->set_display('block_1'); | |
$view->set_arguments(array($tid)); | |
$view->execute(); | |
$result = $view->execute(); | |
return (count($view->result))?node_load($view->result[0]->nid):NULL; | |
} | |
/* | |
* Return the tid of the latest edition | |
*/ | |
function news_features_get_ultima_edicion () { | |
$resultado = NULL; | |
$view = views_get_view('listar_ediciones'); | |
$view->set_display('panel_pane_2'); | |
$view->execute(); | |
if (count($view->result)) return $resultado = $view->result[0]->tid; | |
return $resultado; | |
} | |
/* | |
* Return the complete node object of the featured article | |
* in the latest edition (or else the latest published article) | |
*/ | |
function news_features_get_feature_ultima_edicion() { | |
$tid = news_features_get_ultima_edicion(); | |
if($tid) { | |
$node = news_features_get_sq_node($tid); | |
} | |
if (!$node) { | |
$node = news_features_get_tid_node($tid); | |
} | |
return $node; | |
} | |
function news_features_get_feature_seccion($tid) { | |
$node = news_features_get_sq_node($tid); | |
if (!$node) { | |
$node = news_features_get_tid_node($tid); | |
} | |
return $node; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment