public static function cmp($a, $b)
 {
     if ($a->notebook_id == $b->notebook_id) {
         //                echo "auth plant cmp";
         return Authoritative_Plant::cmp($a->getAuthoritativePlant(), $b->getAuthoritativePlant());
     }
     //            echo "notebook cmp";
     return Notebook::cmp($a->getNotebook(), $b->getNotebook());
 }
 function testCmp()
 {
     $n1 = new Notebook(['notebook_id' => 50, 'name' => 'nA', 'user_id' => 101, 'DB' => $this->DB]);
     $n2 = new Notebook(['notebook_id' => 60, 'name' => 'nB', 'user_id' => 101, 'DB' => $this->DB]);
     $n3 = new Notebook(['notebook_id' => 70, 'name' => 'nB', 'user_id' => 102, 'DB' => $this->DB]);
     $this->assertEqual(Notebook::cmp($n1, $n2), -1);
     $this->assertEqual(Notebook::cmp($n1, $n1), 0);
     $this->assertEqual(Notebook::cmp($n2, $n1), 1);
     $this->assertEqual(Notebook::cmp($n2, $n3), -1);
 }
 public static function cmp($a, $b)
 {
     // role, then action, then type, then target
     if ($a->role_id == $b->role_id) {
         if ($a->action_id == $b->action_id) {
             if (Role_Action_Target::$SORT_PRIORITIES_FOR_TYPES[$a->target_type] == Role_Action_Target::$SORT_PRIORITIES_FOR_TYPES[$b->target_type]) {
                 if ($a->target_id == $b->target_id) {
                     return 0;
                 }
                 if ($a->target_id == 0) {
                     return -1;
                 }
                 if ($b->target_id == 0) {
                     return 1;
                 }
                 switch ($a->target_type) {
                     case 'notebook':
                         return Notebook::cmp($a->getTargets()[0], $b->getTargets()[0]);
                         break;
                     case 'metadata_structure':
                         return Metadata_Structure::cmp($a->getTargets()[0], $b->getTargets()[0]);
                         break;
                     case 'plant':
                         return Authoritative_Plant::cmp($a->getTargets()[0], $b->getTargets()[0]);
                         break;
                     case 'specimen':
                         return Specimen::cmp($a->getTargets()[0], $b->getTargets()[0]);
                         break;
                     default:
                         return 0;
                 }
             }
             return Role_Action_Target::$SORT_PRIORITIES_FOR_TYPES[$a->target_type] < Role_Action_Target::$SORT_PRIORITIES_FOR_TYPES[$b->target_type] ? -1 : 1;
         }
         return Action::cmp($a->getAction(), $b->getAction());
     }
     return Role::cmp($a->getRole(), $b->getRole());
 }