ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilWebLinkItemsContainer Class Reference

Immutable container class for Web Link items. More...

+ Inheritance diagram for ilWebLinkItemsContainer:
+ Collaboration diagram for ilWebLinkItemsContainer:

Public Member Functions

 __construct (int $webr_id, array $items=[])
 
 sort ()
 Sorts the items in this container according to the settings of this web link object. More...
 
 getItems ()
 
 getFirstItem ()
 
 getWebrId ()
 
- Public Member Functions inherited from ilWebLinkBaseItemsContainer
 __construct (array $items=[])
 
 getItems ()
 
 getFirstItem ()
 

Protected Member Functions

 lookupSortMode (int $webr_id)
 
 lookupManualPositions (int $webr_id)
 
 sortArray (array $array, string $sort_by_key, bool $numeric)
 

Protected Attributes

int $webr_id
 
array $items
 
- Protected Attributes inherited from ilWebLinkBaseItemsContainer
array $items
 

Detailed Description

Immutable container class for Web Link items.

Author
Tim Schmitz schmi.nosp@m.tz@l.nosp@m.eifos.nosp@m..de

Definition at line 25 of file class.ilWebLinkItemsContainer.php.

Constructor & Destructor Documentation

◆ __construct()

ilWebLinkItemsContainer::__construct ( int  $webr_id,
array  $items = [] 
)
Parameters
int$webr_id
ilWebLinkItem[]$items

Definition at line 37 of file class.ilWebLinkItemsContainer.php.

38 {
39 $this->webr_id = $webr_id;
41 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $items, $webr_id, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ getFirstItem()

ilWebLinkItemsContainer::getFirstItem ( )

Reimplemented from ilWebLinkBaseItemsContainer.

Definition at line 140 of file class.ilWebLinkItemsContainer.php.

141 {
142 return $this->items[0] ?? null;
143 }
Immutable class for Web Link items.

◆ getItems()

ilWebLinkItemsContainer::getItems ( )
Returns
ilWebLinkItem[]

Reimplemented from ilWebLinkBaseItemsContainer.

Definition at line 135 of file class.ilWebLinkItemsContainer.php.

135 : array
136 {
137 return $this->items;
138 }

References $items.

Referenced by sort().

+ Here is the caller graph for this function:

◆ getWebrId()

ilWebLinkItemsContainer::getWebrId ( )

Definition at line 145 of file class.ilWebLinkItemsContainer.php.

145 : int
146 {
147 return $this->webr_id;
148 }

References $webr_id.

Referenced by sort().

+ Here is the caller graph for this function:

◆ lookupManualPositions()

ilWebLinkItemsContainer::lookupManualPositions ( int  $webr_id)
protected
Returns
int[]

Definition at line 116 of file class.ilWebLinkItemsContainer.php.

116 : array
117 {
119 }
static lookupPositions(int $a_obj_id)

References $webr_id, and ilContainerSorting\lookupPositions().

Referenced by sort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupSortMode()

ilWebLinkItemsContainer::lookupSortMode ( int  $webr_id)
protected

Definition at line 108 of file class.ilWebLinkItemsContainer.php.

References $webr_id, and ilContainerSortingSettings\_lookupSortMode().

Referenced by sort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sort()

ilWebLinkItemsContainer::sort ( )

Sorts the items in this container according to the settings of this web link object.

Definition at line 47 of file class.ilWebLinkItemsContainer.php.

47 : self
48 {
49 $mode = $this->lookupSortMode($this->getWebrId());
50
51 if ($mode == ilContainer::SORT_TITLE) {
52 $items_arr = [];
53
54 foreach ($this->getItems() as $item) {
55 $link_id = $item->getLinkId();
56 $items_arr[$link_id]['title'] = $item->getTitle();
57 $items_arr[$link_id]['item'] = $item;
58 }
59
60 $items_arr = $this->sortArray(
61 $items_arr,
62 'title',
63 false
64 );
65
66 $result = [];
67 foreach ($items_arr as $value) {
68 $result[] = $value['item'];
69 }
70 $this->items = $result;
71 }
72
73 $sorted = $unsorted = [];
74 if ($mode == ilContainer::SORT_MANUAL) {
75 $pos = $this->lookupManualPositions($this->getWebrId());
76 foreach ($this->getItems() as $item) {
77 $link_id = $item->getLinkId();
78 if (isset($pos[$link_id])) {
79 $sorted[$link_id]['title'] = $item->getTitle();
80 $sorted[$link_id]['position'] = (int) $pos[$link_id];
81 $sorted[$link_id]['item'] = $item;
82 } else {
83 $unsorted[$link_id]['title'] = $item->getTitle();
84 $unsorted[$link_id]['item'] = $item;
85 }
86 }
87 $sorted = $this->sortArray(
88 $sorted,
89 'position',
90 true
91 );
92 $unsorted = $this->sortArray(
93 $unsorted,
94 'title',
95 false
96 );
97
98 $result = [];
99 foreach ($sorted + $unsorted as $value) {
100 $result[] = $value['item'];
101 }
102 $this->items = $result;
103 }
104
105 return $this;
106 }
sortArray(array $array, string $sort_by_key, bool $numeric)

References getItems(), getWebrId(), ILIAS\Repository\int(), lookupManualPositions(), lookupSortMode(), ilContainer\SORT_MANUAL, ilContainer\SORT_TITLE, and sortArray().

+ Here is the call graph for this function:

◆ sortArray()

ilWebLinkItemsContainer::sortArray ( array  $array,
string  $sort_by_key,
bool  $numeric 
)
protected

Definition at line 121 of file class.ilWebLinkItemsContainer.php.

121 : array
122 {
124 $array,
125 $sort_by_key,
126 'asc',
127 $numeric,
128 true
129 );
130 }
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)

References ilArrayUtil\sortArray().

Referenced by sort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $items

array ilWebLinkItemsContainer::$items
protected

Definition at line 31 of file class.ilWebLinkItemsContainer.php.

Referenced by __construct(), and getItems().

◆ $webr_id

int ilWebLinkItemsContainer::$webr_id
protected

The documentation for this class was generated from the following file: