123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- /** @package HELLO WORLD::Controller */
- /** import supporting libraries */
- require_once("verysimple/Phreeze/Controller.php");
- /**
- *
- * @package HELLO WORLD::Controller
- * @author ClassBuilder
- * @version 1.0
- */
- class TestController extends Controller
- {
-
- /**
- * Not used but necessary to implement Controller
- * @see Controller::Init()
- */
- protected function Init()
- {
- }
-
- /**
- * Test route that outputs a simple JSON object
- */
- public function JSON()
- {
- $arr = array(
- "message" => "Hello, World!"
- );
-
- $this->RenderJSON($arr);
- }
-
- /**
- * Test route that connects to the database and outputs
- * the number of rows specified in the querystring argument "queries"
- */
- public function DB()
- {
- require_once("Model/World.php");
- $id = mt_rand(1, 10000);
- $world = $this->Phreezer->Get("World",$id);
- $this->RenderJSON($world,'',true);
- }
-
-
- /**
- * Test route that connects to the database and outputs
- * the number of rows specified in the querystring argument "queries"
- */
- public function Query()
- {
- require_once("Model/World.php");
-
- // Read number of queries to run from URL parameter
- $query_count = RequestUtil::Get('queries',1);
-
- // make sure the query count paramter is in range
- if (!is_numeric($query_count)) {
- $query_count = 1;
- }
- else {
- $query_count = max(1,min($query_count,500));
- }
-
- $arr = array();
-
- for ($i = 0; $i < $query_count; $i++) {
-
- $id = mt_rand(1, 10000);
- // convert the Phreezable object into a simple structure for output
- $arr[] = $this->Phreezer->Get("World",$id)->ToObject();
- }
-
- $this->RenderJSON($arr);
-
- }
-
- /**
- * Output the Fortunes test template
- */
- public function Fortunes()
- {
- require_once("Model/Fortune.php");
- require_once("verysimple/Phreeze/PHPRenderEngine.php");
-
- // charset must be set to UTF8 to support multi-byte chars
- $this->Phreezer->DataAdapter->ConnectionSetting->Charset = "utf8";
-
- // obtain fortunes without using 'order by'
- $fortunes = $this->Phreezer->Query('Fortune')->ToObjectArray();
-
- // dynamically add a new, non-persisted Fortune object
- $newFortune = new Fortune($this->Phreezer);
- $newFortune->Id = 0;
- $newFortune->Message = 'Additional fortune added at request time.';
- $fortunes[] = $newFortune;
-
- // sort (will use Fortune->ToString)
- Phreezer::Sort($fortunes);
-
- // Render using a template
- $this->RenderEngine = new PHPRenderEngine('templates');
- $this->Assign('fortunes',$fortunes);
- $this->Render('TestFortunes.php');
- }
-
- /**
- * Test for performing updates
- */
- public function Updates()
- {
- require_once("Model/World.php");
-
- // Read number of queries to run from URL parameter
- $query_count = RequestUtil::Get('queries',1);
-
- $arr = array();
-
- for ($i = 0; $i < $query_count; $i++) {
-
- $id = mt_rand(1, 10000);
-
- $world = $this->Phreezer->Get("World",$id);
-
- // update the random number and persist the record
- $world->Randomnumber = mt_rand(1, 10000);
- $world->Save();
-
- // convert the Phreezable object into a simple structure for output
- $arr[] = array('id'=>$world->Id,'randomNumber'=>$world->Randomnumber);
- }
-
- $this->RenderJSON($arr);
- }
-
- /**
- * Test for outputting plaintext
- */
- public function PlainText()
- {
- header('Content-type: text/plain');
- echo 'Hello, World!';
- }
-
- }
|