I wrote a module that just sets in a table the user that first accessed a node and stores the node id, uid and datetime.

I want this module to be accessible from drupalgap apps so if someone accessed the node from the mobile app then it will trigger the write to the table and if they are not the first it would send them a message that some beat them to it. Can you give me some insigt on how to set this up.

Thanks.

Comments

doors’s picture

Title: How to extend the drupalgap services for a module that writes that a user saw a node first to a table » How to extend the drupalgap services for a module that writes to a table the user who saw a node first
doors’s picture

Issue summary: View changes
tyler.frankenstein’s picture

Title: How to extend the drupalgap services for a module that writes to a table the user who saw a node first » Custom DrupalGap Service Resource Example
Status: Active » Needs review

On the Drupal side of things, you need to implement a custom service resource. Here's an example:

http://drupalcode.org/sandbox/signalpoint/2068317.git/commit/f565f40

Then on the DrupalGap side of things, check out this page for an example:

https://github.com/signalpoint/pathfix/commit/582a52327c656400c23dc8ce96...

Essentially you need to create a JS object like the "DrupalGap Pathfix Services" example code above, so then you can call something like this in DrupalGap:

drupalgap.services.my_service_name.my_resource_name.call({success:function(result){alert(result);}})

Please note, these are old commits and are no longer used in the sandbox module, but the code is still valid and will work.

doors’s picture

I had already sorted out the drupal module by looking at how the drupalgap module implementation.

Based on the Drupalgap Pathfix Services module I did my own module but I still am having some trouble understanding how it works.

This is my implementation:

drupalgap.services.code_comp = {
  'add_winner':{
    'options':{
      'type':'post',
      'path':'code_comp/%id.json',
    },
    'call':function(options){
      try {
        var api_options = drupalgap_chain_callbacks(drupalgap.services.code_comp.add_winner.options, options);
        api_options.path = 'code-comp/' + options.id + '.json';
        drupalgap.api.call(api_options);
      }
      catch (error) {
        navigator.notification.alert(
          error,
          function(){},
          'QR Scanner Error',
          'OK'
        );
      }
    }
  }
};

The node will will have a unique text field that a user will scan and once they are the first person to scan it a record should be written to a table row so that another user cannot see the record and scan it and be assigned as the winner.

I want to send the unique code to my Drupal module via the Services module instead of the node id.

What is the best way to implement this?

tyler.frankenstein’s picture

Stop by #drupal-drupalgap on IRC to discuss this further please.

doors’s picture

Tyler I am a newbie to irc but I am on now and I see you online but I am not getting a response from you.

tyler.frankenstein’s picture

Status: Needs review » Closed (fixed)

A complete example is available here: http://drupalgap.org/node/187

lipinponmala007’s picture

Hi

I followed the complete example @http://drupalgap.org/node/187

But In my case I have an argument to pass to the call back function
In my mymodule.services.inc

i have put

 'args'     => array(
            array(
              'name'         => 'pid',
              'type'         => 'int',
              'description'  => t(' id '),
              'source'       => array('data' => 'pid'),
              'optional'     => FALSE,
            ),
           
          ),

in my_module.resource.inc


function purchase_possibility($pid){
  watchdog($type='mymodule', $message='<pre>'.print_R("$pid",true).'</pre>');
//this is empty
  
}

in custum/mymodule.js in the directory


purchase_pid:{
	    options:{
	      type:"post",
	      path:"mymodule_resources/mymodule_resources.json"
	    },
	    "call":function(options){
	      try {
	    	  
	    	
	        var api_options = drupalgap_chain_callbacks( drupalgap.services.mymodule_resources.purchase_pid.options,options
	        );
	       
	        drupalgap.api.call(api_options);
	      
	        
	      }
	      catch (error) { drupalgap_error(error); }
	    }
	  }

but my my_module.resource.inc i am not getting the $pid it is always empty.

am i am trying in a wrong way? Thanks in advance

lipinponmala007’s picture

Hi

Pleae consider this to be with the previous post

Here is i am trying to callthat service

var pid=value;

try {
	    drupalgap.services.mymodule.purchase_pid.call(
	    		{
	      'pid':productid,
	     
	      'success':function(result){
	     
	      }
	    });
	  }
	  catch (error) { drupalgap_error(error); } 
	
	}

lipinponmala007’s picture

HI

Got it

using api_options.data = 'pid=' + options.pid

tyler.frankenstein’s picture

I've updated the documentation to include example code for DrupalGap 7.x-1.7-alpha mobile app dev kit and beyond:

http://drupalgap.org/node/189