Views (D7): Rewrite output with PHP code ...or other solution for API data

Events happening in the community are now at Drupal community events on www.drupal.org.
greta_drupal's picture

Drupal 7:
I have a custom node field for Yelp ID. I want to use that to pull in Yelp data via Views. Was considering rewriting the Yelp ID field output with the API pull code, but no input filter to allow PHP. In my research, I found a Views PHP module, but it is in dev with lots of bug issues.

Anyone have any other ideas for approach? I've experimented with a few, but seems there must be something more eloquent.

POSSIBLE SCENARIO:

Business directory with mixed results -- some Yelp, some direct Drupal. Each entry would be created as a node (custom content type). For those businesses with a Yelp listing, their Yelp ID will be used to pull details to the page via Yelp API. Ideally, I would want this data to embed on the full node for the business, as well. For those businesses without a Yelp listing, they will complete all Drupal form fields for listing details.

In Drupal 6, there was a PHP snippet option on fields. Never used it before and don't know if it would fit the bill, but it no longer is available anyway.

Yes, there is a Drupal Yelp module, but it simply pulls all the Yelp results together in a chunk (block). I need the business listings to be sorted -- Yelp and not-so-Yelp.

Comments

php

tararowell's picture

If you want to use PHP in Views, it looks like you can with this module: http://drupal.org/project/views_php

You must have missed the part

greta_drupal's picture

You must have missed the part of my original post where I mentioned it...and that it is in dev (with no updates since April 2011 and 78 open issues).

Yelp API

spencerfromsc's picture

Can't remember exactly right now, but I think storing the data that you pull through the API might violate their Terms of Use. Have you considered an approach using Feeds...maybe something along the lines of what they did with this module (http://drupal.org/project/example_web_scraper)? If you've already figured something out, I'd be curious to know what approach you took.

I wouldn't be storing their

greta_drupal's picture

I wouldn't be storing their data. Simply using PHP to pull their data from their db -- using the code they provide for doing so, and co-mingling it with other non-yelp listings upon display. Feeds module would no more than the same as the Drupal Yelp Reviews module. So, query: if Yelp ID (CCK field) populated, pull Yelp rating from Yelp using that Yelp ID, and display it here.

Am just about to start this project. Not quite sure how I will address it -- maybe through custom .tpl file. But, I'd rather do it through Views so that I could manipulate the data display. But, it should be doable, so I'm going forward with the project.

TPL or preprocess hooks

arpieb's picture

You can mangle Views output pretty thoroughly with TPL files, but they invoke more overhead than using one of the many theme or template_preprocess hooks provided by Views. Instead of installing a module that allows you to enter PHP code (which always poses a security risk) I'd go down the path of using the provided hooks or TPL files. That's what they are there for, and give you all kinds of control right down to the field level.

To see what all you can do with Views through its API, install the Advanced Help module and browse to the Views API section of the Views advanced help topic. There are theme hooks and template_preprocess hooks that will probably get you where you're trying to go...

Yes, that is how I expected

greta_drupal's picture

Yes, that is how I expected that I'd need to do it -- through custom .tpl file.

Google Places API

spencerfromsc's picture

Have you considered using the Google Places API for information about the business? If the location does not exist yet in GP, you can simply add it through the API. This might help eliminate the "mixed" database issue and you could still have the field for the Yelp ID, I suppose.

Yes, I looked at Google

greta_drupal's picture

Yes, I looked at Google Places. But, it would be the same issue. (With perhaps some advantages.) Pulling their fields to display with Drupal fields. I think that you are missing the point. I DO want to mix the database fields (for display). But, I want to collect and store all the basic data (e.g., contact info, amenities) through the Drupal site. Using only the Yelp reviews and ratings (most likely nothing else).

Also, Yelp appears to have more data. Another problem with Yelp, and possibly Google Places, is that it isn't enough to simply create a business listing there. If there are not a certain number of reviews/activity, that listing isn't pushed into a Yelp feed. This was the biggest drawback. So, must create a Drupal basic listing to represent each business. Will also rate & review listings through Drupal.

Based on research, couldn't find anyone else doing this. Appreciate your thinking about it; too bad there hasn't been more participation in this thread...it would be (will be) a good use case.

Views PHP - not working?

relish27's picture

I came across this because I recently used the D6 Custom Field with PHP and it worked great. I'm now on a D7 project and was hoping to be able to use it. Doesn't seem like the Views PHP module is working -- I don't see it as an option (and no documentation). If you do ever get this to work, I'd be interested to know...

Thanks.

Atlanta

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: