|
@ -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){ |
|
|
|
|
|
$ids = ''; |
|
|
|
|
|
$count = 0; |
|
|
|
|
|
$aids = array(); |
|
|
$aids = array(); |
|
|
foreach( $recs as $rec){ |
|
|
if( ($recs = $DB->get_records( 'game_attempts', array( 'gameid' => $gameid))) != false) |
|
|
$ids .= ','.$rec->id; |
|
|
{ |
|
|
if( ++$count > 10){ |
|
|
$ids = ''; |
|
|
$count = 0; |
|
|
$count = 0; |
|
|
|
|
|
foreach( $recs as $rec) |
|
|
|
|
|
{ |
|
|
|
|
|
$ids .= ( $ids == '' ? $rec->id : ','.$rec->id); |
|
|
|
|
|
if( ++$count > 10) |
|
|
|
|
|
{ |
|
|
$aids[] = $ids; |
|
|
$aids[] = $ids; |
|
|
|
|
|
$count = 0; |
|
|
$ids = ''; |
|
|
$ids = ''; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if( $ids != ''){ |
|
|
if( $ids != '') |
|
|
$aids[] = $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'); |
|
|
$tables = array( 'game_hangman', 'game_cross', 'game_cryptex', 'game_millionaire', 'game_bookquiz', 'game_sudoku', 'game_snakes'); |
|
|
foreach( $tables as $t){ |
|
|
foreach( $tables as $t) |
|
|
$sql = "DELETE FROM {".$t."} WHERE id IN (".substr( $ids, 1).')'; |
|
|
{ |
|
|
if (! $DB->execute( $sql)) { |
|
|
$sql = "DELETE FROM {".$t."} WHERE id IN (".$ids.')'; |
|
|
$result = false; |
|
|
if (! $DB->execute( $sql)) |
|
|
break; |
|
|
return false; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$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; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if( $result){ |
|
|
|
|
|
$tables = array( 'game_export_javame', 'game_export_html', 'game'); |
|
|
$tables = array( 'game_export_javame', 'game_export_html', 'game'); |
|
|
if (!$DB->delete_records( 'game', array( 'id' => $gameid))) { |
|
|
foreach( $tables as $table) |
|
|
$result = false; |
|
|
{ |
|
|
} |
|
|
if (!$DB->delete_records( $table, array( 'id' => $gameid))) |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $result; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|