Elgg  Version 1.11
EntityPreloader.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
13 
23  public function preload($objects, array $guid_properties) {
24  $guids = $this->getGuidsToLoad($objects, $guid_properties);
25  // If only 1 to load, not worth the overhead of elgg_get_entities(),
26  // get_entity() will handle it later.
27  if (count($guids) > 1) {
28  call_user_func($this->_callable_entity_loader, array(
29  'guids' => $guids,
30  ));
31  }
32  }
33 
43  protected function getGuidsToLoad($objects, array $guid_properties) {
44  if (!is_array($objects) || count($objects) < 2) {
45  return array();
46  }
47  $preload_guids = array();
48  foreach ($objects as $object) {
49  if (is_object($object)) {
50  foreach ($guid_properties as $property) {
51  if (empty($object->{$property})) {
52  continue;
53  }
54  $guid = $object->{$property};
55  if ($guid && !call_user_func($this->_callable_cache_checker, $guid)) {
56  $preload_guids[] = $guid;
57  }
58  }
59  }
60  }
61  return array_unique($preload_guids);
62  }
63 
68  public $_callable_cache_checker = '_elgg_retrieve_cached_entity';
69 
74  public $_callable_entity_loader = 'elgg_get_entities';
75 }
$object
Definition: upgrade.php:12
$guid
Removes an admin notice.
Save menu items.
getGuidsToLoad($objects, array $guid_properties)
Get GUIDs that need to be loaded.
$guids
preload($objects, array $guid_properties)
Preload entities based on the given objects.