Elgg  Version 4.3
entities.php
Go to the documentation of this file.
1 <?php
9 
21  return _elgg_services()->entityTable->getEntityClass($type, $subtype);
22 }
23 
44  _elgg_services()->entityTable->setEntityClass($type, $subtype, $class);
45 }
46 
59  return _elgg_services()->entityTable->getRow($guid);
60 }
61 
69 function get_entity($guid) {
70  if ($guid == 1) {
71  return _elgg_services()->config->site;
72  }
73  return _elgg_services()->entityTable->get($guid);
74 }
75 
90  return _elgg_services()->entityTable->exists($guid);
91 }
92 
100  return _elgg_services()->config->site;
101 }
102 
545 function elgg_get_entities(array $options = []) {
546  return \Elgg\Database\Entities::find($options);
547 }
548 
556 function elgg_count_entities(array $options = []) {
557  $options['count'] = true;
558 
559  return (int) elgg_get_entities($options);
560 }
561 
589 function elgg_list_entities(array $options = [], $getter = 'elgg_get_entities', $viewer = 'elgg_view_entity_list') {
590 
591  $offset_key = isset($options['offset_key']) ? $options['offset_key'] : 'offset';
592 
593  $defaults = [
594  'offset' => (int) max(get_input($offset_key, 0), 0),
595  'limit' => (int) max(get_input('limit', _elgg_services()->config->default_limit), 0),
596  'sort_by' => get_input('sort_by', []),
597  'full_view' => false,
598  'pagination' => true,
599  'no_results' => '',
600  'preload_owners' => true,
601  'preload_containers' => true,
602  ];
603 
604  $options = array_merge($defaults, $options);
605 
606  $options['register_rss_link'] = elgg_extract('register_rss_link', $options, elgg_extract('pagination', $options));
607  if ($options['register_rss_link']) {
609  }
610 
611  if ($options['no_results'] === true) {
612  // @todo remove this conversion in 5.0 in favour of page/components/no_results
613  $options['no_results'] = elgg_echo('notfound');
614  }
615 
616  $options['count'] = false;
617  $entities = call_user_func($getter, $options);
618  $options['count'] = is_array($entities) ? count($entities) : 0;
619 
620  if (!empty($entities) || !empty($options['offset'])) {
621  $count_needed = true;
622  if (!$options['pagination']) {
623  $count_needed = false;
624  } elseif (!$options['offset'] && !$options['limit']) {
625  $count_needed = false;
626  } elseif (($options['count'] < (int) $options['limit']) && !$options['offset']) {
627  $count_needed = false;
628  }
629 
630  if ($count_needed) {
631  $options['count'] = true;
632 
633  $options['count'] = (int) call_user_func($getter, $options);
634  }
635  }
636 
637  return call_user_func($viewer, $entities, $options);
638 }
639 
652 function elgg_get_entity_dates(array $options = []) {
653  return \Elgg\Database\Entities::with($options)->getDates();
654 }
655 
681 function elgg_search(array $options = []) {
682  try {
683  return _elgg_services()->search->search($options);
684  } catch (InvalidParameterException $e) {
685  return false;
686  }
687 }
688 
697 function elgg_get_entity_statistics(int $owner_guid = 0): array {
698 
699  $select = Select::fromTable('entities');
700  $select->select('type')
701  ->addSelect('subtype')
702  ->addSelect('count(*) AS total')
703  ->where($select->compare('enabled', '=', 'yes', ELGG_VALUE_STRING))
704  ->groupBy('type')
705  ->addGroupBy('subtype')
706  ->orderBy('total', 'desc');
707 
708  if (!empty($owner_guid)) {
709  $select->andWhere($select->compare('owner_guid', '=', $owner_guid, ELGG_VALUE_GUID));
710  }
711 
712  $entity_stats = [];
713 
714  $rows = _elgg_services()->db->getData($select);
715  foreach ($rows as $row) {
716  $type = $row->type;
717  if (!isset($entity_stats[$type]) || !is_array($entity_stats[$type])) {
718  $entity_stats[$type] = [];
719  }
720 
721  $entity_stats[$type][$row->subtype] = $row->total;
722  }
723 
724  return $entity_stats;
725 }
726 
738 function elgg_entity_has_capability(string $type, string $subtype, string $capability, bool $default = false): bool {
739  return _elgg_services()->entity_capabilities->hasCapability($type, $subtype, $capability, $default);
740 }
741 
752 function elgg_entity_enable_capability(string $type, string $subtype, string $capability): void {
753  _elgg_services()->entity_capabilities->setCapability($type, $subtype, $capability, true);
754 }
755 
766 function elgg_entity_disable_capability(string $type, string $subtype, string $capability): void {
767  _elgg_services()->entity_capabilities->setCapability($type, $subtype, $capability, false);
768 }
769 
778 function elgg_entity_types_with_capability(string $capability): array {
779  return _elgg_services()->entity_capabilities->getTypesWithCapability($capability);
780 }
$default
Definition: checkbox.php:31
elgg_entity_disable_capability(string $type, string $subtype, string $capability)
Disables the capability for a specified type/subtype.
Definition: entities.php:766
elgg_get_entity_statistics(int $owner_guid=0)
Return an array reporting the number of various entities in the system.
Definition: entities.php:697
$rows
Definition: redis.php:25
$defaults
elgg_get_entity_dates(array $options=[])
Returns a list of months in which entities were updated or created.
Definition: entities.php:652
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
const ELGG_VALUE_GUID
Definition: constants.php:128
elgg_entity_exists($guid)
Does an entity exist?
Definition: entities.php:89
$type
Definition: delete.php:21
elgg_get_entity_as_row(int $guid)
Returns a database row from the entities table.
Definition: entities.php:58
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
elgg_entity_enable_capability(string $type, string $subtype, string $capability)
Enables the capability for a specified type/subtype.
Definition: entities.php:752
elgg_list_entities(array $options=[], $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:589
$options
Elgg admin footer.
Definition: footer.php:6
$class
Definition: summary.php:44
$owner_guid
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
get_input($variable, $default=null, $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_get_entity_class($type, $subtype)
Return the class name registered as a constructor for an entity of a given type and subtype...
Definition: entities.php:20
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:556
$getter
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:99
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
elgg_set_entity_class($type, $subtype, $class="")
Sets class constructor name for entities with given type and subtype.
Definition: entities.php:43
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
const ELGG_VALUE_STRING
Definition: constants.php:127
$subtype
Definition: delete.php:22
if(!$limit=(int) elgg_extract('limit', $vars, elgg_get_config('default_limit'))) $offset_key
Definition: pagination.php:32
elgg_entity_types_with_capability(string $capability)
Returns an array of type/subtypes with the requested capability enabled.
Definition: entities.php:778
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
elgg_entity_has_capability(string $type, string $subtype, string $capability, bool $default=false)
Checks if a capability is enabled for a specified type/subtype.
Definition: entities.php:738
$entity_stats
Definition: numentities.php:3
elgg_search(array $options=[])
Returns search results as an array of entities, as a batch, or a count, depending on parameters given...
Definition: entities.php:681
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69
elgg_register_rss_link()
Include the RSS icon link and link element in the head.
Definition: views.php:1320