37 $this->entities = $entities;
38 $this->
table = $this->db->getTablePrefix() .
'private_settings';
79 'private_setting_name_value_pairs_operator' =>
'AND',
80 'private_setting_name_prefix' =>
'',
86 'private_setting_name',
87 'private_setting_value',
88 'private_setting_name_value_pair',
93 $clauses = $this->getWhereSql(
'e',
96 $options[
'private_setting_name_value_pairs'],
97 $options[
'private_setting_name_value_pairs_operator'],
98 $options[
'private_setting_name_prefix']);
104 } elseif (!isset(
$options[
'wheres'])) {
113 } elseif (!isset(
$options[
'joins'])) {
120 return $this->entities->getEntities(
$options);
134 private function getWhereSql($table, $names = null, $values = null,
135 $pairs = null, $pair_operator =
'AND', $name_prefix =
'') {
144 $return[
'joins'][] =
"JOIN {$this->table} ps on 145 {$table}.guid = ps.entity_guid";
151 if ($names !== null) {
152 if (!is_array($names)) {
153 $names = array($names);
156 $sanitised_names = array();
157 foreach ($names as
$name) {
158 $name = $name_prefix .
$name;
159 $sanitised_names[] =
'\'' . $this->db->sanitizeString($name) .
'\'';
162 $names_str = implode(
',', $sanitised_names);
164 $names_where =
"(ps.name IN ($names_str))";
170 if ($values !== null) {
171 if (!is_array($values)) {
172 $values = array($values);
175 $sanitised_values = array();
176 foreach ($values as
$value) {
181 $sanitised_values[] =
'\'' . $this->db->sanitizeString($value) .
'\'';
184 $values_str = implode(
',', $sanitised_values);
186 $values_where =
"(ps.value IN ($values_str))";
190 if ($names_where && $values_where) {
191 $wheres[] =
"($names_where AND $values_where)";
192 } elseif ($names_where) {
193 $wheres[] =
"($names_where)";
194 } elseif ($values_where) {
195 $wheres[] =
"($values_where)";
199 if (is_array($pairs)) {
204 if (isset($pairs[
'name']) || isset($pairs[
'value'])) {
205 $pairs = array($pairs);
208 $pair_wheres = array();
210 foreach ($pairs as $index => $pair) {
213 if (!is_array($pair)) {
221 if (!isset($pair[
'name']) || !isset($pair[
'value'])) {
226 if (isset($pair[
'operand'])) {
227 $operand = $this->db->sanitizeString($pair[
'operand']);
233 $trimmed_operand = trim(strtolower($operand));
237 if (is_numeric($pair[
'value'])) {
238 $value = $this->db->sanitizeString($pair[
'value']);
239 }
else if (is_array($pair[
'value'])) {
240 $values_array = array();
242 foreach ($pair[
'value'] as $pair_value) {
243 if (is_numeric($pair_value)) {
244 $values_array[] = $this->db->sanitizeString($pair_value);
246 $values_array[] =
"'" . $this->db->sanitizeString($pair_value) .
"'";
251 $value =
'(' . implode(
', ', $values_array) .
')';
257 }
else if ($trimmed_operand ==
'in') {
258 $value =
"({$pair['value']})";
260 $value =
"'" . $this->db->sanitizeString($pair[
'value']) .
"'";
263 $name = $this->db->sanitizeString($name_prefix . $pair[
'name']);
266 $return[
'joins'][] =
"JOIN {$this->table} ps{$i} 267 on {$table}.guid = ps{$i}.entity_guid";
269 $pair_wheres[] =
"(ps{$i}.name = '$name' AND ps{$i}.value 275 $where = implode(
" $pair_operator ", $pair_wheres);
277 $wheres[] =
"($where)";
281 $where = implode(
' AND ', $wheres);
283 $return[
'wheres'][] =
"($where)";
310 $query =
"SELECT value FROM {$this->table} 311 where name = '{$name}' and entity_guid = {$entity_guid}";
312 $setting = $this->db->getDataRow($query);
315 return $setting->value;
336 $query =
"SELECT * FROM {$this->table} WHERE entity_guid = {$entity_guid}";
337 $result = $this->db->getData($query);
361 $name = $this->db->sanitizeString($name);
364 $result = $this->db->insertData(
"INSERT into {$this->table} 365 (entity_guid, name, value) VALUES 366 ($entity_guid, '$name', '$value') 367 ON DUPLICATE KEY UPDATE value='$value'");
388 $name = $this->db->sanitizeString($name);
390 return $this->db->deleteData(
"DELETE FROM {$this->table} 391 WHERE name = '{$name}' 392 AND entity_guid = {$entity_guid}");
410 return $this->db->deleteData(
"DELETE FROM {$this->table} 411 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.
__construct(Database $db, EntityTable $entities)
Constructor.
const ELGG_ENTITIES_ANY_VALUE
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.