Pulling Data not in nodes

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

Enter the genuine Drupal and Services noob.

I have been looking at the integration between flex and Drupal, using services and AMFPHP to pull nodes. However, I haven't seen anything about using AMFPHP to get data that is not part of a node, for example, data specific to a table created by a module.

So: Is it possible to use Services to get data that does not lie in a node? If so, how? I can easily write a method for getting the data I want, the problem is how to use Services to use AMFPHP to send the data to a flex application.

Thanks!

PS. I know the question is probably an easy answer, but my searches have given me nothing. I apologize in advance if it has been asked umpteen million times.

Comments

I suppose it depends on the

tjholowaychuk's picture

I suppose it depends on the module, but you would probably have to create custom services to create,read,update, or delete that additional data if they have not already been created for that module, I have had no need to do this yet but I imagine it would be very similar to the other service calls which are bundled with services


vision media
350designs

Easy as pie, sort of...

codexmas's picture

If you take a look at some of the example services, like the one that returns nodes it's not too hard to imagine how you could put your own SQL statement in and construct some data that you need to return to flex.

For example:
I wrote some services to create a flex secure image browser, one that uses the services to look into a folder that is not in the public_html directory. This is all done of course with PHP in drupal, while the flex application when starting just requests the directory/file info from one service when it loads the first time. I started by duplicating a service function that already existed and creating slightly altered entries in the _service hook that tells drupal what services your module provides.

Two services:
function browse_service_list($dir = '/')
This one as you can see defaults to / for the directory so flex doesn't need any data when it loads(flashvars)
This function returns a PHP object that has a listing of directories in one tree and a listing of files in the directory requested

From that data flex displays the list of folders in a side panel as clickable items that then make the same request but now with the directory path as the argument.

function browse_service_fetch($file, $dir = '', $size = 'thumb')
This function is called for each of the files that are returned in the object from the call above.
It defaults to a thumbnail version, which PHP generates on the fly through drupal's own functions.
Once the thumbnail is present, it is loaded into memory using file_get_contents() and passed back as a ByteArray to flex.

The main function of this application is to provide access to folders of images for logged in members. Lots of other stuff goes on in the background, but that is the real flow of the application. The only magic involved here is the ByteArray sent from PHP to flex. Flex will when cajoled properly automatically decode the raw filestream into an object that can be used as the source for an image on any other flex object.

Aside from that neat piece of functionality the rest of the coding is all very standard stuff.
I do plan on releasing this module and and flex app to the drupal community, time and opportunity allowing.

Cheers!
Gord.

Services Repository

nickvidal's picture

Hi,

One question related is about these different services. The services module provides basic services. If we want to extend those, we create our own. But I suspect developers will want many common services. Is there some kind of services repository where we may find these common services? I didn't find any except for the Services Module issues:

http://drupal.org/project/issues/services

Is this the right place to look for and share services?

BTW, instead of FLEX I'm using Ext (JS Library). More details here:

Web Desktop with Drupal and Ext

Thanks,
Nick

wow they have a nice

tjholowaychuk's picture

wow they have a nice library! that was developed by alot of the developers of aptana was it not?


vision media
350designs

Good News!

Gambler's picture

Ok, So I can easily create the services to get the data that I want...

But how do I do so, a tutorial or example? Even some documentation. Again, the Google Gods have not given me much.

Thanks All!

EDIT: Sorry, I just found these goodies: http://drupal.org/node/144141 Highly explicative.

EDIT: Ok, I have created a custom service method that accomplishes what I want, however, because I will eventually be using it with a remote application, I obviously want to use authentication. How is that done? I have looked at the examples but still don't get it. Whats up with the struct?

Having trouble getting the service to work.

Gambler's picture

I am now having some trouble with some code, hope you can help.

Right now I have a table named courts_seasons with 1 row in it.

Here is the code:

$result = db_query("SELECT * FROM {courts_seasons}");
  $row = db_fetch_object($result);
 
  $i = 0;
 
  foreach($row as $cur_row) {
    if ($cur_row['start_date'] < $cur_row['end_date']) {
   $result = db_query("SELECT sid FROM {courts_seasons} WHERE start_date > $date AND end_date > $date");
      $sid_row .= db_fetch_object($result);
      $num_row = $num_row + db_num_rows($result);
   
   $result = db_query("SELECT sid FROM {courts_seasons} WHERE start_date < $date AND end_date < $date");
      $sid_row .= db_fetch_object($result);
      $num_row = $num_row + db_num_rows($result);
  }
  else {
   $result = db_query("SELECT sid FROM {courts_seasons} WHERE start_date > $date AND end_date < $date");
      $sid_row .= db_fetch_object($result);
      $num_row = $num_row + db_num_rows($result);
  }
  $i++;
  }
 
  return $i;

Each time I run it I get $i=4. Why is the loop running 4 times when I have only 1 row in courts_seasons. Also, when I run the service with data that should give me the row back, I don't get a row back.

I have tried changing it to this:

  array ($sid_row);
 
  foreach($row['sid'] as $sid) {
    if($row['start_date'] < $row['end_date']) {
   $result = db_query("SELECT sid FROM {courts_seasons} WHERE start_date > $date AND end_date > $date");
      if(db_fetch_object($result) != '') { $sid_row[] = $sid; }
    $result = '';
   
   $result = db_query("SELECT sid FROM {courts_seasons} WHERE start_date < $date AND end_date < $date");
      if(db_fetch_object($result) != '') { $sid_row[] = $sid; }
    $result = '';
  }
  else {
   $result = db_query("SELECT sid FROM {courts_seasons} WHERE start_date > $date AND end_date < $date");
      if(db_fetch_object($result) != '') { $sid_row[] = $sid; }
    $result = '';
  }
  $i++;
  }
 
  return $i . ' - ' . $sid_row;
 
}

But I get the error: Invalid argument for foreach() in reference to the line foreach($row['sid'] as $sid) {

Any ideas? Thanks!!!

Services

Group organizers

Group categories

Group notifications

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