예제 #1
0
 function compareRelatedRecords($a, $b)
 {
     //Get literary form to determine if we should compare editions
     $literaryForm = '';
     if (isset($this->fields['literary_form'])) {
         if (is_array($this->fields['literary_form'])) {
             $literaryForm = reset($this->fields['literary_form']);
         } else {
             $literaryForm = $this->fields['literary_form'];
         }
     }
     //First sort by format
     $format1 = $a['format'];
     $format2 = $b['format'];
     $formatComparison = strcasecmp($format1, $format2);
     //Make sure that book is the very first format always
     if ($formatComparison != 0) {
         if ($format1 == 'Book') {
             return -1;
         } elseif ($format2 == 'Book') {
             return 1;
         }
     }
     if ($formatComparison == 0) {
         //Put english titles before spanish by default
         $languageComparison = GroupedWorkDriver::compareLanguagesForRecords($a, $b);
         if ($languageComparison == 0) {
             //Compare editions if available
             $editionComparisonResult = GroupedWorkDriver::compareEditionsForRecords($literaryForm, $a, $b);
             if ($editionComparisonResult == 0) {
                 //Put anything with a local copy higher
                 $localItemComparisonResult = GroupedWorkDriver::compareLocalItemsForRecords($a, $b);
                 if ($localItemComparisonResult == 0) {
                     //Anything that is available goes higher
                     $availabilityComparisonResults = GroupedWorkDriver::compareAvailabilityForRecords($a, $b);
                     if ($availabilityComparisonResults == 0) {
                         //All else being equal, sort by hold ratio
                         if ($a['holdRatio'] == $b['holdRatio']) {
                             //Hold Ratio is the same, last thing to check is the number of copies
                             if ($a['copies'] == $b['copies']) {
                                 return 0;
                             } elseif ($a['copies'] > $b['copies']) {
                                 return -1;
                             } else {
                                 return 1;
                             }
                         } elseif ($a['holdRatio'] > $b['holdRatio']) {
                             return -1;
                         } else {
                             return 1;
                         }
                     } else {
                         return $availabilityComparisonResults;
                     }
                 } else {
                     return $localItemComparisonResult;
                 }
             } else {
                 return $editionComparisonResult;
             }
         } else {
             return $languageComparison;
         }
     } else {
         return $formatComparison;
     }
 }