Evidence::object_sort PHP Method

object_sort() public method

public object_sort ( $a, $b )
    public function object_sort($a, $b)
    {
        // This is used to sort arrays of Elements.
        global $this_field_1;
        global $this_field_1_dir;
        global $this_field_2;
        global $this_field_2_dir;
        if ($this_field_1 == "created") {
            $a1 = strtotime($a->{$this_field_1});
            $b1 = strtotime($b->{$this_field_1});
            if ($a1 == $b1) {
                $a1 = $a->id;
                $b1 = $b->id;
            }
        } else {
            $a1 = strtolower($a->{$this_field_1});
            $b1 = strtolower($b->{$this_field_1});
        }
        if ($this_field_2 == "created") {
            $a2 = strtotime($a->{$this_field_2});
            $b2 = strtotime($b->{$this_field_2});
            if ($a2 == $b2) {
                $a2 = $a->id;
                $b2 = $b->id;
            }
        } else {
            $a2 = strtolower($a->{$this_field_2});
            $b2 = strtolower($b->{$this_field_2});
        }
        //echo("<br />" . $a1 . "/" . $b1 );
        if ($a1 == $b1) {
            //echo("///" . $a2 . "/" . $b2 );
            if ($a2 == $b2) {
                return 0;
            }
            if ($this_field_2_dir == "asc") {
                return $a2 > $b2 ? +1 : -1;
            } else {
                return $a2 < $b2 ? +1 : -1;
            }
        }
        if ($this_field_1_dir == "asc") {
            return $a1 > $b1 ? +1 : -1;
        } else {
            return $a1 < $b1 ? +1 : -1;
        }
    }