Posts Tagged views

Localized terms and views

When you use localized terms (terms have the same tid for all languages, but can be translated in the translate interface)
views has problems translating you terms.

This problem can be resolved by adding the following hook to you custom module

/**
* implementation of hook_views_pre_render
*/
function mymodule_views_pre_render($view) {
if ($view->name == ‘view_name’) {
foreach($view->result as $term) {
$term->term_data_name = tt(’taxonomy:term:’.$term->tid.’:name’, $term->term_data_name);
}
}
}

,

No Comments

Custom sql queries in Views

I came across this when i was looking for a way to use my own sqly queries in combination with views.
Sometimes you can’t always get the things you want by using views (or you’re too lazy to fiddle around with arguments, relationships, etc.)

The idea is simple :

1) test your own custom query in phpmyadmin for example.

2) create a view and save it. You don’t have to set any filters since the SQL will be overwritten.

2) if you haven’t created your own module yet, create one now and place the following code in it.  replace MYMODULE by the name of your own module and VIEW_NAME by the name of the view you’ve just created. Then, change the sql query you see here by your own.

function MYMODULE _views_pre_execute(&$view) {

//drupal_set_message(’—->>>’.$view->name);
if($view->name==”VIEW_NAME”) {

$view->build_info['query']=”SELECT vidnode.nid as nid, vidnode.title as title
FROM node vidnode WHERE vidnode.type=’ptl_remotevideo’
AND vidnode.status <> 0
AND vidnode.nid NOT IN (
SELECT DISTINCT media.field_media_video_ref_nid as video_nid
FROM content_field_media_video_ref media
)”;

}

}

That’s it. I used a node view and it gave me what i wanted. I didn’t have time to check out other settings but i guess it shouldn’t be too hard.

, ,

1 Comment