XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
DelegateFunctions.class.php
1<?php
10
11if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13}
14
19{
29 public static function saveProfile(/*** bool ***/ &$ret, XCube_ActionForm $actionForm)
30 {
31 $handler = Legacy_Utils::getModuleHandler('data', 'profile');
32 if (! $obj = $handler->get($actionForm->get('uid'))) {
33 $obj = $handler->create();
34 $obj->set('uid', $actionForm->get('uid'));
35 }
36 $defHandler = Legacy_Utils::getModuleHandler('definitions', 'profile');
37 $defObjs = $defHandler->getFields4DataEdit();
38 foreach ($defObjs as $def) {
39 $obj->setField($def->get('field_name'), $actionForm->get($def->get('field_name')));
40 }
41 $ret = $handler->insert($obj, true);
42 }
43
52 public static function getProfile(/*** mixed ***/ &$profile, /*** int ***/ $uid)
53 {
54 $handler = Legacy_Utils::getModuleHandler('data', 'profile');
55 $profile = $handler->get($uid);
56 if (! $profile) {
57 $profile = $handler->create();
58 }
59 }
60
69 public static function getDefinition(/*** mixed ***/ &$defArr, /*** string ***/ $action)
70 {
71 $handler = Legacy_Utils::getModuleHandler('definitions', 'profile');
72 switch ($action) {
73 case 'edit':
74 $defArr = $handler->getFields4DataEdit();
75 break;
76 case 'view':
77 default:
78 $defArr = $handler->getFields4DataShow();
79 break;
80 }
81 }
82
90 public static function setupActionForm(XCube_ActionForm $actionForm)
91 {
92 $handler = Legacy_Utils::getModuleHandler('definitions', 'profile');
93 $definitions = $handler->getFields4DataEdit();
94 foreach ($definitions as $def) {
95 $className = $def->mFieldType->getFormPropertyClass();
96 $actionForm->mFormProperties[$def->get('field_name')] = new $className($def->get('field_name'));
97
98 //
99 //validation checks for custom fields
100 //
101 $validationArr = [];
102 $actionForm->mFieldProperties[$def->get('field_name')] = new XCube_FieldProperty($actionForm);
103 //required check
104 if (true == $def->get('required')) {
105 $validationArr[] = 'required';
106 $actionForm->mFieldProperties[$def->get('field_name')]->addMessage('required', _MD_USER_ERROR_REQUIRED, $def->get('label'));
107 }
108 //validation check
109 switch ($def->get('validation')) {
110 case 'email' :
111 $validationArr[] = 'email';
112 $actionForm->mFieldProperties[$def->get('field_name')]->addMessage($def->get('field_name'), _MD_USER_ERROR_EMAIL);
113 break;
114 }
115 $actionForm->mFieldProperties[$def->get('field_name')]->setDependsByArray($validationArr);
116 }
117 }
118
126 public static function loadActionForm(XCube_ActionForm $actionForm)
127 {
128 $defHandler = Legacy_Utils::getModuleHandler('definitions', 'profile');
129 $definitions = $defHandler->getFields4DataEdit();
130 $dataHandler = Legacy_Utils::getModuleHandler('data', 'profile');
131 $profile = $dataHandler->get($actionForm->get('uid'));
132 if (! $profile) {
133 $profile = $dataHandler->create();
134 }
135 foreach ($definitions as $def) {
136 $actionForm->set($def->get('field_name'), $profile->showField($def->get('field_name'), Profile_ActionType::EDIT));
137 }
138 }
139}
140
145{
158 public static function getNormalUri(/*** string ***/ &$uri, /*** string ***/ $dirname, /*** string ***/ $dataname=null, /*** int ***/ $data_id=0, /*** string ***/ $action=null, /*** string ***/ $query=null)
159 {
160 $sUri = '/%s/index.php?action=%s%s';
161 $lUri = '/%s/index.php?action=%s%s&%s=%d';
162 $key = 'uid';
163
164 $table = $dataname ?? 'data';
165
166 if (isset($dataname)) {
167 if ($data_id>0) {
168 if (isset($action)) {
169 $uri = sprintf($lUri, $dirname, ucfirst($dataname), ucfirst($action), $key, $data_id);
170 } else {
171 $uri = sprintf($lUri, $dirname, ucfirst($dataname), 'View', $key, $data_id);
172 }
173 } else {
174 if (isset($action)) {
175 $uri = sprintf($sUri, $dirname, ucfirst($dataname), ucfirst($action));
176 } else {
177 $uri = sprintf($sUri, $dirname, ucfirst($dataname), 'List');
178 }
179 }
180 $uri = isset($query) ? $uri.'&'.$query : $uri;
181 } else {
182 if ($data_id>0) {
183 if (isset($action)) {
184 die('invalid uri');
185 } else {
186 $handler = Legacy_Utils::getModuleHandler($table, $dirname);
187 $key = $handler->mPrimary;
188 $uri = sprintf($lUri, $dirname, ucfirst($table), 'View', $key, $data_id);
189 }
190 $uri = isset($query) ? $uri.'&'.$query : $uri;
191 } else {
192 if (isset($action)) {
193 die('invalid uri');
194 } else {
195 $uri = sprintf('/%s/', $dirname);
196 $uri = isset($query) ? $uri.'index.php?'.$query : $uri;
197 }
198 }
199 }
200 }
201}
static getModuleHandler( $name, $dirname)
static getNormalUri(&$uri, $dirname, $dataname=null, $data_id=0, $action=null, $query=null)
static getProfile(&$profile, $uid)
static saveProfile(&$ret, XCube_ActionForm $actionForm)
static loadActionForm(XCube_ActionForm $actionForm)
static setupActionForm(XCube_ActionForm $actionForm)
static getDefinition(&$defArr, $action)
get( $key, $index=null)
Gets raw value.
set()
Sets the raw value as the value of the form property.
[Abstract] Used for validating member property values of XCube_ActionForm.