Active
Project:
Services Views
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Dec 2012 at 17:19 UTC
Updated:
19 Dec 2015 at 12:51 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
cybertoast commentedI guess I could hard-code hard-code the total into the rendered response. Eg.:
Then insert the total into the item object:
But this seems extremely un-drupal-esque and probably has horrendous unintended consequences. What would potentially be better is if this was configurable via settings for this module, where the label could be set if this stat is to be enabled.
I wonder if anyone with experience with development on services-views could suggest some possible best-practice paths.
Comment #2
ygerasimov commentedI have added a hook to alter views results before sending them to services for rendering. Please see services_views.api.php for example.
Comment #3
cybertoast commentedThanks much, this is much cleaner. The issue though is that the total_rows seem to only be retrievable by setting $view->get_total_rows = TRUE, per http://drupal.org/node/1306196. What do you think about the attached patch (to 7.x.1.x)?
Thanks again - taught me something about drupal's stack development.
Comment #4
ygerasimov commentedI think you can set $view->get_total_rows = TRUE; in one of views hooks. I would try hook_views_pre_build(). So no need services_views to interfere this variable in "case" of "hook_alter tries to get $view->total_rows".
Comment #6
bigwebfoundry commentedI am not able to understand #2, #3, #4.
Please help me where do I need to put this code $view->get_total_rows = TRUE; to output pager informat(count, total rows) in response json , I tried like follwing:
But it didn't work,
I want something like this https://www.drupal.org/node/2301749 but code there is not working with views 3
Please help
Comment #7
derekwebb1 commentedSo what is the variable or parameter to get the services_views module to output the view metadata with the result. I tried to use the hook_services_views_execute_view_alter(&$output, $view) and found that it did nothing at all. From what I can tell from adding watchdog logs, it doesn't even get called when requesting a view via services_views... What does one have to do to get metadata? Any guidance is appreciated.
I used the following and there was no change:
I also found that watchdog logs placed in services_views_execute_view, where the alter is initiated, are not called at all.
Comment #8
derekwebb1 commentedComment #9
derekwebb1 commentedI had to create a new service to load pagination info after the services_views call was made. It would be nice if pagination info was included in the returned results.
Comment #10
derekwebb1 commentedI also tried the alternate path to getting a service with this module: using the individual view service (where you select the view in the services admin page as the resource)
On the plus side, the pagination information as refered to in the api finally showed up. The bad news is no arguments whatsoever are honored, so all of the following fail:
http://mysite.com/myview-service/myview?arg[0]=limit=1
http://mysite.com/myview-service/myview?limit=1
http://mysite.com/myview-service/myview?tid=1
http://mysite.com/myview-service/myview?filters[tid]=1
No arguments are honored. Any suggestions on what I might be doing wrong would be nice. Thanks
Comment #11
fmoutawe commentedHello,
I have the same problem with pagination and my_module_services_views_execute_view_alter hook is not the solution.
This hook allow to modify only the preview (when you are in B.O) !
However, services_views_retrieve() is used to send result to the endpoint.
I will try to find a good solution.
Comment #12
mhmd commentedIn order to make pagination work with services views which comes when you make a services display with path to access like
{endpoint}/{services display path} NOT FROM {endpoint}/views/{view name}
You have to configure EXPOSED OPTIONS from Pager settings link like the image attached
After that you must set ?offset=0&items_per_page=5 after you endpoint url like
{endpoint}/{services display path}?offset=0&items_per_page=5
NOTE : items per page must be like 5,10,20,50,100 and include items to display value.
Comment #13
rasikap commentedYou can enable the views php and write the following code :
if (!isset($static['size'])) {
foreach($view->result as $each_result) {
$result_array[] = $each_result->nid;
}
$size = count($result_array);
$static['size'] = $size;
}
return $static['size'];
This will return the total number of counts of result.
Another approach is to to user views_query_alter to get the total number of records and pass in the result array.
Comment #14
rjdjohnston commentedCheckout this article:
http://www.christophermchurch.com/services-views-api-add-on-module/
And this custom module made by Chris:
https://github.com/cmchurch/drupal_services-views-totals
Works beautifully!!
Comment #15
eternallight commentedAwesome, thanks!