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

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