|
ILIAS
trunk Revision v12.0_alpha-399-g579a087ced2
|
This class is a special implementation of a NewsCollection that is designed to load the complete NewsItems only when needed. More...
Inheritance diagram for ILIAS\News\Data\LazyNewsCollection:
Collaboration diagram for ILIAS\News\Data\LazyNewsCollection:Public Member Functions | |
| __construct (array $news_ids=[], protected ?\Closure $fetch_callback=null) | |
| withFetchCallback (\Closure $callback) | |
| addNewsItems (array $news_items) | |
| Add multiple news items efficiently. More... | |
| load (array $news_ids=[]) | |
| This method loads the provided NewsItems from the database. More... | |
| groupFiles () | |
| groupForums (bool $group_posting_sequence) | |
| contains (int $news_id) | |
This method returns true if the NewsItem exists in this collection. More... | |
| has (int $news_id) | |
This method returns true if the NewsItem exists in this collection and has been loaded. More... | |
| getById (int $news_id) | |
| This method returns the NewsItem with the given id or null if it does not exist. More... | |
| pick (int $offset) | |
| This method returns the NewsItem of the given offset of the collection. More... | |
| pluck (string $key, bool $wrap=false) | |
| INFO: This method will load all NewsItems into the collection. More... | |
| toArray () | |
| INFO: This method will load all NewsItems into the collection. More... | |
| getAggregatedNews (bool $aggregate_files=false, bool $aggregate_forums=false, bool $group_posting_sequence=false) | |
| INFO: This method will load all NewsItems into the collection. More... | |
| merge (NewsCollection $other) | |
| Merge with another collection and returns it as a new collection. More... | |
| exclude (array $news_ids) | |
| Returns a new collection with only the news items that are not in the provided list. More... | |
| limit (?int $limit) | |
| Limit the number of news items and returns it as a new collection. More... | |
Public Member Functions inherited from ILIAS\News\Data\NewsCollection | |
| __construct (array $news_items=[]) | |
| addNewsItems (array $news_items) | |
| Add multiple news items efficiently. More... | |
| addNewsItem (NewsItem $item) | |
| Add a single news item with indexing. More... | |
| getNewsItems () | |
| getNewsForContext (int $context_obj_id, string $context_obj_type) | |
| getNewsByType (string $obj_type) | |
| setUserReadStatus (int $user_id, array $read_news_ids) | |
| isReadByUser (int $user_id, int $news_id) | |
| getUserReadStatus (int $user_id) | |
| groupFiles () | |
| groupForums (bool $group_posting_sequence) | |
| getGroupingFor (NewsItem $item) | |
| Returns the grouping for a given news item. More... | |
| getAggregatedNews (bool $aggregate_files=false, bool $aggregate_forums=false, bool $group_posting_sequence=false) | |
| Get news items in a format compatible with the legacy rendering implementation. More... | |
| jsonSerialize () | |
| getIterator () | |
| count () | |
| isEmpty () | |
| first () | |
| last () | |
| contains (int $news_id) | |
| getById (int $news_id) | |
| getPageFor (int $news_id) | |
| pick (int $offset) | |
| pluck (string $key, bool $wrap=false) | |
| toArray () | |
| merge (NewsCollection $other) | |
| Merge with another collection and returns it as a new collection. More... | |
| limit (?int $limit) | |
| Limit the number of news items and returns it as a new collection. More... | |
| exclude (array $news_ids) | |
| Returns a new collection with only the news items that are not in the provided list. More... | |
| load (array $news_ids=[]) | |
Private Member Functions | |
| regroup (array $items) | |
Private Attributes | |
| bool | $group_files = false |
| int | $group_forums = 0 |
Additional Inherited Members | |
Protected Attributes inherited from ILIAS\News\Data\NewsCollection | |
| array | $news_items = [] |
| array | $context_map = [] |
| array | $type_map = [] |
| array | $user_read_status = [] |
| array | $grouped_items_map = [] |
This class is a special implementation of a NewsCollection that is designed to load the complete NewsItems only when needed.
This lazy loading has the advantage that less main memory is required, since only the IDs of the NewsItems are initially stored in the collection. It also prevents large database queries from being made when only some of the data records are needed.
This class should be used with caution and should not be used across the board. If used incorrectly, lazy loading can lead to a deterioration in performance due to the N+1 problem.
Definition at line 32 of file LazyNewsCollection.php.
| ILIAS\News\Data\LazyNewsCollection::__construct | ( | array | $news_ids = [], |
| protected ?\Closure | $fetch_callback = null |
||
| ) |
Definition at line 37 of file LazyNewsCollection.php.
References ILIAS\GlobalScreen\Provider\__construct().
Here is the call graph for this function:| ILIAS\News\Data\LazyNewsCollection::addNewsItems | ( | array | $news_items | ) |
Add multiple news items efficiently.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 58 of file LazyNewsCollection.php.
References $id, ILIAS\News\Data\NewsCollection\$news_items, and ILIAS\News\Data\NewsCollection\addNewsItem().
Referenced by ILIAS\News\Data\LazyNewsCollection\load().
Here is the call graph for this function:
Here is the caller graph for this function:| ILIAS\News\Data\LazyNewsCollection::contains | ( | int | $news_id | ) |
This method returns true if the NewsItem exists in this collection.
It does not provide any information about whether the NewsItem has been loaded or not.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 159 of file LazyNewsCollection.php.
| ILIAS\News\Data\LazyNewsCollection::exclude | ( | array | $news_ids | ) |
Returns a new collection with only the news items that are not in the provided list.
| int[] | $news_ids |
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 242 of file LazyNewsCollection.php.
| ILIAS\News\Data\LazyNewsCollection::getAggregatedNews | ( | bool | $aggregate_files = false, |
| bool | $aggregate_forums = false, |
||
| bool | $group_posting_sequence = false |
||
| ) |
INFO: This method will load all NewsItems into the collection.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 228 of file LazyNewsCollection.php.
| ILIAS\News\Data\LazyNewsCollection::getById | ( | int | $news_id | ) |
This method returns the NewsItem with the given id or null if it does not exist.
If the NewsItem was not loaded, it will be loaded from the database.
WARNING: this may cause N+1 queries when using this method in a loop. Use load instead, to batch load NewsItems.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 179 of file LazyNewsCollection.php.
References ILIAS\News\Data\LazyNewsCollection\has(), and ILIAS\News\Data\LazyNewsCollection\load().
Referenced by ILIAS\News\Data\LazyNewsCollection\pick().
Here is the call graph for this function:
Here is the caller graph for this function:| ILIAS\News\Data\LazyNewsCollection::groupFiles | ( | ) |
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 116 of file LazyNewsCollection.php.
| ILIAS\News\Data\LazyNewsCollection::groupForums | ( | bool | $group_posting_sequence | ) |
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 122 of file LazyNewsCollection.php.
| ILIAS\News\Data\LazyNewsCollection::has | ( | int | $news_id | ) |
This method returns true if the NewsItem exists in this collection and has been loaded.
Definition at line 167 of file LazyNewsCollection.php.
Referenced by ILIAS\News\Data\LazyNewsCollection\getById().
Here is the caller graph for this function:| ILIAS\News\Data\LazyNewsCollection::limit | ( | ?int | $limit | ) |
Limit the number of news items and returns it as a new collection.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 247 of file LazyNewsCollection.php.
| ILIAS\News\Data\LazyNewsCollection::load | ( | array | $news_ids = [] | ) |
This method loads the provided NewsItems from the database.
If an empty array is provided, it will load all missing NewsItems. It will also load the dependencies of the NewsItems if grouping is enabled.
| int[] | $news_ids |
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 77 of file LazyNewsCollection.php.
References ILIAS\News\Data\LazyNewsCollection\addNewsItems(), and ILIAS\News\Data\LazyNewsCollection\regroup().
Referenced by ILIAS\News\Data\LazyNewsCollection\getById(), ILIAS\News\Data\LazyNewsCollection\pluck(), and ILIAS\News\Data\LazyNewsCollection\toArray().
Here is the call graph for this function:
Here is the caller graph for this function:| ILIAS\News\Data\LazyNewsCollection::merge | ( | NewsCollection | $other | ) |
Merge with another collection and returns it as a new collection.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 237 of file LazyNewsCollection.php.
| ILIAS\News\Data\LazyNewsCollection::pick | ( | int | $offset | ) |
This method returns the NewsItem of the given offset of the collection.
If the NewsItem was not loaded, it will be loaded from the database.
WARNING: this may cause N+1 queries when using this method in a loop. Use load instead, to batch load NewsItems.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 195 of file LazyNewsCollection.php.
References ILIAS\News\Data\LazyNewsCollection\getById().
Here is the call graph for this function:| ILIAS\News\Data\LazyNewsCollection::pluck | ( | string | $key, |
| bool | $wrap = false |
||
| ) |
INFO: This method will load all NewsItems into the collection.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 206 of file LazyNewsCollection.php.
References ILIAS\News\Data\LazyNewsCollection\load().
Here is the call graph for this function:
|
private |
Definition at line 128 of file LazyNewsCollection.php.
Referenced by ILIAS\News\Data\LazyNewsCollection\load().
Here is the caller graph for this function:| ILIAS\News\Data\LazyNewsCollection::toArray | ( | ) |
INFO: This method will load all NewsItems into the collection.
Reimplemented from ILIAS\News\Data\NewsCollection.
Definition at line 219 of file LazyNewsCollection.php.
References ILIAS\News\Data\LazyNewsCollection\load().
Here is the call graph for this function:| ILIAS\News\Data\LazyNewsCollection::withFetchCallback | ( | \Closure | $callback | ) |
Closure(int[], string[]): NewsItem[] $callback
Definition at line 51 of file LazyNewsCollection.php.
|
private |
Definition at line 34 of file LazyNewsCollection.php.
|
private |
Definition at line 35 of file LazyNewsCollection.php.