Exemplo n.º 1
0
 function destroy($id = false)
 {
     global $database;
     if ($id == false) {
         $id = $this->id;
     }
     jTipsLogger::_log("Delete " . $this->_tbl . " record with id = '{$id}'");
     //delete all games and tips where this team was involved
     //first, the games
     $query = "SELECT id FROM #__jtips_games WHERE home_id = " . $database->Quote($id) . " OR away_id = " . $database->Quote($id);
     jTipsLogger::_log('loading games to delete');
     $database->setQuery($query);
     $ids = $database->loadResultArray();
     if (!empty($ids)) {
         $jGame = new jGame($database);
         foreach ($ids as $id) {
             $jGame->destroy($id);
         }
     }
     //now the tips
     $query = "SELECT id FROM #__jtips_tips WHERE game_id IN ('" . implode("', '", $ids) . "')";
     jTipsLogger::_log('loading tips to delete');
     $database->setQuery($query);
     $ids = $database->loadResultArray();
     if (!empty($ids)) {
         $jTip = new jTip($database);
         foreach ($ids as $id) {
             $jTip->destroy($id);
         }
     }
     return $this->delete($id);
 }