ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAdvancedMDRecordObjectOrderings Class Reference
+ Collaboration diagram for ilAdvancedMDRecordObjectOrderings:

Public Member Functions

 __construct ()
 
 deleteByObjId (int $obj_id)
 Delete entries by obj_id. More...
 
 sortRecords (array $records, int $obj_id=null)
 
 compareRecords (ilAdvancedMDRecord $a, ilAdvancedMDRecord $b)
 
 compareLocalRecords (ilAdvancedMDRecord $a, ilAdvancedMDRecord $b)
 

Protected Member Functions

 readPositionsForObject (int $obj_id)
 Read local positions for object. More...
 

Private Attributes

ilDBInterface $db
 
array $record_position_map = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDRecordObjectOrderings::__construct ( )

Definition at line 15 of file class.ilAdvancedMDRecordObjectOrderings.php.

References $DIC.

16  {
17  global $DIC;
18 
19  $this->db = $DIC->database();
20  }
global $DIC
Definition: feed.php:28

Member Function Documentation

◆ compareLocalRecords()

ilAdvancedMDRecordObjectOrderings::compareLocalRecords ( ilAdvancedMDRecord  $a,
ilAdvancedMDRecord  $b 
)
Parameters
ilAdvancedMDRecord$a
ilAdvancedMDRecord$b
Returns
int

Definition at line 100 of file class.ilAdvancedMDRecordObjectOrderings.php.

References ilAdvancedMDRecord\getGlobalPosition(), and ilAdvancedMDRecord\getRecordId().

100  : int
101  {
102  $local_pos_a = $this->record_position_map[$a->getRecordId()] ??
103  ($a->getGlobalPosition() ?: 999);
104  $local_pos_b = $this->record_position_map[$b->getRecordId()] ??
105  ($b->getGlobalPosition() ?: 999);
106  if ($local_pos_a < $local_pos_b) {
107  return -1;
108  }
109  if ($local_pos_a > $local_pos_b) {
110  return 1;
111  }
112  return 0;
113  }
+ Here is the call graph for this function:

◆ compareRecords()

ilAdvancedMDRecordObjectOrderings::compareRecords ( ilAdvancedMDRecord  $a,
ilAdvancedMDRecord  $b 
)
Parameters
ilAdvancedMDRecord$a
ilAdvancedMDRecord$b
Returns
int

Definition at line 77 of file class.ilAdvancedMDRecordObjectOrderings.php.

References ilAdvancedMDRecord\getGlobalPosition(), and ilAdvancedMDRecord\setGlobalPosition().

77  : int
78  {
79  if ($a->getGlobalPosition() == null) {
80  $a->setGlobalPosition(999);
81  }
82  if ($b->getGlobalPosition() == null) {
83  $b->setGlobalPosition(999);
84  }
85 
86  if ($a->getGlobalPosition() < $b->getGlobalPosition()) {
87  return -1;
88  }
89  if ($a->getGlobalPosition() > $b->getGlobalPosition()) {
90  return 1;
91  }
92  return 0;
93  }
+ Here is the call graph for this function:

◆ deleteByObjId()

ilAdvancedMDRecordObjectOrderings::deleteByObjId ( int  $obj_id)

Delete entries by obj_id.

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

References $query.

25  : void
26  {
27  $query = 'DELETE FROM adv_md_record_obj_ord ' .
28  'WHERE obj_id = ' . $this->db->quote($obj_id, 'integer');
29  $this->db->manipulate($query);
30  }
$query

◆ readPositionsForObject()

ilAdvancedMDRecordObjectOrderings::readPositionsForObject ( int  $obj_id)
protected

Read local positions for object.

Definition at line 118 of file class.ilAdvancedMDRecordObjectOrderings.php.

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

Referenced by sortRecords().

118  : void
119  {
120  $query = 'SELECT record_id, position FROM adv_md_record_obj_ord ' .
121  'WHERE obj_id = ' . $this->db->quote($obj_id, 'integer');
122  $res = $this->db->query($query);
123 
124  $this->record_position_map = [];
125  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
126  $this->record_position_map[(int) $row->record_id] = (int) $row->position;
127  }
128  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sortRecords()

ilAdvancedMDRecordObjectOrderings::sortRecords ( array  $records,
int  $obj_id = null 
)
Parameters
ilAdvancedMDRecord[]$records
?int$obj_id
Returns
ilAdvancedMDRecord[]

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

References ilContainer\_lookupContainerSetting(), ilObjectServiceSettingsGUI\CUSTOM_METADATA, and readPositionsForObject().

37  : array
38  {
39  // if local custom meta is not enabled use global sorting
40  $use_global = true;
41  if ($obj_id) {
43  $obj_id,
45  ''
46  )) {
47  $use_global = false;
48  }
49  }
50  if ($use_global) {
51  usort(
52  $records,
53  [
54  __CLASS__,
55  'compareRecords'
56  ]
57  );
58  return $records;
59  } else {
60  $this->readPositionsForObject($obj_id);
61  usort(
62  $records,
63  [
64  __CLASS__,
65  'compareLocalRecords'
66  ]
67  );
68  }
69  return $records;
70  }
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
readPositionsForObject(int $obj_id)
Read local positions for object.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilAdvancedMDRecordObjectOrderings::$db
private

Definition at line 12 of file class.ilAdvancedMDRecordObjectOrderings.php.

◆ $record_position_map

array ilAdvancedMDRecordObjectOrderings::$record_position_map = []
private

Definition at line 13 of file class.ilAdvancedMDRecordObjectOrderings.php.


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