diff --git a/sites/all/modules/planetmath_blocks/planetmath_blocks.module b/sites/all/modules/planetmath_blocks/planetmath_blocks.module index 57c225bc..bf27f024 100644 --- a/sites/all/modules/planetmath_blocks/planetmath_blocks.module +++ b/sites/all/modules/planetmath_blocks/planetmath_blocks.module @@ -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 @@ -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) { @@ -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']; @@ -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 .= '' . 'new '. $result->type . ': ' + if ($result->type == 'article'){ + $kind = "" . $result->metadata . ""; + } else { + $kind = $result->type; + } + + $html .= '' . 'new '. $kind . ': ' . l($result->title . ' ' . $result->version, 'node/' . $result->nid) . ' by ' . l($result->username, 'user/' . $result->uid) . '
'; @@ -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) { @@ -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)); }