Hi,

I am testing the panels 2.0-alpha7 with views 5.s-1.6 and it is great!
I can suggest these modules to the drupal communitiy it is a lot functionality improvement!

I succeeded in building a view with the possibility to get an hierarchy of terms.
I did this by using the views-filter possibility and selecting the top-term I wanted with a "3" in the option field (this way the views.module will filter 3 levels depth from the selected term).

With this view I can show all nodes from all terms underneath the selected top-term.
The only problem is I need to make a view for every top-term I want to have the nodes shown.

It would be great to make the filter possible with an argument. So that you don't need to select the top-term in the view-building, but can give the top-term as a % argument with the url.

Am I clear enough about my future request?
This way you don't have to build a lot of views, but could be able to control a lot of term hierarchy possibilities with one view!

Thanks for these great modules.
greetings,
Martijn

Comments

summit’s picture

Version: 5.x-1.6 » 5.x-1.6-beta5

Hi,

Will it be possible to use the argument for filters, so you can build only one view and use the filter-criteria as arguments?

greetings,
Martijn

summit’s picture

Title: Getting an argument on the filter » VIEWS: Getting an argument on the filter

change title to be more specific.
It would be great if this variable will be possible. I don't have to make a view then for every specific filter-setting.
greetings,
Martijn

buffos’s picture

I second that. Actually filters are static arguments. So either argument could have more operators.

summit’s picture

Hi,

May be there are allready possibilities with the Argument Handling Code.. but I am not that good of a programmer.
Please advice,

greetings,
Martijn

buffos’s picture

Actually after a little bit of search its very easy.

Imagine you want the third filter of your view to contain a word.
You need this to be dynamic.

you set up the view normally. No argument. Just a little bit of argument handling code

You want to call the view with somthing like www.yoursite.com/viewname?searchword=blabla

Step 1

you put just the following

if($_GET['searchword']) { $someword = $_GET['searchword']; } else { $someword = ''; }

/***************************************************************************/
$view->filter[X]['value'] = $someword ;
$view->is_cacheable = 0;
return $args;

where X in the filters is the number of the filter you want to put the search word.

tada... very simple indeed

summit’s picture

Hi,

I don't quite understand how I can use the views-filter-code in the argument-handling-code area.
I am not using arguments, but I would like the filter-options automated, so I can use one view for different websites.
See my post about this subject on: http://drupal.org/node/174714#comment-303683

Can you please help to get the code correct in the way you are dealing with the automated filter-code?

Thanks in advance,
Martijn

summit’s picture

Version: 5.x-1.6-beta5 » 5.x-1.x-dev

Hi,

How can I alter the following views-filter-export-output to working argument handling?

 $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
  );

Something like

$view->filter[1]['tablename'] = 'node';
$view->filter[1]['field' ] = status';
$view->filter[1]['operator' ] = '=';
$view->filter[1]['options] = "";
$view->filter[1]['value'] = '1';

$view->is_cacheable = 0;
return $args;

How do I now the filter[1] is correct?
Is this the correct writing of the code?

thanks in advance,
greetings,
Martijn

summit’s picture

Hi,

What I would like to achieve is that my view gives other results on another url because of the filter-argument-handling.
So the url www.test.com should give another view because of the filter.
I tried to follow the above tips, but the view is not filtering on the term_node_140 on the end...
Do you need to set the filters also on the view, or is the argument handling enough?
Thanks for your help.

This is what I have so far, please alter code if necessary.

global $base_url;
switch ($base_url) {
  case ('http://www.test.com'):
  $view->filter[1]['tablename'] = 'node'; 
  $view->filter[2]['field' ] = status';
  $view->filter[3]['operator' ] = '=';
  $view->filter[4]['options] = "";
  $view->filter[5]['value'] = '1'; 
 
  $view->filter[6]['tablename'] = 'node'; 
  $view->filter[7]['field'] = distinct';
  $view->filter[8]['operator' ] = '=';
  $view->filter[9]['options] = "";
  $view->filter[10]['value'] = 'array (0 => 'distinct')'; 
 
  $view->filter[11]['tablename'] = 'term_node_109';
  $view->filter[12]['field'] = 'tid';
  $view->filter[13]['operator'] = 'AND';
  $view->filter[14]['options'] = '3';
  $view->filter[15]['value'] = 'array (0 => '176')';
  $view->filter[16]['tablename'] = 'term_node_138';
  $view->filter[17]['field'] = 'tid';
  $view->filter[18]['operator'] = 'AND';
  $view->filter[19]['options'] = '3';
  $view->filter[20]['value'] = ' array (0 => '170')';
 
  $view->filter[21]['tablename'] = 'ads';
  $view->filter[22]['field'] = 'adstatus';
  $view->filter[23]['operator'] = 'NOR';
  $view->filter[24]['options'] = '';
  $view->filter[25]['value'] = 'array (0 => 'pending',1 => 'offline',2 => 'unpublished',3  => 'expired', 4 => 'denied',)';
 
  $view->filter[26]['tablename'] = 'term_node_140';
  $view->filter[27]['field'] = 'tid';
  $view->filter[28]['operator'] = 'NOR';
  $view->filter[29]['options'] = '';
  $view->filter[30]['value'] = 'array (0 => '1739',1 => '1737',)';
 
  $view->is_cacheable = 0;
  return $args;
 
break;
  
  default:
  $args[0] = $args[1];
  $view->is_cacheable = 0;
  return $args;
 
  break;
}
summit’s picture

Hi,

I am not getting this to work, sorry people. I tried all sorts of methods last months..
I would really like to use the filter automated, so I don't have to make a view for every taxonomy term.

What I would like is to use the popular content view and be able to use the arguments as how to filter the view.

I am trying the following as stated above:

if($_GET['searchword']) { $someword = $_GET['searchword']; } else { $someword = ''; }

/***************************************************************************/
$view->filter[1]['value'] = $someword ;
$view->is_cacheable = 0;
return $args;

But I got all sorts of MYSQL errors.

Does anybody use the argument handling code to get the popular content view filters so that when you type in a termname as argument, the popular content from this termname and all hierarchies under this one will populate?

Please help?

thanks in advance,
greetings,
Martijn

summit’s picture

Hi Kostas and others,

Kostas thanks for your response on: http://drupal.org/node/161795#comment-584596

Your solution is not exactly what I would like. Would you please assist me a little further?

What I would like is to be able to filter on the first (arg0) and second argument (arg1) in a url.
For example: the url is www.example.com/view_url/region/category
The url is build like this, because of other reasons, so searchword= is not an option for me.

I would like to be able to filter on region and on category.

The filters are the 4th and 5th in the row. So should be [3] and [4] in the array, right, counting the first as zero?
But how do I get the filter to work?

I tried the following in the argument handling code:

if ($args[0]) {
  $filter_1 = $args[0];
  $view->filter[3]['value'] = $filter_1;
  if (args[1]{
    $filter_2 = $args[1];
    $view->filter[4]['value'] = $filter_2;
    }
  }
$view->is_cacheable = 0;
return $args;

But it is not working. May be I need something as: if($_GET['searchword']) { $someword = $_GET['searchword']; } else { $someword = ''; }
But then related to my url need www.example.com/view_url/foo/bar

Can someone help me please?
Thanks in advance!

greetings,
Martijn

Piyavkin’s picture

Hi, Martijn. You have asked me via my contact form about this point, but your contact form is disabled. I'm not sure that return address in the email yours. Where I should place my considerations about the issue?

summit’s picture

StatusFileSize
new49.96 KB
new68 KB

HI Dmitri,

Thanks for your post on: http://drupal.org/node/174714#comment-638306.
Related to your code, I tried building the code I need, but until now unsuccesfull.
I tried:

if (isset($args[0])) {
  $tmparg = taxonomy_get_term_by_name($args[0]);
  // place id of term into filter’s value
  $view->filter[2][value][0] = $tmparg[0]->tid;
    $view->filter[2][options][0] = 3;          <= to get the depth of 3, right?
  }
$view->is_cacheable = 0;
return $args;

My url is www.example.com/view_url/foo/bar
I set the filter and it is the 3th filter, so the first is 0, so I need to use [2], right?
I set the arguments to two taxonomy terms. As seen in attached picture. This is possible by the patch:http://drupal.org/node/77543#comment-633801

I also attach a picture of my filter settings.

What's wrong with the code please, it still will not filter on the first argument (arg(0): foo with a depth of 3?

Thanks in advance for your reply!

greetings,
Martijn

Piyavkin’s picture

Hi,

I set the filter and it is the 3th filter, so the first is 0, so I need to use [2], right?

May be and may be not. Just see what is the filter's id exactly. Try this. Temporarily place as Argument Code this code:


ob_start();
print '<pre>';
print_r($view);
print '</pre>';
$view->page_footer .= ob_get_contents();
$view->page_empty .= ob_get_contents();
// $view->block_footer .= ob_get_contents();
// $view->block_empty .= ob_get_contents();
ob_end_clean();

return $args;

It prints view object. Find [filter] array and check the real id of the filter.

I set the arguments to two taxonomy terms. As seen in attached picture.

Just delete both arguments. For your code above filter(s) only must be manually created.

If you provide the view as a block, then you must use not array $args, but function arg().
Also there may be mess in other fields and options. Verify and be accurate.

summit’s picture

Status: Active » Fixed

Hi,

I got something working with this argument handling code, thanks to Dmitri and others, thanks!

//(arg(0)=area = view_url, arg(1)=<category>, arg(2)=<country or city name>)
// array of term’s objects by name (second argument from arguments)
$tmpterms_0 = taxonomy_get_term_by_name(arg(1));
// array of term’s objects by name (third argument from arguments)
$tmpterms_1 = taxonomy_get_term_by_name(arg(2));
// place id of term (first of array) into first filter’s value
$view->filter[0][value][0] = $tmpterms_0[0]->tid;
// place id of term (first of array) into second filter’s value
$view->filter[1][value][0] = $tmpterms_1[0]->tid;
// change of depth if necessary
$view->filter[0][options] = 3; // or any other integer
$view->filter[1][options] = 3; // or any other integer

No arguments and two taxonomy term filters with a selection (the one will be overwritten by the argument handling code).
The patch http://drupal.org/node/77543#comment-634685 is installed in my testcase.

If you like to comment, or may be have better code to get this done, please reply!

Greetings,
Martijn

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.