Exemplo n.º 1
0
 /**
  * Returns the ID of a free bed (which can be auto-assigned)
  * Returns FALSE if there are no more free beds
  */
 public static function get_free_bed($term, $gender, $randomize = FALSE)
 {
     // Get the list of all free beds
     $beds = HMS_Bed::get_all_free_beds($term, $gender);
     // Check for db errors
     if (PEAR::isError($beds)) {
         return $beds;
     }
     // Check for no results (i.e. no empty beds), return false
     if ($beds == FALSE) {
         return FALSE;
     }
     if ($randomize) {
         // Get a random index between 0 and the max array index (size - 1)
         $random_index = mt_rand(0, sizeof($beds) - 1);
         return $beds[$random_index];
     } else {
         return $beds[0];
     }
 }