Combine two views into one view - drupal

I have two views that I would like to combine into one.
The first view shows all items of X where company ID = Y. This is to give preferential sort to the client first, and then everyone else.
So I created a second view, all items of X, where company ID != Y.
I created it as an Attachment to attach to the first view, but I don't think I got the intended result.
How can I combine these views so the first view results are listed first, and then the second view is too, using the same pager, filters, and arguments?
Is there any way of achieving this without programming it?

From a MySQL point of view, the order-by-field syntax would be the appropriate way to handle this. Example:
SELECT * FROM tickets ORDER BY FIELD(priority, 'High', 'Normal', 'Low');
It would be great if there is a module that add this kind of functionality to Views, but AFAIK, it does not exist.
If you want to solve this without programming, I think you can use the rules module to automatically set the 'sticky' checkbox on nodes where company ID = Y. With that in place, you can order the View on the sticky value.

Along the lines of the 'sticky' idea, if you didn't want to override that, maybe you could add a checkbox field to the company type -- isClient. Make it false for everyone except the client, and sort by that.
I haven't done this, but maybe you need to create both versions as attachments, and attach them both to another display...?

for drupal 5 there was views union. Someone started something for D6, but I don't know how far they got.
http://drupal.org/node/275162

Create the second view as an attachment and attach it to first.
Set all Inherit arguments, Inherit exposed filters and Inherit pager to Yes.

how is the client parameter passed to the view? as an url argument? if so, you can create your second view like i outline here and then select the exclude the argument option on the appropriate location.

usually the easiest way to achieve this is with a small hook_query_alter, but that requires a small amount of programming.

A little bit later... but I've found a better solution using only the Views module:
Create a Block View with that shows the first list that you need ("all items of X where company ID = Y")
Create another View that must be a "Page view" with the second list (all items of X, where company ID != Y)
In the "HEADER" settings of this second view, click "Add" and select "Global: View area".
In the "View to insert" list, select the first you have created (and check "Inherid contextual filters" if you are using it)
And that's it!

Related

Drupal - Edit Views Selective Filters module to rename the option tag

Actually, I try to make a filter criteria who list the available "structures" in my view. I'm using the Views Selective Filter module who does what I want. But in that list, that show the id of my structure and not the name. (I can't show you with an image, actually)
I want that my "structures" name replaces the id in my list (but not the value).
If you have any idea, I would be very grateful.
I found a solution.
I have edited the Views Selective Filter module to allow him to detect and load my structure name.
After that, I just have to change the text of my option before that the id has assigned in.

How to pass arguments between views in Drupal-7

I consistently find myself up against the following use case, and have yet to grok the proper workflow / solution:
I would like to display two views.
In the first view, each row displays one node of type-x.
The second view shows nodes of type-y, which are associated with node type-x via a nodereference, as follows:
View-1 View-2
------ ------
row1 X-a <---> Y-a
row2 X-b <---> Y-b
row3 X-c <---> Y-c
row4 etc <---> etc
For example, X is an event, and Y is a venue. Or, X is a porfolio page, and Y is a paged gallery.
I understand that there are other ways of approaching this - for example using node views rather than fields, but I am trying to leverage views to create 2 distinct custom queries related by an argument passed from one view to the other.
This is a variation of a question I asked earlier (Programmatic Views in Drupal 7), and hopefully a clarification.
Any help, even (or especially) just on the semantic level, is greatly appreciated.
You should use the EVA module. It does what you need in an elegant way.
https://drupal.stackexchange.com/questions/5732/is-there-a-good-tutorial-for-entity-views-attach-module
Hm I am not sure if I understand it correctly, but I think what you want to do is pass an argument to the view and then filter the results by it.
The option to configure the parameters in the UI is called 'Contextual Filters'.
Then you can call the view from your code like this(suppose your parameter is a node id):
<?php
print views_embed_view('example_view', 'page', $node->nid);
?>
If I understand, I think the best way would be to use only one view, and set a relationship on the node reference. Then create a field for the field you are displaying from the first node, and a field for the second node.

Create list of nodes that are referenced at least once

I'm sure this is simple with the Node Relationship module but I can't wrap my head around it.
I have a list called 'Comedian Profile' which has a node reference field for it. You then make - you guess it - profiles for comedians. To make an 'Events' (that doubles as an Ubercart item) you select the comedian. It then creates a view in the profile that lists all of that person's upcoming events.
Now what I need is an listing that shows in order of the date field each comedians name that is referenced(I'll worry about the other fields later). Note that the name is the referenced term.
Is this the right approach? If so could someone point me in the right direction or suggest a better way?
If I got it right, you can accomplish this using views relationships.
Add the field "Comedian" of the Event content type as a Relationship in the view (be sure to check the "Require this relationship" box). Then, add the fields, selecting the relationship you created. If the "Comedian" field is optional, check the "Hide if empty" box.

Views 1: Filter by custom table/field (or using Argument Hand. Code)

I have a page which should list nodes. The views is called from a locality page (a taxonomy term page). What I need is almost the same as using the Taxonomy: tid in arguments and passing the tid.
I can't use the term_node table, as (for other reasons) we have a custom table term_node_hierarchy (with nid and tid only). The table term_node_hierarchy is like term_node but also saves the tid of the parents (from an "external" code)
I've been looking for options but still no joy.
Currently I'm building an array of the nid's that should be displayed on the current page, and passing them like print views_build_view('embed', $view, $matching_nids); but the Argument Node: ID states This argument is a single Node ID. As said, only the first node is displayed when printing the views. It would be great if it could filter on more than one nid.
I'm open to any kind of suggestions on how to do this.
Thanks
You could create your own module for this. You could populate the $page_content variable with the results of your own custom query where you allow the user to sort against multiple nids. You could do this a number of different ways. You could display a list of the existing nids with corresponding checkboxes, so that, when the user clicks submit, all the nids that match the selected checkboxes get used in the query. Then you just display the result of that query. That's the easiest way I can think of to offer that degree of flexibility.

D6: how to get at node fields in preprocess_page()?

i created a view that displays my homepage fine but now a modification is needed: i load 2 fields (images) in my view but need to only display one of those, depending on the value of a third (date) field and today's date. if date field is later than today, show image y and if its earlier than today show image x. this kind of logic cant be done in a view.
so in my template.php id like to output x or y as $vars['img'] in the preprocess_page function. im just wondering, how do i get at the values of those fields? its not a node but a list of node teasers.
the function gets passed &$vars but a print_r of those just shows the html output.
custom sql seems not the way to go.
when i load the view, i just get the html it outputs but (i think) i need the raw data to make the date comparison.
thanks for any pointers!
I'm sure there are some ways to do this, some more hackier than others. I would:
Make a template specific to your view
Create a preprocess function for the view and create a boolean variable, by checking which img that should be displayed.
Lastly I would alter the template slightly by making an if statement that checks if it should display img x or y.
This solution is pretty easy and straight forward, the downside is that it's not completely general as you most likely will need to know the names of the cck field names you are using. It's doubtful you would be able to generalize this anyways.
Edit:
To clarify a bit. You can look at the general views template that's being used, it will give you some insight as to how views prints the different fields. Generally getting at the fields is usually not a big problem when you have the $node object. The reason is that cck adds the fields to the $node object so you can access it there. I believe you can do something in the line of $node->field_[the_name] to get to the field. I would suggest that you use the devel module if you don't already and do a dpm($node) somewhere in the template where you loop through the nodes. That will enable you to see what has been defined on the $node object. It shouldn't be a big problem to print the img from there.
How about using preprocess_node() instead?

Resources