54 private $sortCriteria = [];
65 $criteria = !is_array($sortCriteria) ? [$sortCriteria] : $sortCriteria;
66 foreach ($criteria as $attribute => $direction) {
67 if (is_int($attribute) && $attribute >= 0) {
69 $attrDir = explode(' ', $direction);
70 $attribute = $attrDir[0];
71 $direction = sizeof($attrDir) == 1 ? self::SORTTYPE_ASC :
74 $this->sortCriteria[trim($attribute)] = $direction;
90 $maxWeight = sizeOf($this->sortCriteria);
92 foreach ($this->sortCriteria as $criteria => $sortType) {
93 $weightedValue = ($maxWeight-$i)*($maxWeight-$i);
96 if ($criteria == self::ATTRIB_OID) {
98 ($a->getOID() > $b->getOID()) ? $aGreaterB = 1 : $aGreaterB = -1;
102 else if ($criteria == self::ATTRIB_TYPE) {
104 ($a->getType() > $b->getType()) ? $aGreaterB = 1 : $aGreaterB = -1;
108 else if($a->getValue($criteria) != null || $b->getValue($criteria) != null) {
109 $aValue = strToLower($a->getValue($criteria));
110 $bValue = strToLower($b->getValue($criteria));
111 if ($aValue != $bValue) {
112 ($aValue > $bValue) ? $aGreaterB = 1 : $aGreaterB = -1;
117 $aProperty = strToLower($a->getProperty($criteria));
118 $bProperty = strToLower($b->getProperty($criteria));
119 if ($aProperty != $bProperty) {
120 ($aProperty > $bProperty) ? $aGreaterB = 1 : $aGreaterB = -1;
124 if ($sortType == self::SORTTYPE_ASC) {
125 if ($aGreaterB == 1) { $sumA += $weightedValue; }
126 else if ($aGreaterB == -1) { $sumB += $weightedValue; }
128 else if ($sortType == self::SORTTYPE_DESC) {
129 if ($aGreaterB == 1) { $sumB += $weightedValue; }
130 else if ($aGreaterB == -1) { $sumA += $weightedValue; }
137 if ($sumA == $sumB) { return 0; }
138 return ($sumA > $sumB) ? 1 : -1;
getType()
Get the type of the object.
getOID()
Get the object id of the PersistentObject.
Persistence layer related interfaces and classes.
compare(PersistentObject $a, PersistentObject $b)
Compare function for sorting PersitentObject instances by the list of criterias.
IllegalArgumentException signals an exception in method arguments.
getValue($name)
Get the value of an attribute.
__construct($sortCriteria)
Constructor.
PersistentObject defines the interface of all persistent objects.
getProperty($name)
Get the value of a named property in the object.
ObjectComparator is used to compare persistent objects by given criterias.