XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
DataEditForm.class.php
1<?php
10
11if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13}
14
15require_once XOOPS_ROOT_PATH . '/core/XCube_ActionForm.class.php';
16require_once XOOPS_MODULE_PATH . '/legacy/class/Legacy_Validator.class.php';
17
19{
20 //table field definitions
21 public $mDef = [];
22
26 public function getTokenName()
27 {
28 return 'module.profile.DataEditForm.TOKEN';
29 }
30
34 public function prepare()
35 {
36 $handler =& xoops_getmodulehandler('definitions');
37 $this->mDef = $handler->getFields4DataEdit();
38
39 //
40 // Set form properties
41 //
42 $this->mFormProperties['uid'] =new XCube_IntProperty('uid');
43 foreach (array_keys($this->mDef) as $key) {
44 $className = $this->mDef[$key]->mFieldType->getFormPropertyClass();
45 $this->mFormProperties[$this->mDef[$key]->get('field_name')] =new $className($this->mDef[$key]->get('field_name'));
46
47 //validation checks
48 $validationArr = [];
49 $this->mFieldProperties[$this->mDef[$key]->get('field_name')] =new XCube_FieldProperty($this);
50 //required check
51 if (1 == $this->mDef[$key]->get('required')) {
52 $validationArr[] = 'required';
53 $this->mFieldProperties[$this->mDef[$key]->get('field_name')]->addMessage('required', _MD_PROFILE_ERROR_REQUIRED, $this->mDef[$key]->get('label'));
54 }
55 //validation check
56 switch ($this->mDef[$key]->get('validation')) {
57 case 'email' :
58 $validationArr[] = 'email';
59 $this->mFieldProperties[$this->mDef[$key]->get('field_name')]->addMessage($this->mDef[$key]->get('field_name'), _MD_PROFILE_ERROR_EMAIL);
60 break;
61 }
62 $this->mFieldProperties[$this->mDef[$key]->get('field_name')]->setDependsByArray($validationArr);
63 }
64
65 //
66 // Set field properties
67 //
68 $this->mFieldProperties['uid'] =new XCube_FieldProperty($this);
69 $this->mFieldProperties['uid']->setDependsByArray(['required']);
70 $this->mFieldProperties['uid']->addMessage('required', _MD_PROFILE_ERROR_REQUIRED, _MD_PROFILE_LANG_UID);
71 }
72
77 public function load(&$obj)
78 {
79 $this->set('uid', $obj->get('uid'));
80 foreach (array_keys($this->mDef) as $key) {
81 $this->set($this->mDef[$key]->get('field_name'), $obj->showField($this->mDef[$key]->get('field_name'), Profile_ActionType::EDIT));
82 }
83 }
84
89 public function update(&$obj)
90 {
91 $obj->set('uid', $this->get('uid'));
92 foreach (array_keys($this->mDef) as $key) {
93 $val = ('date' != $this->mDef[$key]->get('type')) ? $this->get($this->mDef[$key]->get('field_name')) : $this->_makeUnixtime($this->mDef[$key]->get('field_name'));
94 $obj->set($this->mDef[$key]->get('field_name'), $val);
95 }
96 }
97
98 protected function _makeUnixtime($key)
99 {
100 $timeArray = explode('/', $this->get($key));
101 return mktime(0, 0, 0, $timeArray[1], $timeArray[2], $timeArray[0]);
102 }
103}
getTokenName()
Gets the token name of this actionform's token.
prepare()
[Abstract] Set up form properties and field properties.
[Abstract] Used for validating member property values of XCube_ActionForm.
Represents int property.