Layar tutorial part 2


SDK Version: 
M3

The first tutorial, we went through the steps to create a simple layer.
In this tutorial, we are going to explain how to include actions in this layer


Add a new table called "ACTION_Table" to the database.

  1. CREATE TABLE IF NOT EXISTS `ACTION_Table` (
  2.   `poiID` varchar(255) NOT NULL,
  3.   `label` varchar(30) NOT NULL,
  4.   `uri` varchar(255) NOT NULL,
  5.   `autoTriggerRange` int(10) default NULL,
  6.   `autoTriggerOnly` tinyint(1) default NULL,
  7.   `ID` int(10) NOT NULL,
  8.   `contentType` varchar(255) default 'application/vnd.layar.internal',
  9.   `method` enum('GET','POST') default 'GET',
  10.   `activityType` int(2) default NULL,
  11.   `params` varchar(255) default NULL,
  12.   `closeBiw` tinyint(1) default '0',
  13.   `showActivity` tinyint(1) default '1',
  14.   `activityMessage` varchar(255) default NULL,
  15.   PRIMARY KEY  (`ID`)
  16. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;


Create a new function to retrieve actions

The new features include a video and MP3 playback, call and email.
  1. function getActions( $poi, $db ) {
  2.    $sql_actions = $db->prepare( " SELECT label,
  3.               uri, autoTriggerRange, autoTriggerOnly,
  4.               contentType, method, activityType, params,
  5.               closeBiw, showActivity, activityMessage
  6.               FROM ACTION_Table WHERE poiID = :id " );
  7.                                                            
  8.   $sql_actions->bindParam( ':id', $poi['id'], PDO::PARAM_INT );
  9.   $sql_actions->execute();
  10.   $count = 0;
  11.   $actions = $sql_actions->fetchAll( PDO::FETCH_ASSOC );
  12.  
  13.   if ( empty( $actions ) ) {
  14.       $poi["actions"] = array();    
  15.   }  else {
  16.       foreach ( $actions as $action ) {
  17.         $poi["actions"][$count] = $action;
  18.         $paramsArray = array();
  19.         if ( substr_count( $action['params'],',' ) ) {
  20.            $paramsArray = explode( ",", $action['params'] );
  21.         }
  22.         else if( strlen( $action['params'] ) ) {
  23.            $paramsArray[0] = $action['params'];
  24.       }
  25.       $poi["actions"][$count]['params'] = $paramsArray;  
  26.       $poi["actions"][$count]['activityType'] = changeToInt $poi["actions"][$count]   ['activityType'] );
  27.       $poi["actions"][$count]['closeBiw'] = changeToBool( $poi["actions"][$count]['closeBiw'] );
  28.       $poi["actions"][$count]['showActivity'] = changeToBool( $poi["actions"][$count]['showActivity'] );    
  29.       $poi["actions"][$count]['autoTriggerRange'] = changeToInt( $poi["actions"][$count]['autoTriggerRange'] );
  30.       $poi["actions"][$count]['autoTriggerOnly'] = changeToBool( $poi["actions"][$count]['autoTriggerOnly'] );
  31.       $count++;
  32.     }
  33.    }
  34.   return $poi["actions"];
  35. }

We use a function called changeToBool to convert a Tinyint value to a Boolean value
and changeToInt to convert string value to integer.

  1. function changeToBool( $value_Tinyint ) {
  2.   if ( $value_Tinyint == 1 )
  3.       $value_Bool = TRUE;
  4.   else
  5.       $value_Bool = FALSE;
  6.   return $value_Bool;
  7. }
  8.  
  9. function changeToInt( $string ) {
  10.   if ( strlen( trim( $string ) ) != 0 ) {
  11.     return (int)$string;
  12.   }
  13.   else
  14.         return NULL;
  15. }

Modify the Gethotspots function
$poi["actions";] = getActions ( $poi, $db );

If you're doing it right, you should see something like this:
sectut

This is the end of the second tutorial. In the next part, we are going to discuss how to implement 2d and 3d objects in a layer.