PHP Classes

File: demos/basicgrid.php

Recommend this page to a friend!
  Classes of Tom Schaefer   d3Extjs   demos/basicgrid.php   Download  
File: demos/basicgrid.php
Role: Example script
Content type: text/plain
Description: proof of concept classes: capsule generation code and build a working reuseable grid panel
Class: d3Extjs
Generate JavaScript code to access ExtJS library
Author: By
Last change:
Date: 11 years ago
Size: 3,995 bytes
 

Contents

Class file image Download
<?php

// this example shows how you can capsule d3extjs generator and take it as javascript rendering view
// this example is taken from
// @see http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.Panel
/**
  Basic idea of this concept:
  As SQL describes data sets,
  d3extjs behaves like a php based language for
  describing extjs components.
  The main goal is to write sophisticated, stable, reusable, dynamic and enhanceable
  code components on top of d3extsj with php.
 */

$showsource = true;


include_once
'../d3.classes.inc.php';
include_once
'../extjs.class.inc.php';

interface
iExt {
  public function
getConfig();
  public function
getType();
}

abstract class
ExtAbstract implements iExt {
  protected
$object;
  protected
$type;
  protected
$config;
  public function
__construct(array $config = array()){
   
$this->config = o3($config);
   
$this->init();
  }
  public function
getType(){
    return
$this->type;
  }
 
  public function
getConfig(){
    return
$this->config;
  }
 
  public function
init(){}
 
  public function
__toString(){
    return
$this->render();
  }
 
  public function
render(){
   
$this->init();
    return (string)
$this->object->colon();
  }
}

class
Ext {
  protected
$object;
  public function
__construct(){}
  public function
create(iExt $type){
   
$this->object = ext()->create($type->getType(), $type->getConfig());
    return
$this;
  }
  public function
get(){
      return
$this->object->get();
  }
  public function
__toString(){
    return (string)
$this->object->colon()->linebreak();
  }
}

class
ExtDataStoreManager extends ExtAbstract {
    protected
$type = "Ext.data.StoreManager";
    public function
init(){
     
$this->object = ext()->data->StoreManager();
    }
   
/**
     * @return extjs4_data_StoreManager
     */
   
public function get($property=false){
      if(
$property){
       
$this->object = ext()->data->StoreManager(extjs::property);
      }
      return
$this->object;
    }
}


class
ExtDataStore extends ExtAbstract {
  protected
$type = "Ext.data.Store";
 
 
/**
   * (non-PHPdoc)
   * @see ExtAbstract::init()
   */
 
public function init(){
   
$this->object = ext()->data->Store();
  }
 
/**
   * @return extjs4_data_Store
   */
 
public function get(){
      return
$this->object;
  }
}

class
ExtGridPanel extends ExtAbstract {
  protected
$type = "Ext.grid.Panel";
 
  public function
init(){
   
$this->object = ext()->grid->Panel();
  }
 
/**
   * @return extjs4_grid_Panel
   */
 
public function get(){
      return
$this->object;
  }
 
}

// init objects
$storeCreate = new Ext();
$panelCreate = new Ext();
$storeManager = new ExtDataStoreManager();

// create store
$store = $storeCreate->create(new ExtDataStore(array(
 
"storeId" => "simpsonsStore",
 
"fields" => array("name","email","phone"),
 
"data" => o3(array("items" => array(
   
o3(array( 'name'=> 'Lisa', "email"=>"lisa@simpsons.com", "phone"=>"555-111-1224" )),
   
o3(array( 'name'=> 'Bart', "email"=>"bart@simpsons.com", "phone"=>"555-222-1234" )),
   
o3(array( 'name'=> 'Homer', "email"=>"home@simpsons.com", "phone"=>"555-222-1244" )),
   
o3(array( 'name'=> 'Marge', "email"=>"marge@simpsons.com", "phone"=>"555-222-1254" ))
  ))),
 
"proxy" => o3(array(
   
"type" => "memory",
   
"reader" => o3(array(
     
"type" => "json",
     
"root" => "items"
   
))
  ))
)));

// create panel
$panel = $panelCreate->create(new ExtGridPanel(array(
 
"title" => "Simpsons",
 
"store" => $storeManager->get(true)->lookup("simpsonsStore"),
 
"columns" => array(
   
o3(array("text"=>"name", "dataIndex"=>"name")),
   
o3(array("text"=>"Email", "dataIndex"=>"email", "flex"=>1)),
   
o3(array("text"=>"phone", "dataIndex"=>"phone")),
  ),
 
"height"=>200, "width"=>400, "renderTo" => ext()->getBody()
)));

echo
"<pre>";
// output
echo $store;
echo
$panel;