public static function cmp($a, $b)
 {
     if (Specimen::$SORT_PRIORITIES_FOR_LINK_TO_TYPES[$a->link_to_type] == Specimen::$SORT_PRIORITIES_FOR_LINK_TO_TYPES[$b->link_to_type]) {
         if ($a->user_id == $b->user_id) {
             if ($a->link_to_id == $b->link_to_id) {
                 if ($a->ordering == $b->ordering) {
                     if ($a->name == $b->name) {
                         if ($a->catalog_identifier == $b->catalog_identifier) {
                             return 0;
                         }
                         return $a->catalog_identifier < $b->catalog_identifier ? -1 : 1;
                     }
                     return $a->name < $b->name ? -1 : 1;
                 }
                 return $a->ordering < $b->ordering ? -1 : 1;
             }
             if ($a->link_to_type == 'authoritative_plant') {
                 return Authoritative_Plant::cmp($a->getLinked(), $b->getLinked());
             }
             if ($a->link_to_type == 'notebook_page') {
                 return Notebook_Page::cmp($a->getLinked(), $b->getLinked());
             }
             return 0;
         }
         return User::cmp($a->getUser(), $b->getUser());
     }
     return Specimen::$SORT_PRIORITIES_FOR_LINK_TO_TYPES[$a->link_to_type] < Specimen::$SORT_PRIORITIES_FOR_LINK_TO_TYPES[$b->link_to_type] ? -1 : 1;
 }
 function testCmp()
 {
     $u1 = new User(['user_id' => 50, 'screen_name' => 'jones, fred', 'DB' => $this->DB]);
     $u2 = new User(['user_id' => 50, 'screen_name' => 'albertson, fred', 'DB' => $this->DB]);
     $u3 = new User(['user_id' => 50, 'screen_name' => 'ji, al', 'DB' => $this->DB]);
     $u4 = new User(['user_id' => 50, 'screen_name' => 'ji, bab', 'DB' => $this->DB]);
     $this->assertEqual(User::cmp($u1, $u2), 1);
     $this->assertEqual(User::cmp($u1, $u1), 0);
     $this->assertEqual(User::cmp($u2, $u1), -1);
     $this->assertEqual(User::cmp($u3, $u4), -1);
 }
 public static function cmp($a, $b)
 {
     if ($a->name == $b->name) {
         if ($a->user_id == $b->user_id) {
             return 0;
         }
         $ua = User::getOneFromDb(['user_id' => $a->user_id], $a->dbConnection);
         $ub = User::getOneFromDb(['user_id' => $b->user_id], $b->dbConnection);
         return User::cmp($ua, $ub);
     }
     return $a->name < $b->name ? -1 : 1;
 }