Adding a Radio button Class selector to Image Block

Permalink
Hi I'm fairly new to PHP, but getting there... what i'm trying to achieve is to adapt the image block in concrete to have an extra section with a series of 4 radio buttons:

Reflect image? No reflection, 33%, 66%, 100%

This then need to write back to the database and then I need to pull out the info and assign a different class depending upon the option selected. I have managed to create the radio buttons, but there are neither saving no affecting the code correctly.

Thanks in advance for your help.

Code i'm using is as follows:

in add/edit.php
<div class="ccm-block-field-group">
<h2><?php echo t('Reflect Image?')?></h2>
<?php  
if($reflect == 4){$r= true;}
elseif($reflect == 1){$rr= true;}
elseif($reflect == 2){$rrr= true;}
elseif($reflect == 3){$rrrr= true;}
else {$r= true;}
?>
   <?php  echo $form->radio('reflect','4', $r);?> <?php   echo t('No Reflection');?> 
   <?php  echo $form->radio('reflect','1', $rr);?> <?php   echo t('33%');?>
   <?php  echo $form->radio('reflect','2', $rrr);?> <?php   echo t('66%');?>
   <?php  echo $form->radio('reflect','3', $rrrr);?> <?php   echo t('100%');?> 
</div>


in db.xml
<field name="reflect" type="I">
      </field>


and in controller.php line 44
$args['reflect'] = (intval($args['reflect']) > 0) ? intval($args['reflect']) : 0;


and in controller.php lines 71-89
$img = "<img border=\"0\" alt=\"{$this->altText}\" src=\"{$relPath}\" {$sizeStr} ";
         $img .= ($align) ? "align=\"{$align}\" " : '';
         $img .= ($reflect) ? "class=\"{$reflect}\" " : '';
         if ($this->reflect > 1){
               echo 'ccm-image-block reflect rheight33' ;
            }
            if ($this->reflect > 2){
               echo 'ccm-image-block reflect rheight66' ;
            }
            if ($this->reflect > 3){
               echo 'ccm-image-block reflect rheight100' ;
            }
            else {
               echo 'ccm-image-block' ;
            }

BHWW
 
c5studio replied on at Permalink Best Answer Reply
c5studio
First of all, if you make changes to the db.xml you need to refresh the database schema. You do this by going to 'Add Functionality' than click edit next to the block and then click refresh.

You have some redundant code in the add/edit.php, this would do the same thing with less code
<div class="ccm-block-field-group">
<h2><?php echo t('Reflect Image?')?></h2>
<?php  echo $form->radio('reflect','4', $reflect);?> <?php   echo t('No Reflection');?> 
<?php  echo $form->radio('reflect','1', $reflect);?> <?php   echo t('33%');?>
<?php  echo $form->radio('reflect','2', $reflect);?> <?php   echo t('66%');?>
<?php  echo $form->radio('reflect','3', $reflect);?> <?php   echo t('100%');?> 
</div>


and your code in controller.php lines 71-89 does not quite make sense, but I think this is what you are looking to do

$img = "<img border=\"1\" alt=\"{$this->altText}\" src=\"{$relPath}\" {$sizeStr} ";
$img .= ($align) ? "align=\"{$align}\" " : '';
if ($this->reflect == 1){
   $img .= "class=\"ccm-image-block reflect rheight33\" ";
}elseif ($this->reflect == 2){
   $img .= "class=\"ccm-image-block reflect rheight66\" ";
}elseif ($this->reflect == 3){
   $img .= "class=\"ccm-image-block reflect rheight100\" ";
}else {
   $img .= "class=\"ccm-image-block\" ";
}
BHWW replied on at Permalink Reply
BHWW
Hi ukao

Thanks for your answer, however it doesn't appear to be doing the trick. I have tried refreshing the database schema, i've put in the code, but the database doesn't seem to be storing the info. If i edit it and select a radio button and then update then when i re edit no radio button is selected.

The source for the page just shows the following:
<img border="1" alt="" src="/~admin14/files/3412/7117/3110/image.jpg" width="334" height="437" class="ccm-image-block" />


Any other advice would be greatly appreciated. Regards
c5studio replied on at Permalink Reply
c5studio
Can you access your database to see if the 'reflect' field is showing up?
BHWW replied on at Permalink Reply
BHWW
Hi ukao

I have access to the database, however i don't know where i'd look to find out.

Cheers
c5studio replied on at Permalink Reply
c5studio
Look in the table 'btcontentimage' in your concrete5 database.
BHWW replied on at Permalink Reply
BHWW
Hi ukao, Excellent work!

The database didn't seem to have the reflect field in it, so I added the field and voila! Thank you for your help.