ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 29 of file class.ilAdvancedMDRecordObjectOrderings.php.

References $DIC.

30  {
31  global $DIC;
32 
33  $this->db = $DIC->database();
34  }
global $DIC
Definition: shib_login.php:26

Member Function Documentation

◆ compareLocalRecords()

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

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

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

114  : int
115  {
116  $local_pos_a = $this->record_position_map[$a->getRecordId()] ??
117  ($a->getGlobalPosition() ?: 999);
118  $local_pos_b = $this->record_position_map[$b->getRecordId()] ??
119  ($b->getGlobalPosition() ?: 999);
120  if ($local_pos_a < $local_pos_b) {
121  return -1;
122  }
123  if ($local_pos_a > $local_pos_b) {
124  return 1;
125  }
126  return 0;
127  }
+ 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 91 of file class.ilAdvancedMDRecordObjectOrderings.php.

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

91  : int
92  {
93  if ($a->getGlobalPosition() == null) {
94  $a->setGlobalPosition(999);
95  }
96  if ($b->getGlobalPosition() == null) {
97  $b->setGlobalPosition(999);
98  }
99 
100  if ($a->getGlobalPosition() < $b->getGlobalPosition()) {
101  return -1;
102  }
103  if ($a->getGlobalPosition() > $b->getGlobalPosition()) {
104  return 1;
105  }
106  return 0;
107  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ deleteByObjId()

ilAdvancedMDRecordObjectOrderings::deleteByObjId ( int  $obj_id)

Delete entries by obj_id.

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

39  : void
40  {
41  $query = 'DELETE FROM adv_md_record_obj_ord ' .
42  'WHERE obj_id = ' . $this->db->quote($obj_id, 'integer');
43  $this->db->manipulate($query);
44  }

◆ readPositionsForObject()

ilAdvancedMDRecordObjectOrderings::readPositionsForObject ( int  $obj_id)
protected

Read local positions for object.

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

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

Referenced by sortRecords().

132  : void
133  {
134  $query = 'SELECT record_id, position FROM adv_md_record_obj_ord ' .
135  'WHERE obj_id = ' . $this->db->quote($obj_id, 'integer');
136  $res = $this->db->query($query);
137 
138  $this->record_position_map = [];
139  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
140  $this->record_position_map[(int) $row->record_id] = (int) $row->position;
141  }
142  }
$res
Definition: ltiservices.php:66
+ 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 51 of file class.ilAdvancedMDRecordObjectOrderings.php.

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

51  : array
52  {
53  // if local custom meta is not enabled use global sorting
54  $use_global = true;
55  if ($obj_id) {
57  $obj_id,
59  ''
60  )) {
61  $use_global = false;
62  }
63  }
64  if ($use_global) {
65  usort(
66  $records,
67  [
68  __CLASS__,
69  'compareRecords'
70  ]
71  );
72  return $records;
73  } else {
74  $this->readPositionsForObject($obj_id);
75  usort(
76  $records,
77  [
78  __CLASS__,
79  'compareLocalRecords'
80  ]
81  );
82  }
83  return $records;
84  }
readPositionsForObject(int $obj_id)
Read local positions for object.
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilAdvancedMDRecordObjectOrderings::$db
private

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

◆ $record_position_map

array ilAdvancedMDRecordObjectOrderings::$record_position_map = []
private

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


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