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

Revision 13744, 5.8 KB checked in by adati, 16 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 $_arrObjParams;
11    var $_arrErr;
12   
13    function SC_FormParamsManager($arrParams = array(), $arrParamsInfo = array()){
14        $this->_arrObjParams = 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, $useRowParams = false){
23        foreach ($arrParamsInfo as $_key => $_value) {
24            $arrParamsInfo[$_key]['value'] = $arrParams[$_key];
25            $this->_arrObjParams[$_key] = new SC_Param($arrParamsInfo[$_key]);
26        }
27        // $_POST¡¢$_GET¤Ï¸¶Â§»ÈÍѶػß
28        if ($useRowParams === true) { return; }
29        unset($_POST, $_GET);
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->_arrObjParams 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           
60            $arrValidateType = $objParam->getValidateType();
61           
62            // Single Validation
63            foreach ($arrValidateType as $method => $args) {
64                $objValidator = SC_Validate::factory($method, $args);
65               
66                if ($objValidator->validate($objParam) == true) {
67                    $this->arrErr[$_key] = $objValidator->getErrorMessage();
68                }
69            }
70        }
71       
72        // Group Validation
73        foreach ($arrGroups as $group => $_value) {
74            // ´û¤Ë¥¨¥é¡¼¤¬¤¢¤ë¾ì¹ç¤Ïvalidation¤ò¹Ô¤ï¤Ê¤¤
75            if (array_key_exists(array_keys($_value), $this->arrErr)) {
76                continue;
77            }
78           
79            $objValidator = SC_Validate::factory('GROUP');
80            if ($objValidator->validate($arrGroups[$group]) === true) {
81                $this->arrErr[$group] = $objValidator->getErrorMessage();
82            }
83        }
84       
85        // ¿Æ»Ò validation
86       
87        return $this;
88    }
89   
90    function getEM(){
91        return $this->getErrorMessage();
92    }
93   
94    function getErrorMessage(){
95        $arrErr = array();
96        foreach ($this->_arrParamsInfo as $_key => $objParam) {
97            if ($onjParam->isRelation === true) {
98                $arrErr[$_key] = $objParam->getRelateErrorMessage();
99            } else {
100                $arrErr[$_key] = $objParam->getErrorMessage();
101            }
102        }
103        return $arrErr;
104    }
105    /**
106     *  static method
107     *  SC_Form::getMode();
108     */
109    function getMode(){
110        $mode = '';
111       
112        if (isset($_POST['mode'])) {
113            $mode = $_POST['mode'];
114        }
115        elseif (isset($_GET['mode'])) {
116            $mode = $_GET['mode'];
117        }
118       
119        return $mode;
120    }
121   
122    function &getObjQuery(){
123        return $this->_objQuery;
124    }
125   
126    function &initObjQuery(){
127        $this->_objQuery = new SC_Query();
128        return $this->_objQuery;
129    }
130   
131    function valiadte(){
132        return $this->objValidate->validate($this->_arrParamsInfo);
133    }
134   
135    function insert($table, $arrAddInsertData = array()){
136        $this->_setDBData($this->arrParams);
137        $this->_objQuery->insert($table, $this->_arrDBData);
138    }
139   
140    function update($table, $arrAddUpdateData = array()) {
141       
142    }
143   
144
145   
146    /**
147     *  ¥Ñ¥é¥á¡¼¥¿¤ò¼èÆÀ¤¹¤ë
148     *
149     *  @access  public
150     *  @param   boolean $escape  true:¥¨¥¹¥±¡¼¥×¤¹¤ë false:¥¨¥¹¥±¡¼¥×¤·¤Ê¤¤
151     *  @param   array   $arrNonEscape ¥¨¥¹¥±¡¼¥×¤·¤Ê¤¤ÃͤòÇÛÎó¤Ç»ØÄê
152     * 
153     *  @return  array | string
154     */
155    function getParams($arrNonEscape = array()){
156        $arrParams = array();
157        if (!is_array($arrNonEscape)) { $arrNonEscape = (array)$arrNonEscape; }
158       
159        foreach ($this->_arrParams as $_key => $_value) {
160            if (isset($arrNonEscape[$_key]) && $arrNonEscape[$_key] == $_key) {
161                $arrRet[$key] = $objParam->getValue();
162            }
163            else {
164                $arrRet[$key] = $objParam->getEscapeValue();
165               
166            }
167        }
168           
169        return $arrParams;
170    }
171   
172    function getParamByKeyName($keyName, $escape = true){
173        if ($escape === true) {
174            return $this->_arrParams[$keyName]->getValue();
175        }
176        else {
177            return $this->_arrParams[$keyName]->getEscapedValue();
178        }
179    }
180   
181    function _setDBData($arrData = array()){
182        foreach ($arrData as $key => $value) {
183            if (is_array($value['value'])) {
184                $count = 1;
185                foreach ($value['value'] as $val) {
186                    $this->_arrDBData[$key . $count] = $val;
187                    $count++;
188                }
189            }
190            else {
191                $this->_arrDBData[$key] = $value['value'];
192            }
193        }
194    }
195    function _addDBData(){
196       
197    }
198   
199    function _getEscapeParams($string){
200       
201    }
202}
203?>
Note: See TracBrowser for help on using the repository browser.