UserPreferences.inc.php
5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/*
* $Id: $
*
* The contents of this file are subject to the KnowledgeTree
* Commercial Editions On-Premise License ("License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.knowledgetree.com/about/legal/
* The terms of this license may change from time to time and the latest
* license will be published from time to time at the above Internet address.
*
* This edition of the KnowledgeTree software
* is NOT licensed to you under Open Source terms.
* You may not redistribute this source code.
* For more information please see the License above.
*
* (c) 2008, 2009, 2010 KnowledgeTree Inc.
* All Rights Reserved.
*
*/
$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..';
$dir = realpath($dir).DIRECTORY_SEPARATOR;
require_once(KT_LIB_DIR . "/ktentity.inc");
class UserPreferences extends KTEntity {
public $iId; // primary key of current object
public $iUserId; // id of user
public $sKey; // description of user preference
public $sValue; // value of user preference
public $_aFieldToSelect = array(
"iId" => "id",
"iUserId" => "user_id",
"sKey" => "prefkey",
"sValue" => "prefvalue",
);
public $_bUsePearError = true;
function UserPreferences($iUserId, $sKey, $sValue) {
$this->iId = -1;
$this->iUserId = $iUserId;
$this->sKey = $sKey;
$this->sValue = $sValue;
}
/**
* Retrieve UserPreferences objects database table name
*
* @author KnowledgeTree Team
* @access public
* @param none
* @return string
*/
function _table () { return KTUtil::getTableName('user_preferences'); }
// ---------------
// Getters/setters
// ---------------
/**
* Retrieve a list of UserPreferences objects
*
* @author KnowledgeTree Team
* @access public
* @param $sWhereClause - string
* @param $aOptions - array
* @return UserPreferences objects - array
*/
public function getList($sWhereClause = null, $aOptions = null) {
if (is_null($aOptions)) { $aOptions = array(); }
$aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby','name');
return KTEntityUtil::getList2('UserPreferences', $sWhereClause, $aOptions);
}
public function getUserPreferences($iUserId, $sKey, $aOptions = null) {
$sWhereClause = "WHERE user_id = '$iUserId' AND prefkey = '$sKey'";
return KTEntityUtil::getList2('UserPreferences', $sWhereClause, $aOptions);
}
/**
* Retrieve a UserPreferences object
*
* @author KnowledgeTree Team
* @access public
* @param $iId - int - Id of template
* @return UserPreferences object
*/
public function get($iId) { return KTEntityUtil::get('UserPreferences', $iId); }
/**
* Retrieve UserPreferences user id
*
* @author KnowledgeTree Team
* @access public
* @param none
* @return string
*/
public function getUserId() { return $this->iUserId; }
/**
* Set the user id
*
* @author KnowledgeTree Team
* @access public
* @param $iUserId - string - the user id
* @return none
*/
public function setUserId($iUserId) { $this->iUserId = $iUserId; }
/**
*
*
* @author KnowledgeTree Team
* @access public
* @param
* @return none
*/
public function setKey($sKey) { $this->sKey = $sKey; }
/**
*
*
* @author KnowledgeTree Team
* @access public
* @param none
* @return string
*/
public function getKey() { return $this->sKey; }
/**
*
*
* @author KnowledgeTree Team
* @access public
* @param
* @return none
*/
public function setValue($sValue) { $this->sValue = $sValue; }
/**
*
*
* @author KnowledgeTree Team
* @access public
* @param none
* @return string
*/
public function getValue() { return $this->sValue; }
// Utility
/**
* Set the template name
*
* @author KnowledgeTree Team
* @access public
* @param $sName - string - the template node name
* @param $iParentId - int - the template id
* @return boolean
*/
public function exists($iUserId, $sKey, $sValue) {
return UserPreferencesUtil::userPreferenceExists($iUserId, $sKey, $sValue);
}
/**
*
*
* @author KnowledgeTree Team
* @access public
* @param $aOptions - array
* @return
*/
public function getAllUserPreferences($userId, $aOptions = null) {
if (is_null($aOptions)) { $aOptions = array(); }
$aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby','name');
$sWhereClause = "WHERE user_id = '$userId'";
return KTEntityUtil::getList2('UserPreferences', $sWhereClause, $aOptions);
}
}
class UserPreferencesUtil {
/**
*
*
* @author KnowledgeTree Team
*
* @return
*/
function userPreferenceExists($iUserId, $sKey, $sValue) {
$sQuery = "SELECT id, name FROM " . KTUtil::getTableName('user_preferences') . " WHERE user_id = ? AND prefkey = ? AND prefvalue = ?";/*ok*/
$aParams = array($iUserId, $sKey, $sValue);
$res = DBUtil::getResultArray(array($sQuery, $aParams));
if (count($res) != 0) {
foreach ($res as $user_pref){
$userid = isset($user_pref['user_id']) ? $user_pref['user_id'] : '';
$key = isset($user_pref['prefkey']) ? $user_pref['prefkey'] : '';
if($sKey == $key && $iUserId == $userid) {
return true;
}
}
return false;
}
return false;
}
}
?>