source: branches/dev/html/test/adachi/SC_FormParamsManager.php @ 14162

Revision 14162, 6.2 KB checked in by adati, 17 years ago (diff)
Line 
1<?php
2
3require_once('SC_Param.php');
4require_once('SC_Validator.php');
5/**
6 * Form¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹
7 */
8class SC_FormParamsManager {
9    var $_arrObjParams;
10    var $_arrErrorMessage;
11    var $_arrGropus;
12   
13    function SC_FormParamsManager($arrParams = array(), $arrParamsInfo = array()){
14        $this->_arrObjParams    = array();
15        $this->_arrErrorMessage = array();
16        $this->_arrGropus       = array();
17       
18        $this->setParams($arrParams, $arrParamsInfo);
19    }
20   
21    function setParams($arrParams, $arrParamsInfo, $useRawParams = false){
22        foreach ($arrParamsInfo as $_key => $_value) {
23            $arrParamsInfo[$_key]['value'] = $arrParams[$_key];
24            $this->_arrObjParams[] = new SC_Param($arrParamsInfo[$_key]);
25        }
26        // $_POST¡¢$_GET¤Ï¸¶Â§»ÈÍѶػß(Ê̥᥽¥Ã¥É¤Ë¤¹¤ë¡©)
27        if ($useRawParams === true) { return; }
28        unset($_POST, $_GET);
29    }
30   
31    function serGroups($groupName, $arrTargetName, $arrValidateMethod){
32        foreach ($arrTargetName as $targetName) {
33            $this->_arrObjParams['group'] = $groupName:
34        );
35        $this->_arrGroups[$groupName]['validateMethd'] = $arrValidateMethod
36    }
37   
38    function validate(){
39        $arrErrorMessage = array();  // ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸³ÊǼÍÑÇÛÎó
40        $arrGroups = $this->_arrGroups;        // Ê£¿ô¹àÌܸ¡¾ÚÍÑÇÛÎó
41       
42        foreach ($this->_arrObjParams as $objParam) {
43            $keyname = $objParam->getKeyName();
44           
45            // Ê£¿ô¹àÌܸ¡¾ÚÍÑÇÛÎó¤ò¹½ÃÛ
46            /*
47            if ($objParam->has_group() === true) {
48                $arrGroups[$objParam->getGroupName()][] = $objParam;
49            }
50            */
51           
52            $arrValidateMethod = $objParam->getValidateMethod();
53           
54            // ñÂιàÌܤθ¡¾Ú
55            foreach ($arrValidateMethod as $method => $args) {
56                $objValidator = SC_Validator::factory($method, $args);
57               
58                if ($objValidator->validate($objParam) === false) {
59                    $arrErrorMessage[$keyname] = $objValidator->getErrorMessage();
60                }
61            }
62        }
63       
64        // Ê£¿ô¹àÌܤθ¡¾Ú
65        foreach ($arrGroups as $groupname => $objParam) {
66            $keyname = $objParam->getKeyName();
67           
68            // ´û¤Ë¥¨¥é¡¼¤¬¤¢¤ë¾ì¹ç¤Ïvalidation¤ò¹Ô¤ï¤Ê¤¤
69            if (array_key_exists($keyname, $arrErrorMessage)) {
70                continue;
71            }
72           
73            $arrValidateMethod = $objParam->getGroupValidateMethod();
74            $objValidator = SC_Validate::factory('GROUP');
75            if ($objValidator->validate($arrGroups[$group]) === true) {
76                $this->arrErr[$group] = $objValidator->getErrorMessage();
77            }
78        }
79       
80        return $arrErrorMessage;
81    }
82   
83    function convert(){
84        foreach ($this->_arrObjParams as &$objParams) {
85            $objParams->convert();
86        }
87    }
88    function is_error(){
89        if (count($this->_arrErrorMessage) > 0) {
90            return true;
91        } else {
92            return false;
93        }
94    }
95   
96    function getEM(){
97        return $this->getErrorMessage();
98    }
99   
100    function getErrorMessage(){
101        $arrErr = array();
102        foreach ($this->_arrParamsInfo as $_key => $objParam) {
103            if ($onjParam->isRelation === true) {
104                $arrErr[$_key] = $objParam->getRelateErrorMessage();
105            } else {
106                $arrErr[$_key] = $objParam->getErrorMessage();
107            }
108        }
109        return $arrErr;
110    }
111    /**
112     *  static method
113     *  SC_Form::getMode();
114     */
115    function getMode(){
116        $mode = '';
117       
118        if (isset($_POST['mode'])) {
119            $mode = $_POST['mode'];
120        }
121        elseif (isset($_GET['mode'])) {
122            $mode = $_GET['mode'];
123        }
124       
125        return $mode;
126    }
127   
128    function &getObjQuery(){
129        return $this->_objQuery;
130    }
131   
132    function &initObjQuery(){
133        $this->_objQuery = new SC_Query();
134        return $this->_objQuery;
135    }
136   
137    function valiadte(){
138        return $this->objValidate->validate($this->_arrParamsInfo);
139    }
140   
141    function insert($table, $arrAddInsertData = array()){
142        $this->_setDBData($this->arrParams);
143        $this->_objQuery->insert($table, $this->_arrDBData);
144    }
145   
146    function update($table, $arrAddUpdateData = array()) {
147       
148    }
149   
150
151   
152    /**
153     *  ¥Ñ¥é¥á¡¼¥¿¤ò¼èÆÀ¤¹¤ë
154     *
155     *  @access  public
156     *  @param   boolean $escape  true:¥¨¥¹¥±¡¼¥×¤¹¤ë false:¥¨¥¹¥±¡¼¥×¤·¤Ê¤¤
157     *  @param   array   $arrNonEscape ¥¨¥¹¥±¡¼¥×¤·¤Ê¤¤ÃͤòÇÛÎó¤Ç»ØÄê
158     * 
159     *  @return  array | string
160     */
161    function getParams($arrNonEscape = array()){
162        $arrParams = array();
163        if (!is_array($arrNonEscape)) { $arrNonEscape = (array)$arrNonEscape; }
164       
165        foreach ($this->_arrParams as $_key => $_value) {
166            if (isset($arrNonEscape[$_key]) && $arrNonEscape[$_key] == $_key) {
167                $arrRet[$key] = $objParam->getValue();
168            }
169            else {
170                $arrRet[$key] = $objParam->getEscapeValue();
171               
172            }
173        }
174           
175        return $arrParams;
176    }
177   
178    function getParamByKeyName($keyName, $escape = true){
179        if ($escape === true) {
180            return $this->_arrParams[$keyName]->getValue();
181        }
182        else {
183            return $this->_arrParams[$keyName]->getEscapedValue();
184        }
185    }
186   
187    function _setDBData($arrData = array()){
188        foreach ($arrData as $key => $value) {
189            if (is_array($value['value'])) {
190                $count = 1;
191                foreach ($value['value'] as $val) {
192                    $this->_arrDBData[$key . $count] = $val;
193                    $count++;
194                }
195            }
196            else {
197                $this->_arrDBData[$key] = $value['value'];
198            }
199        }
200    }
201    function _addDBData(){
202       
203    }
204   
205    function _getEscapeParams($string){
206       
207    }
208}
209?>
Note: See TracBrowser for help on using the repository browser.