Jump to content

Way to allow file ratings without requiring review?


SJ77

Recommended Posts

Posted

You can remove the review field entirely by commenting out the line

$form->add( $editorField );

in the reviewForm() method in /system/Content/Item.php but I cannot for the life of me see how to make such a field optional.

Posted

This is something I want for my own site so I am going to keep researching. It's a little incredible just how many layers of abstraction everything goes through, and not having a debugger really slows things down.

I am sure it must be possible - all form fields are handled through the same classes, and for instance, when adding custom fields to a download you can see on the edit screen that it's possible to control whether or not the editor field can be empty or not:

58accdd5ae98c_ScreenShot2017-02-21at3_31_07PM.thumb.png.9adb10a88a97741886e3334001b57707.png

The first is one of the "default" file download fields and the second is a custom field called "Author." They go through different paths on the back end and somewhere in there is something that makes the first one required and the second one optional... I just need to figure out what.

 

Posted
On 2/21/2017 at 3:33 PM, Linguica said:

not having a debugger really slows things down.

it's not quite a debugger, but I just randomly found out about being able to add this to your constants.php

define('QUERY_LOG', TRUE);

which will show a list of all MySQL queries to load a page, which is nice at least.

Posted

OK, I've found how to turn it off. I haven't made a plugin or anything but it's possible to do.

Go to /system/Content/Item.php around line 3826 and edit

public function reviewForm()

to read

public function reviewForm( $review_required = TRUE )

This introduces a variable you can pass to the reviewForm method to control if the review is required or not and sets its default value to true. Then edit a little below:

			$editorField = new \IPS\Helpers\Form\Editor( static::$formLangPrefix . 'review_text', NULL, TRUE, array(
				'app'			=> static::$application,
				'key'			=> ucfirst( static::$module ),
				'autoSaveKey' 	=> 'review-' . static::$application . '/' . static::$module . '-' . $this->$idColumn,
				'minimize'		=> static::$formLangPrefix . '_review_placeholder'
			), '\IPS\Helpers\Form::floodCheck' );

You want to edit this to

			$editorField = new \IPS\Helpers\Form\Editor( static::$formLangPrefix . 'review_text', NULL, $review_required, array(
				'app'			=> static::$application,
				'key'			=> ucfirst( static::$module ),
				'autoSaveKey' 	=> 'review-' . static::$application . '/' . static::$module . '-' . $this->$idColumn,
				'minimize'		=> static::$formLangPrefix . '_review_placeholder'
			), '\IPS\Helpers\Form::floodCheck' );

the third argument being passed has been changed from TRUE to $review_required. That argument turns out to control whether or not the form field can be left blank or not.

Now go into your theme, and if you want a review form to accept blank reviews with only a star rating, look in downloads > front > view > reviews for

		<div id='elFileReviewForm'>
			{$file->reviewForm()|raw}
		</div>

and edit it to read

		<div id='elFileReviewForm'>
			{$file->reviewForm(FALSE)|raw}
		</div>

You can repeat this in any other template where you want to make the review portion optional.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...