ILIAS  release_7 Revision v7.30-3-g800a261c036
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.

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

References $DIC.

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.

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 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, and Vendor\Package\$b.

◆ compareRecords()

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

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

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 }

References Vendor\Package\$a, and Vendor\Package\$b.

◆ deleteByObjId()

ilAdvancedMDRecordObjectOrderings::deleteByObjId ( int  $obj_id)

Delete entries by obj_id.

Parameters
int$obj_id
Exceptions

ilDatabaseException

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

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

References $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.

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

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

Referenced by sortRecords().

+ 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.

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 }
readPositionsForObject(int $obj_id)
Read local positions for object.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.

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

+ 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: