How can you close a Concrete5 Survey Block?

Permalink
OK, so I make a post and put a survey block on it. Easy. Now say after 3 weeks I want to close voting on it. There does not seem to be any way to do this, all I can think is that I put a note on the page saying it's closed.

AngusHume
 
12345j replied on at Permalink Reply
12345j
you can't change it by default. if you don't mind getting your hands dirty with php then let me know, i'll give you a few changes you can make.
AngusHume replied on at Permalink Reply
AngusHume
I'd appreciate any advice, I'm no programmer but I have been creating a few small changes to standard blocks and managed to create some code to pull comments from the guestbook. So long as I don't have to create code from scratch I'll be fine.
12345j replied on at Permalink Reply
12345j
okay. to close survey just put 1 as the value for the new text box, to open put 0.
you need to add a field to your block. in form.php (or edit+add.php) after copying to root/blocks/survey
<label for="open"><?php echo t('Open?');?></label>
<input type="open" name="open" value="<?php echo $open;?>"/>

then in db.xml after copying put in
<field name="class" type="I"></field> just before the </table></schema>
then refresh the block type from add functionality, and in the view.php copied to root/blocks/survey line 68
if($open!=1){
line 95
<?php }else{
echo 'Survey is closed.';
}?>
AngusHume replied on at Permalink Reply
AngusHume
The PHP gives me a syntax error I'm afraid. Line 70 and 96.
AngusHume replied on at Permalink Reply 1 Attachment
AngusHume
I had a go at hacking something together after looking at your suggestion.

-I added 2 new radio buttons and a heading for selecting a state of closed or open in both edit and add php files.
-Then creating a new field surveyClosed in the database, and refreshed
-then I added a variable to the controller for the above, just like requiresRegistration
-then in view.php I duplicated the code for if voted, but customised it to say it's closed and used the if language as per requiresRegistration (intval etc). This code I made elseif statement which follows the initial hasVoted part.

This is probably horribly inelegant, but seems to work. The result is hopefully foolproof for my client to edit, and when closed shows the vote result with "You voted" if they had, and "survey closed" for those had not, but both see the charted result.

Thanks heaps for you input, it gave me a clue what to try. If you want to see my code mess to offer any further tips I've attached it.
AngusHume replied on at Permalink Reply
AngusHume
Actually I spoke too soon. Line 72 in my code was returning 1 and so it always said closed. My extra radiobox is setting 1 if I want it closed so I just searched on how to test for that instead of turning it into an integer. I hope this is OK, it seems to work now.

I changed this
elseif ((!$controller->surveyClosed() || intval($uID) > 0)) { ?>


to this
elseif ((!$controller->surveyClosed() == 0)) { ?>


I really no idea what I'm doing. I can appreciate a logic sequence of if then etc but have no idea of the syntax, and googling for code is a great waste of my day ;-) What a shame this is not built in to the block already.