ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilAdvancedMDRecordObjectOrderings Class Reference
+ Collaboration diagram for ilAdvancedMDRecordObjectOrderings:

Public Member Functions

 __construct ()
 ilAdvancedMDRecordObjectOrderings constructor. More...
 
 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

 $db
 
 $record_position_map = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDRecordObjectOrderings::__construct ( )

ilAdvancedMDRecordObjectOrderings constructor.

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

References $DIC.

26  {
27  global $DIC;
28 
29  $this->db = $DIC->database();
30  }
global $DIC
Definition: saml.php:7

Member Function Documentation

◆ compareLocalRecords()

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

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

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

117  : int
118  {
119  $local_pos_a = isset($this->record_position_map[$a->getRecordId()]) ?
120  $this->record_position_map[$a->getRecordId()] :
121  (
122  $a->getGlobalPosition() ?
123  $a->getGlobalPosition() :
124  999
125  );
126  $local_pos_b = isset($this->record_position_map[$b->getRecordId()]) ?
127  $this->record_position_map[$b->getRecordId()] :
128  (
129  $b->getGlobalPosition() ?
130  $b->getGlobalPosition() :
131  999
132  );
133  if ($local_pos_a == $local_pos_b) {
134  return 0;
135  }
136  if ($local_pos_a < $local_pos_b) {
137  return -1;
138  }
139  if ($local_pos_a > $local_pos_b) {
140  return 1;
141  }
142  }
+ 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 92 of file class.ilAdvancedMDRecordObjectOrderings.php.

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

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

◆ deleteByObjId()

ilAdvancedMDRecordObjectOrderings::deleteByObjId ( int  $obj_id)

Delete entries by obj_id.

Parameters
int$obj_id
Exceptions

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

References $query.

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  }
$query

◆ readPositionsForObject()

ilAdvancedMDRecordObjectOrderings::readPositionsForObject ( int  $obj_id)
protected

Read local positions for object.

Parameters
int$obj_id

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

References $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by sortRecords().

150  {
151  $query = 'SELECT record_id, position FROM adv_md_record_obj_ord ' .
152  'WHERE obj_id = ' . $this->db->quote($obj_id, 'integer');
153  $res = $this->db->query($query);
154 
155  $this->record_position_map = [];
156  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
157  $this->record_position_map[$row->record_id] = $row->position;
158  }
159  }
foreach($_POST as $key=> $value) $res
$query
$row
+ Here is the caller graph for this function:

◆ sortRecords()

ilAdvancedMDRecordObjectOrderings::sortRecords ( array  $records,
int  $obj_id = null 
)
Parameters
array$records
intobj_id

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

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

52  {
53  // if local custom meta is not enabled use global sorting
54  $use_global = true;
55  if ($obj_id) {
57  $obj_id,
59  false
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 
84  return $records;
85  }
$records
Definition: simple_test.php:22
readPositionsForObject(int $obj_id)
Read local positions for object.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilAdvancedMDRecordObjectOrderings::$db
private

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

◆ $record_position_map

ilAdvancedMDRecordObjectOrderings::$record_position_map = []
private

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


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