Is it possible to have views show a query based on the current node (not 1 set node but any node)
my situation:
A user submits a node with information
another user can donate to that node from another content type using 2 fields: node reference (to pick the node) and integer (to enter donation amount)
I need a block view to show all the donated amounts for the current displayed node
(would be even better if someone told me how to just all the donated amounts up to show the total amount!)
thanks in advance
If you need dynamic filtering, views arguments is your friend.
After you add fields and filters, add an argument Content: node reference (the name would be whatever you chose to name it, but make sure it's node reference).
In the argument setting, for "Action to take if argument is not present" click on provide default argument and choose Node ID from URL, do validation.
Add a block view and enable it on the block settings page. It's only going to show on the appropriate nodes.
Check this tutorial for more detail.
To do calculations, take a look at Views Calc module.
Related
I'm trying to add the editiedon field to the modx manager pages so my users can edit the value using this bit of documentation as a start point:
http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/adding-custom-fields-to-manager-forms
Which does work, but:
how can I make that a date/time field?
how can I place it in the settings tab of the given resource?
Isn't input type="date" the answer to the first question? I'm not sure how you would do the second part, unless you managed to get the rendered content and splice it in there somehow (unless theres som hidden specified method).
Otherwise, you could always solve it with regular form customization. You'll want to create a TV of type Date, and give it a custom default data through a snippet, that just fetches the current resources editedon value. I guess you only need to update the resource/update form set. Under the template variables tab of the set, make sure your TV is connected and change the region value of it to "modx-resource-settings"
There are two different ways which have their own pros & cons.
At first you can use template variable with Date type. It gives you correct ExtJS component for dates and you'll see calendar in TV's tab.
If you'll choose this method you have to create a plugin which invokes on OnBeforeDocFormSave event. There you can redefine modResource editedon property from your TV and it will be saved in proper way. Also you may invoke another event(OnLoadWebDocument). There you can set modResource editedon property from you TV if you want to see correct data.
Pros:
fast calendar integration to the one of modResource's tab
you can use Form Customization for security reasons. It's rather easy and from the box.
Cons:
Additional TV which complicates modResource updating process a little bit
Another method is more complicated (you need skills in ExtJS).
Create plugin which invokes on OnDocFormPrerender event. You can add JS to the modResource page there. Your scripts should render new custom tab to the document where you can add your special field with calendar. So there is special ExtJS component in MODX for these purposes. And of course you need events from first method for loading and updating editedon value.
Also you can just render special field to the existing tab instead of creating new tab and rendering your custom field to it.
Pros:
you don't need TV anymore
it's flexible
Cons:
it's more complicated and takes time
P.S. You can view Xlexicon github repo. There you can find example of rendering new tab and manipulation with modResource properties.
Also you can check modAvatar extra for MODX. There is an example of manupulation with existing tab.
Can we add custom variable in google analytics report.
IE: Our URL is as ?module=global_settings&load_tab=global_settings_tab
Can we set a custom variable "module" and "load_tab" using which we cant to track how many hits on which module in reporting.
You could do this via a custom var. Documentation is here, a way to extract url parameters I leave as an exercise to you (hint: better do it serverside). If you want to store both module and tab you'd need two variables, which might in the long run be a problem - there are only five custom vars available (maybe you should store both values in one variable). Custom vars come in different "scopes" (see docs), since this is about page tracking you should use page level scope.
A tracking call for such a custom var might look like this:
_gaq.push(['_setCustomVar',
1, // This custom var is set to slot #1 (from five)
'Path', // The name acts as a kind of category for the user activity.
'global_settings/global_settings_tab', // This value of the custom variable.
3 // Sets the scope to page-level
]);
With Universal Analytics custom vars do not longer exist, they have been replaced by custom dimensions and custom metrics.
But you do not necessarily need a custom var (or custom dimensions), since the url parameters, unless you strip them out explictly in you view settings, will show up in the reports in any case. But those reports won't be particularly beautiful or readable.
To beaufity your reports (if necessary) I'd recommend an advanced filter.
1) Goto view settinsg, new filter , custom, advanced. In the first dropdown select Request Uri as filter field.
2) In the textbox enter module=(.)&load_tab=(.) This is a regular expression that will take the values for your "module" and "load_tab" parameters and store them in a variable.
3) Skip the second filter field.
4) Set "Output to -> constructor" to Request Uri. In the textfield enter /$A1/$A2 - these are the variables that stores the results from Step 2.
So if your url has been "?module=global_settings&load_tab=global_settings_tab" this filter will change it to "/global_settings/global_settings_tab" in the content reports (note that this will break Inpage Analysis, and as always with filtered data you should keep an unfiltered backup profile) - same for any other value of the parameters. That would be more easily readable, and you would not have to waste custom vars (which do not show up in the standard report in any case), so this might be useful
I have been toiling with this issue for the past 2 days now, and I can't seem to get some functionality working on a customization for a WordPress plugin. I am using latest versions of both JigoShop and WordPress.
URL to project: http://customcasing.ca/product/ipad-case/
Current Functionality
I have 5 product SKUs on the homepage and when clicked lead to their respective product order pages. On these respective pages are a design canvas which I have implemented fabricjs to handle image manipulation. When the user is satisfied, they save the canvas, which then uses the following example code to serialize the image into a JSON object:
saving/loading canvas with JSON
The JSON object is then set as the value of a hidden input within the "Add to cart" form. Then they would be able to choose product color variations, via dropdown boxes.
Now here is where things fall apart
Submitting the "Add to cart" form is supposed to run through a number of classes and post the hidden JSON object value to an aggregated "cart" object. This is called on various pages and a key/value pair is associated with the various attributes of the product. However, all the other key/value pairs are being executed and echo'd on a subsequent order review page...except my custom variable.
Here is the directory architecture
/wp-content
...
/plugins
...
/jigoshop
jigoshop_template_functions.php
jigoshop_actions.php
/classes
jigoshop_cart.class.php
/themes
/customcasing
Here are the code blocks associated with the above structure (pastebin)
jigoshop_template_functions.php
html generator and form
jigoshop_actions.php
form $_post for hidden field
classes/jigoshop_cart.class.php
form validation and key/value pair creation
I have given as much information as I possibly can about my current conditions, if there were to be anything of help on stackoverflow it would be the following Q/A:
Trying to send a hidden input value to next page
If you need any additional information please feel free to ask and I will do my best to elaborate. Also if you need a wider scope of the code I can provide that as well. I would really appreciate any nudge in the right direction.
List -> l_user I have a List node that has a user-reference field (l_user).
Story -> s-user I then have Story nodes that also have a user-reference field (s_user).
There is no direct connection between List and Story.
I want to add a view to List that lists all the stories that reference the same user that list references. Basically something like SELECT stories WHERE story.s_user = this list.l_user and l_user is the user referenced in the list this view is on.
So far the view is being filtered by node:type story but I'm not sure what to use (arguments/filter, etc) to link the story s_user to the list l_user.
Is this doable with Views?
You can do this with a Views argument. What you're trying to do is filter that list by user, and you get the user to filter by from the node you're currently on (or more specifically, the node's user reference field). So what you'll need to do is supply Views with an argument that is equal to the node's user reference field.
To do that, set up your view as normal and as if you were showing every user's node. So you might have a view that's like:
Page 1 (by User 1)
Page 2 (by User 1)
Page 3 (by User 2)
Page 4 (by User 2)
Page 5 (by User 1)
Where the user is a user reference field on each page called Story user reference.
Now, under Arguments add an argument for Content: Story user reference. Now, the view will only show nodes that are posted by the user specified in the argument. The problem is, in a block, there is no argument to specify: you need to provide a default argument.
Still on the argument configuration pane for Content: Story user reference, select Provide default argument under Action to take if argument is not present. You'll get a variety of options, but none of them are what you're looking for: the current node's user reference field.
So you'll need to use the PHP code action and use the following code:
$node = node_load(arg(1));
return $node->field_list_user[0]['uid'];
This loads a node based on the node ID retrieved from the current page's path and returns the node's user reference field (change field_list_user to the name of the user reference field on the list nodes).
So if I'm on node 17 whose user reference field states user 4, the argument that'll be passed to the view is 4. The view will then only show nodes in the view who have user references that are also 4.
Save your view, create a block display, and place it wherever you want. When you visit a node page with a user reference field, the block will populate with the referenced user's nodes.
I'd suggest getting all of the user references from the list node and passing those into a views argument. So your code would look something like this (untested):
$user_ids = array();
foreach ($list_node->l_user as $user_reference) {
$user_ids[] = $user_reference['uid'];
}
$view = views_get_view('list_view');
return $view->preview('block_1', array(implode(',', $user_ids));
That assumes you have a view named 'list_view' with a display named 'block_1' (you can see the machine name when you hover over the display). That display needs to be a node view with a filter of node type 'story' and an argument of content user_l set to take multiple values. There's almost certainly a bug in that code, but I know the general concept works, as I've done it several times before.
To solve this you need to download NodeReferrer. http://drupal.org/project/nodereferrer
It provides a counter part to CCK's node reference field.
Then you can call the field "Node referrer" in your View.
I have a few Views on my Drupal 6 site which take care of some of a node's fields.
For example, I have a content type called Country, which has a field called Capital. I've excluded this field in the node display, but there is a view that takes the node ID as an argument and displays it in the right column. This is all very pretty and has been working out well for me, but how do I take care of the node preview mode? Since the node isn't saved yet, the Capital field won't have its new value yet.
Note: I am ready to do some very dirty hacks to make this work :)
don't hack drupal! :)
One of not so simple and unchecked idea:
use hook_form_alter or hook_nodeapi with validate in custom module, there's you should see data of new capital field, save it somewhere (for example, into sessions), and show it's into block via theming Views field.