82 switch (
$options[
'metastring_type']) {
85 $callback =
'row_to_elggmetadata';
90 $type =
'annotations';
91 $callback =
'row_to_elggannotation';
120 'metastring_case_sensitive' =>
true,
132 'order_by' =>
'n_table.time_created ASC, n_table.id ASC',
136 'selects' => array(),
141 'preload_owners' =>
false,
142 'callback' => $callback,
145 'batch_inc_offset' =>
true,
155 $batch_size =
$options[
'batch_size'];
156 $batch_inc_offset =
$options[
'batch_inc_offset'];
161 return new \ElggBatch(
'_elgg_get_metastring_based_objects',
$options, null, $batch_size, $batch_inc_offset);
166 if (isset(
$options[
'type_subtype_pair'])) {
167 if (isset(
$options[
'type_subtype_pairs'])) {
168 $options[
'type_subtype_pairs'] = array_merge(
$options[
'type_subtype_pairs'],
176 'type',
'subtype',
'type_subtype_pair',
177 'guid',
'owner_guid',
'container_guid',
'site_guid',
178 'metastring_name',
'metastring_value',
179 'metastring_owner_guid',
'metastring_id',
180 'select',
'where',
'join' 192 if (!is_array(
$options[
'wheres'])) {
212 $options[
'metastring_created_time_lower'], null, null);
215 $options[
'metastring_owner_guids']);
219 foreach ($wheres as $i => $where) {
220 if ($where ===
false) {
222 } elseif (empty($where)) {
228 $wheres = array_unique($wheres);
236 $joins[] =
"JOIN {$db_prefix}entities e ON n_table.entity_guid = e.guid";
239 if (!is_array(
$options[
'selects'])) {
249 $custom_callback = (
$options[
'callback'] ==
'row_to_elggmetadata' 250 ||
$options[
'callback'] ==
'row_to_elggannotation');
251 $is_calculation =
$options[
'metastring_calculation'] ?
true :
false;
253 if ($custom_callback || $is_calculation) {
254 $joins[] =
"JOIN {$db_prefix}metastrings n on n_table.name_id = n.id";
255 $joins[] =
"JOIN {$db_prefix}metastrings v on n_table.value_id = v.id";
257 $selects[] =
'n.string as name';
258 $selects[] =
'v.string as value';
262 $joins = array_merge($joins,
$options[
'joins']);
267 $options[
'metastring_case_sensitive']);
269 if ($metastring_clauses) {
270 $wheres = array_merge($wheres, $metastring_clauses[
'wheres']);
271 $joins = array_merge($joins, $metastring_clauses[
'joins']);
274 'table_alias' =>
'n_table',
275 'guid_column' =>
'entity_guid',
279 $distinct =
$options[
'distinct'] ?
"DISTINCT " :
"";
282 $selects = array_unique($selects);
286 foreach ($selects as
$select) {
287 $select_str .=
", $select";
291 $query =
"SELECT $distinct n_table.*{$select_str} FROM {$db_prefix}$type n_table";
294 $query =
"SELECT count($distinct e.guid) as calculation FROM {$db_prefix}$type n_table";
296 $query =
"SELECT {$options['metastring_calculation']}(v.string) as calculation FROM {$db_prefix}$type n_table";
299 foreach ($joins as $i => $join) {
300 if ($join ===
false) {
302 } elseif (empty($join)) {
308 $joins = array_unique($joins);
311 foreach ($joins as $j) {
318 foreach ($wheres as $w) {
319 $query .=
" $w AND ";
333 $query .=
" GROUP BY {$options['group_by']}";
338 $query .=
" ORDER BY {$options['order_by']}, n_table.id";
344 $query .=
" LIMIT $offset, $limit";
349 if (
$options[
'preload_owners'] && is_array($dt) && count($dt) > 1) {
376 $pairs = null, $ids = null, $case_sensitive =
false) {
378 if ((!$names && $names !== 0)
379 && (!$values && $values !== 0)
381 && (!$pairs && $pairs !== 0)) {
391 $binary = ($case_sensitive) ?
' BINARY ' :
'';
402 if ($names !== null) {
403 if (!is_array($names)) {
404 $names = array($names);
407 $sanitised_names = array();
408 foreach ($names as
$name) {
416 if ($names_str = implode(
',', $sanitised_names)) {
417 $return[
'joins'][] =
"JOIN {$db_prefix}metastrings msn on $table.name_id = msn.id";
418 $names_where =
"(msn.string IN ($names_str))";
424 if ($values !== null) {
425 if (!is_array($values)) {
426 $values = array($values);
429 $sanitised_values = array();
430 foreach ($values as
$value) {
438 if ($values_str = implode(
',', $sanitised_values)) {
439 $return[
'joins'][] =
"JOIN {$db_prefix}metastrings msv on $table.value_id = msv.id";
440 $values_where =
"({$binary}msv.string IN ($values_str))";
445 if (!is_array($ids)) {
449 $ids_str = implode(
',', $ids);
452 $wheres[] =
"n_table.id IN ($ids_str)";
456 if ($names_where && $values_where) {
457 $wheres[] =
"($names_where AND $values_where)";
458 } elseif ($names_where) {
459 $wheres[] = $names_where;
460 } elseif ($values_where) {
461 $wheres[] = $values_where;
466 'guid_column' =>
'entity_guid',
469 if ($where = implode(
' AND ', $wheres)) {
470 $return[
'wheres'][] =
"($where)";
493 $prefixes = array(
'metadata_',
'annotation_',
'annotations_');
497 'names' =>
'metastring_names',
498 'values' =>
'metastring_values',
499 'case_sensitive' =>
'metastring_case_sensitive',
500 'owner_guids' =>
'metastring_owner_guids',
501 'created_time_lower' =>
'metastring_created_time_lower',
502 'created_time_upper' =>
'metastring_created_time_upper',
503 'calculation' =>
'metastring_calculation',
504 'ids' =>
'metastring_ids',
507 foreach ($prefixes as $prefix) {
508 $singulars = array(
"{$prefix}name",
"{$prefix}value",
"{$prefix}owner_guid",
"{$prefix}id");
511 foreach ($map as $specific => $normalized) {
512 $key = $prefix . $specific;
545 $type =
'annotation';
546 $table =
"{$db_prefix}annotations";
550 $table =
"{$db_prefix}metadata";
597 if (!$options || !is_array($options)) {
601 $batch = new \ElggBatch(
'_elgg_get_metastring_based_objects', $options, $callback, 50, $inc_offset);
602 return $batch->callbackResult;
620 'metastring_type' =>
$type,
621 'metastring_id' =>
$id,
626 if ($obj && count($obj) == 1) {
649 $type =
'annotation';
664 if ($obj->canEdit()) {
667 if (
$type ==
"annotation") {
675 return (
bool)
delete_data(
"DELETE FROM $table WHERE id = :id", [
695 $valid_types = array(
'metadata',
'annotation');
696 if (!in_array(
$type, $valid_types)) {
702 $n_table = (
$type ==
'annotation') ?
'annotations' :
$type;
704 $singulars = array(
"{$type}_name",
"{$type}_value",
705 "{$type}_name_value_pair",
"{$type}_owner_guid");
710 $options[
"{$type}_name_value_pairs_operator"],
$options[
"{$type}_case_sensitive"],
717 } elseif (!isset(
$options[
'wheres'])) {
726 } elseif (!isset(
$options[
'joins'])) {
732 if ($clauses[
'orders']) {
733 $order_by_metadata = implode(
", ", $clauses[
'orders']);
735 $options[
'order_by'] =
"$order_by_metadata, {$options['order_by']}";
737 $options[
'order_by'] =
"$order_by_metadata, e.time_created DESC";
757 $value[] = $CONFIG->path .
'engine/tests/ElggCoreMetastringsTest.php';
762 $hooks->registerHandler(
'unit_test',
'system',
'_elgg_metastrings_test');
$object
These two snippets demonstrates triggering an event and how to register for that event.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
if($guid==elgg_get_logged_in_user_guid()) $name
delete_data($query, array $params=[])
Remove a row from the database.
const ELGG_ENTITIES_NO_VALUE
_elgg_get_guid_based_where_sql($column, $guids)
Returns SQL where clause for owner and containers.
get_config($name, $site_guid=0)
Gets a configuration value.
_elgg_get_entity_time_where_sql($table, $time_created_upper=null, $time_created_lower=null, $time_updated_upper=null, $time_updated_lower=null)
Returns SQL where clause for entity time limits.
_elgg_sql_reverse_order_by_clause($order_by)
Reverses the ordering in an ORDER BY clause.
get_data_row($query, $callback=null, array $params=[])
Retrieve a single row from the database.
update_data($query, array $params=[], $get_num_rows=false)
Update a row in the database.
sanitise_string($string)
Alias of sanitize_string.
const ELGG_ENTITIES_ANY_VALUE
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
get_data($query, $callback=null, array $params=[])
Retrieve rows from the database.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
sanitise_int($int, $signed=true)
Alias of sanitize_int.
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
elgg_trigger_event($event, $object_type, $object=null)
if(!$collection_name) $id
$enabled
CI CLI installer script.
if(!$num_display) $db_prefix