Development

/plugins/spyFormBuilderInterface2Plugin/lib/action/spyFormActionBase.class.php

You must first sign up to be able to contribute.

root/plugins/spyFormBuilderInterface2Plugin/lib/action/spyFormActionBase.class.php

Revision 16355, 2.6 kB (checked in by lombardot, 4 years ago)

--

Line 
1 <?php
2
3 abstract class spyFormActionBase {
4     
5     protected $options=array();
6     
7     protected $datas=array();
8     
9     protected $context;
10     
11     /** Liste des actions à vérifier avant l'exec */
12     static $_checks=array();
13     
14     public function __construct($options, $datas, spyForm $context){
15         $this->setDatas($datas);
16         $this->context=$context;
17         $this->setOptions($options);
18         $this->configure($options);
19         
20     }
21     
22     /**
23      * Ajoute une vérification
24      *
25      * @param string $cond PHP CODE condition
26      */
27     protected static function addCheck($cond){
28         spyFormActionBase::$_checks[]=$cond;
29     }
30     
31     /**
32      * Supprimme le dernier check de la liste
33      */
34     protected static function removeCheck(){
35         unset(spyFormActionBase::$_checks[(sizeof(spyFormActionBase::$_checks)-1)]);
36     }
37     /**
38      * Verifie l'ensemble des checks et autorise ou non l'exec
39      *
40      * @return boolean
41      */
42     public function checkAll(){
43         $t=true;
44         if(sizeof(spyFormActionBase::$_checks)>0){
45             foreach(spyFormActionBase::$_checks as $check){
46                 
47                 if(eval('return '.$check.' ?>')){
48                     $t=$t;
49                 }else{
50                     $t=false;
51                 }
52             }
53         }
54         return $t;
55     }
56     
57     /**
58      * @return spyForm
59      */
60     public function getContext(){
61         return $this->context;
62     }
63     
64     /**
65      * Retourne un parametre de la requette
66      *
67      * @param string parameter
68      * @param mixed default Value
69      * @return mixed result of the parameter
70      */   
71     public function getRequestParameter($parameter,$default=null){
72         $request=sfContext::getInstance()->getRequest();
73         return ($request->getParameter($parameter))?$request->getParameter($parameter):$default;
74     }
75     
76     public function setOptions($options=array()){
77         $this->options=array_merge($this->getOptions(),$options);
78     }
79     
80     public function setOption($option,$value){
81         $this->options[$option]=$value;
82     }
83     public function getOptions(){
84         return $this->options;
85     }
86     
87     public function getOption($opt_name, $default=null){
88         if(array_key_exists($opt_name,$this->options)){
89             if($this->options[$opt_name]!='')
90                 return $this->options[$opt_name];
91         }
92         return $default;
93     }
94     
95     public function setDatas($datas=array()){
96         $this->datas=array_merge($this->getDatas(),$datas);
97     }
98     
99     public function getDatas(){
100         return $this->datas;
101     }
102     
103     public function getData($field_name, $default=null){
104         if(array_key_exists($field_name,$this->datas)){
105             if($this->datas[$field_name]!='')
106                 return $this->datas[$field_name];
107         }
108         return $default;
109     }
110     
111     /** To set default Options */
112     abstract public function configure($options);
113     
114     /** Execute the action */
115     abstract public function execute();
116     
117     public function preExecute(){
118     
119     }
120 }
121 ?>
Note: See TracBrowser for help on using the browser.