Project:NodeReview
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

This simple patch makes the "Review" box optional.

In concert with http://drupal.org/node/100043 it makes it possible for users to provide ratings and an overall perspective rather than comments on each axis.

AttachmentSize
unrequire_comments.patch948 bytes

Comments

#1

Version:4.7.x-1.x-dev» 5.x-1.x-dev
Status:needs review» needs work

4.7 is now in maintenance mode, so new features should go against Drupal 5 only. Thanks.

#2

Status:needs work» needs review

ok, here is a patch for 5.x.

Also, that first patch was soooooooo wrong. I don't know what I was thinking...

AttachmentSize
reviews_optional.patch 846 bytes

#3

Status:needs review» needs work

This makes reviews optional unconditionally. That means you can't make the review portion required even if you wanted to. That's not really an improvement over it being required unconditionally (the current seutp).

If you can make it configurable per-axis or even per review type, that I'd commit.

#4

Assigned to:greggles» Anonymous

Well, it is somewhat better in that you can make it required by using a hook_form_alter to set #required => TRUE whereas in the current condition (with the custom validation function) you can't do that. right?

I'm unlikely to write that feature as the site that it's on will probably never see life after this incarnation so I'm unassigning myself. so, if anyone needs this feel free to run with it.

#5

I simply want to remove all review per axis and have 1 overall review (a must) at the bottom.

Completely Remove this. Simply remove #required' => TRUE will show the textarea, just not make it a must. so I remove it.

  $form['reviews'][$axis->aid]['review'] = array(
    '#type' => 'textarea',
    '#title' => t('Review'),
    '#default_value' => $reviews[$axis->aid]->review,
    '#required' => TRUE,
  );

But instead I add this in function nodereview_form

    $form['review'] = array(
    '#type' => 'textarea',
    '#title' => t('Review'),
    '#default_value' => $node->review,
    '#weight' => 10,
    '#required' => TRUE
  );

I got the display and validation I wanted, but of course the data are not being save... then I realize I would hack too much, and will get into trouble later when upgrading. An option for this kind of customization is great!

#6

Version:5.x-1.x-dev» 6.x-1.x-dev

Patch works also on D6 version! greetings, Martijn

#7

Hi all,
I took a different approach. On the nodereview admin page, I provided a checkbox for the administrator to choose whether or not vote comments are required. This value is then saved to the database. Axes that require vote comments, as identified by the administrator, remain unchanged but axes that do not require vote comments are still visible and available for users to provide optional comments.

I dont know how to create a patch, sorry, but here is my code - you have to change a number of files and unfortunately, uninstall and reinstall the module which would lose your data...

from nodereview.install, add the following after line 110:

//this creates a description_required field in the database.
'description_required' => array(
        'type' => 'int',
        'not null' => TRUE,
        'length'   => 11,
        'default'  => 0,
        'description' => t('Whether or not a vote description is required.'),
      ),

from nodereview.admin.inc:
replace line 48 with:

$result = db_query("SELECT aid, tag, description, description_required, weight FROM {nodereview_axes} WHERE node_type='%s' ORDER BY weight", $type);

replace line 88 with:

//this ensures any changes to the required description checkbox get recorded when updating the admin page
db_query("UPDATE {nodereview_axes} SET tag='%s', description='%s', description_required=%d, weight=%d WHERE aid=%d", $axis['tag'], $axis['description'], $axis['description_required'], $axis['weight'],  $axis['aid']);

replace line 97 with:

//this updates the insert query to include recording whether or not a vote description is required
db_query("INSERT INTO {nodereview_axes} (node_type, tag, description, weight, description_required) VALUES ('%s', '%s', '%s', %d, %d)", $form_values['node_type'], $axis['tag'], $axis['description'], $axis['weight'], $axis['description_required']);

after line 137, add:

//this adds a description_required checkbox to the form
  $form['description_required'] = array(
    '#type' => 'checkbox',
    '#title' => t('require a vote description'),
    '#return_value' => 1,
    '#default_value' => $record->description_required,
    '#description' => t(''),
  );

from nodereview.theme.inc:
after line 23, add:

//this eliminates the title for the checkbox like the other fields
$form['axes'][$key]['description_required']['#title'] = '';

after line 29, add:

//this renders the checkbox, without this line, your checkbox won't appear
$row[] = drupal_render($form['axes'][$key]['description_required']);

replace line 35:

//this updates the headers to include "require vote comments"
$header = array('use', 'name', 'description', 'require vote comments', 'weight');

From nodereview_node_nodereview.inc:
replace line 128 to the comment for implementation of hook_validate with:

//the #required field now looks at the field we've added to the database indicating whether or not a description/comments are required per axis 
$form['reviews'][$axis->aid]['review'] = array(
    '#type' => 'textarea',
    '#title' => t('Review'),
    '#default_value' => $node->reviews[$axis->aid]['review'],
    '#required' => $axis->description_required,
  );
}

update line 150:

//updates so that if there is no review and a view is required that the form won't validate
if (! $review['review'] && $review['review']['required']==1) {

Hope this helps - if I messed up anywhere, let me know and I'll take a look again,
pete

#8

Status:needs work» needs review

committed #7 by yaworsk with few modifications which will be available in 12 hours

added update on table install for upgrading those who have install the previous dev

/**
* Added description required
*/
function nodereview_update_1() {
$update = array();
$update[] = update_sql("ALTER TABLE {nodereview_axes} ADD `description_required` INT(1) DEFAULT '0' NOT NULL AFTER `description`");
return $update;
}

#9

awesome, thanks for committing that. kept meaning to come back to it to create the patch but it seemed like there wasn't much interest in it and i've been busy...

#10

Status:needs review» fixed

#11

Status:fixed» needs work

Raw DDL queries should not be used in update hooks in D6. Instead, use this:

http://api.drupal.org/api/drupal/update.php/function/db_add_column/6

Daniel, please correct the update hook and then re-fix this issue.

#12

just reading the comments on the the db_add_column api page, should it actually use db_add_field? http://api.drupal.org/api/drupal/includes--database.pgsql.inc/function/d...

#13

Gr. Yes, yes it should. Bad me for confusing the two. (I think we fixed that in D7... :-) )

#14

Status:needs work» needs review

Hi Crell and Yaworsk,

I am guessing, a quick convert will look like this:

<?php
/**
* Added description required
*/
function nodereview_update_1() {
 
$ret = array();
 
db_add_field(&$ret, 'nodereview_axes', 'description_required', array('description' => t('Whether or not a vote description is required.'), 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));  return $ret;
}
?>

I haven't tried, will this work?

#15

Status:needs review» closed (fixed)

Ok, tested! committed to dev, available in 12hours.