Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / direct / php / classes / TestAction.php
1 <?php
2 class TestAction {
3     function doEcho($data){
4         return $data;
5     }
6
7     function multiply($num){
8         if(!is_numeric($num)){
9             throw new Exception('Call to multiply with a value that is not a number');
10         }
11         return $num*8;
12     }
13
14     function getTree($id){
15         $out = array();
16         if($id == "root"){
17                 for($i = 1; $i <= 5; ++$i){
18                     array_push($out, array(
19                         'id'=>'n' . $i,
20                         'text'=>'Node ' . $i,
21                         'leaf'=>false
22                     ));
23                 }
24         }else if(strlen($id) == 2){
25                 $num = substr($id, 1);
26                 for($i = 1; $i <= 5; ++$i){
27                     array_push($out, array(
28                         'id'=>$id . $i,
29                         'text'=>'Node ' . $num . '.' . $i,
30                         'leaf'=>true
31                     ));
32                 }
33         }
34         return $out;
35     }
36     
37     function getGrid($params){
38         $sort = $params->sort[0];
39         $field = $sort->property;
40         $direction = $sort->direction;
41         
42         /*
43          * Here we would apply a proper sort from the DB, but since
44          * it's such a small dataset we will just sort by hand here.
45          */
46          
47         if ($field == 'name') {
48             $data = array(array(
49                 'name'=>'ABC Accounting',
50                 'turnover'=>50000
51             ), array(
52                 'name'=>'Ezy Video Rental',
53                 'turnover'=>106300
54             ), array(
55                 'name'=>'Greens Fruit Grocery',
56                 'turnover'=>120000
57             ), array(
58                 'name'=>'Icecream Express',
59                 'turnover'=>73000
60             ), array(
61                 'name'=>'Ripped Gym',
62                 'turnover'=>88400
63             ), array(
64                 'name'=>'Smith Auto Mechanic',
65                 'turnover'=>222980
66             ));
67         } else {
68             $data = array(array(
69                 'name'=>'ABC Accounting',
70                 'turnover'=>50000
71             ), array(
72                 'name'=>'Icecream Express',
73                 'turnover'=>73000
74             ), array(
75                 'name'=>'Ripped Gym',
76                 'turnover'=>88400
77             ), array(
78                 'name'=>'Ezy Video Rental',
79                 'turnover'=>106300
80             ), array(
81                 'name'=>'Greens Fruit Grocery',
82                 'turnover'=>120000
83             ), array(
84                 'name'=>'Smith Auto Mechanic',
85                 'turnover'=>222980
86             ));
87         }
88         if ($direction == 'DESC') {
89             $data = array_reverse($data);
90         }
91         return $data;
92     }
93     
94     function showDetails($data){
95         $first = $data->firstName;
96         $last = $data->lastName; 
97         $age = $data->age;
98         return "Hi $first $last, you are $age years old.";
99     }
100 }