Skip to content
This repository has been archived by the owner on May 2, 2018. It is now read-only.

Commit

Permalink
change queries for blocks on front page; fix #258
Browse files Browse the repository at this point in the history
  • Loading branch information
holtzermann17 committed Nov 29, 2012
1 parent f5ce106 commit cd58052
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions sites/all/modules/planetmath_blocks/planetmath_blocks.module
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,29 @@ function planetmath_blocks_queryGeneral($type, $sortBy = 'n.created') {
return $return;
}

function planetmath_blocks_queryEncyclopedia() {
$results = db_query("SELECT n.nid AS nid, n.title AS title, n.uid, fdb.body_value AS body, u.`name` AS username, n.created, n.changed
FROM node n
LEFT JOIN field_data_body fdb ON n.nid = fdb.entity_id
INNER JOIN users u ON u.uid = n.uid
INNER JOIN field_data_field_published f ON n.nid = f.entity_id
INNER JOIN field_data_field_section s ON n.nid = s.entity_id
WHERE n.`type` = 'article'
AND f.field_published_value = 1
AND s.field_section_value = 'Reference'
ORDER BY n.created DESC LIMIT 0," . PLANETMATH_BLOCKS_NUMBER_OF_ITEMS_ON_BLOCK);
$return = array();
foreach ($results as $result) {
$return[] = $result;
}
return $return;
}

/**
* Queries for the block views
*
* Note, we want to skip things where "created" is the same as "changed"
* (i.e. we're at version 1).
*/
function planetmath_blocks_queryRevisions($type, $sortBy = 'n.created') {
$results = db_query("SELECT n.nid AS nid, n.title AS title, n.uid, fdb.body_value AS body, u.`name` AS username, n.created, n.changed
Expand All @@ -75,6 +96,7 @@ function planetmath_blocks_queryRevisions($type, $sortBy = 'n.created') {
INNER JOIN field_data_field_published f ON n.nid = f.entity_id
WHERE n.`type` = :type
AND f.field_published_value = 1
AND n.created <> n.changed
ORDER BY $sortBy DESC LIMIT 0," . PLANETMATH_BLOCKS_NUMBER_OF_ITEMS_ON_BLOCK, array(':type' => $type));
$return = array();
foreach ($results as $result) {
Expand All @@ -96,14 +118,29 @@ function planetmath_blocks_queryPersonalResponses($uid) {
return $return;
}

function planetmath_blocks_queryEverythingElse($sortBy = 'n.changed') {
$results = db_query("SELECT n.nid AS nid, n.title AS title, n.type as type, n.uid, fdb.body_value AS body, u.`name` AS username, n.created
// I want the non-encyclopedia articles to show up here in addition to all the
// other stuff... I think maybe easiest way to achieve this is with a UNION?
function planetmath_blocks_queryEverythingElse() {
$results = db_query("(SELECT n.nid AS nid, n.title AS title, n.type as type, n.uid, fdb.body_value AS body, u.`name` AS username, n.created AS created, n.changed, 'foo' AS metadata
FROM node n
LEFT JOIN field_data_body fdb ON n.nid = fdb.entity_id
INNER JOIN users u ON u.uid = n.uid
WHERE n.`type` IN (:type) ORDER BY n.changed DESC)
UNION ALL
(SELECT n.nid AS nid, n.title AS title, n.type as type, n.uid, fdb.body_value AS body, u.`name` AS username, n.created AS created, n.changed, s.field_section_value AS metadata
FROM node n
LEFT JOIN field_data_body fdb ON n.nid = fdb.entity_id
INNER JOIN users u ON u.uid = n.uid
WHERE n.`type` IN (:type) ORDER BY $sortBy DESC LIMIT 0," . PLANETMATH_BLOCKS_EVERYTHING_ELSE_NUMBER_OF_ITEMS_ON_BLOCK, array(':type' => unserialize(PLANETMATH_BLOCKS_EVERYTHING_ELSE_TYPES)));
INNER JOIN field_data_field_published f ON n.nid = f.entity_id
INNER JOIN field_data_field_section s ON n.nid = s.entity_id
WHERE n.`type` = 'article'
AND f.field_published_value = 1
AND s.field_section_value <> 'Reference'
ORDER BY n.created DESC) ORDER BY created DESC
LIMIT 0," . PLANETMATH_BLOCKS_EVERYTHING_ELSE_NUMBER_OF_ITEMS_ON_BLOCK, array(':type' => unserialize(PLANETMATH_BLOCKS_EVERYTHING_ELSE_TYPES)));
$return = array();
// We will filter out the groups that are not of subtype "Team".
// We will filter out any GROUPS that are not of subtype "Team".
// NB. this could be done with another subselect and a bigger union.
foreach ($results as $result) {
if ($result->type == 'group') {
$subtype = node_load($result->nid)->field_group_subtype['und'][0]['value'];
Expand Down Expand Up @@ -410,7 +447,13 @@ function planetmath_blocks_blockThemeEverythingElseWithDate($results, $sortBy =
// It would be nice to include the "parent" in some fashion, when it exists, i.e.
// new solution XX to problem YY.

$html .= '<span>' . 'new '. $result->type . ': '
if ($result->type == 'article'){
$kind = "<em>" . $result->metadata . "</em>";
} else {
$kind = $result->type;
}

$html .= '<span>' . 'new '. $kind . ': '
. l($result->title . ' ' . $result->version, 'node/' . $result->nid)
. ' by ' . l($result->username, 'user/' . $result->uid)
. '</span><br />';
Expand Down Expand Up @@ -623,8 +666,7 @@ function planetmath_blocks_block_view($delta = '') {
);
}

$block_names = array('article' => 'Latest Additions',
'request' => 'Requests',
$block_names = array('request' => 'Requests',
'forum' => 'Messages');

foreach ($block_names as $name => $blocktitle) {
Expand All @@ -636,6 +678,12 @@ function planetmath_blocks_block_view($delta = '') {
}
}

if ($delta == 'article'){
$block = array(
'subject'=> "New in Encyclopedia",
'content'=> planetmath_blocks_blockThemeResultsWithDate(planetmath_blocks_queryEncyclopedia()));
}

if ($delta == 'correction') {
$block = planetmath_blocks_block_corrections(arg(1));
}
Expand Down

0 comments on commit cd58052

Please sign in to comment.