开发者

Regionalizing content display to users with matching region in profile

开发者 https://www.devze.com 2023-03-13 18:23 出处:网络
The requirement is to display all public content and all content that has been restricted to the viewer\'s region.

The requirement is to display all public content and all content that has been restricted to the viewer's region.

Currently this is being accomplished by producing two views in blocks on a standard page. One view i开发者_Python百科s set up to display all news articles that do not have a "N" in a "restrict to region" field. Another view is set up to display all news articles that have a "Y" in a "restrict to region" field AND uses php code in a contextual filter to add the condition that the "region" field in the news article matches the "region" field in the user profile. Stacking these views in the content field of a standard page results in a page that returns all news articles that are not restricted AND all news articles that are restricted to the user's region.

Undesirable complications of this strategy include separate pagination and the necessity of creating multiple views to extend the functionality to additional content types or to expand to cities or states.

Can you think of a way to apply the complex filter on a single view so as to avoid the need for presenting a separate unrestricted view followed by a view restricted to records who's region matches the viewer's region?

Or to apply the filter as a permission on fields?

Thanks n advance,


It's quite simple you're using the wrong tool for the job.

PHP is not your tool of choice for this, you should be using the SQL directly.

$q="SELECT * 
FROM 
articles 
WHERE 
limited_to_region=0

UNION

SELECT 
a.* 
FROM 
articles a 
INNER JOIN
regions r
ON
a.rid=r.id 
AND
r.id='".$_SESSION["user"]["region"]."';";

(I don't know your datamodel, you could/should have a relation item in between etc. but this best practice is far from the norm so ...)

This way your filtering and all that is transparent to your front end anyway, faster, limitless AND does not waste time/bandwidth transferring unneeded information.


add another column at your table [articles, news] in database for tags (text-type)[few tags can be set, split them by comma], then create another table that contains tags, give id of those tags to your articles/news. you can filter this content by finding users location by IP-Address, or setting an cookie if you know somehow where user is coming from.


Hope you're using Location for profiles and articles.

It sounds like to do want to mix these two result sets into one item list. Back in the day it would be Views Union

Believe Ovideiu is correct about Views OR being the most modern solution to this. Its says dev, but folks use it in production.

If you don't have to combine the two set you could use Views Exclude Previous to take care of your duplicate items.

Unfortunately, when I've done this in the past we've had to create our own custom (yet cached) output solutions because we could control the query. But you can still use drupal queries and node_loads to make use of templates, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消