Elgg  Version 1.10
EntityPreloader.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
13 
17  protected $properties;
18 
24  public function __construct(array $guid_properties) {
25  $this->properties = $guid_properties;
26  }
27 
35  public function preload($objects) {
36  $guids = $this->getGuidsToLoad($objects);
37  // If only 1 to load, not worth the overhead of elgg_get_entities(),
38  // get_entity() will handle it later.
39  if (count($guids) > 1) {
40  call_user_func($this->_callable_entity_loader, array(
41  'guids' => $guids,
42  ));
43  }
44  }
45 
54  protected function getGuidsToLoad($objects) {
55  if (!is_array($objects) || count($objects) < 2) {
56  return array();
57  }
58  $preload_guids = array();
59  foreach ($objects as $object) {
60  if (is_object($object)) {
61  foreach ($this->properties as $property) {
62  if (empty($object->{$property})) {
63  continue;
64  }
65  $guid = $object->{$property};
66  if ($guid && !call_user_func($this->_callable_cache_checker, $guid)) {
67  $preload_guids[] = $guid;
68  }
69  }
70  }
71  }
72  return array_unique($preload_guids);
73  }
74 
79  public $_callable_cache_checker = '_elgg_retrieve_cached_entity';
80 
85  public $_callable_entity_loader = 'elgg_get_entities';
86 }
$object
Definition: upgrade.php:12
$guid
Removes an admin notice.
preload($objects)
Preload entities based on the given objects.
getGuidsToLoad($objects)
Get GUIDs that need to be loaded.
Save menu items.
__construct(array $guid_properties)
Configure the preloader to check these properties of fetched objects for GUIDs.
$guids