Source for file data-store.php

Documentation is available at data-store.php

  1. <!--
  2.  | Demonstrates the following tasks using Facebook's Data Store:
  3.  |
  4.  | * Create a WMSFacebook instance (wrapper for Facebook's $facebook class)
  5.  | * Obtain a WMSFacebookApplication instance (for application-specific tasks)
  6.  | * Create a WMSFacebookDataStore (framework for Facebook's data store API)
  7.  | * Create a Facebook Object (i.e., "table")
  8.  | * Create a Facebook Property (i.e., "column")
  9.  | * Insert a Facebook Property (i.e., "row")
  10.  | * Associate a user's ID with an inserted row.
  11.  | * Select a Facebook Property (i.e., "row")
  12.  | * Remove the Facebook Object and all its data
  13.  | * Remove the Facebook Association and all its data
  14.  |
  15.  | The WMSFacebook API simplifies the exposed Data Store API.
  16.  |
  17.  | For this example to work, the constants $APP_API_KEY, $APP_SECRET,
  18.  | and $APP_URL must be defined. This file must exist at the same
  19.  | level as the "wmsfacebook" subdirectory.
  20.  +-->
  21. <p>
  22. <?
  23.   require_once 'constants.php';
  24.   require_once 'wmsfacebook/WMSFacebook.php';
  25.  
  26.   $wmsFacebook new WMSFacebook$APP_API_KEY$APP_SECRET );
  27.   $wmsUser $wmsFacebook->login$APP_URL );
  28.   $wmsApp $wmsFacebook->getWMSFacebookApplication();
  29.  
  30.   // Create the "table" and a "column" for that table.
  31.   //
  32.   $wmsDataStore $wmsFacebook->getWMSFacebookDataStore();
  33.   $myTable $wmsDataStore->createObjectType'my_table' );
  34.   $property $myTable->createPropertyString'my_column' );
  35.  
  36.   // Define the link for the user's ID and the "my_table" ID.
  37.   //
  38.   $userTableLink $wmsDataStore->createAssociationLink(
  39.    'user_table''user_id''table_id' );
  40.  
  41.   // Assign a value to the property that will be saved using Facebook's data
  42.   // store.
  43.   //
  44.   $property->setValue"Facebook Data Store API" );
  45.  
  46.   // Insert the property value into the data store.
  47.   //
  48.   $wmsRow $myTable->insertProperties();
  49.  
  50.   // Set the association between this Facebook user and the row data
  51.   // that was just inserted.
  52.   //
  53.   $association $userTableLink->associate(
  54.    $wmsUser->getId()$wmsRow->getId() );
  55.  
  56.   // Get the IDs of the rows that have been associated with the user.
  57.   //
  58.   $wmsRows $userTableLink->getAssociatedObjects$wmsUser->getId() );
  59.  
  60.   // Iterate over the rows to get the properties (i.e., values) for each
  61.   // row.
  62.   //
  63.   foreach$wmsRows as $row {
  64.     $properties $row->select();
  65.  
  66.     // Display the row data.
  67.     //
  68.     print_r$properties );
  69.   }
  70.  
  71.   // Remove all references to this table from the Facebook Data Store
  72.   // Normally you would not perform these steps as they will erase
  73.   // all the data for the given table, as well as erasing all associated
  74.   // links for this application.
  75.   //
  76.   // However, since this is example code, it behooves us to tidy up.
  77.   //
  78.   $myTable->drop();
  79.   $userTableLink->drop();
  80. ?>
  81. </p>

Documentation generated on Mon, 17 Dec 2007 20:10:40 -0800 by phpDocumentor 1.4.0