42 $this->entities = $entities;
43 $this->cache = $cache;
44 $this->
table = $this->db->prefix .
'private_settings';
85 'private_setting_name_value_pairs_operator' =>
'AND',
86 'private_setting_name_prefix' =>
'',
92 'private_setting_name',
93 'private_setting_value',
94 'private_setting_name_value_pair',
99 $clauses = $this->getWhereSql(
'e',
102 $options[
'private_setting_name_value_pairs'],
103 $options[
'private_setting_name_value_pairs_operator'],
104 $options[
'private_setting_name_prefix']);
110 } elseif (!isset(
$options[
'wheres'])) {
119 } elseif (!isset(
$options[
'joins'])) {
126 return $this->entities->getEntities(
$options);
140 private function getWhereSql($table, $names = null, $values = null,
141 $pairs = null, $pair_operator =
'AND', $name_prefix =
'') {
150 $return[
'joins'][] =
"JOIN {$this->table} ps on 151 {$table}.guid = ps.entity_guid";
157 if ($names !== null) {
158 if (!is_array($names)) {
159 $names = array($names);
162 $sanitised_names = array();
163 foreach ($names as
$name) {
164 $name = $name_prefix .
$name;
165 $sanitised_names[] =
'\'' . $this->db->sanitizeString($name) .
'\'';
168 $names_str = implode(
',', $sanitised_names);
170 $names_where =
"(ps.name IN ($names_str))";
176 if ($values !== null) {
177 if (!is_array($values)) {
178 $values = array($values);
181 $sanitised_values = array();
182 foreach ($values as
$value) {
187 $sanitised_values[] =
'\'' . $this->db->sanitizeString($value) .
'\'';
190 $values_str = implode(
',', $sanitised_values);
192 $values_where =
"(ps.value IN ($values_str))";
196 if ($names_where && $values_where) {
197 $wheres[] =
"($names_where AND $values_where)";
198 } elseif ($names_where) {
199 $wheres[] =
"($names_where)";
200 } elseif ($values_where) {
201 $wheres[] =
"($values_where)";
205 if (is_array($pairs)) {
210 if (isset($pairs[
'name']) || isset($pairs[
'value'])) {
211 $pairs = array($pairs);
214 $pair_wheres = array();
216 foreach ($pairs as
$index => $pair) {
219 if (!is_array($pair)) {
227 if (!isset($pair[
'name']) || !isset($pair[
'value'])) {
232 if (isset($pair[
'operand'])) {
233 $operand = $this->db->sanitizeString($pair[
'operand']);
239 $trimmed_operand = trim(strtolower($operand));
243 if (is_numeric($pair[
'value'])) {
244 $value = $this->db->sanitizeString($pair[
'value']);
245 }
else if (is_array($pair[
'value'])) {
246 $values_array = array();
248 foreach ($pair[
'value'] as $pair_value) {
249 if (is_numeric($pair_value)) {
250 $values_array[] = $this->db->sanitizeString($pair_value);
252 $values_array[] =
"'" . $this->db->sanitizeString($pair_value) .
"'";
257 $value =
'(' . implode(
', ', $values_array) .
')';
263 }
else if ($trimmed_operand ==
'in') {
264 $value =
"({$pair['value']})";
266 $value =
"'" . $this->db->sanitizeString($pair[
'value']) .
"'";
269 $name = $this->db->sanitizeString($name_prefix . $pair[
'name']);
272 $return[
'joins'][] =
"JOIN {$this->table} ps{$i} 273 on {$table}.guid = ps{$i}.entity_guid";
275 $pair_wheres[] =
"(ps{$i}.name = '$name' AND ps{$i}.value 281 $where = implode(
" $pair_operator ", $pair_wheres);
283 $wheres[] =
"($where)";
287 $where = implode(
' AND ', $wheres);
289 $return[
'wheres'][] =
"($where)";
308 if (isset($values[
$name])) {
309 return $values[
$name];
313 $name = $this->db->sanitizeString($name);
321 $query =
"SELECT value FROM {$this->table} 322 where name = '{$name}' and entity_guid = {$entity_guid}";
323 $setting = $this->db->getDataRow($query);
326 return $setting->value;
347 $query =
"SELECT * FROM {$this->table} WHERE entity_guid = {$entity_guid}";
348 $result = $this->db->getData($query);
375 $name = $this->db->sanitizeString($name);
378 $result = $this->db->insertData(
"INSERT into {$this->table} 379 (entity_guid, name, value) VALUES 380 ($entity_guid, '$name', '$value') 381 ON DUPLICATE KEY UPDATE value='$value'");
405 $name = $this->db->sanitizeString($name);
407 return $this->db->deleteData(
"DELETE FROM {$this->table} 408 WHERE name = '{$name}' 409 AND entity_guid = {$entity_guid}");
430 return $this->db->deleteData(
"DELETE FROM {$this->table} 431 WHERE entity_guid = {$entity_guid}");
if($guid==elgg_get_logged_in_user_guid()) $name
removeAllForEntity($entity_guid)
Deletes all private settings for an entity.
Private settings for entities.
In memory cache of (non-user-specific, non-internal) plugin settings.
const ELGG_ENTITIES_ANY_VALUE
__construct(Database $db, EntityTable $entities, PluginSettingsCache $cache)
Constructor.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
getAll($entity_guid)
Return an array of all private settings.
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
getEntities(array $options=array())
Returns entities based upon private settings.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use