XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
Definitions.class.php
Go to the documentation of this file.
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12class Profile_DefinitionsObject extends XoopsSimpleObject
13{
14 public $mFieldType = null; //Profile_FieldType
15
16 public function Profile_DefinitionsObject()
17 {
18 self::__construct();
19 }
20
24 public function __construct()
25 {
26 $this->initVar('field_id', XOBJ_DTYPE_INT, '', false);
27 $this->initVar('field_name', XOBJ_DTYPE_STRING, '', false, 32);
28 $this->initVar('label', XOBJ_DTYPE_STRING, '', false, 191);
29 $this->initVar('type', XOBJ_DTYPE_STRING, '', false, 32);
30 $this->initVar('validation', XOBJ_DTYPE_STRING, '', false, 191);
31 $this->initVar('required', XOBJ_DTYPE_BOOL, 0, false);
32 $this->initVar('show_form', XOBJ_DTYPE_BOOL, 1, false);
33 $this->initVar('weight', XOBJ_DTYPE_INT, 10, false);
34 $this->initVar('description', XOBJ_DTYPE_TEXT, '', false);
35 $this->initVar('access', XOBJ_DTYPE_TEXT, '', false);
36 $this->initVar('options', XOBJ_DTYPE_TEXT, '', false);
37 }
38
42 public function getFields()
43 {
44 $cri = new Criteria('1', '1');
45 $cri->setSort('weight');
46
47 return $this->getObjects($cri);
48 }
49
50 public function setFieldTypeObject()
51 {
52 if (! $this->mFieldType) {
53 $className = 'Profile_FieldType'.ucfirst($this->get('type'));
54 $this->mFieldType = new $className();
55 }
56 }
57
58 public function getDefault()
59 {
60 return $this->mFieldType->getDefault($this->get('options'));
61 }
62}
63
65{
66 public $mTable = 'profile_definitions';
67 public $mPrimary = 'field_id';
68 public $mClass = 'Profile_DefinitionsObject';
69
73 public function getFields4DataEdit()
74 {
75 $criteria = new CriteriaCompo();
76 $criteria->add(new Criteria('show_form', '1'));
77 $criteria->setSort('weight');
78
79 return $this->getObjects($criteria);
80 }
81
87 public function getFields4DataShow($uid=0)
88 {
89 $uid = ($uid>0) ? $uid : Legacy_Utils::getUid();
90 $lHandler =& xoops_getmodulehandler('groups_users_link', 'user');
91
92 $criteria = new CriteriaCompo();
93 $criteria->setSort('weight');
94 $fieldArr = $this->getObjects($criteria);
95 foreach (array_keys($fieldArr) as $keyF) {
96 $flag = false;
97 $accessArr = explode(',', $fieldArr[$keyF]->get('access'));
98 if (0 === $uid) { //guest
99 if (in_array(XOOPS_GROUP_ANONYMOUS, $accessArr)) {
100 $flag = true;
101 }
102 } else {
103 foreach (array_keys($accessArr) as $keyA) {
104 if ($lHandler->isUserOfGroup($uid, $accessArr[$keyA])) {
105 $flag = true;
106 }
107 }
108 }
109 if (! $flag) {
110 unset($fieldArr[$keyF]);
111 }
112 }
113
114 return $fieldArr;
115 }
116
123 public function insert(&$obj, $force = false)
124 {
125 global $xoopsDB;
126 $obj->setFieldTypeObject();
127 if ($obj->isNew()) {
128 $sql = 'ALTER TABLE '. $xoopsDB->prefix('profile_data') .' ADD `'. $obj->get('field_name') .'` '. $obj->mFieldType->getTableQuery();
129 $xoopsDB->query($sql);
130 } else {
131 $oldObj = $this->get($obj->get('field_id'));
132 if ($oldObj->get('field_name')!=$obj->get('field_name')) {
133 $sql = 'ALTER TABLE '. $xoopsDB->prefix('profile_data') .' CHANGE `'. $oldObj->get('field_name') .'` `'. $obj->get('field_name') .'` '. $oldObj->mFieldType->getTableQuery();
134 $xoopsDB->query($sql);
135 }
136 }
137
138 return parent::insert($obj, $force);
139 }
140
147 public function delete(&$obj, $force = false)
148 {
149 global $xoopsDB;
150 $sql = 'ALTER TABLE '. $xoopsDB->prefix('profile_data') .' DROP `'. $obj->get('field_name') .'`';
151 $xoopsDB->query($sql);
152
153 return parent::delete($obj, $force);
154 }
155
156 public function getDefinitions($show_form=true)
157 {
158 $criteria = new CriteriaCompo();
159 $criteria->setSort('weight', 'ASC');
160 if (true == $show_form) {
161 $criteria->add(new Criteria('show_form', 1));
162 }
163 $definitions = $this->getObjects($criteria);
164 $defArr = [];
165 foreach ($definitions as $def) {
166 $defArr[$def->get('field_name')] = $def;
167 }
168 return $defArr;
169 }
170
174 public function getTypeList()
175 {
176 return [
177 Profile_FormType::STRING,
178 Profile_FormType::TEXT,
179 Profile_FormType::INT,
180 Profile_FormType::FLOAT,
181 Profile_FormType::DATE,
182 Profile_FormType::CHECKBOX,
183 Profile_FormType::SELECTBOX,
184 Profile_FormType::URI
185 ];
186 }
187
188 public static function getReservedNameList()
189 {
190 return ['uid', 'name', 'uname', 'email', 'url', 'user_avatar', 'user_regdate', 'user_icq', 'user_from', 'user_sig', 'user_viewemail', 'actkey', 'user_aim', 'user_yim', 'user_msnm', 'pass', 'posts', 'attachsig', 'rank', 'level', 'theme', 'timezone_offset', 'last_login', 'umode', 'uorder', 'notify_method', 'notify_mode', 'user_occ', 'bio', 'user_intrest', 'user_mailok', 'user_name'];
191 }
192
196 public function getValidationList()
197 {
198 return ['email'];
199 }
200
201 public function &getObjects($criteria = null, $limit = null, $start = null, $id_as_key = false)
202 {
203 $objs = parent::getObjects($criteria, $limit, $start, $id_as_key);
204
205 foreach (array_keys($objs) as $key) {
206 $objs[$key]->setFieldTypeObject();
207 }
208 return $objs;
209 }
210}
& getObjects($criteria=null, $limit=null, $start=null, $id_as_key=false)