I have a view with two fields (A and B), both of them numeric. I want to make a filter to show nodes when A + B = 0
How can I make this? I suppose I should add A and B as hidden fields and then there should be a calculated field anywhere allowing to add(), concatenate(), .... But I have been unable to find this module.
Thanks
Lluís, You could use http://drupal.org/project/computed_field to store the computed data on the node itself, then filter on that data in the view.
Otherwise, if you do not want to store redundant data, and want to do the math at the view runtime, you could look into a custom module solution that uses hook_views_tables() and custom written handlers.
Seth
Lluís wrote:
I have a view with two fields (A and B), both of them numeric. I want to make a filter to show nodes when A + B = 0
How can I make this? I suppose I should add A and B as hidden fields and then there should be a calculated field anywhere allowing to add(), concatenate(), .... But I have been unable to find this module.
Thanks
Hi, Lluís
have you tried computed_field module? If a understood you question, it may solve that.
[]s
Lluís wrote:
I have a view with two fields (A and B), both of them numeric. I want to make a filter to show nodes when A + B = 0
How can I make this? I suppose I should add A and B as hidden fields and then there should be a calculated field anywhere allowing to add(), concatenate(), .... But I have been unable to find this module.
Thanks
On Tue, Aug 25, 2009 at 2:55 PM, Jocimar Lopesgavranha@rankcine.com wrote:
Hi, Lluís
have you tried computed_field module? If a understood you question, it may solve that.
If I am right computed_field is useful when using cck, but I am using a custom module with custom content types. I am trying to write a module to allow SQL operations using hidden fields inside the query. I thing it is the best option because there is no redundant data.
My final query should look like: SELECT (a+b) AS any_alias, C FROM table GROUP BY C I have had a look at views_calc but it cannot work with grouped queries.
[]s
Lluís wrote:
I have a view with two fields (A and B), both of them numeric. I want to make a filter to show nodes when A + B = 0
How can I make this? I suppose I should add A and B as hidden fields and then there should be a calculated field anywhere allowing to add(), concatenate(), .... But I have been unable to find this module.
Thanks
-- [ Drupal support list | http://lists.drupal.org/ ]
Lluís,
First, what version of Views are you using?
If Views 1 (Drupal 5): what you need then is for your custom module to implement hook_views_tables(). That is how you tell the views module about your data and define fields and filters that are available to it. start here: http://drupal.org/node/99564 and read through to part 5: Filters.
If Views 2 (Drupal 6): you need to use hook_views_data() which you can read more about here: http://views-help.doc.logrus.com/help/views/api-tables. from that documentation page, in the Describing Fields On Tables section: "... each table can also have an unlimited number of field designations; these correspond roughly to fields on the table, though it is very common to use non-fields to display data that isn't directly in a field, such as data arrived from formulae..." be sure to have a look at http://views-help.doc.logrus.com/help/views/api as well for info on using hook_views_api() and where the other views hooks should be placed.
Seth
Lluís wrote:
On Tue, Aug 25, 2009 at 2:55 PM, Jocimar Lopesgavranha@rankcine.com wrote:
Hi, Lluís
have you tried computed_field module? If a understood you question, it may solve that.
If I am right computed_field is useful when using cck, but I am using a custom module with custom content types. I am trying to write a module to allow SQL operations using hidden fields inside the query. I thing it is the best option because there is no redundant data.
My final query should look like: SELECT (a+b) AS any_alias, C FROM table GROUP BY C I have had a look at views_calc but it cannot work with grouped queries.
[]s
Lluís wrote:
I have a view with two fields (A and B), both of them numeric. I want to make a filter to show nodes when A + B = 0
How can I make this? I suppose I should add A and B as hidden fields and then there should be a calculated field anywhere allowing to add(), concatenate(), .... But I have been unable to find this module.
Thanks
-- [ Drupal support list | http://lists.drupal.org/ ]
I use Drupal6 and Views2.
My problem is that I want to operate with fields from diferent tables (and modules). Can this be achieved just with hook_views_data()?
On Tue, Aug 25, 2009 at 3:44 PM, Seth Freachsfreach@gmail.com wrote:
Lluís,
First, what version of Views are you using?
If Views 1 (Drupal 5): what you need then is for your custom module to implement hook_views_tables(). That is how you tell the views module about your data and define fields and filters that are available to it. start here: http://drupal.org/node/99564 and read through to part 5: Filters.
If Views 2 (Drupal 6): you need to use hook_views_data() which you can read more about here: http://views-help.doc.logrus.com/help/views/api-tables. from that documentation page, in the Describing Fields On Tables section: "... each table can also have an unlimited number of field designations; these correspond roughly to fields on the table, though it is very common to use non-fields to display data that isn't directly in a field, such as data arrived from formulae..." be sure to have a look at http://views-help.doc.logrus.com/help/views/api as well for info on using hook_views_api() and where the other views hooks should be placed.
Seth
Ok, I have developed a module to allow add fields. I started my code using views_groupby and views_calc and the module can be extended to allow other SQL operations using handlers.
My problem right now is that despite generating a correct SQL, my field don't appear on view. In my handler I have:
function query() { ............. $this->view->query->add_field(NULL, $string,'sum'); ............. }
function render($values) { return $values->sum; }
And my field is defined as:
$data['views_operations']['views_sql_operatedfields'] = array( 'title' => t('Sum fields'), 'help' => t('Sum all the selected fields; you first have to add them to the view.'), 'field' => array( 'handler' => 'views_operations_handler_field_sum', ) );
Any hint of why my field don't appear in the view?
Thanks
On Wed, Aug 26, 2009 at 11:30 AM, Lluísenboig@gmail.com wrote:
I use Drupal6 and Views2.
My problem is that I want to operate with fields from diferent tables (and modules). Can this be achieved just with hook_views_data()?
On Tue, Aug 25, 2009 at 3:44 PM, Seth Freachsfreach@gmail.com wrote:
Lluís,
First, what version of Views are you using?
If Views 1 (Drupal 5): what you need then is for your custom module to implement hook_views_tables(). That is how you tell the views module about your data and define fields and filters that are available to it. start here: http://drupal.org/node/99564 and read through to part 5: Filters.
If Views 2 (Drupal 6): you need to use hook_views_data() which you can read more about here: http://views-help.doc.logrus.com/help/views/api-tables. from that documentation page, in the Describing Fields On Tables section: "... each table can also have an unlimited number of field designations; these correspond roughly to fields on the table, though it is very common to use non-fields to display data that isn't directly in a field, such as data arrived from formulae..." be sure to have a look at http://views-help.doc.logrus.com/help/views/api as well for info on using hook_views_api() and where the other views hooks should be placed.
Seth
-- *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
I found the problem; views_groupby code was hiding the field; I changed some code and its done; thanks anyway.
On Thu, Aug 27, 2009 at 10:58 AM, Lluísenboig@gmail.com wrote:
Ok, I have developed a module to allow add fields. I started my code using views_groupby and views_calc and the module can be extended to allow other SQL operations using handlers.
My problem right now is that despite generating a correct SQL, my field don't appear on view. In my handler I have:
function query() { ............. $this->view->query->add_field(NULL, $string,'sum'); ............. }
function render($values) { return $values->sum; }
And my field is defined as:
$data['views_operations']['views_sql_operatedfields'] = array( 'title' => t('Sum fields'), 'help' => t('Sum all the selected fields; you first have to add them to the view.'), 'field' => array( 'handler' => 'views_operations_handler_field_sum', ) );
Any hint of why my field don't appear in the view?
Thanks
On Wed, Aug 26, 2009 at 11:30 AM, Lluísenboig@gmail.com wrote:
I use Drupal6 and Views2.
My problem is that I want to operate with fields from diferent tables (and modules). Can this be achieved just with hook_views_data()?
On Tue, Aug 25, 2009 at 3:44 PM, Seth Freachsfreach@gmail.com wrote:
Lluís,
First, what version of Views are you using?
If Views 1 (Drupal 5): what you need then is for your custom module to implement hook_views_tables(). That is how you tell the views module about your data and define fields and filters that are available to it. start here: http://drupal.org/node/99564 and read through to part 5: Filters.
If Views 2 (Drupal 6): you need to use hook_views_data() which you can read more about here: http://views-help.doc.logrus.com/help/views/api-tables. from that documentation page, in the Describing Fields On Tables section: "... each table can also have an unlimited number of field designations; these correspond roughly to fields on the table, though it is very common to use non-fields to display data that isn't directly in a field, such as data arrived from formulae..." be sure to have a look at http://views-help.doc.logrus.com/help/views/api as well for info on using hook_views_api() and where the other views hooks should be placed.
Seth
-- *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.
-- *La vida és com una taronja, què esperes a exprimir-la? *Si creus que l'educació és cara, prova la ignorància. *La vida és com una moneda, la pots gastar en el que vulguis però només una vegada. *Abans d'imprimir aquest missatge, pensa en el medi ambient.