Filter Blocks based on Cookie value

Permalink
Anyone know if it is possible to filter out blocks based on a Cookie value, I have a request from a client, to have a disclaimer where the user would select what kind of customer they were (trade or Retail), based on the value, we would like to filter out any relevant blocks.

I'm thinking the blocks would have an attribute as to which whether they are trade, retail or both.

And also, we might just apply this to certain editable areas.

Any ideas?

Thanks

 
12345j replied on at Permalink Reply
12345j
id just set up two editable areas. something like this
<?php 
$p = new Permissions($page);
if((isset($_COOKIE['userPurchaserType'])&&$_COOKIE['userPurchaserType']=='trade')||$p->canWrite()){
$a=new Area('trade');
$a->display($c);
}
if((isset($_COOKIE['userPurchaserType'])&&$_COOKIE['userPurchaserType']=='retail')||$p->canWrite()){
$a=new Area('retail');
$a->display($c);
}
if(!isset($_COOKIE['userPurchaserType'])){
//do a js popup here for them to select if they're trade or retail.
}

if you can edit the page you see both areas, and if your a user you'll only see blocks in the trade or the retail areas. make sense?
biscutty replied on at Permalink Reply
Thanks for the reply 12345J

Thinking about it as there are sometimes a mix of articles, so having them separated might not work too well.

I was hoping to do this at a php/cms level, but might have to look at a javascript solution if it is not possible.
TheRealSean replied on at Permalink Best Answer Reply
TheRealSean
Good Morning :)
That would allow for different areas to be split up which is handy if you want whole areas to be displayed or hidden depending on the cookie status.

To display different articles/pages in a page list you could then apply that same logic to the page list,

It would look something like this
//this should probably be set in the controller within on_view?
   $userPurchaserType = $_COOKIE['userPurchaserType'];
   $p = new Permissions($page);
 foreach ($pages as $page):
 //assuming its only going to be one option
   $pageType = $page->getAttribute('pageType');
   //check to see if the User is the allowed to view the page.
   //otherwise don't show the pages
        //assuming the cookie value is the same as the page attribute
   if ($pageType==$userPurchaserType || $pageType == "" || $p->canWrite()) {
      //display relevant articles
      //if the user is not set this will only display pages that do not have an attribute
   }
 endforeach;


Does that make sense?

Regards
-Sean
biscutty replied on at Permalink Reply
Thanks Sean, we'll give it a go