Login   Register  
PHP Classes
elePHPant
Icontem

File: user.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jesse Estevez  >  Result Class - Rule-based system for processing data tied to a DB result id.  >  user.php  >  Download  
File: user.php
Role: ???
Content type: text/plain
Description: A sample page and class instance.
Class: Result Class - Rule-based system for processing data tied to a DB result id.
Author: By
Last change:
Date: 2000-06-15 23:29
Size: 2,946 bytes
 

Contents

Class file image Download
<?
include ( 'result.inc' );

// NOTE:
// It may seem like this is a lot of code for one instance of one class.
// Well, it is, I guess.
// In fact, most applications are more involved than this example.
// However, it is possible for this class to contain nearly all of the 
// logic for your page.

/*---------------------------- QUERY -----------------------------*/

/* Put what you need to put here to execute a query and get a valid result_id */

/*---------------------------- RESULT -----------------------------*/

$r = new result ( $result_id );
$r->debug = TRUE;

/*-- 

There are three rules on this page.
Notice that they have different min and max values.
If num rows returned by the result_id is within the min
and max for a rule, then that rule is applied.

The rules don't have the same format.  For example,
the Edit User rule uses a template element that the others don't.

If a format has a key of "data", then all rows returned by the result_id
will be passed to that element of the format.

All format elements will be passed whatever is specified by the 'arguments'.
This feature could be used to have one button 
sometimes say "Add", sometimes "Delete" and 
sometimes "Edit" for example.


*/
// What this rule does...
// If no results are returned, we want to to put a form
// to let the web user run a different search.
$r->set_result_rule
	(
	array
		(
		'name'			=> 'User Search',
		'min' 			=> 0,
		'max' 			=> 0,
		'template' 		=> 'user',
		'format'  		=> array ( 'start','user_info','end' ),
		'arguments'		=> array ( 'submit' => 'Search' )
		)
	);


// If one result is returned, we want to edit it.
// Notice that the 'format' uses 'data' as an array key
// to specify where data from db should be sent.
$r->set_result_rule
	(
	array
		(
		'name'			=> 'User Edit',
		'min' 			=> 1,
		'max' 			=> 1,
		'template' 		=> 'user',
		'format'  		=> array ( 'start','data' => 'user_info', 'user_friends','end' ),
		'arguments'		=> array ( 'submit' => 'Edit' )
		)
	);

// If more than 2 and less then 11 results are returned
// show them all and let the chooser choose which
// one they want to use.
$r->set_result_rule
	(
	array
		(
		'name'			=> 'Choose User',
		'min' 			=> 2,
		'max' 			=> 11,
		'template'		=>'user', 
		'format' 		=> array ( 'start','data'=>'choose_user','end' ) 
		)
	);



// If more than 12 results are returned
// force the user to further refine their search.
$r->set_result_rule
	(
	array
		(
		'name'			=> 'Refine Search',
		'min' 			=> 12,
		'max' 			=> 99999,
		'template'		=>'user', 
		'format' 		=> array ( 'start','user','end' ),
		'arguments'		=> array ( 'submit' => 'Refine Search' )
		)
	);



$form = $r->get_result_html (  );


/*---------------------------- PAGE -------------------------------*/

/* Put what you need to put here to print $form to the browswer */

?>