id = $id; $this->login = $login; $this->fullName = $fullName; $this->email = $email; $this->isAdmin = $isAdmin; $this->pwd = $pwd; $this->comment = $comment; } function getID() { return $this->id; } function getLogin() { return $this->login; } function getFullName() { return $this->fullName; } function getPwd() { return $this->pwd; } function getEmail() { return $this->email; } function getComment() { return $this->comment; } function getIsAdmin() { return $this->isAdmin; } } class collection { var $dataSet = array(); //Creates a new data item and adds it to our array function add($id,$login,$fullName,$email,$isAdmin,$pwd,$comment) { $this->dataSet[] = new dataItem($id,$login,$fullName,$email,$isAdmin,$pwd,$comment); } //The wrapper sort function function sortDataSet($s) { //Sort by the given parameter switch($s) { case "fullName": //Note use of array to reference member method of this object in callback uasort($this->dataSet,array($this,"cmpName")); break; case "login": uasort($this->dataSet,array($this,"cmpX")); break; case "id": uasort($this->dataSet,array($this,"cmpY")); break; case "added": default: //Re-sort array by original keys ksort($this->dataSet); } } //Callback function for sorting by name //$a and $b are dataItem objects function cmpName($a,$b) { //Use sort() for simple alphabetical comparison //Convert to lowercase to ensure consistent behaviour $sortable = array(strtolower($a->fullName),strtolower($b->fullName)); $sorted = $sortable; sort($sorted); //If the names have switched position, return -1. Otherwise, return 1. return ($sorted[0] == $sortable[0]) ? -1 : 1; } //Callback function for sorting by x //$a and $b are dataItem objects function cmpX($a,$b) { //Use sort() for simple alphabetical comparison //Convert to lowercase to ensure consistent behaviour $sortable = array(strtolower($a->x),strtolower($b->x)); $sorted = $sortable; sort($sorted); //If the names have switched position, return -1. Otherwise, return 1. return ($sorted[0] == $sortable[0]) ? -1 : 1; } //Callback function for sorting by y //$a and $b are dataItem objects function cmpY($a,$b) { //If $a's y attribute >= $b's y attribute, return 1. Otherwise, return -1. return ($a->y >= $b->y) ? 1 : -1; } } ?>