|
@ -189,60 +189,53 @@ function game_before_add_or_update(&$game) { |
|
|
function game_delete_instance($gameid) { |
|
|
function game_delete_instance($gameid) { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
$result = true; |
|
|
|
|
|
|
|
|
|
|
|
# Delete any dependent records here # |
|
|
# Delete any dependent records here # |
|
|
|
|
|
|
|
|
if( ($recs = $DB->get_records( 'game_attempts', array( 'gameid' => $gameid))) != false){ |
|
|
$aids = array(); |
|
|
$ids = ''; |
|
|
if( ($recs = $DB->get_records( 'game_attempts', array( 'gameid' => $gameid))) != false) |
|
|
$count = 0; |
|
|
{ |
|
|
$aids = array(); |
|
|
$ids = ''; |
|
|
foreach( $recs as $rec){ |
|
|
$count = 0; |
|
|
$ids .= ','.$rec->id; |
|
|
foreach( $recs as $rec) |
|
|
if( ++$count > 10){ |
|
|
{ |
|
|
$count = 0; |
|
|
$ids .= ( $ids == '' ? $rec->id : ','.$rec->id); |
|
|
$aids[] = $ids; |
|
|
if( ++$count > 10) |
|
|
$ids = ''; |
|
|
{ |
|
|
} |
|
|
$aids[] = $ids; |
|
|
} |
|
|
$count = 0; |
|
|
if( $ids != ''){ |
|
|
$ids = ''; |
|
|
$aids[] = $ids; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if( $ids != '') |
|
|
|
|
|
$aids[] = $ids; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
foreach( $aids as $ids){ |
|
|
foreach( $aids as $ids) |
|
|
if( $result == false){ |
|
|
{ |
|
|
break; |
|
|
$tables = array( 'game_hangman', 'game_cross', 'game_cryptex', 'game_millionaire', 'game_bookquiz', 'game_sudoku', 'game_snakes'); |
|
|
} |
|
|
foreach( $tables as $t) |
|
|
$tables = array( 'game_hangman', 'game_cross', 'game_cryptex', 'game_millionaire', 'game_bookquiz', 'game_sudoku', 'game_snakes'); |
|
|
{ |
|
|
foreach( $tables as $t){ |
|
|
$sql = "DELETE FROM {".$t."} WHERE id IN (".$ids.')'; |
|
|
$sql = "DELETE FROM {".$t."} WHERE id IN (".substr( $ids, 1).')'; |
|
|
if (! $DB->execute( $sql)) |
|
|
if (! $DB->execute( $sql)) { |
|
|
return false; |
|
|
$result = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$tables = array( 'game_attempts', 'game_grades', 'game_bookquiz_questions', 'game_queries', 'game_repetitions'); |
|
|
$tables = array( 'game_attempts', 'game_grades', 'game_bookquiz_questions', 'game_queries', 'game_repetitions'); |
|
|
foreach( $tables as $t){ |
|
|
foreach( $tables as $t) |
|
|
if( $result == false){ |
|
|
{ |
|
|
break; |
|
|
if (! $DB->delete_records( $t, array( 'gameid' => $gameid))) |
|
|
} |
|
|
return false; |
|
|
|
|
|
} |
|
|
if (! $DB->delete_records( $t, array( 'gameid' => $gameid))) { |
|
|
|
|
|
$result = false; |
|
|
$tables = array( 'game_export_javame', 'game_export_html', 'game'); |
|
|
} |
|
|
foreach( $tables as $table) |
|
|
} |
|
|
{ |
|
|
|
|
|
if (!$DB->delete_records( $table, array( 'id' => $gameid))) |
|
|
if( $result){ |
|
|
return false; |
|
|
$tables = array( 'game_export_javame', 'game_export_html', 'game'); |
|
|
|
|
|
if (!$DB->delete_records( 'game', array( 'id' => $gameid))) { |
|
|
|
|
|
$result = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $result; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|