Permalink
Browse files

Latest dev snapshot

  • Loading branch information...
1 parent e714e6b commit 43f80584dd91dc11eeb33fe68f74929411830297 @ngmaloney ngmaloney committed Jun 7, 2011
View
16 assets/scf_collections.css
@@ -0,0 +1,16 @@
+div.node-moderation-form-wrapper {
+ display: block;
+ float: left;
+ margin: 0 10px auto auto;
+ z-index: 999;
+}
+
+.node-moderation-form-wrapper .form-item {
+ padding: 0 0 0 0;
+}
+
+div.view-scf-collections-queue .node {
+ margin-left: 10px;
+ clear: right;
+ display: block;
+}
View
7 modules/scf_biblio_query/scf_biblio_query.module
@@ -6,7 +6,7 @@
include_once('scf_biblio_query.features.inc');
-define('BIBLIO_QUERY_LIMIT', 10); //TODO: Remember to increase this!
+define('BIBLIO_QUERY_LIMIT', 200); //TODO: Remember to increase this!
define('SCF_BIBLIO_QUERY_NODE_TYPE', 'biblio_topic_query');
/**
@@ -62,7 +62,6 @@ function scf_biblio_query_cron() {
* An object describing the feed to be refreshed.
*/
function scf_biblio_query_execute($feed) {
- dd('hi');
if(!$feed) {
return;
}
@@ -74,7 +73,7 @@ function scf_biblio_query_execute($feed) {
// Establish the date range for the query.
// @todo should we not try to query any paper which is older than the previous
// [Saturday] or begining of the POW period?
- $checked = isset($feed->field_checked[LANGUAGE_NONE][0]['value']) ? $node->field_checked[LANGUAGE_NONE][0]['value'] : 0;
+ $checked = isset($feed->field_checked[LANGUAGE_NONE][0]['value']) ? $feed->field_checked[LANGUAGE_NONE][0]['value'] : time();
$query = isset($feed->body[LANGUAGE_NONE][0]['value']) ? $feed->body[LANGUAGE_NONE][0]['value'] : NULL;
$minDate = date('Y/m/d', $checked);
@@ -99,7 +98,7 @@ function scf_biblio_query_execute($feed) {
$imported = 0;
// Node ID's for queue
$queue_nids = array();
-
+ dd($results);
foreach($results->IdList->Id as $pmid) {
$article = $Eclient->fetch((string)$pmid)->PubmedArticle;
if (!$article) {
View
1 scf_collections.info
@@ -17,6 +17,7 @@ features[node][] = "collection"
features[node][] = "topic_queue"
features[views_view][] = "scf_collections_queue"
files[] = "scf_collections.test"
+stylesheets[all][] = "assets/scf_collections.css"
name = "SCF Collections"
package = "SCF"
php = "5.2.4"
View
188 scf_collections.module
@@ -47,6 +47,15 @@ function scf_collections_menu() {
'access arguments' => array(1),
'weight' => 7,
);
+ $items['node/%node/preview'] = array(
+ 'title' => 'Preview',
+ 'type' => MENU_LOCAL_TASK,
+ 'page callback' => 'scf_collections_queue_view',
+ 'page arguments' => array(1,2),
+ 'access callback' => 'scf_collections_local_task_loader',
+ 'access arguments' => array(1),
+ 'weight' => 8,
+ );
return $items;
}
@@ -74,14 +83,42 @@ function scf_collections_admin_paths() {
function scf_collections_queue_view($node, $review_status) {
$view = views_get_view(SCF_COLLECTIONS_QUEUE_VIEW);
$output = '';
- $statuses = array('not_reviewed','accepted','rejected');
+ $statuses = array('not_reviewed','accepted','rejected','preview');
$view_output = array();
if(in_array($review_status,$statuses)) {
$view_output = $view->execute_display($review_status, array($node->nid));
}
return (!empty($view_output['content'])) ? $view_output['content'] : '';
}
+/**
+ * Add default node template to theme suggestion
+**/
+function scf_collections_theme_registry_alter(&$theme_registry) {
+ $mod_path = drupal_get_path('module', 'scf_collections') . '/templates';
+ $theme_registry_copy = $theme_registry; // munge on a copy
+ _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'scf_collections', $mod_path);
+ $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
+ $hooks = array('node');
+ foreach ($hooks as $h) {
+ _scf_collections_insert_after_first_element($theme_registry[$h]['theme paths'], $mod_path);
+ }
+ // Add Theme hook for altering view
+ // Code from http://drupal.org/node/303586#comment-2552974
+ //$theme_registry['views_view_row_node__papers_of_the_week']['preprocess functions'][] = 'pow_preprocess_views_view_row_node__papers_of_the_week';
+}
+
+/**
+ * Helper function for re-ordering arrays (needed by theme_registry_alter)
+**/
+function _scf_collections_insert_after_first_element(&$a, $element) {
+ if(is_array($a)) {
+ $first_element = array_shift($a);
+ array_unshift($a, $first_element, $element);
+ }
+}
+
+
/**
* Access callback for ONLY displaying the scf_collections local tasks
* if the node type is SCFC_TOPIC_QUEUE_TYPE
@@ -105,7 +142,117 @@ function scf_collections_local_task_loader($node) {
*/
function scf_collections_form_alter(&$form, &$form_state, $form_id) {
//Hide elements from the topic queue node form
- dd($form_id);
+ if($form_id == 'topic_queue_node_form') {
+ /*
+ unset($form['field_not_reviewed_nodes']);
+ unset($form['field_accepted_nodes']);
+ unset($form['field_rejected_nodes']);
+ */
+ }
+}
+
+/**
+* Implements hook_preprocess_node().
+*
+* This function injects a moderation form to the normal node teaser view
+*/
+function scf_collections_preprocess_node(&$vars) {
+ if($vars['view_mode'] == 'teaser_moderation') {
+ $vars['theme_hook_suggestions'][] = 'node__teaser_moderation';
+ $node = node_load($vars['nid']);
+ $node_view = node_view($node, 'teaser');
+ $parent_node = menu_get_object();
+ $vars['content'] = array();
+ $vars['moderation_form']['#markup'] = '<div class="node-moderation-form-wrapper">';
+ $vars['moderation_form']['#markup'] .= drupal_render(drupal_get_form('scf_collections_moderation_form', array('parent_node' => $parent_node, 'node' => $node)));
+ $vars['moderation_form']['#markup'] .= '</div>';
+ $vars['content']['#markup'] = drupal_render($node_view);
+ }
+}
+
+/**
+* Implements hook_entity_info_alter().
+* Adds a moderation form view for a node teaser.
+*/
+function scf_collections_entity_info_alter(&$entity_info) {
+ $entity_info['node']['view modes']['teaser_moderation'] = array(
+ 'label' => t('SCF Collection Moderation'),
+ 'custom settings' => TRUE,
+ );
+}
+
+/**
+ * Implements hook_form()
+ * Renders the node moderation form
+*/
+function scf_collections_moderation_form($form, &$form_state, $extra = null) {
+ $review_statuses = array('not_reviewed' => 'Not Reviewed', 'accepted' => 'Accepted', 'rejected' => 'Rejected');
+ $nid = isset($extra['node']->nid) ? $extra['node']->nid : '';
+ $pnid = isset($extra['parent_node']->nid) ? $extra['parent_node']->nid : '';
+ $default = _scf_collections_get_node_queue($extra['parent_node'], $nid);
+ $form['moderation_form']['review_status'] = array(
+ '#title' => 'paper review status',
+ '#type' => 'radios',
+ '#options' => $review_statuses,
+ '#default_value' => $default,
+ '#ajax' => array(
+ 'callback' => 'scf_collections_moderation_form_callback',
+ ),
+ );
+ $form['parent_node'] = array('#type' => 'value', '#value' => $pnid);
+ $form['node'] = array('#type' => 'value', '#value' => $nid);
+ return $form;
+}
+
+/**
+ * Callback for handling moderation calls
+ */
+function scf_collections_moderation_form_callback($form, $form_state) {
+ //Add the node to the correct queue
+ scf_collections_add_to_queue(array($form_state['values']['node']), $form_state['values']['parent_node'], $form_state['values']['review_status']);
+ // Dom element containing node
+ $element = "#node-" . $form_state['values']['node'] . "-moderation-form";
+ $commands = array();
+ //Hide the calling node form
+ //$commands[] = ajax_command_invoke($element, 'fadeOut');
+ $commands[] = ajax_command_remove($element);
+ return array('#type' => 'ajax', '#commands' => $commands);
+}
+
+
+
+/**
+ * Helper function for determining which queue a node is in
+ * @param $parent_node
+ * Parent node object to search
+ * @param $nid
+ * Nid of node to search by
+*/
+function _scf_collections_get_node_queue($parent_node, $nid) {
+ //Iterate through Not Reviewed nodes
+ if(!empty($parent_node->field_not_reviewed_nodes[LANGUAGE_NONE])) {
+ foreach($parent_node->field_not_reviewed_nodes[LANGUAGE_NONE] as $row) {
+ if($row['nid'] == $nid) {
+ return 'not_reviewed';
+ }
+ }
+ }
+ //Iterate Through Accepted Nodes
+ if(!empty($parent_node->field_accepted_nodes[LANGUAGE_NONE])) {
+ foreach($parent_node->field_accepted_nodes[LANGUAGE_NONE] as $row) {
+ if($row['nid'] == $nid) {
+ return 'accepted';
+ }
+ }
+ }
+ //Iterate Through Rejected Nodes
+ if(!empty($parent_node->field_rejected_nodes[LANGUAGE_NONE])) {
+ foreach($parent_node->field_rejected_nodes[LANGUAGE_NONE] as $row) {
+ if($row['nid'] == $nid) {
+ return 'rejected';
+ }
+ }
+ }
}
/** Database Related Hooks **/
@@ -123,23 +270,50 @@ function scf_collections_form_alter(&$form, &$form_state, $form_id) {
* SCFC_ACCEPTED
* SCFC_REJECTED
*/
-function scf_collections_add_to_queue($nids,$queue_nid,$queue = SCFC_NOT_REVIEWED) {
+function scf_collections_add_to_queue($nids, $queue_nid, $queue = SCFC_NOT_REVIEWED) {
$qnode = node_load($queue_nid);
if(!$qnode) {
return;
}
foreach($nids as $nid) {
+
+ $this_nid = array('nid' => $nid);
+ // Remove node from queues
+ if(!empty($qnode->field_accepted_nodes[LANGUAGE_NONE])) {
+ foreach($qnode->field_accepted_nodes[LANGUAGE_NONE] as $k => $v) {
+ if($v['nid'] == $nid) {
+ unset($qnode->field_accepted_nodes[LANGUAGE_NONE][$k]);
+ }
+ }
+ }
+ if(!empty($qnode->field_not_reviewed_nodes[LANGUAGE_NONE])) {
+ foreach($qnode->field_not_reviewed_nodes[LANGUAGE_NONE] as $k => $v) {
+ if($v['nid'] == $nid) {
+ unset($qnode->field_not_reviewed_nodes[LANGUAGE_NONE][$k]);
+ }
+ }
+ }
+ if(!empty($qnode->field_rejected_nodes[LANGUAGE_NONE])) {
+ foreach($qnode->field_rejected_nodes[LANGUAGE_NONE] as $k => $v) {
+ if($v['nid'] == $nid) {
+ unset($qnode->field_rejected_nodes[LANGUAGE_NONE][$k]);
+ }
+ }
+ }
+
+ //Add Node to new queue
switch($queue) {
case SCFC_ACCEPTED:
- $qnode->field_accepted_nodes[LANGUAGE_NONE][] = array('nid' => $nid);
+ $qnode->field_accepted_nodes[LANGUAGE_NONE][] = $this_nid;
break;
case SCFC_REJECTED:
- $qnode->field_accepted_nodes[LANGUAGE_NONE][] = array('nid' => $nid);
+ $qnode->field_rejected_nodes[LANGUAGE_NONE][] = $this_nid;
break;
default:
- $qnode->field_not_reviewed_nodes[LANGUAGE_NONE][] = array('nid' => $nid);
+ $qnode->field_not_reviewed_nodes[LANGUAGE_NONE][] = $this_nid;
break;
}
}
- return node_save($qnode);
+ $result = node_save($qnode);
+ return $result;
}
View
10 scf_collections.test
@@ -135,7 +135,7 @@ class SCFLibraryAPITestCase extends SCFCollectionsWebTestCase {
}
function setUp() {
- // Enable any module that you will need in your tests.
+ parent::setUp('scf_collections');
$this->biblio_nodes = array(
0 => $this->createBiblioNode(),
1 => $this->createBiblioNode(),
@@ -162,13 +162,15 @@ class SCFLibraryAPITestCase extends SCFCollectionsWebTestCase {
//Test Not Reviewed
scf_collections_add_to_queue($queue_nodes,$node->nid,'not_reviewed');
$node = node_load($node->nid);
- $this->assertNotNull($node->field_not_reviewed_nodes);
+ $this->assertFalse(empty($node->field_not_reviewed_nodes));
//Test Accepted
+ $node = node_load($node->nid);
scf_collections_add_to_queue($queue_nodes,$node->nid,'accepted');
- $this->assertNotNull($node->field_accepted_nodes);
+ $this->assertFalse(empty($node->field_accepted_nodes));
//Test Rejected
+ $node = node_load($node->nid);
scf_collections_add_to_queue($queue_nodes,$node->nid,'rejected');
- $this->assertNotNull($node->field_rejected_nodes);
+ $this->assertFalse(empty($node->field_rejected_nodes));
}
}
View
101 templates/node--biblio--teaser-moderation.tpl.php.bak
@@ -0,0 +1,101 @@
+<?php
+// $Id: node.tpl.php,v 1.34 2010/12/01 00:18:15 webchick Exp $
+
+/**
+ * @file
+ * Default theme implementation to display a node.
+ *
+ * Available variables:
+ * - $title: the (sanitized) title of the node.
+ * - $content: An array of node items. Use render($content) to print them all,
+ * or print a subset such as render($content['field_example']). Use
+ * hide($content['field_example']) to temporarily suppress the printing of a
+ * given element.
+ * - $user_picture: The node author's picture from user-picture.tpl.php.
+ * - $date: Formatted creation date. Preprocess functions can reformat it by
+ * calling format_date() with the desired parameters on the $created variable.
+ * - $name: Themed username of node author output from theme_username().
+ * - $node_url: Direct url of the current node.
+ * - $display_submitted: Whether submission information should be displayed.
+ * - $submitted: Submission information created from $name and $date during
+ * template_preprocess_node().
+ * - $classes: String of classes that can be used to style contextually through
+ * CSS. It can be manipulated through the variable $classes_array from
+ * preprocess functions. The default values can be one or more of the
+ * following:
+ * - node: The current template type, i.e., "theming hook".
+ * - node-[type]: The current node type. For example, if the node is a
+ * "Blog entry" it would result in "node-blog". Note that the machine
+ * name will often be in a short form of the human readable label.
+ * - node-teaser: Nodes in teaser form.
+ * - node-preview: Nodes in preview mode.
+ * The following are controlled through the node publishing options.
+ * - node-promoted: Nodes promoted to the front page.
+ * - node-sticky: Nodes ordered above other non-sticky nodes in teaser
+ * listings.
+ * - node-unpublished: Unpublished nodes visible only to administrators.
+ * - $title_prefix (array): An array containing additional output populated by
+ * modules, intended to be displayed in front of the main title tag that
+ * appears in the template.
+ * - $title_suffix (array): An array containing additional output populated by
+ * modules, intended to be displayed after the main title tag that appears in
+ * the template.
+ *
+ * Other variables:
+ * - $node: Full node object. Contains data that may not be safe.
+ * - $type: Node type, i.e. story, page, blog, etc.
+ * - $comment_count: Number of comments attached to the node.
+ * - $uid: User ID of the node author.
+ * - $created: Time the node was published formatted in Unix timestamp.
+ * - $classes_array: Array of html class attribute values. It is flattened
+ * into a string within the variable $classes.
+ * - $zebra: Outputs either "even" or "odd". Useful for zebra striping in
+ * teaser listings.
+ * - $id: Position of the node. Increments each time it's output.
+ *
+ * Node status variables:
+ * - $view_mode: View mode, e.g. 'full', 'teaser'...
+ * - $teaser: Flag for the teaser state (shortcut for $view_mode == 'teaser').
+ * - $page: Flag for the full page state.
+ * - $promote: Flag for front page promotion state.
+ * - $sticky: Flags for sticky post setting.
+ * - $status: Flag for published status.
+ * - $comment: State of comment settings for the node.
+ * - $readmore: Flags true if the teaser content of the node cannot hold the
+ * main body content.
+ * - $is_front: Flags true when presented in the front page.
+ * - $logged_in: Flags true when the current user is a logged-in member.
+ * - $is_admin: Flags true when the current user is an administrator.
+ *
+ * Field variables: for each field instance attached to the node a corresponding
+ * variable is defined, e.g. $node->body becomes $body. When needing to access
+ * a field's raw values, developers/themers are strongly encouraged to use these
+ * variables. Otherwise they will have to explicitly specify the desired field
+ * language, e.g. $node->body['en'], thus overriding any language negotiation
+ * rule that was previously applied.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_node()
+ * @see template_process()
+ */
+?>
+<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
+
+ <?php print render($title_prefix); ?>
+ <?php if (!$page): ?>
+ <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
+ <?php endif; ?>
+ <?php print render($title_suffix); ?>
+
+ <div class="content"<?php print $content_attributes; ?>>
+ <?php
+ // We hide the comments and links now so that we can render them later.
+ hide($content['comments']);
+ hide($content['links']);
+ print render($content);
+ ?>
+ </div>
+
+ <?php print render($content['links']); ?>
+
+</div>
View
11 templates/node--teaser-moderation.tpl.php
@@ -0,0 +1,11 @@
+<div id="node-<?php print $node->nid; ?>-moderation-form">
+ <?php print render($moderation_form); ?>
+ <div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
+ <div class="content"<?php print $content_attributes; ?>>
+ <?php
+ // We hide the comments and links now so that we can render them later.
+ print render($content);
+ ?>
+ </div><!-- /.content -->
+ </div><!-- /#node-<?php print $node->nid; ?> -->
+</div><!--<?php print $node->nid; ?>-moderation-form -->

0 comments on commit 43f8058

Please sign in to comment.