Conduct Web experiments using PHP, Part 1
By Paul Meagher2005-03-16
SR package
• StimulusResponse.php
• StimulusResponse1D.php
• StimulusResponse2D.php
• StimulusResponse3D.php
Web developers who want to conduct Web experiments with this package can select the SR class based on the number of factors they intend to factorially manipulate. For example, if you are only going to manipulate one factor (such as different ad banners with no factorial manipulation of ad banner components), then choose the StimulusResponse1D.php class to:
• Generate the stimulus codes for your Web experiment
• Assign a random stimulus code (such as a Web offer) to each new visitor
• Log whether a visitor responded to the assigned offer
The classes with the 1D, 2D, and 3D suffixes extend the StimulusResponse.php base class by implementing the generation, assignment, and logging functions. These functions are called interface methods in the StimulusResponse.php source in Listing 2.
Listing 2. Source code for StimulusResponse.php base class
<?php
/**
* @package SR
*
* Base class for stimulus-response package. Implements common
* methods and defines interface methods to be implemented in
* classes that extend the base class.
*/
class StimulusResponse {
/**
* String to hold name of stimulus table.
*/
var $table = "";
/**
* Associative array to hold factor names and factor levels.
*/
var $factors = array();
/**
* Associative array to hold a retrieved stimulus code.
*/
var $code = array();
/*
* Boolean variable indicating whether a response has been
* observed or not for a particular visitor.
*/
var $success = false;
/*
* Boolean variable indicating whether a stimulus code has been
* generated or not for a particular visitor.
*/
var $generated = false;
/**
* Boolean variable used to turn debugging output on or off.
*/
var $debug = true;
/**
* Method for setting the table that holds, or will hold,
* the stimulus codes and responses for the Web experiment.
*/
function setTable($table) {
$this->table = $table;
}
/**
* Method for removing existing stimulus codes and responses.
*/
function emptyTable($table) {
global $db;
$sql = " DELETE FROM $this->table ";
$result = $db->query($sql);
if (DB::isError($result)) {
die($result->getMessage());
} else {
return true;
}
}
/**
* Method for defining the stimulus factors to be used
* as well as their factor levels.
*/
function setFactors($factors) {
$this->factors = $factors;
}
/**
* Method for generating and inserting stimulus codes into
* the stimulus table.
*/
function insertStimulusCodes($num_reps) {
// interface method
}
/**
* Method for selecting a random and unused stimulus code
* from the stimulus table.
*/
function getRandomStimulusCode($vis_id) {
// interface method
}
/**
* Method for logging any response to the stimulus if any are present.
*/
function logResponse($vis_id, $resp_col, $response=false) {
// interface method
}
}
?>
Tutorial pages:
|
First published by IBM developerWorks
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Conduct Web experiments using PHP, Part 1"
You must be logged in to post a comment.
Link to This Tutorial Page!

